From cf56ae8136def874793895733d595349b20d9c19 Mon Sep 17 00:00:00 2001 From: Yuriy Date: Sat, 18 May 2024 00:44:13 -0400 Subject: [PATCH] formatting and cleanup --- Chrome-Functions.ahk | 175 ++++++++++++++++++++++--------------------- Shared-GoTos.ahk | 12 ++- 2 files changed, 99 insertions(+), 88 deletions(-) diff --git a/Chrome-Functions.ahk b/Chrome-Functions.ahk index 5a19ce7..2d41252 100644 --- a/Chrome-Functions.ahk +++ b/Chrome-Functions.ahk @@ -310,144 +310,147 @@ DownloadLatestChromium(){ SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging") MsgBox 0x40,, %Message% + ChromeFilepath := ; clear out chromefilepath variable in case the path changed + ToolTip return } +/* +*/ +CheckForChromeUpdates(ChromeFilepath := ""){ + if(ChromeFilepath = "") + ChromeFilepath := GetInstalledChromeFilepath() - CheckForChromeUpdates(ChromeFilepath := ""){ - if(ChromeFilepath = "") - ChromeFilepath := GetInstalledChromeFilepath() - - CurrentInstalledChromeVersion := GetInstalledChromeVersion() - CurrentChromeStableVersion := GetLatestChromeStableVersion() - - if(CurrentInstalledChromeVersion < CurrentChromeStableVersion){ - ChromeUpdateAvailable := 1 - return ChromeUpdateAvailable - } - else, Return 0 - + CurrentInstalledChromeVersion := GetInstalledChromeVersion() + CurrentChromeStableVersion := GetLatestChromeStableVersion() + if(CurrentInstalledChromeVersion < CurrentChromeStableVersion){ + ChromeUpdateAvailable := 1 + return ChromeUpdateAvailable } + else, Return 0 - GetInstalledChromeFilepath(){ - ; ChromeFilepath is global variable +} - if(ChromeFilepath = ""){ - ChromePortableFilepath = %A_ScriptDir%\Lib\chrome-win64\chrome.exe - ChromePortableFilepath2 = %A_ScriptDir%\Lib\chrome-win64\chrome-win64\chrome.exe ; filepath of chrome.exe that was downloaded automatically using this uploader +GetInstalledChromeFilepath(){ + ; ChromeFilepath is global variable - if(FileExist(ChromePortableFilepath) or FileExist(ChromePortableFilepath2)){ - if(FileExist(ChromePortableFilepath2)) - ChromeFilepath := ChromePortableFilepath2 + if(ChromeFilepath = ""){ - if(FileExist(ChromePortableFilepath)) - ChromeFilepath := ChromePortableFilepath + ChromePortableFilepath = %A_ScriptDir%\Lib\chrome-win64\chrome.exe + ChromePortableFilepath2 = %A_ScriptDir%\Lib\chrome-win64\chrome-win64\chrome.exe ; filepath of chrome.exe that was downloaded automatically using this uploader - Message = Using Chromium Portable for Upload - SaveOrPostProgress(Message:=Message,PostType:="ErrorLoggingTextFile,DiscordErrorLogging") - } - else { - MsgBox 0x10, Chromium Portable not Found, Chromium Portable not found. `nPlease make sure it's located at one of the following paths and then try again.`n`n%ChromePortableFilepath% `nOR`n%ChromePortableFilepath2% + if(FileExist(ChromePortableFilepath) or FileExist(ChromePortableFilepath2)){ + if(FileExist(ChromePortableFilepath2)) + ChromeFilepath := ChromePortableFilepath2 + if(FileExist(ChromePortableFilepath)) + ChromeFilepath := ChromePortableFilepath - ; Leave this in for now, but i don't think we will be going to using the system Chrome in the future. - ; if(FileExist("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe")) - ; ChromeFilepath = C:\Program Files (x86)\Google\Chrome\Application\chrome.exe - - ; if(FileExist("C:\Program Files\Google\Chrome\Application\chrome.exe")) - ; ChromeFilepath = C:\Program Files\Google\Chrome\Application\chrome.exe - } + Message = Using Chromium Portable for Upload + SaveOrPostProgress(Message:=Message,PostType:="ErrorLoggingTextFile,DiscordErrorLogging") } - ToolTip + else { + MsgBox 0x10, Chromium Portable not Found, Chromium Portable not found. `nPlease make sure it's located at one of the following paths and then try again.`n`n%ChromePortableFilepath% `nOR`n%ChromePortableFilepath2% - } - GetInstalledChromeVersion(){ + ; Leave this in for now, but i don't think we will be going to using the system Chrome in the future. + ; if(FileExist("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe")) + ; ChromeFilepath = C:\Program Files (x86)\Google\Chrome\Application\chrome.exe - if(ChromeFilepath = ""){ - GetInstalledChromeFilepath() + ; if(FileExist("C:\Program Files\Google\Chrome\Application\chrome.exe")) + ; ChromeFilepath = C:\Program Files\Google\Chrome\Application\chrome.exe } + } + ToolTip - GetInstalledChromeVersionCommand = powershell (Get-Item '%ChromeFilepath%').VersionInfo.ProductVersion - InstalledChromeVersion := RunCMD(GetInstalledChromeVersionCommand) +} - if(InStr(InstalledChromeVersion, "`r")) - InstalledChromeVersion := StrReplace(InstalledChromeVersion, "`r") ; replace any newline characters that powershell returns +GetInstalledChromeVersion(){ - return InstalledChromeVersion + if(ChromeFilepath = ""){ + GetInstalledChromeFilepath() } + GetInstalledChromeVersionCommand = powershell (Get-Item '%ChromeFilepath%').VersionInfo.ProductVersion + InstalledChromeVersion := RunCMD(GetInstalledChromeVersionCommand) - GetLatestChromeStableVersion(){ + if(InStr(InstalledChromeVersion, "`r")) + InstalledChromeVersion := StrReplace(InstalledChromeVersion, "`r") ; replace any newline characters that powershell returns - ; https://github.com/GoogleChromeLabs/chrome-for-testing#json-api-endpoints - json_str := urldownloadtovar("https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions.json") + return InstalledChromeVersion +} - ; converts json data variable into object - parsed := JSON.Load(json_str) +GetLatestChromeStableVersion(){ + ; https://github.com/GoogleChromeLabs/chrome-for-testing#json-api-endpoints + json_str := urldownloadtovar("https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions.json") - try ChromeStableLatestVersion := parsed.channels.stable.version - if(ChromeStableLatestVersion = ""){ - return "Failed to parse json. " - } + ; converts json data variable into object + parsed := JSON.Load(json_str) + - return ChromeStableLatestVersion + try ChromeStableLatestVersion := parsed.channels.stable.version + + if(ChromeStableLatestVersion = ""){ + return "Failed to parse json. " } + return ChromeStableLatestVersion +} - GetDownloadURLOfChromeAndDriver(InstalledChromeVersion){ - ; Will return the download URL of Chrome for Testing and Chrome Driver, seperated by a || - ; https://github.com/GoogleChromeLabs/chrome-for-testing#json-api-endpoints - json_str := urldownloadtovar("https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json") +GetDownloadURLOfChromeAndDriver(InstalledChromeVersion){ + ; Will return the download URL of Chrome for Testing and Chrome Driver, seperated by a || - ; requires #include of json.ahk in parent script - parsed := JSON.Load(json_str) + ; https://github.com/GoogleChromeLabs/chrome-for-testing#json-api-endpoints + json_str := urldownloadtovar("https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json") - ChromelabsJsonEntriesCount := parsed.versions.count() + ; requires #include of json.ahk in parent script + parsed := JSON.Load(json_str) - if(ChromelabsJsonEntriesCount = ""){ - return "Failed to parse chromedriver json. " - } + ChromelabsJsonEntriesCount := parsed.versions.count() - loop % ChromelabsJsonEntriesCount { + if(ChromelabsJsonEntriesCount = ""){ + return "Failed to parse chromedriver json. " + } - if(A_index = ChromelabsJsonEntriesCount){ - Message = "Failed to find %InstalledChromeVersion% in the ChromeLabs Json" - return Message - } + loop % ChromelabsJsonEntriesCount { - if(InstalledChromeVersion = parsed.versions[A_Index].version){ + if(A_index = ChromelabsJsonEntriesCount){ + Message = "Failed to find %InstalledChromeVersion% in the ChromeLabs Json" + return Message + } - VersionIndex := A_Index + if(InstalledChromeVersion = parsed.versions[A_Index].version){ - ; loop through the platforms to get download URL for Chrome - loop % parsed.versions[VersionIndex].downloads.chrome.count() { + VersionIndex := A_Index - if(parsed.versions[VersionIndex].downloads.chrome[A_Index].platform = "win64") - chromeDLURL64 := parsed.versions[VersionIndex].downloads.chrome[A_Index].url - } + ; loop through the platforms to get download URL for Chrome + loop % parsed.versions[VersionIndex].downloads.chrome.count() { + if(parsed.versions[VersionIndex].downloads.chrome[A_Index].platform = "win64") + chromeDLURL64 := parsed.versions[VersionIndex].downloads.chrome[A_Index].url + } - ; loop through the platforms to get download URL for Chromedriver - loop % parsed.versions[VersionIndex].downloads.chromedriver.count() { - if(parsed.versions[VersionIndex].downloads.chromedriver[A_Index].platform = "win64") - chromedriverDLURL64 := parsed.versions[VersionIndex].downloads.chromedriver[A_Index].url - } + ; loop through the platforms to get download URL for Chromedriver + loop % parsed.versions[VersionIndex].downloads.chromedriver.count() { - break + if(parsed.versions[VersionIndex].downloads.chromedriver[A_Index].platform = "win64") + chromedriverDLURL64 := parsed.versions[VersionIndex].downloads.chromedriver[A_Index].url } + + break } + } - URLS = %chromeDLURL64%||%chromedriverDLURL64% - return URLS - } \ No newline at end of file + URLS = %chromeDLURL64%||%chromedriverDLURL64% + return URLS +} \ No newline at end of file diff --git a/Shared-GoTos.ahk b/Shared-GoTos.ahk index 0a82f61..7a8a842 100644 --- a/Shared-GoTos.ahk +++ b/Shared-GoTos.ahk @@ -44,12 +44,10 @@ if(!status){ } } - Status := DownloadLatestChromium() if(Status) GuiControl,,ChromeUpdateAvailable, Chrome Up-to-Date - Return /* */ @@ -65,7 +63,17 @@ if(A_GuiControl = "PasteClipboardToSMPTitle"){ GuiControl,,PostTitle, %Clipboard% } +if(A_GuiControl = "PasteClipboardToFLSTitle"){ + GuiControl,,LivestreamTitle, %Clipboard% +} + +if(A_GuiControl = "PasteClipboardToFLSDescription"){ + GuiControl,,LivestreamDescription, %Clipboard% +} +if(A_GuiControl = "PasteClipboardToFLSTags"){ + GuiControl,,LivestreamTags, %Clipboard% +} Return \ No newline at end of file