Game_FindBy(_Object, _Value) { Return XML_Find("Game", _Object, _Value) } Game_ImportSourceMods() { ModsPath := Tool_IsInstalled("Steam") . "\steamapps\SourceMods" If InStr(FileExist(ModsPath), "D") { ; If ModPath exists and is a directory Loop, %ModsPath%\*, 2 ; Loop through all directories under the mod path { If FileExist(A_LoopFileFullPath . "\gameinfo.txt") { ModTitle := "" ModLongPath := A_LoopFileLongPath Loop, Read, %A_LoopFileFullPath%\gameinfo.txt { ThisLine := A_LoopReadLine If (SubStr(ThisLine, 1, 4) = "game") and Not ModTitle { If InStr(ThisLine, """") { FirstQuote := InStr(ThisLine, """")+1 LastQuote := InStr(ThisLine, """", false, 0) ModTitle := SubStr(ThisLine, FirstQuote, LastQuote-FirstQuote) } Else ModTitle := SubStr(ThisLine, 5) If ModTitle { ModVersion := String_SeparateVersion(ModTitle) If Not GameId := Game_FindBy("title", ModTitle) { GameId := Game_GenerateId(ModTitle) Result := XML_Set("Game", GameId, "title", ModTitle) Result := XML_Set("Game", GameId, "@type", "mod" Result := XML_Set("Game", GameId, "@source", "sourcemods") } If ModVersion Result := XML_Set("Game", GameId, "version", ModVersion) Result := XML_Set("Game", GameId, "path", ModLongPath) } } Else If ModTitle { If ModIcon := String_ExtractValue(ThisLine, "icon") { Result := XML_Set("Game", GameId, "icon", ModIcon) } Else If ModType := String_ExtractValue(ThisLine, "type") { Result := XML_Set("Game", GameId, "type", ModType) } Else If ModDevUrl := String_ExtractValue(ThisLine, "developer_url") { Result := XML_Set("Game", GameId, "developer", "") Result := XML_Set("Game", GameId, "developer/@url", ModDevUrl) } Else If ModDev := String_ExtractValue(ThisLine, "developer") { Result := XML_Set("Game", GameId, "developer", ModDev) } } XML("Game", "save") } } } } Else Result := false } Game_ImportSteamShortcuts() { ShortcutsPath := Tool_IsInstalled("Steam") . "\config\shortcuts.vdf" If FileExist(ShortcutsPath) { FileRead, Shortcuts, %ShortcutsPath% ; Get file into var FileGetSize, Size, %ShortcutsPath% ; Get size for loop Loop, %Size% { ; Loop through each char If (NumGet(&Shortcuts+(A_Index-1), 0, "UChar") <= 31) ; If non-literal character NumPut(32, &Shortcuts+(A_Index-1), 0, "UChar") ; Replace with a space } VarSetCapacity(Shortcuts, -1) ; Reset the variable size Shortcuts := StringReplace(Shortcuts, "AppName", "¢", 1) Shortcuts := SubStr(Shortcuts, InStr(Shortcuts, "¢")) ; Start at first occurence Loop, Parse, Shortcuts, ¢ { Pos := InStr(A_LoopField, " Exe """) Title := SubStr(A_LoopField, 1, Pos) Exe := SubStr(SubStr(A_LoopField, Pos+6), 1, InStr(SubStr(A_LoopField, Pos+6), """")-1) If Title and Exe { Pos := InStr(SubStr(A_LoopField, Pos+6), """") NewStr := SubStr(A_LoopField, Pos) StartDirPos := InStr(NewStr, "StartDir """)+10 StartDir := SubStr(SubStr(NewStr, StartDirPos, 1, InStr(SubStr(NewStr, StartDirPos, """")-1) Title = %Title% Exe = %Exe% StartDir = %StartDir% GameId := Game_FindByTitle(Title) If Not XML_Get("Game", GameId) { Result := XML_Set("Game", GameId, "@source", "non-steam") Result := XML_Set("Game", GameId, "title", Title) Result := XML_Set("Game", GameId, "exe", Exe) Result := XML_Set("Game", GameId, "startdir", StartDir) Result := XML_Set("Game", GameId, "icon", Icon) If Version := Game_FindVersion(GameId) Result := XML_Set("Game", GameId, "version", Version) } XML("Game", "save") } } } Else Result := false Return Result } Game_FindVersion(_GameId, _Verify=false) { Version := XML_Get("Game", GameId, "version") StartDir := XML_Get("Game", GameId, "startdir") If (Title and Not Version and InStr(FileExist(StartDir), "D")) { Loop, %StartDir%*Readme*, 0, 1 ; Loop through any readme files in the game's dir { Readme := FileRead(A_LoopFileFullPath) Pos := RegExMatch(Readme, "(Version|V)[. -]*([0-9]+[0-9A-Za-z.]*)", Version) ; Try to find a version Version = %Version% If (SubStr(Version, StrLen(Version)) = ".") Version := SubStr(Version, 1, StrLen(Version)-1) ; Remove trailing dot If Version Break } If Version { If _Verify Version := Game_VerifyVersion(GameId, Version) Result := Version } Else Result := false } Else Result := false Return Result } Game_GenerateId(_Title) { _Title = %_Title% If InStr(_Title, " ") { _Title := RegExReplace(_Title, "[^A-Za-z0-9 -]+") _Title := RegExReplace(_Title, "([a-z]+)([A-Z]+)", "$1 $2") _Title := RegExReplace(_Title, "[- ]+", "¢") Loop, Parse, _Title, ¢ Result += SubStr(A_LoopField, 1, 1) } Else Result := StringLower(_Title) If XML_Find("Game", Result) Result := GameGui_DuplicateId(Result, _Title) Return Result } Game_DataCleanUp(_ID="") { Single := _ID ? true : false If Not Single IDs := XML_Find("Game", "@id") Loop { _ID := Single ? _ID : SA_Get(IDs, A_Index) If Not _ID Break If ((PatchVersion := XML_Get("Game", _ID, "patch/version")) and (PatchDownload := XML_Get("Game", _ID, "patch/download"))) { DownloadStatus := uTorrent_DownloadStatus(PatchDownload) If PatchDownloadFinished := XML_Get("Game", _ID, "patch/download/@finished") { If Not DownloadStatus { Result := XML_Delete("Game", _ID, "patch") } } Else If PatchDownloadStarted := XML_Get("Game", _ID, "patch/download/@started") { If (DownloadStatus != 2) { If (DownloadStatus = 3) { Result := XML_Set("Game", _ID, "patch/download/@finished", A_Now) } Else Result := XML_Delete("Game", _ID, "patch") } } Else If PatchDownloadAdded := XML_Get("Game", _ID, "patch/download/@added") { If (DownloadStatus != 1) { If (DownloadStatus = 3) { Result := XML_Set("Game", _ID, "patch/download/@started", A_Now) Result := XML_Set("Game", _ID, "patch/download/@finished", A_Now) } Else If (DownloadStatus = 2) { Result := XML_Set("Game", _ID, "patch/download/@started", A_Now) } Else Result := XML_Delete("Game", _ID, "patch") } } Version := XML_Get("Game", _ID, "version") PatchVersion := XML_Get("Game", _ID, "patch/version") If (Version and PatchVersion and Version = PatchVersion) Result := XML_Set("Game", _ID, "patch/@installed", A_Now) If PatchInstalled := XML_Get("Game", _ID, "patch/@installed") { If cfg_Updates_Clean Result := Game_PatchDelete(_ID) Result := XML_Delete("Game", _ID, "patch") } } If Single Break } XML("Game", "save") Return true } Game_PatchDelete(_ID) { if XML_Get("Game", _ID, "@id") { DownloadFile := XML_Get("Game", _ID, "patch/download") Result := uTorrent_DeleteDownload(DownloadFile) } Else Result := false Return Result } Game_PatchFind(_ID="") { TrayEvent := TrayIcon_Set("Processing", "Searching for game patches...") Single := _ID ? true : false If Not Single IDs := XML_Find("Game", "@id") Loop { _ID := Single ? _ID : SA_Get(IDs, A_Index) If Not _ID Break Title := XML_Get("Game", _ID, "title") If Not Version := XML_Get("Game", _ID, "version") Version := Game_FindVersion(_ID) PatchVersion := XML_Get("Game", _ID, "patch/version") If FoundPatch := GameUpdates_FindPatch(Title) { FoundVersion := SA_Get(FoundPatch, "version") FoundUrl := SA_Get(FoundPatch, "url") If (FoundVersion and (FoundVersion > Version or Not Version) and (FoundVersion > PatchVersion or Not PatchVersion)) { If XML_Get("Game", _ID, "patch") { Result := XML_Set("Game", _ID, "patch/@installed", "0") If XML_Get("Game", _ID, "patch/download") { Result := Game_PatchDelete(_ID) Result := XML_Delete("Game", _ID, "patch/download") } } Else XML_Set("Game", _ID, "patch") Result := XML_Set("Game", _ID, "patch/version", FoundVersion) Result := XML_Set("Game", _ID, "patch/url", FoundUrl) } } If Single Break } Result := XML("Game", "save") TrayIcon_Unset(TrayEvent) Return Result } Game_PatchDownload(_ID="") { TrayEvent := TrayIcon_Set("Processing", "Processing game patches...") Single := _ID ? true : false If Not Single IDs := XML_Find("Game", "@id") Loop { _ID := Single ? _ID : SA_Get(IDs, A_Index) If Not _ID Break Version := XML_Get("Game", _ID, "version") If PatchVersion := XML_Get("Game", _ID, "patch/version") and PatchVersion > Version { If Not XML_Get("Game", _ID, "patch/download") Result := XML_Set("Game", _ID, "patch/download") Added := XML_Get("Game", _ID, "patch/download/@added") Started := XML_Get("Game", _ID, "patch/download/@started") Finished := XML_Get("Game", _ID, "patch/download/@finished") If Not Added and Not Started and Not Finished { If Url := XML_Get("Game", _ID, "patch/url") { Filename := uTorrent_AddTorrentFromUrl(Url) Result := XML_Set("Game", _ID, "patch/download", Filename) Result := XML_Set("Game", _ID, "patch/download/@added", A_Now) } } If Added and Not Finished uTorrent_StartDownloads() } If Single Break } Result := XML("Game", "save") TrayIcon_Unset(TrayEvent) Return Result } Game_PatchDownloadMonitor(_ID="") { Single := _ID ? true : false If Not Single IDs := XML_Find("Game", "@id") Loop { _ID := Single ? _ID : SA_Get(IDs, A_Index) If Not _ID Break If Filename := XML_Get("Game", _ID, "patch/download") { Added := XML_Get("Game", _ID, "patch/download/@added") Started := XML_Get("Game", _ID, "patch/download/@started") Finished := XML_Get("Game", _ID, "patch/download/@finished") DownloadStatus := uTorrent_DownloadStatus(Filename) If Not Added { Result := Game_PatchDownload(_ID) } Else If Not Started { If (DownloadStatus = 2) { Result := XML_Set("Game", _ID, "patch/download/@started", A_Now) } Else If (DownloadStatus = 3) { Result := XML_Set("Game", _ID, "patch/download/@started", A_Now) Result := XML_Set("Game", _ID, "patch/download/@finished", A_Now) } } Else If Not Finished { If (DownloadStatus = 3) { Result := XML_Set("Game", _ID, "patch/download/@finished", A_Now) } Else If (DownloadStatus != 2) { ; failed Retries := XML_Get("Game", _ID, "patch/@retries") If (Retries < 3 or Not Retries) { Retries := Retries ? Retries : 0 Result := XML_Delete("Game", _ID, "patch/download") Result := XML_Set("Game", _ID, "patch/@retries", Retries+1) } Else { Result := XML_Delete("Game", _ID, "patch") } } Else { } } Else PatchReady := true } If Single Break } If PatchReady TrayIcon_Alert("Patch", "There is a game patch available", "GameGui_Display()") XML("Game", "save") Return Result } Game_PatchInstall(_ID="") { global DownloadsDir TrayEvent := TrayIcon_Set("Processing", "Installing patch...") Single := _ID ? true : false If Not Single IDs := XML_Find("Game", "@id") Loop { _ID := Single ? _ID : SA_Get(IDs, A_Index) If Not _ID Break If Filename := XML_Get("Game", _ID, "patch/download") { If Finished := XML_Get("Game", _ID, "patch/download/@finished") { If PatchExe := uTorrent_FindExeInTorrent(Filename) RunWait, %PatchExe% PatchVersion := XML_Get("Game", _ID, "patch/version") If (SW_MsgBox("Was " . _Title . " successfully patched to version " . PatchVersion . "?", "Confirm Patch", 4) = "Yes") { Result := XML_Set("Game", _ID, "version", PatchVersion) Result := XML_Set("Game", _ID, "patch/@installed", A_Now) } Else If (SW_MsgBox("Delete the associated patch files?", "Confirm Deletion", 4) = "Yes") { Result := Game_PatchDelete(_ID) } Else { If (SW_MsgBox(PatchExe . " missing. Redownload " . _Title . " patch data?", "Patch Data Missing", 4) = "Yes") { Result := XML_Delete("Game", _ID, "patch/download/@started") Result := XML_Delete("Game", _ID, "patch/download/@finished") Result := uTorrent_RestartDownload(Filename) } Else Result := Game_PatchDelete(_ID) } } } If Single Break } Result := XML("Game", "save") Result := TrayIcon_Unset(TrayEvent) Return Result } Game_CDKeyAdd(_ID, _Key="", _Option="") { Result := XML_Set("Game", _ID, "cdkey", _Key) If _Option > 0 and _Option < 5 Result := XML_Set("Game", _ID, "cdkey/@option", _Option) Return Result } Game_CDKeyDel(_ID) { Result := XML_Delete("Game", _ID, "cdkey") Return Result } Game_CDKeyGet(_ID) { If Title := XML_Get("Game", _ID, "title") { Key := XML_Get("Game", _ID, "cdkey") Option := XML_Get("Game", _ID, "cdkey/@option") Result := SA_Set(Result := "", "title", Title) Result := SA_Set(Result, "cdkey", Key) Result := SA_Set(Result, "option", Option) } Else Result := false Return Result } Game_CDKeyList(_Type = 0, _Separator = "", _ListAll = false) { ; _Type = 0 - Returns list of all sub-arrays ; _Type = 1 - Returns list of all titles ; _Type = 2 - Returns list of all keys ; _Type = 3 - Returns list of all options If Not _Separator { If _Type _Separator := "|" Else _Separator := "`n" } IDs := XML_Find("Game", "@id") Loop SA_Len(IDs) { ID := SA_Get(IDs, A_Index) Title := XML_Get("Game", ID) If Key := XML_Get("Game", ID, "cdkey") or _ListAll { Option := XML_Get("Game", ID, "cdkey/@option") If _Type = 1 Add := Title Else If _Type = 2 Add := Key Else If _Type = 3 Add := Option Else { Add := "" Add := SA_Set(Add, "title", Title) Add := SA_Set(Add, "cdkey", Key) Add := SA_Set(Add, "option", Option) } List .= List ? _Separator . Add : Add } } Return List }