Skip to content

Commit

Permalink
Rationalise detection of major version
Browse files Browse the repository at this point in the history
  • Loading branch information
TAC109 committed Feb 11, 2024
1 parent 5317916 commit ff6de2e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
12 changes: 6 additions & 6 deletions Compiler.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

AhkCompile(AhkFile, ExeFile, ResourceID, CustomIcon, BinFile, UseMPRESS, fileCP)
{
global ExeFileTmp, ExeFileG, SilentMode
global ExeFileTmp, ExeFileG, SilentMode, MjrVn

tempWD := new CTempWD(AhkWorkingDir) ; Original Ahk2Exe starting directory
SplitPath AhkFile,, Ahk_Dir,, Ahk_Name
Expand Down Expand Up @@ -48,13 +48,13 @@ AhkCompile(AhkFile, ExeFile, ResourceID, CustomIcon, BinFile, UseMPRESS, fileCP)
Util_Error("Ahk2Exe must be compiled with a Unicode 32-bit .exe Base file."
, 0x2)

MjrVn := SubStr(BinType.Version,1,1)
DerefIncludeVars.A_AhkVersion := BinType.Version
DerefIncludeVars.A_PtrSize := BinType.PtrSize
DerefIncludeVars.A_IsUnicode := BinType.IsUnicode
DerefIncludeVars.A_BasePath := BinFile

global AhkPath := UseAhkPath ; = any /ahk parameter

; V2 alphas and betas expected to match as breaking changes between versions
if (AhkPath = "") ; Later v2 versions will have base as .exe, so should match
if !(AhkPath := ExeFiles[BinType.Version BinType.Summary]) ; .exe vs base?
Expand Down Expand Up @@ -120,7 +120,7 @@ AhkCompile(AhkFile, ExeFile, ResourceID, CustomIcon, BinFile, UseMPRESS, fileCP)
Reload := 1
} } }
if Reload
run "%ExeFileG%", %ExeFileG%\..
Run "%ExeFileG%", %ExeFileG%\..
Util_HideHourglass()
Util_Status("")
return ExeFileG
Expand All @@ -129,10 +129,10 @@ AhkCompile(AhkFile, ExeFile, ResourceID, CustomIcon, BinFile, UseMPRESS, fileCP)

BundleAhkScript(ExeFile, ResourceID, AhkFile, UseMPRESS, IcoFile
, fileCP, BinFile, VerInfo)
{
{ global MjrVn
if fileCP is space
if SubStr(DerefIncludeVars.A_AhkVersion,1,1) = 2
fileCP := "UTF-8" ; Default for v2 is UTF-8
if (MjrVn != 1)
fileCP := "UTF-8" ; Default for v2+ is UTF-8
else fileCP := A_FileEncoding

try FileEncoding, %fileCP%
Expand Down
13 changes: 6 additions & 7 deletions ScriptParser.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
;
PreprocessScript(ByRef ScriptText, AhkScript, Directives, PriorLines
, FileList := "", FirstScriptDir := "", Options := "", iOption := 0)
{ global DirDoneG, PriorLine
{ global DirDoneG, PriorLine, MjrVn
SplitPath, AhkScript, ScriptName, ScriptDir
if !IsObject(FileList)
{
Expand All @@ -18,7 +18,7 @@ PreprocessScript(ByRef ScriptText, AhkScript, Directives, PriorLines
oldLineFile := DerefIncludeVars.A_LineFile
DerefIncludeVars.A_LineFile := AhkScript

if SubStr(DerefIncludeVars.A_AhkVersion,1,1)=2 ; Handle v2 default folder
if (MjrVn != 1) ; Handle v2+ default folder
{ OldWorkingDirv2 := A_WorkingDir
SetWorkingDir %ScriptDir%
}
Expand Down Expand Up @@ -54,7 +54,7 @@ PreprocessScript(ByRef ScriptText, AhkScript, Directives, PriorLines
else if StrStartsWith(tline, "/*")
{ if StrStartsWith(tline, "/*@Ahk2Exe-Keep")
cmtBlock := 2
else if !(SubStr(DerefIncludeVars.A_AhkVersion,1,1)=2 &&tline~="\*/$")
else if !(MjrVn != 1 && tline ~= "\*/$")
cmtBlock := 1
continue
} else if (cmtBlock = 2 && StrStartsWith(tline, "*/"))
Expand Down Expand Up @@ -144,8 +144,7 @@ PreprocessScript(ByRef ScriptText, AhkScript, Directives, PriorLines
Util_Error("Error: #Delimiter is not supported.", 0x22)
else
ScriptText .= (contSection ? A_LoopReadLine : tline) "`n"
} else if (tline~="^\*/"
|| SubStr(DerefIncludeVars.A_AhkVersion,1,1)=2 && tline~="\*/$")
} else if (tline~="^\*/" || MjrVn != 1 && tline~="\*/$")
cmtBlock := 0 ; End block comment
} ; End file-read loop
Loop, % !!IsFirstScript ; Like "if IsFirstScript" but can "break" from block
Expand Down Expand Up @@ -191,7 +190,7 @@ PreprocessScript(ByRef ScriptText, AhkScript, Directives, PriorLines
IfExist, %ilib%
{ FileGetSize wk, %ilib%
if wk > 3
{ if SubStr(DerefIncludeVars.A_AhkVersion,1,1)=1
{ if (MjrVn != 1)
{ Loop 4 ; v1 - Generate random label prefix
{ Random wk, 97, 122
ScriptText .= Chr(wk) ; Prevent possible '#Warn Unreachable'
Expand All @@ -210,7 +209,7 @@ PreprocessScript(ByRef ScriptText, AhkScript, Directives, PriorLines
if OldWorkingDir
SetWorkingDir, %OldWorkingDir%

if SubStr(DerefIncludeVars.A_AhkVersion,1,1)=2 ; Handle v2 default folder
if (MjrVn != 1) ; Handle v2+ default folder
SetWorkingDir %OldWorkingDirv2%
}
; --------------------------- End PreprocessScript -----------------------------
Expand Down

0 comments on commit ff6de2e

Please sign in to comment.