/* Installing, Removing, and paths */ Tool_IsInstalled(_ID) { _RegResult := Tool_GetRegKey(_ID) _Path := XML_Get("Tool", _ID, "path") If (_Path and SubStr(_Path, 0) != "\") _Path .= "\" ; Add a slash to the end of the reg path If (_Path and FileExist(_Path . "*")) { Return SubStr(_Path, 1, StrLen(_Path) - 1) } Else If _RegResult { StringReplace, _PathFromReg, _RegResult, /, \, All If (SubStr(_PathFromReg, -2, 3) = "exe") { If FileExist(_PathFromReg) Return SubStr(_PathFromReg, 1, InStr(_PathFromReg, "\", false, 0)) } If (_PathFromReg) and (SubStr(_PathFromReg, 0) != "\") _PathFromReg .= "\" ; Add a slash to the end of the reg path If (_PathFromReg and FileExist(_PathFromReg . "*")) { Return SubStr(_PathFromReg, 1, StrLen(_PathFromReg) - 1) } Else Return false } Else Return false } Tool_Install(_ID, _Download = true, _DeleteInstaller = false, _DownloadsDir = "") { global DownloadsDir If Not _DownloadsDir _DownloadsDir := DownloadsDir _File := XML_Get("Tool", _ID, "install") _SubDir := XML_Get("Tool", _ID, "install/@dir") _Installer := _SubDir ? _DownloadsDir . "\" . _SubDir . "\" . _File : _DownloadsDir . "\" . _File If (_Download and Not FileExist(_Installer)) { _Result := Tool_Prompt(_ID, "download") } If FileExist(_Installer) { RunWait, %_Installer% ; Change above to Run, and use this section to monitor the installation process and ascertain the install dir _InstallPath := Tool_IsInstalled(_ID) _Result := true } If _DeleteInstaller { If _SubDir { FileRemoveDir, %_DownloadsDir%\%_SubDir%, 1 } Else { FileDelete, %_Installer% } } If _InstallPath Return _InstallPath Else Return _Result } Tool_Locate(_ID, _Path = "") { If Not _Path { _Path := XML_Get("Tool", _ID, "path") If Not _Path _Path := Tool_GetRegKey(_ID, "path") } If Not _Path { _Manual := true _Title := XML_Get("Tool", _ID, "title") _Exe := XML_Get("Tool", _ID, "exe") FileSelectFolder, _Path,, 0, Please select the location of %_Exe% (%_Title%) } If (_Path and InStr(FileExist(_Path), "D")) { If _Manual XML_Set("Tool", _ID, "path", _Path) _Result := _Path } Else _Result := false Return _Result } /* Downloading */ Tool_Download(_ID, _Overwrite = false) { global DownloadsDir, 7zip _DownloadURL := XML_Get("Tool", _ID, "download/url") _DownloadFile := XML_Get("Tool", _ID, "download/file") If (_DownloadURL and _DownloadFile) { If Not InStr(FileExist(DownloadsDir), "D") FileCreateDir, %DownloadsDir% If Not _Overwrite or Not FileExist(DownloadsDir . "\" . _DownloadFile) { If ConnectedToInternet() { _Result := File_Download(_DownloadURL, _DownloadFile) If XML_Get("Tool", _ID, "download/file/@extract") { File_Extract(_DownloadFile, DownloadsDir . "\" . XML_Get("Tool", _ID, "download/file/@dir"), DownloadsDir) } Result := _DownloadFile } } } } /* Tool Running */ Tool_IsRunning(_ID) { _Exe := XML_Get("Tool", _ID, "exe") If _Exe { Process, Exist, %_Exe% _Result := ErrorLevel } Else _Result := false Return _Result } Tool_Run(_ID, _Prompt = true) { _Path := Tool_IsInstalled(_ID) If _Path { _Result := Tool_IsRunning(_ID) If Not _Result { ; OSD("Starting " . XML_Get("Tool", _ID, "title")) _Exe := XML_Get("Tool", _ID, "exe") _Params := XML_Get("Tool", _ID, "exe/@params") _AutoRunParams := XML_Get("Tool", _ID, "exe/@autorun_params") Run, %_Exe% %_Params% %_AutoRunParams%, %_Path%,, _Result If (XML_Get("Tool", _ID, "@locked")) Tool_Lock(_ID) } } Else { If _Prompt { If Tool_Prompt(_ID) _Result := Tool_Run(_ID, false) } } Return _Result } Tool_Search(_Path = "", _Match = "", _Expr = "") { Result := XML_Find("Tool", _Path, _Match, _Expr) } Tool_Watch(_ID = "") { If _ID { If XML_Get("Tool", _ID, "@watch") { If Tool_IsRunning(_ID) Result := true Else Result := Tool_Run(_ID) } Else Result := false } Else { IDs = XML_Find("Tool", "@watch", "1") Loop,% SA_Len(IDs) { _ID := SA_Get(IDs, A_Index) If _ID and XML_Get("Tool", _ID, "@watch") { If Tool_IsRunning(_ID) Result := true Else Result := Tool_Run(_ID) } Else Result := false } } Return Result } /* REVAMP Tool_AutoRun(_ID = "", _Run = true, _FailPrompt = true) { global cfg_Tools_AutoRunDelay If _ID { _Result = XML_Get("Tool", _ID, "@autorun") If _Result and _Run _Result := Tool_Run(_ID, _FailPrompt) } Else { _AllClear := true _Tools := Tool_Get("Tool") Loop,% AHKA_Size(_Tools) { _ID := AHKA_Get(_Tools, A_Index) If XML_Get("Tool", _ID, "@enabled") { _Result := XML_Get("Tool", _ID, "@autorun") If _Result and _Run { _Result := Tool_Run(_ID, _FailPrompt) If Not _Result _AllClear := false } If cfg_Tools_AutoRunDelay > 0 Sleep,%cfg_Tools_AutoRunDelay% } } _Result := _AllClear } Return _Result } */ /* Registry related */ Tool_GetRegKey(_ID, _RegKeyID = "", _Value = true) { If Not _RegKeyID _RegKeyID := "path" _RegKey := XML_Get("Tool", _ID, "regkeys/regkey[@id=" . _RegKeyID . "]") _ValName := "" If _RegKey { If _Value { If (SubStr(_RegKey, 0) != "\") { _ValName := SubStr(_RegKey, InStr(_RegKey, "\", 1, 0) + 1) _RegKey := SubStr(_RegKey, 1, InStr(_RegKey, "\", 1, 0)) } _RegPath := SubStr(_RegKey, InStr(_RegKey, "\", 1) + 1, InStr(_RegKey, "\", 1, 0) - 1) _RegRootKey := SubStr(_RegKey, 1, InStr(_RegKey, "\", 1, 1) - 1) RegRead, _Result, %_RegRootKey%, %_RegPath%, %_ValName% } Else _Result := false } Else _Result := false Return _Result } /* Tool Locking */ Tool_LockTools(_ID = "", _Action = "") { static Lock_Tools = "" _Len := SA_Len(Lock_Tools) If _Len { If _ID is integer _Result := SA_Get(Lock_Tools, _ID) Else If _ID { Loop, %_Len% { If (SA_Get(Lock_Tools, A_Index) = _ID) { _Result := A_Index Break } } If (_Action = "add" and Not _Result) { SA_Set(Lock_Tools, _ID) XML_Set("Tool", _ID, "@locked", 1) } Else If (_Action = "del" and _Result) { SA_Del(Lock_Tools, _Result) XML_Set("Tool", _ID, "@locked", 0) } } Else _Result := _Len } Else _Result := false Return _Result } Tool_IsLocked(_ID) { _Result := XML_Get("Tool", _ID, "@locked") _Len := SA_Len(Lock_Tools) If _Result and _Len { Loop, %Len% { _Data := SA_Get(Lock_Tools, A_Index) If _Data = _Id Break } If _Data != _Id _Result := false } Else _Result := false } Tool_LockToggle(_ID) { If Tool_IsLocked(_ID) Result := Tool_Unlock(_ID) Else Result := Tool_Lock(_ID) Return Result } Tool_Lock(_ID) { _Locked := Tool_IsLocked(_ID) _LockPW := Tool_SetLockPassword(_ID) If _LockPW and Not _Locked Tool_LockTools(_ID, "add") Else _Result := false Return _Result } Tool_LockAll() { If (Unlocked_Tools := Tool_Search("@locked", "1", "!=")) { Loop,% SA_Len(Unlocked_Tools) { Result := Tool_Lock(SA_Get(Unlocked_Tools, A_Index)) If Not Result Return Result } } } Tool_Unlock(_ID) { _Locked := Tool_IsLocked(_ID) _InArray := Tool_LockTools(_ID) If _Locked and _InArray { _Result := Tool_LockChallenge(_ID) If _Result Tool_LockTools(_ID, "del") } Else _Result := false Return _Result } Tool_UnlockAll() { If (Locked_Tools := Tool_Search("@locked", "1")) { Loop,% SA_Len(Locked_Tools) { Result := Tool_Unlock(SA_Get(Locked_Tools, A_Index)) If Not Result Return Result } } } Tool_SetLockPassword(_ID, _Change = false) { _LockPassword := XML_Get("Tool", _ID, "@password") If _Change or Not _LockPassword { _Title := XML_Get("Tool", _ID, "title") Loop { _Password1 := SW_Password("Set Password", "Enter your desired password for " . _Title . ":") _Password2 := SW_Password("Password Verification", "Re-Enter your desired lock password for " . _Title . ":") If (_Password1 and (_Password1 = _Password2)) { _Password1 := String_Encrypt(_Password1) If _Password1 { _Result := XML_Set("Tool", _ID, "@password", _Password1) } Else _Result := false If _Result _Result := _Password1 Break } } } Else _Result := _LockPassword Return _Result } Tool_LockChallenge(_ID) { _LockPassword := String_Decrypt(XML_Get("Tool", _ID, "@password")) _Title := XML_Get("Tool", _ID, "title") _ChallengePassword := SW_Password("Enter Password", "Enter the password for " . _Title . " to unlock the window:") _Result := (_LockPassword and _LockPassword = _ChallengePassword) ? true : false Return _Result } Tool_SetTimer(_Timer, _Action="") { static _LockTimer_Set = 0, _ChallengeTimer_Set = 0 _TimerVar := "_" . _Timer . "_Set" _DefTimer := (_Timer = "LockTimer") ? 100 : 1000 _Timer := "Tool_" . _Timer If (_Action = "On") _Action := _DefTimer If _Action is integer { SetTimer, %_Timer%, _%Action% _Result := %_TimerVar% := _Action } Else If (_Action = "Off") { SetTimer, %_Timer%, Off _Result := %_TimerVar% := false } Else If (_Action = "") { _Result := %_TimerVar% } Else _Result := false Return _Result } Tool_LockTimer: Tool_LockTimer() Return Tool_ChallengeTimer: Tool_ChallengeTimer() Return Tool_LockTimer() { global Lock_Challenge Loop,% Tool_LockTools() { _ID := SA_Get(Lock_Tools, A_Index) _Exe := XML_Get("Tool", _ID, "exe") Process, Exist, %_Exe% _PID := ErrorLevel If _PID { _WinTitle := XML_Get("Tool", _ID, "wintitle") If Not _WinTitle _WinTitle := "" If WinExist(_WinTitle . " ahk_pid " . _PID) { WinKill,%WinLockTitle% ahk_pid %_PID% Lock_Challenge := _ID } } } } Tool_ChallengeTimer() { global Lock_Challenge If Lock_Challenge { _Result := Tool_Unlock(Lock_Challenge) Lock_Challenge := false } Tool_SetTimer("ChallengeTimer", "Off") Return _Result } /* Misc Tool Functions */ Tool_Prompt(_ID, _Type = "") { If Not _Type _Type := "missing" _Title := XML_Get("Tool", _ID, "title") If (_Type = "missing") { _Buttons := XML_Get("Tool", _ID, "download/url") ? 7 : 8 _Result := SW_MsgBox(_Result, "The executable for " . _Title . " could not be found. Please choose what you would like to do.", _Title . " Not Found", _Buttons) If (_Result = "Install") { _Result := Tool_Install(_ID) } Else If (_Result = "Locate") { _Result := Tool_Locate(_ID) } Else If (_Result = "Disable") { XML_Set("Tool", _ID, "@enabled", 0) _Result := false } Else { ; Ignore _Result := false } } Else If (_Type = "download") { _Buttons := 4 ;Yes/No _Result := SW_MsgBox(_Result, "The installer for " . _Title . " needs to be downloaded. Would you like to continue?", _Title . " Download Confirmation", _Buttons) If (_Result = "Yes") { _Result := Tool_Download(_ID) } Else _Result := false } Return _Result } Tool_Create(_ID, _Title="", _Description="", _Exe="", _RegKey="", _DownloadFile="", _DownloadURL="") { local Result If _Title Result := XML_Set("Tool", _ID, "title", _Title) If _Description Result := XML_Set("Tool", _ID, "description", _Description) If _RegKey Result := XML_Set("Tool", _ID, "regkey", _RegKey) If _DownloadFile or _DownloadURL { If XML_Set("Tool", _ID, "download", "") { If _DownloadFile Result := XML_Set("Tool", _ID, "download", _DownloadFile) If _DownloadURL Result := XML_Set("Tool", _ID, "download/@url", _DownloadURL) } } If _Exe Result := XML_Set("Tool", _ID, "exe", _Exe) Return Result }