uTorrent_IsInstalled() { global cfg_uTorrent_InstallDir Return FileExist(cfg_uTorrent_InstallDir . "\utorrent.exe") } uTorrent_Install(_Prompt = true) { global cfg_uTorrent_DownloadURL, cfg_uTorrent_InstallDir, GuiDir If Not uTorrent_IsInstalled { Continue := _Prompt ? SW_MsgBox("Would you like to download the uTorrent client to facilitate game updates?", "Download uTorrent", 4) : "Yes" If (Continue = "Yes") { OSD("Configuring uTorrent") Loc := SW_Download(cfg_Torrent_DownloadURL, "utorrent.exe", "uTorrent") If Loc { FileMove, %Loc%, %cfg_Torrent_InstallDir%\utorrent.exe, 1 Dirs := "torrents\old,torrents\in,torrents\active,downloads,completed" Loop, Parse, Dirs, `, FileCreateDir, %cfg_uTorrent_InstallDir%\%A_LoopField% File_Extract(uTorrentFile, cfg_uTorrent_InstallDir) Result := uTorrent_SetDirs() If Result OSD("uTorrent Configured Successfully") Else { SW_MsgBox("uTorrent Configuration Failed", "SteamLab Error") Result := false } } Else { SW_MsgBox("uTorrent Download Failed", "SteamLab Error") Result := false } } Else Result := false } Else Result := false Return true } uTorrent_Uninstall() { If uTorrent_IsInstalled() { FileRemoveDir, %cfg_uTorrent_InstallDir%, 1 Result := true } Else Result := false Return Result } uTorrent_SetDirs() { ; Replace directory info in the binary settings.dat file global cfg_uTorrent_InstallDir Settings = %cfg_uTorrent_InstallDir%\settings.dat Loop { FileGetSize, Size, %Settings% FileRead, Data, %Settings% Loop, %Size% If (*(&Data + (A_Index-1)) = 0) DllCall("RtlFillMemory", UInt, &Data+(A_Index-1), Int, 1, UChar, 32) Offset := InStr(Data, "%A_ScriptDir%") If (Offset = 0) Break BinRead(Settings, Num, 2, Offset - 4) Num := SubStr(Num, 2, 1) . SubStr(Num, 4, 1) Num := StrLen(A_ScriptDir) + Num - 13 Num := SubStr(String2Hex(Num), 2) ScriptDir := A_ScriptDir Bin2Hex(ScriptDirHex, ScriptDir) BinRead(Settings, End, 0, Offset + 12) EndHex := Num . "3a" . SubStr(ScriptDirHex, 1, StrLen(ScriptDirHex) - 40) . End BinWrite(Settings, EndHex, 0, Offset - 4) } Return true } uTorrent_StartDownloads() { local Result If FileExist(cfg_uTorrent_InstallDir . "\torrents\in\*") or FileExist(cfg_uTorrent_InstallDir . "\torrents\active\*") { GameXML_InstallDownloader() Process, Exist, utorrent.exe If Not ErrorLevel Run, utorrent.exe /MINIMIZED /NOINSTALL, %cfg_uTorrent_InstallDir%\ SetTimer, MonitorGameDownloads, 30000 } } uTorrent_DeleteDownload(_File) { global cfg_uTorrent_InstallDir TorrentFile := cfg_uTorrent_InstallDir . "\torrents\old\" . _File If FileExist(TorrentFile) { Torrent_Load(Torrent, TorrentFile) Files := Torrent_GetFiles(Torrent) Dir := ErrorLevel Torrent_Load(Torrent) ; Unload Loop, Parse, Files, `n If A_LoopField { If InStr(FileExist(cfg_uTorrent_InstallDir . "\completed\" . A_LoopField), "D") FileRemoveDir, %cfg_uTorrent_InstallDir%\completed\%A_LoopField% Else FileDelete, %cfg_uTorrent_InstallDir%\completed\%A_LoopField% } If Dir FileRemoveDir, %cfg_uTorrent_InstallDir%\completed\%Dir% FileDelete, %TorrentFile% } Return 1 } ; 0: error ; 1: new ; 2: active ; 3: finished ; 4: removed uTorrent_DownloadStatus(_File) { } uTorrent_DownloadExists(_File) { global cfg_uTorrent_InstallDir If FileExist(cfg_uTorrent_InstallDir . "\torrents\old\" . _File) Result := true Else If FileExist(cfg Return Result } uTorrent_DownloadActive(_File) { global cfg_uTorrent_InstallDir FileExist(cfg_uTorrent_InstallDir . "\torrents\active\" . _File) } uTorrent_AddTorrentFromUrl(_Url) { global cfg_uTorrent_InstallDir Filename := SubStr(_Url, InStr(_Url, "/", false, 0) + 1) Filename := StringReplace(Filename, "%20", A_Space, 1) URLDownloadtofile, %Url%, %cfg_uTorrent_InstallDir%\torrents\in\%Filename% Return Filename } uTorrent_IsRunning() { Process, Exist, utorrent.exe Return ErrorLevel } uTorrent_GetTorrentPath(_File) { global cfg_uTorrent_InstallDir If Result := FileExist(cfg_uTorrent_InstallDir . "\torrents\old\" . _File) { } Else If Result := FileExist(cfg_uTorrent_InstallDir . "\torrents\active\" . _File) { } Else If Result := FileExist(cfg_uTorrent_InstallDir . "\torrents\in\" . _File) { } Else Result := false } uTorrent_FindExeInTorrent(_File) { global cfg_uTorrent_InstallDir TorrentPath := uTorrent_GetTorrentPath(_File) If FileExist(TorrentPath) { Torrent := "" Torrent_Load(Torrent, TorrentPath) Files := Torrent_GetFiles(Torrent) If InStr(Files, "`n") { Loop, Parse, Files, `n { SplitPath, A_LoopField,,, FileExt If (FileExt = "exe") { Result := A_LoopField Break } } } Else Result := Files } Else Result := false If Result Result := cfg_uTorrent_InstallDir . "\completed\" . Result If Not FileExist(Result) Result := false Return Result } uTorrent_RestartDownload(_File) { global cfg_uTorrent_InstallDir FileMove, %cfg_uTorrent_InstallDir%\torrents\old\%_File%, %cfg_uTorrent_InstallDir%\torrents\in\%_File% uTorrent_StartDownloads() Return true }