diff --git a/.github/workflows/ahk-lint-format-compile.yml b/.github/workflows/ahk-lint-format-compile.yml index 95e17c5..548abeb 100644 --- a/.github/workflows/ahk-lint-format-compile.yml +++ b/.github/workflows/ahk-lint-format-compile.yml @@ -19,11 +19,20 @@ jobs: - uses: actions/checkout@v6 - name: Install AutoHotkey v1.1 (Portable) - run: choco install autohotkey.portable --version=1.1.37.02 -y + run: choco install autohotkey.portable -y shell: pwsh - - name: Install AutoHotkey v2 - run: choco install autohotkey --version=2.0.19 -y + run: choco install autohotkey -y + shell: pwsh + - name: Install Ahk2Exe + run: | + $url = "https://github.com/AutoHotkey/Ahk2Exe/releases/latest/download/Ahk2Exe1.zip" + $dest = "C:\Ahk2Exe" + New-Item -ItemType Directory -Force -Path $dest | Out-Null + Invoke-WebRequest -Uri $url -OutFile "$dest\Ahk2Exe.zip" + Expand-Archive "$dest\Ahk2Exe.zip" -DestinationPath $dest -Force + Remove-Item "$dest\Ahk2Exe.zip" + Write-Host "Ahk2Exe installed to $dest" shell: pwsh - name: Verify Installations @@ -37,11 +46,10 @@ jobs: Write-Host "Installed AHK v1: $((Get-Item $ahkV1).VersionInfo.FileVersion)" Write-Host "Installed AHK v2: $(& $ahkV2 --version)" shell: pwsh - - name: Syntax Check & Format Validation run: | - $compilerV1 = "C:\ProgramData\chocolatey\lib\autohotkey.portable\tools\Compiler\Ahk2Exe.exe" - $compilerV2 = "$env:ProgramFiles\AutoHotkey\Compiler\Ahk2Exe.exe" + $compilerExe = "C:\Ahk2Exe\Ahk2Exe.exe" + $tempDir = New-Item -Type Directory -Force "$env:TEMP\ahk-$(Get-Random)" $syntaxErrors = @() $formatIssues = @() @@ -66,7 +74,8 @@ jobs: $isV2 = $true } - $compiler = if ($isV2) { $compilerV2; $v2Count++ } else { $compilerV1; $v1Count++ } + if ($isV2) { $v2Count++ } else { $v1Count++ } + $compiler = $compilerExe $version = if ($isV2) { "v2" } else { "v1" } # Syntax check diff --git a/Other/AutoStartManager.ahk b/Other/AutoStartManager.ahk index e2145ec..56e77a8 100644 --- a/Other/AutoStartManager.ahk +++ b/Other/AutoStartManager.ahk @@ -35,12 +35,44 @@ if (!FileExist(configFile)) { ; Read configuration try { - exeName := IniRead(configFile, emulatorName, "exe") - key := IniRead(configFile, emulatorName, "key", "F11") - maximize := IniRead(configFile, emulatorName, "maximize", "true") = "true" - delay := Integer(IniRead(configFile, emulatorName, "delay", "0")) - activate := IniRead(configFile, emulatorName, "activate", "false") = "true" - special := IniRead(configFile, emulatorName, "special", "none") + ; Optimization: Read the entire section once to reduce disk I/O + sectionContent := IniRead(configFile, emulatorName) + if (sectionContent = "") { + throw Error("Section '" . emulatorName . "' not found in config file or is empty") + } + config := Map() + config.CaseSense := "Off" ; Ensure case-insensitive lookups (INI standard) + Loop Parse, sectionContent, "`n", "`r" { + if (p := InStr(A_LoopField, "=")) { + k := Trim(SubStr(A_LoopField, 1, p-1)) + v := Trim(SubStr(A_LoopField, p+1)) + config[k] := v + } + } + + if !config.Has("exe") { + if (config.Count = 0) + throw Error("Section '" . emulatorName . "' is empty or missing required key 'exe'") + else + throw Error("Key 'exe' not found in section '" . emulatorName . "'") + } + + exeName := config["exe"] + key := config.Has("key") ? config["key"] : "F11" + maximize := (config.Has("maximize") ? config["maximize"] : "true") = "true" + if config.Has("delay") { + delayRaw := config["delay"] + if RegExMatch(delayRaw, "^[+-]?\d+$") { + delay := Integer(delayRaw) + } else { + throw Error("Invalid delay value '" . delayRaw . "' in section '" . emulatorName . "': must be an integer number of milliseconds") + } + } else { + delay := 0 + } + activate := (config.Has("activate") ? config["activate"] : "false") = "true" + special := config.Has("special") ? config["special"] : "none" + } catch Error as err { MsgBox("Error reading config for " . emulatorName . ":`n" . err.Message) ExitApp()