-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: Add launcher written in AHK v2. (#191)
Need to add CI to compile ahk to exe and include in build.
- Loading branch information
Showing
10 changed files
with
546 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
:: convenience for building locally. ci will build this otherwise. | ||
"C:\Program Files\AutoHotkey\Compiler\Ahk2Exe.exe" /in "dqxclarity.ahk" /base "C:\Program Files\AutoHotkey\v2\AutoHotkey64.exe" /icon "img/rosie.ico" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,289 @@ | ||
#Requires AutoHotkey v2.0 | ||
#SingleInstance force | ||
#Include <json> | ||
#Include <image> | ||
#Include <md5> | ||
|
||
/* read ini */ | ||
ini := {} | ||
ini.enabledeepl := IniRead(".\user_settings.ini", "translation", "enabledeepltranslate", "False") | ||
ini.deeplkey := IniRead(".\user_settings.ini", "translation", "deepltranslatekey", "") | ||
ini.enablegoogletranslate := IniRead(".\user_settings.ini", "translation", "enablegoogletranslate", "False") | ||
ini.googletranslatekey := IniRead(".\user_settings.ini", "translation", "googletranslatekey", "") | ||
ini.communitylogging := IniRead(".\user_settings.ini", "launcher", "communitylogging", "False") | ||
ini.playernames := IniRead(".\user_settings.ini", "launcher", "playernames", "False") | ||
ini.npcnames := IniRead(".\user_settings.ini", "launcher", "npcnames", "False") | ||
ini.updategamefiles := IniRead(".\user_settings.ini", "launcher", "updategamefiles", "False") | ||
ini.disableupdates := IniRead(".\user_settings.ini", "launcher", "disableupdates", "False") | ||
/* main window */ | ||
Launcher := Gui() | ||
Launcher.Opt("-MaximizeBox") | ||
Launcher.AddPicture("YP+1 w150 h-1 vImage", LoadImageFromResource("img/rosie.png")) | ||
/* configuration group */ | ||
Launcher.AddGroupBox("ys+10 w200 h120 c0B817C", "Configuration") | ||
Launcher.AddCheckBox("XP+10 YP+20 vCommunityLogging Checked" . ConvertBoolToState(ini.communitylogging), "Community Logging") | ||
Launcher.AddCheckBox("vPlayerNames Checked" . ConvertBoolToState(ini.playernames), "Player Names") | ||
Launcher.AddCheckBox("vNPCNames Checked" . ConvertBoolToState(ini.npcnames), "NPC Names") | ||
Launcher.AddCheckBox("vUpdateGameFiles Checked" . ConvertBoolToState(ini.updategamefiles), "Update Game Files") | ||
Launcher.AddCheckBox("vDisableUpdates Checked" . ConvertBoolToState(ini.disableupdates), "Disable Updates") | ||
Launcher.AddStatusBar("vStatusBar", "") | ||
/* api group */ | ||
Launcher.AddGroupBox("Section YP+30 XP-10 w200 h150 c0B817C", "API Settings") | ||
Launcher.AddCheckBox("XP+10 YP+20 vUseDeepL Checked" . ConvertBoolToState(ini.enabledeepl), "Use DeepL") | ||
Launcher.AddEdit("YP+20 W180 r1 vDeepLKey", ini.deeplkey).Opt("+Password") | ||
Launcher.AddCheckBox("XP vUseGoogleTranslate Checked" . ConvertBoolToState(ini.enablegoogletranslate), "Use Google Translate") | ||
Launcher.AddEdit("YP+20 W180 r1 vGoogleTranslateKey", ini.googletranslatekey).Opt("+Password") | ||
Launcher.AddButton("YP+30 w180 vValidateKey", "Validate Enabled Key").OnEvent("Click", ValidateKey) | ||
/* launch */ | ||
Launcher.AddButton("YP+60 XS+10 w80 h30 vRunProgram", "Run").Opt("+Default") | ||
Launcher.AddButton("x+20 vGitHub w80 h30", "GitHub").OnEvent("Click", OpenGitHub) | ||
/* tooltips */ | ||
Launcher["CommunityLogging"].ToolTip := "Enables logging of internal game files to a text file." | ||
Launcher["PlayerNames"].ToolTip := "Transliterates Japanese player names to English." | ||
Launcher["NPCNames"].ToolTip := "Translate Japanese NPC names to English." | ||
Launcher["UpdateGameFiles"].ToolTip := "Downloads/updates the modded DAT/IDX files." | ||
Launcher["DisableUpdates"].ToolTip := "Don't check for dqxclarity updates on launch." | ||
Launcher["UseDeepL"].ToolTip := "Enable DeepL as your choice of external translation." | ||
Launcher["UseGoogleTranslate"].ToolTip := "Enable Google Translate as your choice of external translation." | ||
Launcher["DeepLKey"].ToolTip := "Paste your DeepL API Key here." | ||
Launcher["GoogleTranslateKey"].ToolTip := "Paste your Google Translate API Key here." | ||
Launcher["ValidateKey"].ToolTip := "Validate that the selected API key works. Check here for status." | ||
Launcher["Run"].ToolTip := "Run the program." | ||
Launcher["GitHub"].ToolTip := "View the source code in your default browser." | ||
/* function handlers */ | ||
Launcher["CommunityLogging"].OnEvent("Click", CommunityLoggingWarning) | ||
Launcher["UseDeepL"].OnEvent("Click", CheckedDeepL) | ||
Launcher["UseGoogleTranslate"].OnEvent("Click", CheckedGoogleTranslate) | ||
Launcher["RunProgram"].OnEvent("Click", RunProgram) | ||
/* show launcher */ | ||
Launcher.Show("AutoSize Center") | ||
OnMessage(0x0200, On_WM_MOUSEMOVE) | ||
CheckedDeepL(*) { | ||
/* | ||
Behavior when the "Use DeepL" checkbox is checked. | ||
*/ | ||
Launcher["UseGoogleTranslate"].value := 0 | ||
Launcher["GoogleTranslateKey"].Opt("+Disabled") | ||
Launcher["DeepLKey"].Opt("-Disabled") | ||
} | ||
|
||
|
||
CheckedGoogleTranslate(*) { | ||
/* | ||
Behavior when the "Use Google Translate" checkbox is checked. | ||
*/ | ||
Launcher["UseDeepL"].value := 0 | ||
Launcher["DeepLKey"].Opt("+Disabled") | ||
Launcher["GoogleTranslateKey"].Opt("-Disabled") | ||
} | ||
|
||
|
||
ValidateKey(*) { | ||
/* | ||
Validates the enabled API key by reaching out to whichever | ||
API service is checked. | ||
*/ | ||
if (Launcher["UseDeepL"].value = 1) { | ||
DeepLKey := Launcher["DeepLKey"].value | ||
if (DeepLKey) { | ||
if (SubStr(DeepLKey, "-3") = ":fx") | ||
url := "https://api-free.deepl.com/v2/usage" | ||
else | ||
url := "https://api.deepl.com/v2/usage" | ||
|
||
web := ComObject('WinHttp.WinHttpRequest.5.1') | ||
web.Open("GET", url) | ||
web.SetRequestHeader("Authorization", "DeepL-Auth-Key " . DeepLKey) | ||
web.Send() | ||
web.WaitForResponse() | ||
Response := JSON.parse(web.ResponseText) | ||
|
||
try { | ||
PercentageUsed := Round(Response["character_count"] / Response["character_limit"] * 100, 2) | ||
UpdateStatusBar(Response["character_count"] . "/" . Response["character_limit"] . " characters used, or approximately " . PercentageUsed . "%.") | ||
} catch { | ||
UpdateStatusBar("Failed to validate key.") | ||
} | ||
} else { | ||
UpdateStatusBar("Enter a key before attempting to validate.") | ||
} | ||
} else if (Launcher["UseGoogleTranslate"].value = 1){ | ||
GoogleTranslateKey := Launcher["GoogleTranslateKey"].value | ||
if (GoogleTranslateKey) { | ||
url := "https://translation.googleapis.com/language/translate/v2?q=a&target=es&source=en&key=" . GoogleTranslateKey | ||
web := ComObject('WinHttp.WinHttpRequest.5.1') | ||
web.Open("GET", url) | ||
web.Send() | ||
web.WaitForResponse() | ||
Response := JSON.parse(web.ResponseText) | ||
try { | ||
if (Response["data"]["translations"]){ | ||
UpdateStatusBar("Key successfully validated.") | ||
} | ||
} catch { | ||
UpdateStatusBar(Response["error"]["message"]) | ||
} | ||
} | ||
} else { | ||
UpdateStatusBar("Enable an API service before validating.") | ||
} | ||
} | ||
|
||
|
||
UpdateStatusBar(text) { | ||
/* | ||
Updates the status bar at the bottom of the GUI. | ||
@param text Text to update the status bar. | ||
*/ | ||
Launcher["StatusBar"].SetText(text) | ||
} | ||
|
||
|
||
CommunityLoggingWarning(*) { | ||
if Launcher["CommunityLogging"].value = 1 { | ||
Result := MsgBox("You have enabled community logging.`n`nThis feature is unstable and may result in unexpected behavior while playing, up to and including crashes. Do not report issues of crashing if you have this enabled.`n`nIf you still want to enable this to help with the project, click `"Yes.`" Otherwise, click `"No.`"", "Community Logging", "YN Icon! Default2 0x1000") | ||
if (Result = "No") { | ||
Launcher["CommunityLogging"].value := 0 | ||
} | ||
} | ||
} | ||
|
||
|
||
OpenGitHub(*) { | ||
/* | ||
Opens the dqxclarity repository in the user's browser. | ||
*/ | ||
Run("https://github.com/dqx-translation-project/dqxclarity") | ||
} | ||
|
||
|
||
HttpRequest(verb, url) { | ||
/* | ||
Sends an HTTP request and returns a response. | ||
@param verb Type of request to send (GET, POST, etc.) | ||
@param url The URL to send the request to. | ||
*/ | ||
web := ComObject('WinHttp.WinHttpRequest.5.1') | ||
web.Open(verb, url) | ||
web.Send() | ||
web.WaitForResponse() | ||
return web.ReponseText | ||
} | ||
|
||
|
||
ConvertBoolToState(value) { | ||
/* | ||
Used for interpreting the values of the user_settings.ini file. | ||
@param value Value to convert to a state. | ||
*/ | ||
if (value = "True") | ||
return 1 | ||
else | ||
return 0 | ||
} | ||
|
||
|
||
ConvertStateToBool(value) { | ||
/* | ||
Used for interpreting the values of the user_settings.ini file. | ||
@param value Value to convert to a bool. | ||
*/ | ||
if (value = "1") | ||
return "True" | ||
else | ||
return "False" | ||
} | ||
|
||
|
||
On_WM_MOUSEMOVE(wParam, lParam, msg, Hwnd) { | ||
/* | ||
Updates the status bar at the bottom of the GUI | ||
based on what control the user has their mouse | ||
hovered over. | ||
*/ | ||
static PrevHwnd := 0 | ||
if (Hwnd != PrevHwnd) | ||
{ | ||
CurrControl := GuiCtrlFromHwnd(Hwnd) | ||
if CurrControl | ||
{ | ||
if !CurrControl.HasProp("ToolTip") | ||
return | ||
UpdateStatusBar(CurrControl.ToolTip) | ||
} | ||
PrevHwnd := Hwnd | ||
} | ||
} | ||
|
||
|
||
FakeFileInstall(*) { | ||
/* | ||
This is necessary to exist during compile. This tells Ahk2exe to | ||
include the file during compilation, but since we never call the | ||
function, it won't extract the image | ||
*/ | ||
FileInstall("img/rosie.png", "*") | ||
} | ||
|
||
|
||
SaveToIni(*) { | ||
/* | ||
Saves all of the user settings to user_settings.ini. | ||
*/ | ||
IniWrite(ConvertStateToBool(Launcher["CommunityLogging"].value), ".\user_settings.ini", "launcher", "communitylogging") | ||
IniWrite(ConvertStateToBool(Launcher["PlayerNames"].value), ".\user_settings.ini", "launcher", "playernames") | ||
IniWrite(ConvertStateToBool(Launcher["NPCNames"].value), ".\user_settings.ini", "launcher", "npcnames") | ||
IniWrite(ConvertStateToBool(Launcher["UpdateGameFiles"].value), ".\user_settings.ini", "launcher", "updategamefiles") | ||
IniWrite(ConvertStateToBool(Launcher["DisableUpdates"].value), ".\user_settings.ini", "launcher", "disableupdates") | ||
IniWrite(ConvertStateToBool(Launcher["UseDeepL"].value), ".\user_settings.ini", "translation", "enabledeepltranslate") | ||
IniWrite(Launcher["DeepLKey"].value, ".\user_settings.ini", "translation", "deepltranslatekey") | ||
IniWrite(ConvertStateToBool(Launcher["UseGoogleTranslate"].value), ".\user_settings.ini", "translation", "enablegoogletranslate") | ||
IniWrite(Launcher["GoogleTranslateKey"].value, ".\user_settings.ini", "translation", "googletranslatekey") | ||
} | ||
|
||
|
||
GetClarityArgs(*) { | ||
/* | ||
Read the GUI to see which arguments we need to pass to dqxclarity. | ||
Returns the appropriate arguments. | ||
*/ | ||
args := "" | ||
if (Launcher["CommunityLogging"].value = 1) | ||
args := args . "l" | ||
if (Launcher["PlayerNames"].value = 1) | ||
args := args . "p" | ||
if (Launcher["NPCNames"].value = 1) | ||
args := args . "n" | ||
if (Launcher["UpdateGameFiles"].value = 1) | ||
args := args . "d" | ||
if (Launcher["DisableUpdates"].value = 1) | ||
args := args . "u" | ||
if (Launcher["UseDeepL"].value = 1 or Launcher["UseGoogleTranslate"].value = 1) | ||
args := args . "c" | ||
|
||
if (args) | ||
return "-ClarityArgs `"-" . args . "`"" | ||
else | ||
return "" | ||
return args | ||
} | ||
|
||
RunProgram(*) { | ||
SaveToIni | ||
Run("cmd.exe /c powershell.exe -ExecutionPolicy Unrestricted -File run_clarity.ps1 " . GetClarityArgs()) | ||
ExitApp | ||
} |
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.