Compare commits
20 Commits
3620e37e45
...
1.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
05800d08a9 | ||
|
|
7d967c7f33 | ||
|
|
1dd0557970 | ||
| 1e77871bd8 | |||
|
|
57e132fafd | ||
| 71b950c57f | |||
| cf82847058 | |||
| cfce669061 | |||
| 0b9b63b715 | |||
| 1962743565 | |||
| ca7145fa82 | |||
| 1c000184df | |||
| 7106ed522f | |||
| 74e67e5ab9 | |||
| f358623f86 | |||
| 7afb2274a2 | |||
| 324d5a177a | |||
| ed887d5045 | |||
| 84c64bd428 | |||
| c6cf2a408a |
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
Chromedriver-Mover.exe
|
||||
@@ -13,56 +13,347 @@ global DriverTitleArray
|
||||
global LastWebsitePostURL
|
||||
global CurrentTabURL
|
||||
global URLOfLastErrorPage
|
||||
|
||||
|
||||
global chromeDLURL64
|
||||
global chromedriverDLURL64
|
||||
global InstalledChromeVersion
|
||||
|
||||
|
||||
; Chrome Related Functions
|
||||
;------------------------------------------------
|
||||
GetChromeFilepath(){
|
||||
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
|
||||
ChromeExtractedDirectory = %A_ScriptDir%\Lib\chrome-win64
|
||||
|
||||
ChromeDriverMoverEXEFilepath = %A_ScriptDir%\Lib\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
|
||||
|
||||
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, %ChromeExtractedDirectory%, 1
|
||||
|
||||
*/
|
||||
|
||||
if(!FileExist(ParentFolder)){
|
||||
; msgbox, creating dir
|
||||
FileCreateDir, %ParentFolder%
|
||||
}
|
||||
|
||||
|
||||
; 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% to:`n%ChromeDriverDownloadZipFilepath%
|
||||
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
|
||||
UrlDownloadToFile, %chromedriverDLURL64%, %ChromeDriverDownloadZipFilepath%
|
||||
|
||||
Message = Downloading Chromium v%ChromeStableLatestVersion% to:`n%ChromeDownloadZipFilepath%
|
||||
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, %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
|
||||
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, 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")
|
||||
|
||||
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 30 seconds 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 := ""){
|
||||
if(ChromeFilepath = "")
|
||||
ChromeFilepath := GetInstalledChromeFilepath()
|
||||
|
||||
CurrentInstalledChromeVersion := GetInstalledChromeVersion()
|
||||
CurrentChromeStableVersion := GetLatestChromeStableVersion()
|
||||
|
||||
if(CurrentInstalledChromeVersion < CurrentChromeStableVersion){
|
||||
ChromeUpdateAvailable := 1
|
||||
return ChromeUpdateAvailable
|
||||
}
|
||||
else, Return 0
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
GetInstalledChromeFilepath(){
|
||||
; ChromeFilepath is global variable
|
||||
; Establish Variable with Filepath to be used throughout the script
|
||||
|
||||
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
|
||||
|
||||
if(FileExist(ChromePortableFilepath)){
|
||||
if(FileExist(ChromePortableFilepath) or FileExist(ChromePortableFilepath2)){
|
||||
if(FileExist(ChromePortableFilepath2))
|
||||
ChromeFilepath := ChromePortableFilepath2
|
||||
|
||||
if(FileExist(ChromePortableFilepath))
|
||||
ChromeFilepath := ChromePortableFilepath
|
||||
|
||||
Message = Using Chromium Portable for Upload
|
||||
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
|
||||
SaveOrPostProgress(Message:=Message,PostType:="ErrorLoggingTextFile,DiscordErrorLogging")
|
||||
}
|
||||
else {
|
||||
if(FileExist("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"))
|
||||
ChromeFilepath = 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%
|
||||
|
||||
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
|
||||
|
||||
}
|
||||
|
||||
GetChromeVersion(){
|
||||
; 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
|
||||
GetInstalledChromeVersion(){
|
||||
|
||||
if(ChromeFilepath = ""){
|
||||
GetChromeFilepath()
|
||||
GetInstalledChromeFilepath()
|
||||
}
|
||||
|
||||
GetChromeVersionCommand = powershell (Get-Item '%ChromeFilepath%').VersionInfo.ProductVersion
|
||||
Chromeversion := RunCMD(GetChromeVersionCommand)
|
||||
ChromeVersion := StrReplace(ChromeVersion, "`r")[1] ; replace any newline characters that powershell returns
|
||||
return ChromeVersion
|
||||
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
|
||||
|
||||
return InstalledChromeVersion
|
||||
}
|
||||
|
||||
|
||||
GetURLofLatestChromedriver(ChromeVersion){
|
||||
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")
|
||||
|
||||
|
||||
; converts json data variable into object
|
||||
parsed := JSON.Load(json_str)
|
||||
|
||||
|
||||
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")
|
||||
@@ -79,30 +370,33 @@ GetURLofLatestChromedriver(ChromeVersion){
|
||||
loop % 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
|
||||
}
|
||||
|
||||
if(ChromeVersion = parsed.versions[A_Index].version){
|
||||
if(InstalledChromeVersion = parsed.versions[A_Index].version){
|
||||
|
||||
VersionIndex := A_Index
|
||||
|
||||
; loop through the platforms to get download 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() {
|
||||
|
||||
; 64 bit version
|
||||
if(parsed.versions[VersionIndex].downloads.chromedriver[A_Index].platform = "win64")
|
||||
chromedriverDLURL64 := parsed.versions[VersionIndex].downloads.chromedriver[A_Index].url
|
||||
|
||||
; 32 bit version
|
||||
if(parsed.versions[VersionIndex].downloads.chromedriver[A_Index].platform = "win32")
|
||||
chromedriverDLURL32 := parsed.versions[VersionIndex].downloads.chromedriver[A_Index].url
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
; Msgbox % "chromedriverDLURL32: " chromedriverDLURL32
|
||||
; Msgbox % "chromedriverDLURL64: " chromedriverDLURL64
|
||||
return chromedriverDLURL32
|
||||
URLS = %chromeDLURL64%||%chromedriverDLURL64%
|
||||
return URLS
|
||||
}
|
||||
71
Chromedriver-Mover-Compiler.ahk
Normal file
71
Chromedriver-Mover-Compiler.ahk
Normal file
@@ -0,0 +1,71 @@
|
||||
;---ENVIRONMENT---------------------------------------------------------------------
|
||||
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
|
||||
;#Warn ; Enable warnings to assist with detecting common errors.
|
||||
;DetectHiddenWindows, On
|
||||
#SingleInstance, Force
|
||||
DetectHiddenWindows, ON
|
||||
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
|
||||
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
|
||||
;SetKeyDelay, 500
|
||||
CoordMode, ToolTip, Screen
|
||||
CoordMode, Mouse, Screen
|
||||
; #NoTrayIcon
|
||||
; Menu, Tray, Icon, RMScriptManager.ico
|
||||
|
||||
;---Notes/Extra Info/#Includes------------------------------------------------------
|
||||
|
||||
|
||||
;---VARIABLES-----------------------------------------------------------------------
|
||||
|
||||
;---MAIN SCRIPT---------------------------------------------------------------------
|
||||
|
||||
AHKFilepath = %A_ScriptDir%\Chromedriver-Mover.ahk
|
||||
Exefilepath = %A_ScriptDir%\Chromedriver-Mover.exe
|
||||
icopath = %A_ScriptDir%\Chromedriver-Mover.ico
|
||||
|
||||
|
||||
|
||||
; Kill any active intances of the uploaders so the .exe file can be overwriten by the compilation
|
||||
process, close, Chromedriver-Mover.exe
|
||||
|
||||
sleep, 1000
|
||||
|
||||
; Delete the .exe file so it can be repalced
|
||||
if(FileExist(Exefilepath)){
|
||||
FileDelete, %Exefilepath%
|
||||
if(ErrorLevel){
|
||||
msgbox, failed to delete Exe file. Please delete manually and re-run the compiler.
|
||||
ExitApp
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(!FileExist(AHKFilepath)){
|
||||
msgbox, %AHKFilepath% does not exist`nExiting
|
||||
ExitApp
|
||||
}
|
||||
|
||||
|
||||
if(!FileExist(icopath)){
|
||||
msgbox, %icopath% does not exist`nExiting
|
||||
ExitApp
|
||||
}
|
||||
|
||||
|
||||
run, %comspec% /c ""C:\Program Files\AutoHotkey\Compiler\Ahk2Exe.exe" /in "%AHKFilepath%" /out "%exefilepath%" /icon "%icopath%""
|
||||
|
||||
ExitApp
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
;---FUNCTIONS-----------------------------------------------------------------------
|
||||
133
Chromedriver-Mover.ahk
Normal file
133
Chromedriver-Mover.ahk
Normal file
@@ -0,0 +1,133 @@
|
||||
; ENVIRONMENT
|
||||
;------------------------------------------------
|
||||
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
|
||||
;#Warn ; Enable warnings to assist with detecting common errors.
|
||||
;DetectHiddenWindows, On
|
||||
#SingleInstance, Force
|
||||
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
|
||||
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
|
||||
;SetKeyDelay, 500
|
||||
CoordMode, ToolTip, Screen
|
||||
CoordMode, Mouse, Screen
|
||||
; #NoTrayIcon
|
||||
|
||||
; Notes/Extra Info/#Includes
|
||||
;------------------------------------------------
|
||||
; #Include C:\Users\%A_Username%\Syncthing\Scripts\AutoHotKey\RadialMenu\My codes\My Global Variables.ahk
|
||||
|
||||
if(InStr(A_ScriptFullPath, ".ahk")){
|
||||
try Menu, Tray, Icon, %A_ScriptDir%\Assets\icon.ico
|
||||
}
|
||||
|
||||
; Menu, Tray, Icon, C:\Users\%A_Username%\Syncthing\Git\Copy-ChromeDriver-To-Program-Files\Assets\icon.ico
|
||||
|
||||
ChromeDriverTemporaryFilepath = %1%
|
||||
|
||||
; Msgbox % "Passed in ChromeDriverTemporaryFilepath: " ChromeDriverTemporaryFilepath
|
||||
|
||||
; msgbox
|
||||
; VARIABLES
|
||||
;------------------------------------------------
|
||||
SettingsFilepath = %A_ScriptDir%\ChromedriverMover.ini
|
||||
|
||||
; Msgbox % "SettingsFilepath: " SettingsFilepath
|
||||
if(ChromeDriverTemporaryFilepath)
|
||||
IniWrite, %ChromeDriverTemporaryFilepath%, %SettingsFilepath%, Selenium, ChromeDriverTemporaryFilepath
|
||||
|
||||
|
||||
; MAIN SCRIPT
|
||||
;------------------------------------------------
|
||||
StartScriptAsAdmin()
|
||||
|
||||
if(ChromeDriverTemporaryFilepath = "")
|
||||
IniRead, ChromeDriverTemporaryFilepath, %SettingsFilepath%, Selenium, ChromeDriverTemporaryFilepath
|
||||
|
||||
|
||||
ChromeDriverProgramFilesFilepath = C:\Program Files\SeleniumBasic\chromedriver.exe
|
||||
|
||||
|
||||
if(FileExist(ChromeDriverProgramFilesFilepath)){
|
||||
|
||||
FileDelete, %ChromeDriverProgramFilesFilepath%
|
||||
if(ErrorLevel){
|
||||
msgbox, failed to delete old chromedriver from: C:\Program Files\SeleniumBasic\chromedriver.exe. Please make sure all Selenium Connected instances of Chromium are closed and then try again or move the Chromedriver.exe file manually from:`n%ChromeDriverTemporaryFilepath%
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
if(FileExist(ChromeDriverProgramFilesFilepath)){
|
||||
msgbox, failed to delete old chromedriver from: C:\Program Files\SeleniumBasic\chromedriver.exe. Please run this program as admin or move the chromedriver manually from:`n%ChromeDriverTemporaryFilepath%
|
||||
ExitApp
|
||||
}
|
||||
|
||||
; msgbox, pause
|
||||
|
||||
; Msgbox % "ChromeDriverTemporaryFilepath: " ChromeDriverTemporaryFilepath
|
||||
|
||||
if(!InStr(ChromeDriverTemporaryFilepath, ".exe")){ ; parent directory passed in instead of exact filepath. Loop through directory contents and find the .exe file
|
||||
|
||||
Loop, files, %ChromeDriverTemporaryFilepath%\*.*, DFR
|
||||
{ ; D = Directories, F = Files, R = Recursive
|
||||
|
||||
SplitPath, A_LoopFileFullPath, FileNameWExt, FileDir, FileExt, FileNameNoExt,
|
||||
|
||||
if(FileNameWExt = "chromedriver.exe"){
|
||||
ChromeDriverTemporaryFilepath := A_LoopFileFullPath
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(!InStr(ChromeDriverTemporaryFilepath, ".exe")){
|
||||
msgbox, Failed to find chromedriver.exe to move. Please move the chromedriver manually.
|
||||
ExitApp
|
||||
}
|
||||
|
||||
|
||||
FileCopy, %ChromeDriverTemporaryFilepath%, %ChromeDriverProgramFilesFilepath%, 1
|
||||
if(ErrorLevel){
|
||||
msgbox, unable to copy chromedriver.exe from: `n%ChromeDriverTemporaryFilepath%`nto:`n%ChromeDriverProgramFilesFilepath%
|
||||
ExitApp
|
||||
}
|
||||
|
||||
|
||||
if(!FileExist(ChromeDriverProgramFilesFilepath)){
|
||||
msgbox, failed to move chromedriver to %ChromeDriverProgramFilesFilepath%. Please run this program as admin or move the chromedriver manually.
|
||||
ExitApp
|
||||
}
|
||||
|
||||
; clear the settings file
|
||||
IniWrite, %A_Tab%, %SettingsFilepath%, Selenium, ChromeDriverTemporaryFilepath
|
||||
|
||||
ExitApp
|
||||
|
||||
|
||||
|
||||
; Functions
|
||||
;------------------------------------------------
|
||||
|
||||
StartScriptAsAdmin(){
|
||||
full_command_line := DllCall("GetCommandLine", "str")
|
||||
|
||||
if not (A_IsAdmin or RegExMatch(full_command_line, " /restart(?!\S)")) {
|
||||
try {
|
||||
if A_IsCompiled
|
||||
Run *RunAs "%A_ScriptFullPath%" /restart
|
||||
else
|
||||
Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%"
|
||||
}
|
||||
ExitApp
|
||||
}
|
||||
|
||||
if(!A_IsAdmin){
|
||||
Msgbox, failed to get admin to move chromedriver to program files
|
||||
Return
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
; Misc
|
||||
;------------------------------------------------
|
||||
; Escape::ExitApp
|
||||
BIN
Chromedriver-Mover.ico
Normal file
BIN
Chromedriver-Mover.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 179 KiB |
@@ -35,9 +35,10 @@ SaveOrPostProgress(Message:="",PostType:=""){
|
||||
if(InStr(PostType, "Tooltip")){
|
||||
TooltipThis(Message)
|
||||
}
|
||||
if(InStr(PostType, "ErrorLoggingTextFile")){
|
||||
/* if(InStr(PostType, "ErrorLoggingTextFile")){
|
||||
Func_LogErrorsToTextFile(Message)
|
||||
}
|
||||
*/
|
||||
if(InStr(PostType, "ErrorSummaryVar")){
|
||||
Func_LogErrorsToVar(Message)
|
||||
}
|
||||
@@ -383,37 +384,12 @@ OnMsgBoxUpdateAvailable() {
|
||||
}
|
||||
|
||||
|
||||
OnMsgBoxChromeDriverFailed() {
|
||||
DetectHiddenWindows, On
|
||||
Process, Exist
|
||||
If (WinExist("ahk_class #32770 ahk_pid " . ErrorLevel)) {
|
||||
WinMove,, 0
|
||||
ControlSetText Button1, Reload Script
|
||||
ControlSetText Button2, ChromeDriver
|
||||
ControlSetText Button3, Instructions
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SaveCurrentChromeVersionToIniFile(){
|
||||
|
||||
; Msgbox % "ChromeFilepath: " ChromeFilepath
|
||||
GetChromeVersionCommand = powershell (Get-Item '%ChromeFilepath%').VersionInfo.ProductVersion
|
||||
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
|
||||
if(InstalledChromeVersion = "")
|
||||
InstalledChromeVersion := GetInstalledChromeVersion()
|
||||
|
||||
; Msgbox % "Chromeversion: " Chromeversion
|
||||
|
||||
|
||||
if(ChromeFilepath = "")
|
||||
return
|
||||
|
||||
; Chromeversion := StrSplit(Chromeversion, "`n")
|
||||
; Chromeversion := Chromeversion[4]
|
||||
IniWrite, %ChromeVersion%, Settings.ini, Misc, ChromeVersion
|
||||
IniWrite, %InstalledChromeVersion%, Settings.ini, Misc, ChromeVersion
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -8,7 +8,12 @@ CheckForUpdates(GitReleasesAPIURL){
|
||||
data := URLDownloadToVar(GitReleasesAPIURL)
|
||||
; Msgbox % "data: " data
|
||||
|
||||
parsed := JSON.Load(data)
|
||||
try, parsed := JSON.Load(data)
|
||||
catch e {
|
||||
Message = Failed to check for updates. Gitea Releases API returned blank or malformed data.
|
||||
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
|
||||
Return
|
||||
}
|
||||
|
||||
UpdateVersionNumber := parsed.1.name
|
||||
|
||||
@@ -36,7 +41,12 @@ CheckForUpdates(GitReleasesAPIURL){
|
||||
UpdateScript(){
|
||||
data := URLDownloadToVar(GitReleasesAPIURL)
|
||||
|
||||
parsed := JSON.Load(data)
|
||||
try parsed := JSON.Load(data)
|
||||
catch e {
|
||||
Message = Failed to check for updates. Gitea Releases API returned blank or malformed data.
|
||||
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
|
||||
Return
|
||||
}
|
||||
|
||||
UpdateVersionNumber := parsed.1.name
|
||||
ChangeLog := parsed.1.body
|
||||
|
||||
@@ -2,11 +2,10 @@
|
||||
;------------------------------------------------
|
||||
; Selenium Related Functions
|
||||
|
||||
global MouseClicksSaved
|
||||
|
||||
ShowSeleniumErrorMsgbox(){
|
||||
|
||||
; Clipboard := ChromeVersion
|
||||
; Msgbox % "Chromeversion: " Chromeversion
|
||||
IniRead, PreviousWorkingChromeVersion, Settings.ini, Misc, ChromeVersion, %A_Space%
|
||||
; IniWrite, %ChromeVersion%, Settings.ini, Misc, ChromeVersion
|
||||
; msgbox, failed to connect to Chrome for some reason.
|
||||
@@ -14,27 +13,44 @@ ShowSeleniumErrorMsgbox(){
|
||||
; SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
|
||||
|
||||
OnMessage(0x44, "OnMsgBoxChromeDriverFailed")
|
||||
MsgBox 0x40043, Error, Failed to Connect to Chrome. `nMost likely issue is either Chrome has some sort of dialogue box open or ChromeDriver needs to be updated.`n`nClick "Reload" to reload the script to try again`nClick "ChromeDriver" to open up the ChromeDriver download page. `n`nClick "Instructions" to open up the instructions website for updating Chromedriver.`n`nPossibly Helpful Info:`nCurrent Chrome Version: %Chromeversion%Chrome Version of Last Successfull Upload: %PreviousWorkingChromeVersion%
|
||||
MsgBox 0x40043, Error, Failed to Connect to Chrome. `nPossible Causes for this:`n1) One of your tabs is stuck loading/refreshing. (Try closing all tabs and restarting) `n2) Chrome has a dialogue box open in one of your tabs. `n3) ChromeDriver needs to be updated.`n`nClick "Restart" to try the Upload again`nClick "ChromeDriver" to open up the ChromeDriver download page. `n`nClick "Instructions" to open up the instructions website for updating Chromedriver.`n`nPossibly Helpful Info:`nCurrent Chrome Version: %Chromeversion% `nChrome Version of Last Successfull Upload: %PreviousWorkingChromeVersion%
|
||||
OnMessage(0x44, "")
|
||||
|
||||
IfMsgBox Yes, {
|
||||
; Reload script
|
||||
Reload
|
||||
} Else IfMsgBox No, {
|
||||
; Open Instructions Gitea page
|
||||
|
||||
if(InStr(A_ScriptName, "Video"))
|
||||
URL = https://freedomain.dev/yuriy/video-uploader#installation
|
||||
else,
|
||||
URL = https://freedomain.dev/yuriy/social-media-poster#installation
|
||||
|
||||
run, %URL%
|
||||
run, "%A_ScriptFullPath%" "LastPost"
|
||||
}
|
||||
Else IfMsgBox No, {
|
||||
; open chromedriver download page
|
||||
|
||||
run, https://chromedriver.chromium.org/downloads
|
||||
ExitApp
|
||||
run, "%A_ScriptFullPath%" "LastPost"
|
||||
; open chromedriver site
|
||||
} Else IfMsgBox Cancel, {
|
||||
URL = https://git.freedomainplaylists.com/yuriy/Freedomain-Social-Media-Poster#installation
|
||||
run, %url%
|
||||
; Reload with last post
|
||||
run, "%A_ScriptFullPath%" "LastPost"
|
||||
}
|
||||
ExitApp
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
*/
|
||||
|
||||
OnMsgBoxChromeDriverFailed() {
|
||||
DetectHiddenWindows, On
|
||||
Process, Exist
|
||||
If (WinExist("ahk_class #32770 ahk_pid " . ErrorLevel)) {
|
||||
WinMove,, 0
|
||||
ControlSetText Button1, Instructions
|
||||
ControlSetText Button2, ChromeDriver
|
||||
ControlSetText Button3, Restart
|
||||
}
|
||||
}
|
||||
|
||||
; -------------------------------Tab Navigation & Activation-------------------------------
|
||||
|
||||
@@ -183,12 +199,12 @@ CheckCurrentTabForCurrentSite(){
|
||||
|
||||
if(!InStr(CurrentTabURL, CurrentSite)){
|
||||
Message = Chromedriver failed to switch to %CurrentSite%. Current Tab URL: %CurrentTabURL%
|
||||
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
|
||||
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar")
|
||||
return "Failed"
|
||||
}
|
||||
else, {
|
||||
Message = CheckCurrentTabForCurrentSite() passed successfully
|
||||
SaveOrPostProgress(Message:=Message,PostType:="ErrorLoggingTextFile,DiscordErrorLogging")
|
||||
SaveOrPostProgress(Message:=Message,PostType:="ErrorLoggingTextFile")
|
||||
}
|
||||
}
|
||||
/*
|
||||
@@ -226,8 +242,8 @@ NavigateFromBaseURLTo(URL,PageTitle := "TodoDeleteme"){
|
||||
; extract Base URL from Full URL
|
||||
URLBase := ExtractBaseURL(URL)
|
||||
|
||||
Message = Checking for URLBase: %URLBase% within ChromeTabsURLArray
|
||||
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
|
||||
; Message = Checking for URLBase: %URLBase% within ChromeTabsURLArray
|
||||
; SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
|
||||
|
||||
; msgbox % HasSubstringVal(ChromeTabsURLArray, URLBase) . "`n`n is the status of URLbase in ChromeTabsURLArray"
|
||||
|
||||
@@ -235,7 +251,7 @@ NavigateFromBaseURLTo(URL,PageTitle := "TodoDeleteme"){
|
||||
if(!HasSubstringVal(ChromeTabsURLArray, URLBase))
|
||||
{
|
||||
; DevModeMsgBox("Creating new tab")
|
||||
Message = Chrome tab does not exist. Creating new tab ;. Creating new tab with URL: %URL%
|
||||
Message = Chrome tab does not exist in ChromeTabsURLArray. Creating new tab ;. Creating new tab with URL: %URL%
|
||||
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
|
||||
|
||||
try, run "%ChromeFilepath%" "%URL%"
|
||||
@@ -394,12 +410,12 @@ ActivateChromeTab(URL){
|
||||
if(A_index < 3){
|
||||
if(CurrentTabURL = StartingTabURL){
|
||||
Message = Current Tab URL is THE SAME as Starting URL after %A_index% tab switches`nStuck on this tab?
|
||||
SaveOrPostProgress(Message:=Message,PostType:="ErrorLoggingTextFile,DiscordErrorLogging")
|
||||
SaveOrPostProgress(Message:=Message,PostType:="ErrorLoggingTextFile")
|
||||
CheckForAlerts()
|
||||
}
|
||||
else, {
|
||||
Message = Current Tab URL is DIFFERENT from starting URL after %A_index% tab switches
|
||||
SaveOrPostProgress(Message:=Message,PostType:="ErrorLoggingTextFile,DiscordErrorLogging")
|
||||
SaveOrPostProgress(Message:=Message,PostType:="ErrorLoggingTextFile")
|
||||
}
|
||||
|
||||
if(LastActiveTab = CurrentTabURL){
|
||||
@@ -429,7 +445,7 @@ ActivateChromeTab(URL){
|
||||
; / loop through tabs
|
||||
}
|
||||
Message = ActivateChromeTab function failed to activate tab for %urlBase% after looping through %NumberOfTabActivationLoops% tabs
|
||||
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
|
||||
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
|
||||
return "Failed"
|
||||
}
|
||||
|
||||
@@ -438,7 +454,7 @@ ActivateChromeTab(URL){
|
||||
|
||||
CheckForAlerts(){
|
||||
Message = Checking for Any Obstructing Alerts in Chrome
|
||||
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
|
||||
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
|
||||
|
||||
status := 1
|
||||
try driver.SwitchToAlert()
|
||||
@@ -450,7 +466,7 @@ CheckForAlerts(){
|
||||
if(status){
|
||||
; msgbox, alert found
|
||||
; Message = Page Alert Found. Dismissing.
|
||||
Message = Page Alert Found. Accepting.
|
||||
Message = Page Alert Found. Accepting so page gets refreshed.
|
||||
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
|
||||
try driver.switchToalert().accept()
|
||||
; try driver.switchToalert().dismiss()
|
||||
@@ -519,7 +535,7 @@ ConnectToChrome(URL := "", Profile := "Profile 1", IP_Port := "127.0.0.1:9222"){
|
||||
|
||||
|
||||
if(ChromeFilepath = ""){
|
||||
GetChromeFilepath()
|
||||
GetInstalledChromeFilepath()
|
||||
}
|
||||
|
||||
if(!winExist("ahk_exe chrome.exe")){
|
||||
@@ -655,6 +671,7 @@ Selenium_LoopToClickID(IDName,NumOfLoops:=1,SleepLength:=1000){
|
||||
sleep, %SleepLength%
|
||||
Continue
|
||||
}
|
||||
MouseClicksSaved += 1
|
||||
Return
|
||||
}
|
||||
}
|
||||
@@ -670,6 +687,7 @@ Selenium_LoopToClickName(ElementName,NumOfLoops:=1,SleepLength:=1000){
|
||||
sleep, %SleepLength%
|
||||
Continue
|
||||
}
|
||||
MouseClicksSaved += 1
|
||||
Return
|
||||
}
|
||||
}
|
||||
@@ -729,6 +747,7 @@ Selenium_LoopToClickXpath(Xpath,NumOfLoops:=1,SleepLength:=1000){
|
||||
sleep, %SleepLength%
|
||||
Continue
|
||||
}
|
||||
MouseClicksSaved += 1
|
||||
Return
|
||||
}
|
||||
}
|
||||
@@ -754,6 +773,7 @@ Selenium_LoopToClickXpathAndWaitForOpenWindow(Xpath,NumOfLoops:=1,SleepLength:=1
|
||||
sleep, %SleepLength%
|
||||
Continue
|
||||
}
|
||||
MouseClicksSaved += 1
|
||||
Return
|
||||
}
|
||||
}
|
||||
@@ -773,6 +793,29 @@ Selenium_LoopToClearXpath(Xpath,NumOfLoops:=1,SleepLength:=1000){
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Selenium_TypeTextIntoElement(Text, Xpath){
|
||||
|
||||
StrLengthOfPost := StrLen(Text)
|
||||
Loop % StrLengthOfPost{
|
||||
|
||||
Current_Char := SubStr(Text, A_index, 1)
|
||||
; Msgbox % "Current_Char: " Current_Char
|
||||
|
||||
; driver.FindElementByXPath(Xpath).SendKeys(VAR)
|
||||
|
||||
Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=1,SleepLength:=100,StringTextContent:=Current_Char)
|
||||
if(Status){
|
||||
Message = Failed to Input Text
|
||||
Return Message
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
SaveDriverURLOFErrorPage(){ ; save the url of the result page. That way if a tab is not found for a site, we can open up a tab from this tab instead of middle of nowhere. That way we can keep the tabs together
|
||||
try URLOfLastErrorPage := driver.URL
|
||||
}
|
||||
|
||||
@@ -1,61 +1,12 @@
|
||||
;---ENVIRONMENT---------------------------------------------------------------------
|
||||
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
|
||||
;#Warn ; Enable warnings to assist with detecting common errors.
|
||||
;DetectHiddenWindows, On
|
||||
#SingleInstance, Force
|
||||
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
|
||||
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
|
||||
;SetKeyDelay, 500
|
||||
CoordMode, ToolTip, Screen
|
||||
CoordMode, Mouse, Screen
|
||||
;#NoTrayIcon
|
||||
;Menu, Tray, Icon, ..\Icons\ICONNAMEHERE
|
||||
|
||||
;---Notes/Extra Info/#Includes------------------------------------------------------
|
||||
|
||||
|
||||
;---VARIABLES-----------------------------------------------------------------------
|
||||
|
||||
|
||||
;---MAIN SCRIPT---------------------------------------------------------------------
|
||||
/*
|
||||
; Example Code:
|
||||
#include URLDownloadToVar.ahk
|
||||
URL = https://www.bitchute.com/video/WdxitRyWLZQ/
|
||||
URLContents := URLDownloadToVar(URL)
|
||||
TextFileName := yyyy . MM . dd . "_URLToVarDownload"
|
||||
FileAppend, URLContents, %A_ScriptDir%/%TextFileName%.txt
|
||||
run, %A_ScriptDir%/%TextFileName%.txt
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
; Example 2
|
||||
#SingleInstance,Force
|
||||
url=https://api.coindesk.com/v1/bpi/currentprice.json ; Plce URL here
|
||||
Gui,Add,Edit,w800 h500,% URLDownloadToVar(url)
|
||||
Gui,show,
|
||||
return
|
||||
|
||||
*/
|
||||
|
||||
; Example 2
|
||||
/*#SingleInstance,Force
|
||||
url=https://fdrpodcasts.com/api/?method=QueryPodcasts&keyword=4500 ; Plce URL here
|
||||
url := URLDownloadToVar(url)
|
||||
url := StrReplace(URL, "\/", "/")
|
||||
|
||||
Msgbox % "url: " url
|
||||
|
||||
Gui,Add,Edit,w800 h500,% URLDownloadToVar(url)
|
||||
Gui,show,
|
||||
return
|
||||
|
||||
*/
|
||||
|
||||
URLDownloadToVar(url){
|
||||
hObject:=ComObjCreate("WinHttp.WinHttpRequest.5.1")
|
||||
hObject.Open("GET",url)
|
||||
hObject.Send()
|
||||
|
||||
try hObject.Send()
|
||||
catch e {
|
||||
return ""
|
||||
; msgbox, failed!
|
||||
}
|
||||
|
||||
return hObject.ResponseText
|
||||
}
|
||||
79
Zip.ahk
Normal file
79
Zip.ahk
Normal file
@@ -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 -------------------------------------
|
||||
Reference in New Issue
Block a user