Skip to content

Commit ff6de2e

Browse files
committed
Rationalise detection of major version
1 parent 5317916 commit ff6de2e

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

Compiler.ahk

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
AhkCompile(AhkFile, ExeFile, ResourceID, CustomIcon, BinFile, UseMPRESS, fileCP)
99
{
10-
global ExeFileTmp, ExeFileG, SilentMode
10+
global ExeFileTmp, ExeFileG, SilentMode, MjrVn
1111

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

51+
MjrVn := SubStr(BinType.Version,1,1)
5152
DerefIncludeVars.A_AhkVersion := BinType.Version
5253
DerefIncludeVars.A_PtrSize := BinType.PtrSize
5354
DerefIncludeVars.A_IsUnicode := BinType.IsUnicode
5455
DerefIncludeVars.A_BasePath := BinFile
5556

5657
global AhkPath := UseAhkPath ; = any /ahk parameter
57-
5858
; V2 alphas and betas expected to match as breaking changes between versions
5959
if (AhkPath = "") ; Later v2 versions will have base as .exe, so should match
6060
if !(AhkPath := ExeFiles[BinType.Version BinType.Summary]) ; .exe vs base?
@@ -120,7 +120,7 @@ AhkCompile(AhkFile, ExeFile, ResourceID, CustomIcon, BinFile, UseMPRESS, fileCP)
120120
Reload := 1
121121
} } }
122122
if Reload
123-
run "%ExeFileG%", %ExeFileG%\..
123+
Run "%ExeFileG%", %ExeFileG%\..
124124
Util_HideHourglass()
125125
Util_Status("")
126126
return ExeFileG
@@ -129,10 +129,10 @@ AhkCompile(AhkFile, ExeFile, ResourceID, CustomIcon, BinFile, UseMPRESS, fileCP)
129129

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

138138
try FileEncoding, %fileCP%

ScriptParser.ahk

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
;
44
PreprocessScript(ByRef ScriptText, AhkScript, Directives, PriorLines
55
, FileList := "", FirstScriptDir := "", Options := "", iOption := 0)
6-
{ global DirDoneG, PriorLine
6+
{ global DirDoneG, PriorLine, MjrVn
77
SplitPath, AhkScript, ScriptName, ScriptDir
88
if !IsObject(FileList)
99
{
@@ -18,7 +18,7 @@ PreprocessScript(ByRef ScriptText, AhkScript, Directives, PriorLines
1818
oldLineFile := DerefIncludeVars.A_LineFile
1919
DerefIncludeVars.A_LineFile := AhkScript
2020

21-
if SubStr(DerefIncludeVars.A_AhkVersion,1,1)=2 ; Handle v2 default folder
21+
if (MjrVn != 1) ; Handle v2+ default folder
2222
{ OldWorkingDirv2 := A_WorkingDir
2323
SetWorkingDir %ScriptDir%
2424
}
@@ -54,7 +54,7 @@ PreprocessScript(ByRef ScriptText, AhkScript, Directives, PriorLines
5454
else if StrStartsWith(tline, "/*")
5555
{ if StrStartsWith(tline, "/*@Ahk2Exe-Keep")
5656
cmtBlock := 2
57-
else if !(SubStr(DerefIncludeVars.A_AhkVersion,1,1)=2 &&tline~="\*/$")
57+
else if !(MjrVn != 1 && tline ~= "\*/$")
5858
cmtBlock := 1
5959
continue
6060
} else if (cmtBlock = 2 && StrStartsWith(tline, "*/"))
@@ -144,8 +144,7 @@ PreprocessScript(ByRef ScriptText, AhkScript, Directives, PriorLines
144144
Util_Error("Error: #Delimiter is not supported.", 0x22)
145145
else
146146
ScriptText .= (contSection ? A_LoopReadLine : tline) "`n"
147-
} else if (tline~="^\*/"
148-
|| SubStr(DerefIncludeVars.A_AhkVersion,1,1)=2 && tline~="\*/$")
147+
} else if (tline~="^\*/" || MjrVn != 1 && tline~="\*/$")
149148
cmtBlock := 0 ; End block comment
150149
} ; End file-read loop
151150
Loop, % !!IsFirstScript ; Like "if IsFirstScript" but can "break" from block
@@ -191,7 +190,7 @@ PreprocessScript(ByRef ScriptText, AhkScript, Directives, PriorLines
191190
IfExist, %ilib%
192191
{ FileGetSize wk, %ilib%
193192
if wk > 3
194-
{ if SubStr(DerefIncludeVars.A_AhkVersion,1,1)=1
193+
{ if (MjrVn != 1)
195194
{ Loop 4 ; v1 - Generate random label prefix
196195
{ Random wk, 97, 122
197196
ScriptText .= Chr(wk) ; Prevent possible '#Warn Unreachable'
@@ -210,7 +209,7 @@ PreprocessScript(ByRef ScriptText, AhkScript, Directives, PriorLines
210209
if OldWorkingDir
211210
SetWorkingDir, %OldWorkingDir%
212211

213-
if SubStr(DerefIncludeVars.A_AhkVersion,1,1)=2 ; Handle v2 default folder
212+
if (MjrVn != 1) ; Handle v2+ default folder
214213
SetWorkingDir %OldWorkingDirv2%
215214
}
216215
; --------------------------- End PreprocessScript -----------------------------

0 commit comments

Comments
 (0)