added ability to automatically download newest chromium-testing and chromedriver

main
Yuriy 1 year ago
parent ca7145fa82
commit 1962743565

@ -15,25 +15,216 @@ global CurrentTabURL
global URLOfLastErrorPage global URLOfLastErrorPage
global chromeDLURL64 global chromeDLURL64
global chromedriverDLURL64 global chromedriverDLURL64
global ChromeVersion global InstalledChromeVersion
; Chrome Related Functions ; Chrome Related Functions
;------------------------------------------------ ;------------------------------------------------
DownladAndExtractZip(URL, Directory){ DownloadLatestChromium(){
if(ChromeFilepath = "")
ChromeFilepath := GetInstalledChromeFilepath()
if(chromedriverDLURL64 ="" or chromeDLURL64 = ""){
ChromeStableLatestVersion := GetLatestChromeStableVersion()
GetDownloadURLOfChromeAndDriver(ChromeStableLatestVersion)
}
; Msgbox % "chromedriverDLURL64: " chromedriverDLURL64
; Msgbox % "chromeDLURL64: " chromeDLURL64
ParentFolder = %A_ScriptDir%\Lib\Downloads
ChromeDriverDownloadZipFilepath = %ParentFolder%\chromedriver-win64.zip
ChromeDriverDownloadFilepath = %ParentFolder%\chromedriver-win64
ChromeDriverTemporaryExeFilepath = %ParentFolder%\chromedriver-win64\chromedriver-win64\chromedriver.exe
ChromeDownloadZipFilepath = %ParentFolder%\chrome-win64.zip
ChromeDownloadFilepath = C:\Users\%A_Username%\Syncthing\Git\Freedomain-Video-Uploader\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
ChromeDriverProgramFilesExeFilepath = C:\Program Files\SeleniumBasic\chromedriver.exe
ManualMoveChromedriverMessage =Please manually copy chromedriver.exe from:`n`n%ChromeDriverDownloadFilepath%`n`nTo:`n`nC:\Program Files\SeleniumBasic\chromedriver.exe
/*
With URLDownloadToFile you don't need to delete pre-existing files, as they get overwriten when a new file is downloaded.
FileRemoveDir, %ParentFolder%, 1
if(ErrorLevel){
Message = Failed to download Parent Download Folder.
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
}
if(!FileExist(ParentFolder)){
; msgbox, creating dir
FileCreateDir, %ParentFolder%
}
Msgbox % "ParentFolder: " ParentFolder
msgbox % FileExist(ParentFolder)
if(!FileExist(ParentFolder)){
msgbox, creating dir
FileCreateDir, %ParentFolder%
}
FileDelete, %ChromeDriverDownloadZipFilepath%
if(ErrorLevel)
msgbox, failed to delete %ChromeDriverDownloadZipFilepath%
FileRemoveDir, %ChromeDownloadZipFilepath%, 1
if(ErrorLevel)
msgbox, failed to delete %ChromeDownloadZipFilepath%
FileRemoveDir, %ChromeDriverDownloadFilepath%, 1
msgbox, failed to delete %ChromeDriverDownloadFilepath%
FileRemoveDir, %ChromeDownloadFilepath%, 1
*/
if(!FileExist(ParentFolder)){
; msgbox, creating dir
FileCreateDir, %ParentFolder%
}
FileGetTime, ChromeDriverExeOldCreationTime, %ChromeDriverProgramFilesExeFilepath%, C
Message = Downloading Chromedriver v%ChromeStableLatestVersion%
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
UrlDownloadToFile, %chromedriverDLURL64%, %ChromeDriverDownloadZipFilepath%
Message = Downloading Chromium v%ChromeStableLatestVersion%
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
UrlDownloadToFile, %chromeDLURL64%, %ChromeDownloadZipFilepath%
; delete the pre-existing chrome-win64 directory
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%
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar")
ToolTip
return
}
Message = Extracting Chromedriver v%ChromeStableLatestVersion% Zip file
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
Unzip(ChromeDriverDownloadZipFilepath, ChromeDriverDownloadFilepath)
Message = Extracting Chromium v%ChromeStableLatestVersion% Zip file
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
Unzip(ChromeDownloadZipFilepath, ChromeDownloadFilepath)
; UrlDownloadToFile, %, Filename ; Check if the Copy-ChromeDriver-To-Program-Files.exe file exists
Message = Checking Chromedriver-Mover.exe exists
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
if(!FileExist(ChromeDriverMoverEXEFilepath)){
Message = Chromedriver-Mover not found. Downloading from Gitea
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
UrlDownloadToFile, %ChromeDriverMoverURL%, %ChromeDriverMoverEXEFilepath%
if(ErrorLevel){
Message = Failed to download the Copy-ChromeDriver-To-Program-Files.exe executable. `n`n%ManualMoveChromedriverMessage%
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
ToolTip
Return
}
}
if(!FileExist(ChromeDriverMoverEXEFilepath)){
Message = ChromeDriver-Mover not found after downloading. `nPossibly triggered and deleted by Antivirus?`n`n%ManualMoveChromedriverMessage%
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging,msgbox")
ToolTip
return
}
Message = Starting up Chromedriver-Mover
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
; Msgbox % "ChromeDriverMoverEXEFilepath: " ChromeDriverMoverEXEFilepath
; Msgbox % "ChromeDriverDownloadFilepath: " ChromeDriverDownloadFilepath
try, Run "%ChromeDriverMoverEXEFilepath%" "%ChromeDriverDownloadFilepath%"
if(ErrorLevel = "ERROR"){
Message = Failed to run Chromedriver-Mover.exe program to automatically copy the chromedriver to Program Files.`n%ManualMoveChromedriverMessage%
MsgBox 0x40,, %Message%
}
Message = Waiting for new Chromedriver to get moved to C:\Program Files\SeleniumBasic\
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
Loop, 30 {
sleep, 1000
FileGetTime, ChromeDriverExeCurrentCreationTime, %ChromeDriverProgramFilesExeFilepath%, C
; Msgbox % "ChromeDriverExeOldCreationTime: " ChromeDriverExeOldCreationTime
; Msgbox % "ChromeDriverExeCurrentCreationTime: " ChromeDriverExeCurrentCreationTime
if(ErrorLevel){
Message = chromedriver.exe not found in %ChromeDriverProgramFilesExeFilepath%. `nWaiting for new version to get copied over.
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
; sleep, 1000
Continue
}
if(ChromeDriverExeCurrentCreationTime != ChromeDriverExeOldCreationTime and ChromeDriverExeCurrentCreationTime != ""){
break
}
; sleep, 1000
Continue
}
if(!FileExist(ChromeDriverProgramFilesExeFilepath)){
Message = Failed to Automatically move chromedriver.exe`n%ManualMoveChromedriverMessage%
MsgBox 0x40,, %Message%
ToolTip
return
}
Message = Chromium and Chromedriver.exe were updated successfully.
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
MsgBox 0x40,, %Message%
ToolTip
return
} }
CheckForChromeUpdates(ChromeFilepath := ""){ CheckForChromeUpdates(ChromeFilepath := ""){
if(ChromeFilepath = "") if(ChromeFilepath = "")
ChromeFilepath := GetChromeFilepath ChromeFilepath := GetInstalledChromeFilepath()
CurrentChromeVersion := GetChromeVersion() CurrentInstalledChromeVersion := GetInstalledChromeVersion()
CurrentChromeStableVersion := GetLatestChromeStableVersion() CurrentChromeStableVersion := GetLatestChromeStableVersion()
if(CurrentChromeVersion < CurrentChromeStableVersion){ if(CurrentInstalledChromeVersion < CurrentChromeStableVersion){
ChromeUpdateAvailable := 1 ChromeUpdateAvailable := 1
return ChromeUpdateAvailable return ChromeUpdateAvailable
} }
@ -43,51 +234,53 @@ CheckForChromeUpdates(ChromeFilepath := ""){
} }
GetChromeFilepath(){ GetInstalledChromeFilepath(){
; ChromeFilepath is global variable ; ChromeFilepath is global variable
; Establish Variable with Filepath to be used throughout the script
if(ChromeFilepath = ""){ if(ChromeFilepath = ""){
ChromePortableFilepath = %A_ScriptDir%\Lib\chrome-win64\chrome.exe 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
if(FileExist(ChromePortableFilepath) or FileExist(ChromePortableFilepath2)){
if(FileExist(ChromePortableFilepath2))
ChromeFilepath := ChromePortableFilepath2
if(FileExist(ChromePortableFilepath)){ if(FileExist(ChromePortableFilepath))
ChromeFilepath := ChromePortableFilepath ChromeFilepath := ChromePortableFilepath
Message = Using Chromium Portable for Upload Message = Using Chromium Portable for Upload
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging") SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
} }
else { else {
if(FileExist("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe")) 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%
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 ; 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
} }
} }
ToolTip ToolTip
} }
GetChromeVersion(){ GetInstalledChromeVersion(){
; https://stackoverflow.com/questions/52457766/how-can-i-get-google-chromes-version-number
; Command = powershell `$ChromePath = 'C:\Program Files\Google\Chrome\Application\chrome.exe' `; [System.Diagnostics.FileVersionInfo]::GetVersionInfo($ChromePath).ProductVersion
; command = powershell $(Get-Package -Name 'Google Chrome').Version
; ChromeVersion := RunCMD(command)
; ChromeVersion := StrSplit(ChromeVersion, "`r")[1] ; remove newline character if it exists
if(ChromeFilepath = ""){ if(ChromeFilepath = ""){
GetChromeFilepath() GetInstalledChromeFilepath()
} }
GetChromeVersionCommand = powershell (Get-Item '%ChromeFilepath%').VersionInfo.ProductVersion GetInstalledChromeVersionCommand = powershell (Get-Item '%ChromeFilepath%').VersionInfo.ProductVersion
Chromeversion := RunCMD(GetChromeVersionCommand) InstalledChromeVersion := RunCMD(GetInstalledChromeVersionCommand)
if(InStr(ChromeVersion, "`r")) if(InStr(InstalledChromeVersion, "`r"))
ChromeVersion := StrReplace(ChromeVersion, "`r") ; replace any newline characters that powershell returns InstalledChromeVersion := StrReplace(InstalledChromeVersion, "`r") ; replace any newline characters that powershell returns
return ChromeVersion return InstalledChromeVersion
} }
@ -101,17 +294,17 @@ GetLatestChromeStableVersion(){
parsed := JSON.Load(json_str) parsed := JSON.Load(json_str)
try CurrentChromeStableVersion := parsed.channels.stable.version try ChromeStableLatestVersion := parsed.channels.stable.version
if(CurrentChromeStableVersion = ""){ if(ChromeStableLatestVersion = ""){
return "Failed to parse json. " return "Failed to parse json. "
} }
return CurrentChromeStableVersion return ChromeStableLatestVersion
} }
GetDownloadURLOfChromeAndDriver(ChromeVersion){ GetDownloadURLOfChromeAndDriver(InstalledChromeVersion){
; Will return the download URL of Chrome for Testing and Chrome Driver, seperated by a || ; 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 ; https://github.com/GoogleChromeLabs/chrome-for-testing#json-api-endpoints
@ -129,11 +322,11 @@ GetDownloadURLOfChromeAndDriver(ChromeVersion){
loop % ChromelabsJsonEntriesCount { loop % ChromelabsJsonEntriesCount {
if(A_index = ChromelabsJsonEntriesCount){ if(A_index = ChromelabsJsonEntriesCount){
Message = "Failed to find %ChromeVersion% in the ChromeLabs Json" Message = "Failed to find %InstalledChromeVersion% in the ChromeLabs Json"
return Message return Message
} }
if(ChromeVersion = parsed.versions[A_Index].version){ if(InstalledChromeVersion = parsed.versions[A_Index].version){
VersionIndex := A_Index VersionIndex := A_Index
@ -141,7 +334,7 @@ GetDownloadURLOfChromeAndDriver(ChromeVersion){
loop % parsed.versions[VersionIndex].downloads.chrome.count() { loop % parsed.versions[VersionIndex].downloads.chrome.count() {
if(parsed.versions[VersionIndex].downloads.chrome[A_Index].platform = "win64") if(parsed.versions[VersionIndex].downloads.chrome[A_Index].platform = "win64")
chromeDLURL64 := parsed.versions[VersionIndex].downloads.chromedriver[A_Index].url chromeDLURL64 := parsed.versions[VersionIndex].downloads.chrome[A_Index].url
} }

@ -385,23 +385,10 @@ OnMsgBoxUpdateAvailable() {
SaveCurrentChromeVersionToIniFile(){ SaveCurrentChromeVersionToIniFile(){
; Msgbox % "ChromeFilepath: " ChromeFilepath if(InstalledChromeVersion = "")
GetChromeVersionCommand = powershell (Get-Item '%ChromeFilepath%').VersionInfo.ProductVersion InstalledChromeVersion := GetInstalledChromeVersion()
Chromeversion := RunCMD(GetChromeVersionCommand)
if(InStr(ChromeVersion, "scripts is disabled on this system")){
ChromeVersion = Not Able to Grab Because: "scripts are disabled in powershell"
}
; Msgbox % "Chromeversion: " Chromeversion
; Msgbox % "Chromeversion: " Chromeversion
if(ChromeFilepath = "")
return
; Chromeversion := StrSplit(Chromeversion, "`n") IniWrite, %InstalledChromeVersion%, Settings.ini, Misc, ChromeVersion
; Chromeversion := Chromeversion[4]
IniWrite, %ChromeVersion%, Settings.ini, Misc, ChromeVersion
} }

@ -535,7 +535,7 @@ ConnectToChrome(URL := "", Profile := "Profile 1", IP_Port := "127.0.0.1:9222"){
if(ChromeFilepath = ""){ if(ChromeFilepath = ""){
GetChromeFilepath() GetInstalledChromeFilepath()
} }
if(!winExist("ahk_exe chrome.exe")){ if(!winExist("ahk_exe chrome.exe")){

@ -0,0 +1,79 @@
; Zip/Unzip file(s)/folder(s)/wildcard pattern files
; Requires: Autohotkey_L, Windows > XP
; URL: http://www.autohotkey.com/forum/viewtopic.php?t=65401
; Credits: Sean for original idea
; #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
;; --------- EXAMPLE CODE -------------------------------------
; FilesToZip = D:\Projects\AHK\_Temp\Test\ ;Example of folder to compress
; FilesToZip = D:\Projects\AHK\_Temp\Test\*.ahk ;Example of wildcards to compress
; FilesToZip := A_ScriptFullPath ;Example of file to compress
; zipfilepath := A_ScriptDir . "\Test.zip" ;Zip file to be created
; unzipDirectory := A_ScriptDir . "\ext\" ;Directory to unzip files
; Zip(FilesToZip,zipfilepath)
; Sleep, 500
; path1 = C:\Users\%A_Username%\Syncthing\Git\Freedomain-Video-Uploader\Lib\Downloads\chrome-win64.zip
; path2 = C:\Users\%A_Username%\Syncthing\Git\Freedomain-Social-Media-Poster\Lib\chrome-win64
; Unzip(path1, path2)
;; --------- END EXAMPLE -------------------------------------
;; ----------- THE FUNCTIONS -------------------------------------
Zip(FilesToZip,zipfilepath)
{
If Not FileExist(zipfilepath)
CreateZipFile(zipfilepath)
psh := ComObjCreate( "Shell.Application" )
pzip := psh.Namespace( zipfilepath )
if InStr(FileExist(FilesToZip), "D")
FilesToZip .= SubStr(FilesToZip,0)="\" ? "*.*" : "\*.*"
loop,%FilesToZip%,1
{
zipped++
ToolTip Zipping %A_LoopFileName% ..
pzip.CopyHere( A_LoopFileLongPath, 4|16 )
Loop
{
done := pzip.items().count
if done = %zipped%
break
}
done := -1
}
ToolTip
}
CreateZipFile(zipfilepath)
{
Header1 := "PK" . Chr(5) . Chr(6)
VarSetCapacity(Header2, 18, 0)
file := FileOpen(zipfilepath,"w")
file.Write(Header1)
file.RawWrite(Header2,18)
file.close()
}
Unzip(zipfilepath, unzipDirectory)
{
fso := ComObjCreate("Scripting.FileSystemObject")
If Not fso.FolderExists(unzipDirectory) ;http://www.autohotkey.com/forum/viewtopic.php?p=402574
fso.CreateFolder(unzipDirectory)
psh := ComObjCreate("Shell.Application")
zippedItems := psh.Namespace( zipfilepath ).items().count
psh.Namespace( unzipDirectory ).CopyHere( psh.Namespace( zipfilepath ).items, 4|16 )
Loop {
sleep 50
unzippedItems := psh.Namespace( unzipDirectory ).items().count
ToolTip Unzipping in progress..
IfEqual,zippedItems,%unzippedItems%
break
}
ToolTip
}
;; ----------- END FUNCTIONS -------------------------------------
Loading…
Cancel
Save