You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
133 lines
4.2 KiB
Plaintext
133 lines
4.2 KiB
Plaintext
; 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 |