diff --git a/Chrome-Functions.ahk b/Chrome-Functions.ahk index dfd599f..d1a405d 100644 --- a/Chrome-Functions.ahk +++ b/Chrome-Functions.ahk @@ -37,10 +37,10 @@ DownloadLatestChromium(){ ChromeDriverDownloadFilepath = %ParentFolder%\chromedriver-win64 ChromeDriverTemporaryExeFilepath = %ParentFolder%\chromedriver-win64\chromedriver-win64\chromedriver.exe ChromeDownloadZipFilepath = %ParentFolder%\chrome-win64.zip - ChromeDownloadFilepath = %A_ScriptDir%\Lib\chrome-win64 + ChromeExtractedDirectory = %A_ScriptDir%\Lib\chrome-win64 ChromeDriverMoverEXEFilepath = %A_ScriptDir%\Lib\Chromedriver-Mover.exe - ChromeDriverMoverURL = https://git.freedomainplaylists.com/yuriy/Chromedriver-Mover/releases/download/1.0/Chromedriver-Mover.exe + ChromeDriverMoverURL = https://git.freedomainplaylists.com/yuriy/Chromedriver-Mover/releases/download/1.1/Chromedriver-Mover.exe ChromeDriverProgramFilesExeFilepath = C:\Program Files\SeleniumBasic\chromedriver.exe @@ -79,7 +79,7 @@ DownloadLatestChromium(){ FileRemoveDir, %ChromeDriverDownloadFilepath%, 1 msgbox, failed to delete %ChromeDriverDownloadFilepath% - FileRemoveDir, %ChromeDownloadFilepath%, 1 + FileRemoveDir, %ChromeExtractedDirectory%, 1 */ @@ -89,16 +89,41 @@ DownloadLatestChromium(){ } + ; close any open instances of Chromium + SetTitleMatchMode, 2 ; substring + + + if(WinExist(" - Chromium")){ + Message = Trying to close any open Chromium Windows + SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging") + + Loop, 10 { + + WinClose, - Chromium ; , WinText, SecondsToWait, ExcludeTitle, ExcludeText] + sleep, 500 + } + } + + if(WinExist(" - Chromium")){ + Message = Failed to close existing Chromium Window(s). Please close them manually and then click the "Update Chrome" button again + SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging") + ToolTip + MsgBox 0x10,, %Message% + return + } + + + ; msgbox FileGetTime, ChromeDriverExeOldCreationTime, %ChromeDriverProgramFilesExeFilepath%, C - Message = Downloading Chromedriver v%ChromeStableLatestVersion% + Message = Downloading Chromedriver v%ChromeStableLatestVersion% to:`n%ChromeDriverDownloadZipFilepath% SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging") UrlDownloadToFile, %chromedriverDLURL64%, %ChromeDriverDownloadZipFilepath% - Message = Downloading Chromium v%ChromeStableLatestVersion% + Message = Downloading Chromium v%ChromeStableLatestVersion% to:`n%ChromeDownloadZipFilepath% SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging") UrlDownloadToFile, %chromeDLURL64%, %ChromeDownloadZipFilepath% @@ -107,16 +132,36 @@ DownloadLatestChromium(){ Message = Deleting Old Chromium Directory SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging") - FileRemoveDir, %ChromeDownloadFilepath%, 1 - if(FileExist(ChromeDownloadFilepath)){ - Message = Failed to delete the old Chromium. `nPlease manually delete the following directory and then run the Chrome Update again.`n`n %ChromeDownloadFilepath% + FileRemoveDir, %ChromeExtractedDirectory%, 1 + if(FileExist(ChromeExtractedDirectory)){ + Message = Failed to delete the old Chromium. `nPlease manually delete the following directory and then run the Chrome Update again.`n`n %ChromeExtractedDirectory% SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar") + + MsgBox 0x10,, %Message% ToolTip return } + ; Double check that .zip files exist + ChromeDriverZipExists := FileExist(ChromeDriverDownloadZipFilepath) + if(!ChromeDriverZipExists){ + Message = Download of chromedriver failed for some reason. chromedriver.zip not found. + SaveOrPostProgress(Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging") + MsgBox 0x10,, %Message% + Return + } + + ChromeZipExists := FileExist(ChromeDownloadZipFilepath) + if(!ChromeZipExists){ + Message = Download of chrome failed for some reason. chrome.zip not found. + SaveOrPostProgress(Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging") + MsgBox 0x10,, %Message% + Return + } + + Message = Extracting Chromedriver v%ChromeStableLatestVersion% Zip file @@ -125,13 +170,16 @@ DownloadLatestChromium(){ Message = Extracting Chromium v%ChromeStableLatestVersion% Zip file SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging") - Unzip(ChromeDownloadZipFilepath, ChromeDownloadFilepath) + Unzip(ChromeDownloadZipFilepath, ChromeExtractedDirectory) ; Check if the Copy-ChromeDriver-To-Program-Files.exe file exists + ; @todo, remove later. this is temporary to fix chromedriver-mover being broken and needing to be replaced + FileDelete, %ChromeDriverMoverEXEFilepath% + Message = Checking Chromedriver-Mover.exe exists SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging") @@ -172,7 +220,7 @@ DownloadLatestChromium(){ } - Message = Waiting for new Chromedriver to get moved to C:\Program Files\SeleniumBasic\ + Message = Waiting 30 seconds for new Chromedriver to get moved to C:\Program Files\SeleniumBasic\ SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging") Loop, 30 { @@ -250,7 +298,7 @@ GetInstalledChromeFilepath(){ ChromeFilepath := ChromePortableFilepath Message = Using Chromium Portable for Upload - SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging") + 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%