@@ -333,16 +333,15 @@ async function compileScript(editor: TextEditor) {
333333 let cmd = '' , cmdop = workspace . getConfiguration ( 'AutoHotkey2' ) . CompilerCMD as string ;
334334 const { document } = editor ;
335335 const ws = workspace . getWorkspaceFolder ( document . uri ) ?. uri . fsPath ?? '' ;
336- const compilePath = findFile ( [ 'Compiler\\Ahk2Exe.exe' , '..\\Compiler\\Ahk2Exe.exe' ] , ws ) ;
337- const executePath = resolvePath ( ahkpath_cur , ws ) ;
338- if ( ! compilePath ) {
339- window . showErrorMessage ( localize ( 'ahk2.filenotexist' , 'Ahk2Exe.exe' ) ) ;
340- return ;
341- }
342- if ( ! executePath ) {
343- const s = ahkpath_cur || 'AutoHotkey.exe' ;
344- window . showErrorMessage ( localize ( 'ahk2.filenotexist' , s ) ) ;
345- return ;
336+ cmdop = cmdop . replace ( / ( [ ' " ] ? ) \$ \{ e x e c P a t h \} \1/ gi, '\0' ) ;
337+ if ( cmdop . includes ( '\0' ) ) {
338+ const executePath = resolvePath ( ahkpath_cur , ws ) ;
339+ if ( ! executePath ) {
340+ const s = ahkpath_cur || 'AutoHotkey.exe' ;
341+ window . showErrorMessage ( localize ( 'ahk2.filenotexist' , s ) ) ;
342+ return ;
343+ }
344+ cmdop = cmdop . replaceAll ( '\0' , `"${ executePath } "` ) ;
346345 }
347346 if ( document . isUntitled || document . uri . scheme !== 'file' ) {
348347 window . showErrorMessage ( localize ( 'ahk2.savebeforecompilation' ) ) ;
@@ -352,12 +351,16 @@ async function compileScript(editor: TextEditor) {
352351 const currentPath = document . uri . fsPath ;
353352 const exePath = currentPath . replace ( / \. \w + $ / , '.exe' ) ;
354353 const prev_mtime = getFileMtime ( exePath ) ;
355- cmdop = cmdop . replace ( / ( [ ' " ] ? ) \$ \{ e x e c P a t h \} \1/ gi, `"${ executePath } "` ) ;
356354 if ( cmdop . match ( / \b a h k 2 e x e \w * \. e x e / i) ) {
357355 cmd = cmdop + ' /in ' + currentPath ;
358356 if ( ! cmd . toLowerCase ( ) . includes ( ' /out ' ) )
359357 cmd += '/out "' + exePath + '"' ;
360358 } else {
359+ const compilePath = findFile ( [ 'Compiler\\Ahk2Exe.exe' , '..\\Compiler\\Ahk2Exe.exe' ] , ws ) ;
360+ if ( ! compilePath ) {
361+ window . showErrorMessage ( localize ( 'ahk2.filenotexist' , 'Ahk2Exe.exe' ) ) ;
362+ return ;
363+ }
361364 cmd = `"${ compilePath } " ${ cmdop } /in "${ currentPath } " ` ;
362365 if ( ! cmdop . toLowerCase ( ) . includes ( ' /out ' ) )
363366 cmd += '/out "' + exePath + '"' ;
0 commit comments