Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add /silent #77

Merged
merged 25 commits into from Aug 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
cc45bbe
Add `/headless` and `/ForceReload` switches
SaifAqqad Jun 4, 2021
542b737
Fix Bad params error strings
SaifAqqad Jun 4, 2021
51b4f10
Fix blank output file if `/out` is not passed
SaifAqqad Jun 4, 2021
cdd4267
Rename `/headless` to `/silent`
SaifAqqad Jun 4, 2021
bf2b7d8
Fix: not exiting with exitcode value
SaifAqqad Jun 4, 2021
9b1bc39
Add `/verbose` to output util_status to stdout
SaifAqqad Jun 4, 2021
1234a26
Output util_info to stdout with CLIMode
SaifAqqad Jun 4, 2021
35d291b
Add descriptions for CLI params
SaifAqqad Jun 4, 2021
90dfb72
Revert "Add descriptions for CLI params"
SaifAqqad Jun 4, 2021
fe2d252
Remove ConsoleApp directive
SaifAqqad Jun 5, 2021
719eb71
Use `global CLIMode` instead of Assume-global
SaifAqqad Jun 6, 2021
7fe2086
Remove extra `Error: ` from `Util_Error` Strings
SaifAqqad Jun 10, 2021
fda1be1
Fix `Util_info` is dependant on CLIMode
SaifAqqad Jun 10, 2021
2ca9500
Use `global Verbose` instead of Assume-global
SaifAqqad Jun 10, 2021
2d077ba
Only output to stderr if it exists
SaifAqqad Jun 14, 2021
297d35b
Merge branch 'master' into master
SaifAqqad Jul 14, 2021
6441d8e
Merge branch 'master' into master
SaifAqqad Jul 29, 2021
8f30cce
Merge branch 'master' into master
SaifAqqad Aug 7, 2021
2eef6ce
Merge branch 'master' of https://github.com/AutoHotkey/Ahk2Exe into m…
SaifAqqad Aug 25, 2021
4a52160
Merge branch 'master' into master
SaifAqqad Aug 25, 2021
7266d18
Restore original error messages
SaifAqqad Aug 25, 2021
9b2fa25
Remove /ForceReload
SaifAqqad Aug 25, 2021
00184f3
Remove unnecessary % signs
SaifAqqad Aug 25, 2021
54d01a2
Merge remote-tracking branch 'upstream/master'
SaifAqqad Aug 26, 2021
ddf79e1
Replace /verbose with optional /silent parameter
SaifAqqad Aug 26, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
69 changes: 52 additions & 17 deletions Ahk2Exe.ahk
Expand Up @@ -306,7 +306,10 @@ ParseCmdLine:
if !A_Args.MaxIndex()
return
Error_ForceExit := true
CLIMode := true ; Set default - may be overridden.

; Set defaults - may be overridden.
CLIMode := true
SilentMode := 0 ; 0=off, 1=on, 2=verbose
p := A_Args.Clone() ; Don't deplete A_Args here as needed in 'Restart:'

while p.MaxIndex()
Expand All @@ -329,13 +332,17 @@ while p.MaxIndex()
if (AhkFile = "" && CLIMode)
BadParams("Error: No input file specified.")

if (SilentMode && !CLIMode){
BadParams("Error: /silent requires CLI mode.")
}

if BinFile =
BinFile := LastBinFile
return

BadParams(Message, ErrorCode=0x3)
{ global Error_ForceExit := true
Util_Error(Message, ErrorCode,, "Command Line Parameters:`n`n" A_ScriptName "`n`t /in infile.ahk`n`t [/out outfile.exe]`n`t [/icon iconfile.ico]`n`t [/base AutoHotkeySC.bin]`n`t [/ResourceID #1]`n`t [/compress 0 (none), 1 (MPRESS), or 2 (UPX)]`n`t [/cp codepage]`n`t [/ahk path\name]`n`t [/gui]")
Util_Error(Message, ErrorCode,, "Command Line Parameters:`n`n" A_ScriptName "`n`t /in infile.ahk`n`t [/out outfile.exe]`n`t [/icon iconfile.ico]`n`t [/base AutoHotkeySC.bin]`n`t [/ResourceID #1]`n`t [/compress 0 (none), 1 (MPRESS), or 2 (UPX)]`n`t [/cp codepage]`n`t [/ahk path\name]`n`t [/gui]`n`t [/silent [verbose]]")
}

CmdArg_Gui() {
Expand Down Expand Up @@ -397,6 +404,14 @@ CmdArg_CP(p2) { ; for example: '/cp 1252' or '/cp UTF-8'
ScriptFileCP := p2
}

CmdArg_Silent(){
global
if p[1] = "verbose"
{ SilentMode := 2
p.RemoveAt(1)
} else SilentMode := 1
}

CmdArg_Pass() {
BadParams("Error: Password protection is not supported.", 0x24)
}
Expand Down Expand Up @@ -699,12 +714,17 @@ Special thanks:
return

Util_Status(s)
{ SB_SetText(s)
{
global SilentMode
if SilentMode = 2 ; verbose
if s not in ,Ready
FileAppend, Ahk2Exe Status: %s%`n, *
SB_SetText(s)
}

Util_Error(txt, exitcode, extra := "", extra1 := "")
{
global CLIMode, Error_ForceExit, ExeFileTmp
global CLIMode, Error_ForceExit, ExeFileTmp, SilentMode

if extra
txt .= "`n`nSpecifically:`n" extra
Expand All @@ -713,32 +733,47 @@ Util_Error(txt, exitcode, extra := "", extra1 := "")
txt .= "`n`n" extra1

Util_HideHourglass()
if exitcode
MsgBox, 16, Ahk2Exe Error, % txt
else {
MsgBox, 49, Ahk2Exe Warning, % txt
. (extra||extra1 ? "" : "`n`nPress 'OK' to continue, or 'Cancel' to abandon.")
IfMsgBox Cancel
exitcode := 2
if SilentMode {
txt := "Ahk2Exe " txt "`n"
try FileAppend, %txt%, **
catch
FileAppend, %txt%, *
} else {
if exitcode
MsgBox, 16, Ahk2Exe Error, % txt
else {
MsgBox, 49, Ahk2Exe Warning, % txt
. (extra||extra1 ? "" : "`n`nPress 'OK' to continue, or 'Cancel' to abandon.")
IfMsgBox Cancel
exitcode := 2
}
}
if (exitcode && ExeFileTmp && FileExist(ExeFileTmp))
{ FileDelete, %ExeFileTmp%
ExeFileTmp =
}

if CLIMode && exitcode
FileAppend, Failed to compile: %ExeFile%`n, *
if CLIMode && exitcode{
try FileAppend, Failed to compile: %ExeFile%`n, **
catch
FileAppend, Failed to compile: %ExeFile%`n, *
}
Util_Status("Ready")

if exitcode
if !Error_ForceExit
Exit, exitcode
else ExitApp, exitcode
if Error_ForceExit || SilentMode
ExitApp, exitcode
else Exit, exitcode
Util_DisplayHourglass()
}

Util_Info(txt)
{ MsgBox, 64, Ahk2Exe, % txt
{
global SilentMode
if SilentMode
FileAppend, Ahk2Exe Info: %txt%`n, *
else
MsgBox, 64, Ahk2Exe, % txt
}

Util_DisplayHourglass() ; Change IDC_ARROW (32512) to IDC_APPSTARTING (32650)
Expand Down
38 changes: 22 additions & 16 deletions Compiler.ahk
Expand Up @@ -7,7 +7,7 @@

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

SetWorkingDir %AhkWorkingDir%
SplitPath AhkFile,, Ahk_Dir,, Ahk_Name
Expand Down Expand Up @@ -82,21 +82,27 @@ global StdLibDir := Util_GetFullPath(AhkPath "\..\Lib")
if !WinExist("ahk_exe " ExeFileG)
Util_Error("Error: Could not move final compiled binary file to "
. "destination. (C1)", 0x45, """" ExeFileG """")
else
{ SetTimer Buttons, 50
wk := """" RegExReplace(ExeFileG, "^.+\\") """"
MsgBox 51,Ahk2Exe Query,% "Warning: " wk " is still running, "
. "and needs to be unloaded to allow replacement with this new version."
. "`n`n Press the appropriate button to continue."
. " ('Reload' unloads and reloads the new " wk " without any parameters.)"
IfMsgBox Cancel
Util_Error("Error: Could not move final compiled binary file to "
. "destination. (C2)", 0x45, """" ExeFileG """")
WinClose ahk_exe %ExeFileG%
WinWaitClose ahk_exe %ExeFileG%,,1
IfMsgBox No
Reload := 1
} }
else
{ wk := """" RegExReplace(ExeFileG, "^.+\\") """"
if SilentMode
Util_Error(wk " is still running, "
. "and needs to be unloaded to allow replacement with this new version.", 0x45)
else
{ SetTimer Buttons, 50
MsgBox 51,Ahk2Exe Query,% "Warning: " wk " is still running, "
. "and needs to be unloaded to allow replacement with this new version."
. "`n`n Press the appropriate button to continue."
. " ('Reload' unloads and reloads the new " wk " without any parameters.)"
IfMsgBox Cancel
Util_Error("Error: Could not move final compiled binary file to "
. "destination. (C2)", 0x45, """" ExeFileG """")
WinClose ahk_exe %ExeFileG%
WinWaitClose ahk_exe %ExeFileG%,,1
IfMsgBox No
Reload := 1
}
}
}
if Reload
run "%ExeFileG%", %ExeFileG%\..
Util_HideHourglass()
Expand Down