Compare commits

..

61 Commits

Author SHA1 Message Date
95bda715cb fixed errorlog to text formatting 2024-07-04 00:45:14 -04:00
ae2027826f telegram API always return data instead of only on error 2024-07-04 00:38:16 -04:00
670b97d6b1 cleared error message 2024-07-04 00:28:26 -04:00
4a1d2a5d9d removed deletion of chromedrivermover when updating chrome 2024-07-04 00:17:16 -04:00
8447b6009a Gitea automation functions 2024-07-02 19:25:30 -04:00
62e8afebb8 aspect ratio calc function 2024-06-24 22:34:51 -04:00
e654611bf3 added devmode status message 2024-06-21 22:53:08 -04:00
6bf72336d0 Telegram return API result always 2024-06-18 15:24:45 -04:00
fd6be690da modularization and added functionality to download/update post scheduler 2024-06-08 18:27:56 -04:00
a3d89a9892 icon 2024-05-24 01:22:20 -04:00
a5bc6225b6 added openerrorlog and giteapage as shared goto 2024-05-22 23:51:48 -04:00
4ac3c76641 fixed tooltips 2024-05-22 23:42:06 -04:00
96a8fb9566 error log message updates 2024-05-22 23:37:32 -04:00
cf56ae8136 formatting and cleanup 2024-05-18 00:44:13 -04:00
738e1af443 merged modules 2024-05-17 23:36:39 -04:00
f71def4542 added chrome goto 2024-05-17 23:32:09 -04:00
20c2f44b0c added sample function call 2024-05-17 22:31:35 -04:00
997ee862ed bug fix for msgbox confirm function 2024-05-17 20:25:45 -04:00
b378de8106 function add and expansion 2024-05-17 19:36:18 -04:00
ed307493b8 renamed lib 2024-05-17 18:40:09 -04:00
2860e4868f formatting and cleanup 2024-05-16 14:46:11 -04:00
0e02ae24bd small bug fixes and improvements 2024-05-09 21:48:29 -04:00
b19482e10d readme 2024-05-09 15:37:36 -04:00
d7d3ce039f formatting, added reusable lib for update checks 2024-05-09 15:36:35 -04:00
8395c5c367 generate date ordinals function 2024-05-08 13:59:06 -04:00
124a26c3b0 fixed broken function, bit o' organization 2024-05-04 14:55:54 -04:00
b5c3b4a606 error checkign and general msgbox window 2024-05-03 12:52:49 -04:00
Yuriy
43dd2c3f28 expanded function 2024-05-02 00:29:19 -04:00
Yuriy
88c48e133e expanded function 2024-05-02 00:29:11 -04:00
Yuriy
2e0c81f34f merged misc and general functions 2024-05-01 14:22:34 -04:00
Yuriy
b8ffb10db1 improved chrome update functionality 2024-04-26 19:41:40 -04:00
Yuriy
5671242faf modularization and addition of Locals Specific Functions 2024-04-25 19:57:26 -04:00
Yuriy
8a532ac787 removed duplicate function 2024-04-20 19:19:42 -04:00
Yuriy
f20332d6c6 merged in misc functions from video uploader, modularized lbry functions into it's own file 2024-04-19 18:58:15 -04:00
Yuriy
f625e782eb removed reusetabs variable. Set to always be enabled 2024-04-17 17:28:54 -04:00
Yuriy
c18e9897ee bug fixes for when there are no errorlog filepath or discord webhook 2024-04-17 17:09:32 -04:00
Yuriy
075859934a bug fixes for when there are no errorlog filepath or discord webhook 2024-04-17 17:09:08 -04:00
Yuriy
88b4b2c119 small cleanup 2024-04-16 22:49:45 -04:00
Yuriy
e32fe026e9 made update chec failure silent instead of showing msgbox 2023-12-19 15:36:01 -05:00
981051a9e8 re-enabled logging to text file, updated+fixed URLdownloadtovar error message 2023-12-18 23:36:06 -05:00
Yuriy
f15d3ed2f0 updated URLs 2023-12-15 17:35:47 -05:00
Yuriy
05800d08a9 added automated compiler for Chromedriver-mover 2023-12-15 16:35:35 -05:00
Yuriy
7d967c7f33 Merge branch 'main' of https://freedomain.dev/yuriy/posters-shared-functions 2023-12-15 16:30:22 -05:00
Yuriy
1dd0557970 added chrome-driver mover tool 2023-12-15 16:30:12 -05:00
1e77871bd8 updated docs url 2023-12-11 13:27:57 -05:00
Yuriy
57e132fafd updated links to freedomain.dev 2023-12-11 13:20:38 -05:00
71b950c57f removed logging to text file due to causing selenium error bug for unknown reason 2023-11-03 22:42:43 -04:00
cf82847058 Fixed errors when gitea not available 2023-10-22 02:22:08 -04:00
cfce669061 chrome updater bug fixes 2023-10-22 01:19:49 -04:00
0b9b63b715 fixed chrome/chromedriver downloading 2023-10-22 00:28:38 -04:00
1962743565 added ability to automatically download newest chromium-testing and chromedriver 2023-09-20 20:45:12 -04:00
ca7145fa82 added ability to save statistic for selenium mouse clicks 2023-09-17 14:25:54 -04:00
1c000184df reworked selenium connection error message 2023-09-17 00:15:31 -04:00
7106ed522f added function to check if chrome needs update 2023-09-16 22:45:00 -04:00
74e67e5ab9 started on adding chrome/chromedriver auto downloading 2023-09-16 21:31:53 -04:00
f358623f86 Merge branch 'main' of https://git.freedomainplaylists.com/yuriy/Freedomain-Posters-Shared-Functions 2023-08-20 01:22:30 -04:00
7afb2274a2 added function to get latest stable chrome version, function to get URLs for chrome and chromedriver for that given version 2023-08-20 01:20:16 -04:00
324d5a177a code cleanup 2023-08-20 00:48:05 -04:00
ed887d5045 updated error message on selenium no connect 2023-08-20 00:42:10 -04:00
84c64bd428 removed discord messages for repetative messages so errorlog is easier to read 2023-08-20 00:36:38 -04:00
c6cf2a408a added function to send text to xpath element letter-by-letter 2023-07-30 22:14:41 -04:00
24 changed files with 1839 additions and 230 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
Chromedriver-Mover.exe

View File

@@ -1,10 +1,13 @@
;---FUNCTIONS----------------------------------------------------------------------- ;---FUNCTIONS-----------------------------------------------------------------------
; Misc Functions that are called by both the Video and Social Media poster ; Misc Functions that are called by both the Video and Social Media poster
; -------------------------------Discord------------------------------- ; -------------------------------Discord-------------------------------
PostToDiscordChannel(Message,WebhookChannel){ PostToDiscordChannel(Message,WebhookChannel){
; Don't try to post a message if there is no webhook url
if(WebhookChannel = "")
Return
; Msgbox % "Message: " Message ; Msgbox % "Message: " Message
; Msgbox % "WebhookChannel: " WebhookChannel ; Msgbox % "WebhookChannel: " WebhookChannel
@@ -28,8 +31,6 @@ PostToDiscordChannel(Message,WebhookChannel){
} }
) )
; Msgbox % "JsonString: " JsonString
;
try WebRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1") try WebRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1")
try WebRequest.Open("POST", WebhookChannel, false) try WebRequest.Open("POST", WebhookChannel, false)
try WebRequest.SetRequestHeader("Content-Type", "application/json") try WebRequest.SetRequestHeader("Content-Type", "application/json")
@@ -50,14 +51,14 @@ TelegramMsgBox(Text:="", TelegramBotToken := "", TelegramBotChatID :=""){
; Replace all forbidden characters - https://www.ascii-code.com/ ; Replace all forbidden characters - https://www.ascii-code.com/
; Text := StrReplace(Text, "`%", "%25") ; percent with
Text := StrReplace(Text, "`n", "%0A") ; New Line Text := StrReplace(Text, "`n", "%0A") ; New Line
; Text := StrReplace(Text, "`n", "%0A") ; New Line ; Text := StrReplace(Text, "`n", "%0A") ; New Line
; Text := StrReplace(Text, " ", "%23") ; New Line ; Text := StrReplace(Text, " ", "%23") ; New Line
; Text := ; Text :=
; Text := StrReplace(Text, "`n", "%0A") ; New Line ; Text := StrReplace(Text, "`n", "%0A") ; New Line
; Text := StrReplace(Text, "`%", "%25") ; percent with
; Msgbox % "Text: " Text ; Msgbox % "Text: " Text
ErrorLoggingPath = %A_ScriptDir%\Lib\ErrorLogging\check.rups ErrorLoggingPath = %A_ScriptDir%\Lib\ErrorLogging\check.rups
@@ -93,6 +94,7 @@ TelegramMsgBox(Text:="", TelegramBotToken := "", TelegramBotChatID :=""){
; -------------------------------/TelegramAPI------------------------------- ; -------------------------------/TelegramAPI-------------------------------
; Telegram Message API ; Telegram Message API
; https://core.telegram.org/bots/api
;------------------------------------------------ ;------------------------------------------------
SendTelegramMessage(token, chatID, text := "", ParseMode := "MarkdownV2") ; you could add more options; compare the Telegram API docs SendTelegramMessage(token, chatID, text := "", ParseMode := "MarkdownV2") ; you could add more options; compare the Telegram API docs
{ {
@@ -115,7 +117,7 @@ SendTelegramMessage(token, chatID, text := "", ParseMode := "MarkdownV2")
json_resp := whr.ResponseText json_resp := whr.ResponseText
whr := ; free COM object whr := ; free COM object
; Msgbox % "json_resp: " json_resp ; Msgbox % "json_resp: " json_resp
if(InStr(json_resp, "error_code")) ; if(InStr(json_resp, "error_code"))
Return json_resp Return json_resp
} }
@@ -142,6 +144,7 @@ pre-formatted fixed-width code block written in the Python programming language
; -------------------------------Telegram Image Sending------------------------------- ; -------------------------------Telegram Image Sending-------------------------------
; https://www.autohotkey.com/boards/viewtopic.php?t=68417 ; https://www.autohotkey.com/boards/viewtopic.php?t=68417
; https://core.telegram.org/bots/api
SendTelegramPhoto(token, chatID, file, caption := "", ParseMode := "MarkdownV2") ; you could add more options; compare the Telegram API docs SendTelegramPhoto(token, chatID, file, caption := "", ParseMode := "MarkdownV2") ; you could add more options; compare the Telegram API docs
{ {
@@ -164,7 +167,7 @@ SendTelegramPhoto(token, chatID, file, caption := "", ParseMode := "MarkdownV2")
whr := ; free COM object whr := ; free COM object
; Msgbox % "json_resp: " json_resp ; Msgbox % "json_resp: " json_resp
if(InStr(json_resp, "error_code")) ; if(InStr(json_resp, "error_code"))
Return json_resp Return json_resp
} }
@@ -192,7 +195,7 @@ SendTelegramVideo(token, chatID, file, caption := "", ParseMode := "MarkdownV2")
whr := ; free COM object whr := ; free COM object
; Msgbox % "json_resp: " json_resp ; Msgbox % "json_resp: " json_resp
if(InStr(json_resp, "error_code")) ; if(InStr(json_resp, "error_code"))
Return json_resp Return json_resp
} }
@@ -221,7 +224,7 @@ SendTelegramFile(token, chatID, file, caption := "", ParseMode := "MarkdownV2")
whr := ; free COM object whr := ; free COM object
; Msgbox % "json_resp: " json_resp ; Msgbox % "json_resp: " json_resp
if(InStr(json_resp, "error_code")) ; if(InStr(json_resp, "error_code"))
Return json_resp Return json_resp
} }

BIN
Assets/Icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

BIN
Assets/Icon.xcf Normal file

Binary file not shown.

BIN
Assets/Share.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View File

@@ -13,56 +13,396 @@ global DriverTitleArray
global LastWebsitePostURL global LastWebsitePostURL
global CurrentTabURL global CurrentTabURL
global URLOfLastErrorPage global URLOfLastErrorPage
global chromeDLURL64
global chromedriverDLURL64
global InstalledChromeVersion
; Chrome Related Functions ; Chrome Related Functions
;------------------------------------------------ ;------------------------------------------------
GetChromeFilepath(){ DownloadLatestChromium(){
; ChromeFilepath is global variable Message = Checking Variables for Downloading Newest Chrome
; Establish Variable with Filepath to be used throughout the script SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
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://freedomain.dev/attachments/b7b608b6-379a-42bb-a7c4-23fd67a05bb3
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
}
*/
; make sure all instances of chrome are closed
Loop, {
ChromeOpen := WinExist("ahk_exe chrome.exe")
if(ChromeOpen) {
Message = Chrome is Open. Asking user to close instances before continuing.
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
MsgBox 0x41, Chrome is Open, Please close all instances of Chrome and then click OK to continue with replacing Chrome with the newest version.
IfMsgBox OK, {
} Else IfMsgBox Cancel, {
ToolTip
return
}
}
else,
break
}
; make sure all instances of chromedriver.exe are closed
Message = Checking and killing any instances of the chromedriver.exe process
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
Loop, 5 {
Process, Exist, chromedriver.exe
ChromedriverExists := ErrorLevel
if(ChromedriverExists){
Message = Chromedriver Exists on check number %A_Index%
SaveOrPostProgress(Message:=Message,PostType:="ErrorLoggingTextFile,DiscordErrorLogging")
Process, Close, chromedriver.exe
sleep, 5000 ; wait 5 seconds before checking again
continue
}
else,
break
Message = Chrome Update Failed. Unable to kill background chromedriver.exe process
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
return
}
FileGetTime, ChromeDriverExeOldCreationTime, %ChromeDriverProgramFilesExeFilepath%, C
Message = Downloading Chromedriver v%ChromeStableLatestVersion% `nFrom: %chromedriverDLURL64%`nTo: %ChromeDriverDownloadZipFilepath%
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
UrlDownloadToFile, %chromedriverDLURL64%, %ChromeDriverDownloadZipFilepath%
Message = Downloading Chromium v%ChromeStableLatestVersion% `nfrom: %chromeDLURL64% to:`n%ChromeDownloadZipFilepath%`n(This might take 1-2 minutes)
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%
ChromeFilepath := ; clear out chromefilepath variable in case the path changed
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
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)){ if(FileExist(ChromePortableFilepath) or FileExist(ChromePortableFilepath2)){
if(FileExist(ChromePortableFilepath2))
ChromeFilepath := ChromePortableFilepath2
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:="ErrorLoggingTextFile,DiscordErrorLogging")
} }
else { else {
if(FileExist("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe")) Message = Chrome.exe not found in \Lib\
ChromeFilepath = C:\Program Files (x86)\Google\Chrome\Application\chrome.exe SaveOrPostProgress(Message,PostType:=",ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
if(FileExist("C:\Program Files\Google\Chrome\Application\chrome.exe")) MsgBox 0x10, Chrome Not Found, Chrome for Testing not found.`nIf this is your first time running on this computer, please click the "Chrome Up-To-Date" button to download the latest chrome binaries.
ChromeFilepath = C:\Program Files\Google\Chrome\Application\chrome.exe
} }
} }
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)
ChromeVersion := StrReplace(ChromeVersion, "`r")[1] ; replace any newline characters that powershell returns
return ChromeVersion 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 ; 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") json_str := urldownloadtovar("https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json")
@@ -79,30 +419,33 @@ GetURLofLatestChromedriver(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
; 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() { loop % parsed.versions[VersionIndex].downloads.chromedriver.count() {
; 64 bit version
if(parsed.versions[VersionIndex].downloads.chromedriver[A_Index].platform = "win64") if(parsed.versions[VersionIndex].downloads.chromedriver[A_Index].platform = "win64")
chromedriverDLURL64 := parsed.versions[VersionIndex].downloads.chromedriver[A_Index].url 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 break
} }
} }
; Msgbox % "chromedriverDLURL32: " chromedriverDLURL32 URLS = %chromeDLURL64%||%chromedriverDLURL64%
; Msgbox % "chromedriverDLURL64: " chromedriverDLURL64 return URLS
return chromedriverDLURL32
} }

View 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
View 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

Binary file not shown.

After

Width:  |  Height:  |  Size: 179 KiB

View File

@@ -102,15 +102,16 @@ TimedToolTip(Text, x="", y="",RemoveAfterTime:=2000, SetWhichToolTip="") {
; -------------------------------LogErrorsToTextFile------------------------------- ; -------------------------------LogErrorsToTextFile-------------------------------
Func_LogErrorsToTextFile(Text){ Func_LogErrorsToTextFile(Text){
; Do not log if we do not have an errorlog filepath
if(ErrorLoggingFilePath = "")
return
; ErrorLoggingFile := Filepath ; ErrorLoggingFile := Filepath
FormatTime, TodayDate , YYYYMMDDHH24MISS, yyyyMMdd_hhmmss FormatTime, TodayDate , YYYYMMDDHH24MISS, yyyyMMdd_hhmmss
text =
(
---------------%TodayDate%--------------- text =`n`n---------------%TodayDate%---------------`n%Text%
%Text%
)
FileAppend, %Text%, %ErrorLoggingFilePath% FileAppend, %Text%, %ErrorLoggingFilePath%
} }
; -------------------------------/LogErrorsToTextFile------------------------------- ; -------------------------------/LogErrorsToTextFile-------------------------------
@@ -132,6 +133,10 @@ CheckDirExistAndCreate(Path){
; -------------------------------/CheckDirExistAndCreate------------------------------- ; -------------------------------/CheckDirExistAndCreate-------------------------------
; Script Updates
; ------------------------------------------------
CheckIfUpdateAvailable(Filepath, CurrentVersion){ CheckIfUpdateAvailable(Filepath, CurrentVersion){
FileRead, ScriptUpdateContents, %Filepath% FileRead, ScriptUpdateContents, %Filepath%
@@ -370,50 +375,12 @@ Return Var
} }
; OnMsgbox Functions
;------------------------------------------------
OnMsgBoxUpdateAvailable() {
DetectHiddenWindows, On
Process, Exist
If (WinExist("ahk_class #32770 ahk_pid " . ErrorLevel)) {
ControlSetText Button1, Cancel
ControlSetText Button2, Install
}
}
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(){ 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 IniWrite, %InstalledChromeVersion%, Settings.ini, Misc, ChromeVersion
if(ChromeFilepath = "")
return
; Chromeversion := StrSplit(Chromeversion, "`n")
; Chromeversion := Chromeversion[4]
IniWrite, %ChromeVersion%, Settings.ini, Misc, ChromeVersion
} }
@@ -445,3 +412,286 @@ HasSubstringVal(haystack, needle)
; -------------------------------Functions-------------------------------
; https://www.autohotkey.com/docs/v2/Functions.htm#Variadic
Join(sep, params*) {
For index, param in params
str .= param . sep
return SubStr(str, 1, -StrLen(sep))
}
LogErrorToTextFile(Error){
/* if(LogErrorsToTextFile != 1)
Return
*/
ErrorLoggingFile := VideoFolderDir . "\" . "ErrorLogging.txt"
FormatTime, TodayDate , YYYYMMDDHH24MISS, yyyyMMdd_hhmmss
text =
(
---------------%TodayDate%---------------
%CurrentSite%: %Error%
)
if(LogErrorsToMsgbox)
Msgbox % "Text: " Text
FileAppend, %Text%, %ErrorLoggingFile%
} ; End of Function
/*
*/
AddToTotalVideosUploadedCount(){
; IniRead, TotalVideosUploaded, %SettingsIniFilepath%, General, TotalVideosUploaded, %A_Space%
TotalVideosUploaded += 1
; IniWrite, %TotalVideosUploaded%, %SettingsIniFilepath%, General, TotalVideosUploaded
}
Check_For_Stuck_Video_Upload(Index_Number, Upload_Status){
if(A_index = 1){ ; Create a blank array
ProgressStatusArray := []
Return
}
Message = Upload Status: %Upload_Status%
SaveOrPostProgress(Message:=Message,PostType:="Tooltip")
; if we reached the last loop number:
if(A_index = %Number_of_loops_to_Check_Upload_status%){
Message = Upload Most Likely Failed: Video Hasn't Finished Uploading after 1 hour.
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
SaveDriverURLOFErrorPage()
Return "Failed"
}
; If progress is still the same after a ten minute interval then error out
if(HasVal(Array_Index_Num_of_Upload_StatusChecks, A_index)){ ; if current index is in Array of index numbers to check status during
; Send a notification message of upload status
Message = Upload Status: %Upload_Status%
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
; if current upload_status is in the array of values that are updated every 10 mins
if(HasVal(ProgressStatusArray, Upload_Status)){
Message = Upload Failed (E#4508)`nUpload Stuck at same point for 10 minutes. Stuck Status: %ProgressStatus%
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
SaveDriverURLOFErrorPage()
Return "Failed"
}
ProgressStatusArray.Push(Upload_Status) ; append current status to array
}
} ; end of func
/*
*/
; Find the longest word in a string of words
FindLongestWordInString(m, calloutNumber, pos, haystack, pattern){
Global wordLength, longestWord
len := StrLen(m)
If ( len > wordLength )
{
wordLength := len
longestWord := m
; MsgBox, %m%
}
}
/*
*/
; Split a long string into multiple pieces based on the string lengtht you want and return an array with all strings
SplitStringWithSentences(text, maxChunkSize) {
sentences := StrSplit(text, "\. ") ; split at period with space after it
currentChunk := ""
chunks := []
Loop, % sentences.Length()
{
sentence := sentences[A_Index]
CurrentChunkAndSentence := currentChunk . sentence
; Msgbox % "CurrentChunkAndSentence: " CurrentChunkAndSentence
; msgbox % StrLen(CurrentChunkAndSentence)
if (StrLen(CurrentChunkAndSentence) <= maxChunkSize)
{
currentChunk .= sentence . "\. "
}
else
{
chunks.Push(currentChunk)
currentChunk := sentence . "\. "
}
}
if (currentChunk != "")
chunks.Push(currentChunk)
return chunks
}
CreateErrorLoggingFiles(Directory := ""){
FormatTime, TodayDate, YYYYMMDDHH24MISS, yyyyMMdd_hhmmss
ErrorLoggingDirectory := Directory
if(ErrorLoggingDirectory = ""){
ErrorLoggingDirectory := A_ScriptDir . "\Lib\ErrorLogging"
; If directory for error logging doesn't exist, create it
if(!FileExist(ErrorLoggingDirectory))
FileCreateDir, %ErrorLoggingDirectory%
ErrorLoggingDirectory := ErrorLoggingDirectory . "\" . TodayDate . "_" . ScriptAbbreviatedName
}
; Msgbox % "ErrorLoggingDirectory: " ErrorLoggingDirectory
FileCreateDir, %ErrorLoggingDirectory%
; Create variables with filepaths that content will be saved to.
global ErrorLoggingFilePath := ErrorLoggingDirectory . "\" . "ErrorLogging.txt"
global StatusFileFilePath := ErrorLoggingDirectory . "\" . "PostStatus.ini"
global PostTitleFilePath := ErrorLoggingDirectory . "\" . "PostTitle.txt"
global PostBodyFilePath := ErrorLoggingDirectory . "\" . "PostBody.txt"
global PostTagsFilePath := ErrorLoggingDirectory . "\" . "PostTags.txt"
PostStatusesFilepath := ErrorLoggingDirectory . "\" . "Status.ini"
; Msgbox % "ErrorLoggingDirectory: " ErrorLoggingDirectory
Return
}
; if passed argument is .exe file, then script has just been updated and we need to delete the old .exe file
CheckIfUpdateInstalled(PassedInArgument :=""){
if(InStr(PassedInArgument,".exe")){
FileDelete, %PassedInArgument%
if(ErrorLevel){ ; most likely because the old version hasn't finished exiting yet
Message = Failed to Delete Old .exe file after Updating
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar")
}
}
}
; https://www.autohotkey.com/boards/viewtopic.php?t=59936
GetDateOrdinalSuffix(D) {
Static Special := {1: "st", 2: "nd", 3: "rd", 21: "st", 22: "nd", 23: "rd", 31: "st"}
Return D . ((S := Special[D]) ? S : "th")
}
; Calculate the aspect ratio of a video/image using the width + height
getAspectRatio(width, height) {
gcd := gcdFunc(width, height)
return round(width/gcd) ":" round(height/gcd)
}
; The gcdFunc() is a helper function that calculates the GCD (greatest common divisor) of two numbers using the Euclidean algorithm.
; Used for calculating aspect ratio of Videos
gcdFunc(a, b) {
while b
t := b, b := Mod(a, b), a := t
return a
}
; OnMsgbox - Custom Msgbox Screens
;------------------------------------------------
ConfirmBeforeSubmitMsgboxFunc(){
/*
; Snippet to for check:
if (ConfirmBeforeSubmit && ConfirmBeforeSubmitMsgboxFunc() != true) {
Message = User Selected STOP button when asked for confirmation. Cancelling Rest of Site Upload.
SaveOrPostProgress(Message:=Message, PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
return
}
*/
OnMessage(0x44, "OnMsgBoxUserConfirmation")
MsgBox 0x21, User Confirmation, Please check that all data was input correctly and fix any mistakes and then click PROCEED to finalize the Upload.`n`nClick STOP to cancel the rest of this Upload and move on to the next website.
OnMessage(0x44, "")
IfMsgBox OK, {
return true
} Else IfMsgBox Cancel, {
Message = User Selected STOP button when asked for confirmation. Cancelling Rest of Site Upload.
Return %Message%
}
}
OnMsgBoxUpdateAvailable() {
DetectHiddenWindows, On
Process, Exist
If (WinExist("ahk_class #32770 ahk_pid " . ErrorLevel)) {
ControlSetText Button1, Cancel
ControlSetText Button2, Install
}
}
; Show a user confirmation msgbox with a PROCEED and STOP buttons
; Used by the "Confirm before Submit" checkbox
OnMsgBoxUserConfirmation() {
DetectHiddenWindows, On
Process, Exist
If (WinExist("ahk_class #32770 ahk_pid " . ErrorLevel)) {
ControlSetText Button1, PROCEED
ControlSetText Button2, STOP
}
}
OnMsgBoxConfirmChromiumOverwrite() {
DetectHiddenWindows, On
Process, Exist
If (WinExist("ahk_class #32770 ahk_pid " . ErrorLevel)) {
ControlSetText Button1, Cancel
ControlSetText Button2, Yes
}
}
OnMsgBoxPodcastFinish() {
DetectHiddenWindows, On
Process, Exist
If (WinExist("ahk_class #32770 ahk_pid " . ErrorLevel)) {
WinMove,, 0
}
}
OnMsgBoxSocialMediaPoster() {
DetectHiddenWindows, On
Process, Exist
If (WinExist("ahk_class #32770 ahk_pid " . ErrorLevel)) {
ControlSetText Button1, Yes
ControlSetText Button2, Not Now
}
}

View File

@@ -0,0 +1,47 @@
$apiurl=$args[0]
$apitoken=$args[1]
$filename=$args[2]
$filepath=$args[3]
Write-Host "apiurl: $apiurl"
Write-Host "apitoken: $apitoken"
Write-Host "filename: $filename"
Write-Host "filepath: $filepath"
# Load the required .NET assemblies
Add-Type -AssemblyName System.Net.Http
# Create Object and Load the required .NET assemblies
$httpClient = New-Object System.Net.Http.HttpClient
# $url = 'https://git.zinchuk.xyz/api/v1/repos/yuriy/TestRepo/releases/22/assets'
# $fileName = 'TestFile58.exe'
# $token = '2cf4a54d941'
$headers = @{
'accept' = 'application/json'
'Content-Type' = 'multipart/form-data'
}
# $filePath = "C:\Users\yuriy\Syncthing\Git\TestREpo\test.exe"
$fileBytes = [System.IO.File]::ReadAllBytes($filePath)
$fileStream = [System.IO.MemoryStream]::new($fileBytes)
$httpClient = [System.Net.Http.HttpClient]::new()
$httpClient.DefaultRequestHeaders.Add('Authorization', "Bearer $apitoken")
$multipartFormData = New-Object System.Net.Http.MultipartFormDataContent
$fileContent = New-Object System.Net.Http.StreamContent -ArgumentList $fileStream
$fileContent.Headers.ContentDisposition = New-Object System.Net.Http.Headers.ContentDispositionHeaderValue -ArgumentList "form-data"
$fileContent.Headers.ContentDisposition.Name = "attachment"
$fileContent.Headers.ContentDisposition.FileName = $fileName
# $fileContent.Headers.ContentType = [System.Net.Http.Headers.MediaTypeHeaderValue]::Parse("text/plain")
$fileContent.Headers.ContentType = [System.Net.Http.Headers.MediaTypeHeaderValue]::Parse("application/x-msdownload")
$multipartFormData.Add($fileContent)
$response = $httpClient.PostAsync($apiurl, $multipartFormData).Result
$responseContent = $response.Content.ReadAsStringAsync().Result
Write-Output $responseContent

62
Gitea-CreateRelease.ps1 Normal file
View File

@@ -0,0 +1,62 @@
<#
.SYNOPSIS
Create a new release on on a Gitea site using the Gitea API
.DESCRIPTION
The Add-Numbers function takes two integer parameters, $Number1 and $Number2,
and returns the sum of those two numbers.
.PARAMETER APIURL
The Repo Releases API URL of the Gitea site, including the API Key.
Example: "https://gitea.example.com/api/v1/repos/yuriy/TESTREPO/releases?token=aaabbbcccdd"
.PARAMETER ReleaseName
Name for the release that will be created
.PARAMETER ReleaseTag
Tag for the release that will be created
.PARAMETER ReleaseBody
Body Text for the release that will be created
.EXAMPLE
Gitea-CreateRelease.ps1 "https://gitea.example.com/api/v1/repos/yuriy/TESTREPO/releases?token=aaabbbcccdd" "1.0" "1.0" "Initial Release"
.NOTES
This function was created as an example for a PowerShell documentation demonstration.
.LINK
https://example.com/powershell-functions
#>
$APIURL=$args[0]
$ReleaseName=$args[1]
$ReleaseTag=$args[2]
$ReleaseBody=$args[3]
<#
Write-Host "APIURL: $APIURL"
Write-Host "ReleaseTag: $ReleaseTag"
Write-Host "ReleaseName: $ReleaseName"
Write-Host "ReleaseBody: $ReleaseBody"
#>
$headers = @{
"accept" = "application/json"
"Content-Type" = "application/json"
}
$body = @{
"body" = "${ReleaseBody}"
"draft" = $false
"name" = "${ReleaseTag}"
"prerelease" = $false
"tag_name" = "${ReleaseTag}"
# "target_commitish" = "string"
} | ConvertTo-Json
# Write-Host "body: " $body
$Result = Invoke-RestMethod -Uri $APIURL -Method Post -Headers $headers -Body $body
Write-Host $Result

View File

@@ -1,34 +1,28 @@
; GITEA Functions ; GITEA Functions
;------------------------------------------------ ;------------------------------------------------
CheckForUpdates(GitReleasesAPIURL){ CheckForUpdates(GitReleasesAPIURL, CurrentVersionNumber := 0){
; msgbox, checking for updates Message = Checking For Updates at %GitReleasesAPIURL%
Message = Checking For Updates
SaveOrPostProgress(Message,PostType:="ErrorLoggingTextFile") SaveOrPostProgress(Message,PostType:="ErrorLoggingTextFile")
data := URLDownloadToVar(GitReleasesAPIURL) data := URLDownloadToVar(GitReleasesAPIURL)
; Msgbox % "data: " data ; Msgbox % "data: " data
parsed := JSON.Load(data) try, parsed := JSON.Load(data)
catch e {
UpdateVersionNumber := parsed.1.name Message = Failed to check for updates. Gitea Releases API returned blank or malformed data.
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
; Message = UpdateVersionNumber: %UpdateVersionNumber% Return
; DevModeMsgBox(Message)
if(ScriptVersion = UpdateVersionNumber OR ScriptVersion > UpdateVersionNumber){
ToolTip
return 0
} }
else, {
LatestReleaseVersionNumber := parsed.1.name
if(CurrentVersionNumber >= LatestReleaseVersionNumber)
UpdateAvailable := 0
else,
UpdateAvailable := 1 UpdateAvailable := 1
; msgbox, update found!
Message = Program Update Found ToolTip
SaveOrPostProgress(Message:=Message,PostType:="ErrorLoggingTextFile") return UpdateAvailable
; IniWrite, 1, %SettingsIniFilepath%, %ScriptSettingsSection%, UpdateAvailable
; ToolTip
return 1
}
} }
@@ -36,26 +30,25 @@ CheckForUpdates(GitReleasesAPIURL){
UpdateScript(){ UpdateScript(){
data := URLDownloadToVar(GitReleasesAPIURL) 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 UpdateVersionNumber := parsed.1.name
ChangeLog := parsed.1.body ChangeLog := parsed.1.body
exename := parsed.1.assets.1.name exename := parsed.1.assets.1.name
exeURL := parsed.1.assets.1.browser_download_url exeURL := parsed.1.assets.1.browser_download_url
; Msgbox % "UpdateVersionNumber: " UpdateVersionNumber
; msgbox, Version: %Version%
; Msgbox % "ChangeLog: " ChangeLog
; Msgbox % "exeURL: " exeURL
; Msgbox % "exename: " exename
ExeName := StrReplace(exename, ".exe", "") ExeName := StrReplace(exename, ".exe", "")
UpdateExeName = %exename% %UpdateVersionNumber%.exe UpdateExeName = %exename% %UpdateVersionNumber%.exe
UpdateExeFilepath = %A_ScriptDir%\%UpdateExeName% UpdateExeFilepath = %A_ScriptDir%\%UpdateExeName%
if(ScriptVersion = UpdateVersionNumber){ if(ScriptVersion =< UpdateVersionNumber){
; IniWrite, 0, %SettingsIniFilepath%, %ScriptSettingsSection%, UpdateAvailable ; IniWrite, 0, %SettingsIniFilepath%, %ScriptSettingsSection%, UpdateAvailable
MsgBox, You are Up-To-Date MsgBox, You are Up-To-Date, There are no new updates to download.
; IniRead, UpdateAvailable, %SettingsIniFilepath%, %ScriptSettingsSection%, UpdateAvailable, 0 ; IniRead, UpdateAvailable, %SettingsIniFilepath%, %ScriptSettingsSection%, UpdateAvailable, 0
return return
} }
@@ -71,10 +64,12 @@ UpdateScript(){
} }
Else IfMsgBox No, { Else IfMsgBox No, {
SaveOrPostProgress(Message:="Downloading Update",PostType:="Tooltip,ErrorLoggingTextFile") SaveOrPostProgress(Message:="Downloading Update",PostType:="Tooltip,ErrorLoggingTextFile")
; Msgbox, downloading to: %A_ScriptDir%\%UpdateExeName%
UrlDownloadToFile, %exeURL%, %UpdateExeFilepath% UrlDownloadToFile, %exeURL%, %UpdateExeFilepath%
run, "%UpdateExeFilepath%" "%A_ScriptFullPath%" run, "%UpdateExeFilepath%" "%A_ScriptFullPath%"
ExitApp ExitApp
} }
return return
} }

63
Gitea-Functions.ps1 Normal file
View File

@@ -0,0 +1,63 @@
<#
.SYNOPSIS
Adds two numbers and returns the result.
.DESCRIPTION
The Add-Numbers function takes two integer parameters, $Number1 and $Number2,
and returns the sum of those two numbers.
.PARAMETER Number1
The first number to add.
.PARAMETER Number2
The second number to add.
.EXAMPLE
$sum = Add-Numbers -Number1 5 -Number2 10
Write-Host "The sum is: $sum"
.NOTES
This function was created as an example for a PowerShell documentation demonstration.
.LINK
https://example.com/powershell-functions
#>
$APIURL=$args[0]
$ReleaseName=$args[1]
$ReleaseTag=$args[2]
$ReleaseBody=$args[3]
function CreateRelease {
param (
[string]$APIURL,
[string]$ReleaseName,
[string]$ReleaseID,
[string]$ReleaseBody,
)
$headers = @{
"accept" = "application/json"
"Content-Type" = "application/json"
}
$body = @{
"body" = "${ReleaseBody}"
"draft" = $false
"name" = "${ReleaseTag}"
"prerelease" = $false
"tag_name" = "${ReleaseTag}"
"target_commitish" = "string"
} | ConvertTo-Json
# Write-Host "body: " $body
$Result = Invoke-RestMethod -Uri $APIURL -Method Post -Headers $headers -Body $body
Write-Host $Result
}
Write-FullName -FirstName "John" -LastName "Doe"

149
LBRY-Functions.ahk Normal file
View File

@@ -0,0 +1,149 @@
CheckLBRYProcess(){
; Check if LBRY Process exists
Process, Exist,LBRY.exe
if(ErrorLevel = 0) ; if doesn't exist
{
Message = Not Running. Starting up LBRY.exe
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
LBRYExeFilepath = C:\Program Files\LBRY\LBRY.exe
if(!FileExist(LBRYExeFilepath)){
Message = Failed to Find LBRY.exe executable. LBRY not installed?
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
Return
}
Message = Checking LBRY daemon_settings.yml file for Odysee Wallet Servers
SaveOrPostProgress(Message:=Message,PostType:=",ErrorLoggingTextFile,DiscordErrorLogging")
; FileRead, daemon_settingsFileContent, C:\Users\%A_UserName%\AppData\Local\lbry\lbrynet\daemon_settings.yml
; if(!InStr(daemon_settingsFileContent, "a-hub1.odysee.com")){
; Message = Odysee wallet server is not in daemon_settings.yml. Replacing File with required settings.
; SaveOrPostProgress(Message:=Message,PostType:=",DiscordErrorLogging")
; LBRYDaemonSettingsFP = C:\Users\%A_UserName%\AppData\Local\lbry\lbrynet\daemon_settings.yml
; LBRYDaemonSettingsBackupFP = C:\Users\%A_UserName%\AppData\Local\lbry\lbrynet\daemon_settings_BU.yml
; ; Msgbox % "daemon_settingsText: " daemon_settingsText
; FileMove, %LBRYDaemonSettingsFP%, %LBRYDaemonSettingsBackupFP%, 1 ; Dest [, Flag (1 = overwrite)]
; UrlDownloadToFile, https://freedomain.dev/yuriy/video-uploader/raw/branch/main/Assets/daemon_settings.yml , %LBRYDaemonSettingsFP%
; sleep, 1000
; if(!FileExist(LBRYDaemonSettingsFP)){
; Message = Failed to download the custom daemon_settings.yml file from git. Restoring Original File
; SaveOrPostProgress(Message:=Message,PostType:=",ErrorLoggingTextFile,DiscordErrorLogging")
; FileMove,%LBRYDaemonSettingsBackupFP%,%LBRYDaemonSettingsFP%, 1
; }
; }
try run, "%LBRYExeFilepath%"
Message = Waiting 1 Minute for LBRY to start up
SaveOrPostProgress(Message:=Message,PostType:="Tooltip")
Sleep, 60000 ; 1 minute
Process, Exist,LBRY.exe
if(ErrorLevel = 0) ; if doesn't exist
{
Message = Failed to Start LBRY.exe after 60 seconds of waiting
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
Return
}
WinMinimize, LBRY
}
Return
}
GetPermanentLBRYURL(UploadResult){
SingleQuotationmark = "
UploadResult := StrSplit(UploadResult, "`n") ; split results by new line
; Iterate through the array of the results
Loop % UploadResult.Length() {
PermanentURL := UploadResult[A_Index]
if(InStr(PermanentURL, "permanent_url"))
Break
}
; Starting Result: "permanent_url": "lbry://Test-Video-161-Numbered#c9ad9afe54c7178d6f870b59bbe129aef8efc3ff",
PermanentURL := StrSplit(PermanentURL, "lbry:")
PermanentURL := "lbry:" . PermanentURL[2]
PermanentURL := StrReplace(PermanentURL, ",", "")
PermanentURL := StrReplace(PermanentURL, SingleQuotationmark, "")
PermanentURL := StrReplace(PermanentURL, "`n", "")
PermanentURL := StrReplace(PermanentURL, "`r", "")
; End Result lbry://Test-Video-161-Numbered#c9ad9afe54c7178d6f870b59bbe129aef8efc3ff
Return PermanentURL
}
GetLBRYCanonicalURL(LBRYJSONObject){ ; input json string
; ResolveURL := StrSplit(LBRYResolveAPICommand, "lbry://")
; ResolveURL := "lbry://" . ResolveURL[2]
; StrReplace(Haystack, SearchText [, ReplaceText, OutputVarCount, Limit := -1])
LBRYPermanentURLJsonOBJ := StrReplace(LBRYJSONObject, LBRYPermanentURL, "LBRYPermanentURL")
; clipboard := LBRYPermanentURLJsonOBJ
; DevModeMsgBox(LBRYPermanentURLJsonOBJ)
try parsed := JSON.Load(LBRYPermanentURLJsonOBJ)
try LBRYCanonicalURL := parsed.LBRYPermanentURL.canonical_url
; DevModeMsgBox(LBRYCanonicalURL)
if(LBRYCanonicalURL = ""){
Return "" ; return blank
}
; otherwise return the LBRY url
LBRYCanonicalURL := StrReplace(LBRYCanonicalURL, "lbry://", "https://lbry.tv/")
Return LBRYCanonicalURL
}
LBRYCMDTextReplacement(LBRYURLSlug){
SingleQUote = "
LBRYURLSlug := StrReplace(LBRYURLSlug, " ", "_") ; replace all spaces with dashes
LBRYURLSlug := StrReplace(LBRYURLSlug, ":", "_") ; replace all colons with dashes
LBRYURLSlug := StrReplace(LBRYURLSlug, ",", "_") ; replace all colons with dashes
LBRYURLSlug := StrReplace(LBRYURLSlug, "?", "") ; replace all colons with dashes
LBRYURLSlug := StrReplace(LBRYURLSlug, "!", "") ; replace all colons with dashes
LBRYURLSlug := StrReplace(LBRYURLSlug, "`;", "_") ; replace all colons with dashes
LBRYURLSlug := StrReplace(LBRYURLSlug, "/", "_") ; replace all colons with dashes
; LBRYURLSlug := StrReplace(LBRYURLSlug, "?", "") ; replace all colons with dashes
LBRYURLSlug := StrReplace(LBRYURLSlug, "<", "_") ; replace all colons with dashes
LBRYURLSlug := StrReplace(LBRYURLSlug, ">", "_") ; replace all colons with dashes
LBRYURLSlug := StrReplace(LBRYURLSlug, SingleQUote, "") ; replace all colons with dashes
LBRYURLSlug := StrReplace(LBRYURLSlug, "'", "") ; replace all colons with dashes
LBRYURLSlug := StrReplace(LBRYURLSlug, "=", "") ; replace all colons with dashes
LBRYURLSlug := StrReplace(LBRYURLSlug, ";", "") ; replace all colons with dashes
LBRYURLSlug := StrReplace(LBRYURLSlug, ")", "") ; replace all colons with dashes
LBRYURLSlug := StrReplace(LBRYURLSlug, "(", "") ; replace all colons with dashes
LBRYURLSlug := StrReplace(LBRYURLSlug, "___", "_") ; replace all colons with dashes
LBRYURLSlug := StrReplace(LBRYURLSlug, "__", "_") ; replace all colons with dashes
LBRYURLSlug := StrReplace(LBRYURLSlug, "__", "_") ; replace all colons with dashes
Return LBRYURLSlug
}
GetLBRYAPIErrorFromString(UploadResult){
UploadResultArray := StrSplit(UploadResult, "message")
LBRYAPIError := UploadResultArray[2]
; LBRYAPIErrorStrLen := StrLen(LBRYAPIError)
; LBRYAPIErrorStrToTrim := LBRYAPIErrorStrLen - 3
; Msgbox % "LBRYAPIErrorStrToTrim: " LBRYAPIErrorStrToTrim
LBRYAPIError := SubStr(LBRYAPIError, 4)
LBRYAPIError := StrReplace(LBRYAPIError, "}", "")
; Msgbox % "LBRYAPIError: " LBRYAPIError
Return LBRYAPIError
}

54
Locals-Functions.ahk Normal file
View File

@@ -0,0 +1,54 @@
; Iterate over Locals posts on the home page until found post with title
; ------------------------------------------------
GrabLocalsPostURLUsingTitle(PostTitle){
Loop, 10 {
Message = Checking Post %A_index% on page for Post Titled`n%PostTitle%
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
ToolTip, %A_Index%
; first two items can be skipped.
; new Post box and Create other forms of posts box
if(A_index < 3)
Continue
; Xpath for each post box on the main page
Xpath = //body/div/div/div/div/div/div[1]/div[%A_Index%]
try ElementInnerText := driver.findelementbyxpath(Xpath).Attribute("innerText") ;XPATH Inner Text
Try ElementOuterHTML := driver.findelementbyxpath(Xpath).Attribute("outerHTML") ;XPATH-ID & Tag
if(Devmode){
Msgbox % "ElementInnerText: " ElementInnerText "`n" "ElementOuterHTML: " ElementOuterHTML
}
if(InStr(ElementInnerText, PostTitle)){
Message = Found Post Title in Element Number: %A_index%
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
; Pull Out the Post URL from the OuterHTML using RegEx
regexMatch := RegExMatch(ElementOuterHTML, "data-post-url=""([^""]+)""", match)
if (regexMatch)
{
PostURL := match1
Message = URL Pulled out from OuterHTML: %PostURL%
Return PostURL
}
else {
Message = Failed to Pull out URL from OuterHTML
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
Return "Failed"
}
}
}
Message = Failed to find New Post in the first 10 posts
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
Return "Failed"
}

View File

View File

@@ -1,4 +1,5 @@
Function Libraries used in the following Projects: Function Libraries used in the following Projects:
- [Freedomain Social Media Poster](https://git.freedomainplaylists.com/yuriy/Freedomain-Social-Media-Poster) - [Freedomain Social Media Poster](https://freedomain.dev/yuriy/social-media-poster)
- [Freedomain Video Uploader](https://git.freedomainplaylists.com/yuriy/Freedomain-Video-Uploader) - [Freedomain Video Uploader](https://freedomain.dev/yuriy/video-uploader)
- [Freedomain Reposter](https://git.freedomainplaylists.com/yuriy/Freedomain-Reposter) - [Freedomain Clips Uploader](https://freedomain.dev/yuriy/clips-uploader)
- [Freedomain Livestream Scheduler](https://freedomain.dev/yuriy/livestream-scheduler)

View File

@@ -2,11 +2,10 @@
;------------------------------------------------ ;------------------------------------------------
; Selenium Related Functions ; Selenium Related Functions
global MouseClicksSaved
ShowSeleniumErrorMsgbox(){ ShowSeleniumErrorMsgbox(){
; Clipboard := ChromeVersion
; Msgbox % "Chromeversion: " Chromeversion
IniRead, PreviousWorkingChromeVersion, Settings.ini, Misc, ChromeVersion, %A_Space% IniRead, PreviousWorkingChromeVersion, Settings.ini, Misc, ChromeVersion, %A_Space%
; IniWrite, %ChromeVersion%, Settings.ini, Misc, ChromeVersion ; IniWrite, %ChromeVersion%, Settings.ini, Misc, ChromeVersion
; msgbox, failed to connect to Chrome for some reason. ; msgbox, failed to connect to Chrome for some reason.
@@ -14,27 +13,44 @@ ShowSeleniumErrorMsgbox(){
; SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging") ; SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
OnMessage(0x44, "OnMsgBoxChromeDriverFailed") 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, "") OnMessage(0x44, "")
IfMsgBox Yes, {
; 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
IfMsgBox Yes, {
; Reload script
Reload
} Else IfMsgBox No, {
run, https://chromedriver.chromium.org/downloads run, https://chromedriver.chromium.org/downloads
ExitApp run, "%A_ScriptFullPath%" "LastPost"
; open chromedriver site ; open chromedriver site
} Else IfMsgBox Cancel, { } Else IfMsgBox Cancel, {
URL = https://git.freedomainplaylists.com/yuriy/Freedomain-Social-Media-Poster#installation ; Reload with last post
run, %url% run, "%A_ScriptFullPath%" "LastPost"
} }
ExitApp 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------------------------------- ; -------------------------------Tab Navigation & Activation-------------------------------
@@ -57,7 +73,6 @@ CheckSeleniumDriver(){
} }
DriverStatus := 1 DriverStatus := 1
if(ReuseTabs)
CreateArrayOfChromeTabs() CreateArrayOfChromeTabs()
@@ -183,12 +198,12 @@ CheckCurrentTabForCurrentSite(){
if(!InStr(CurrentTabURL, CurrentSite)){ if(!InStr(CurrentTabURL, CurrentSite)){
Message = Chromedriver failed to switch to %CurrentSite%. Current Tab URL: %CurrentTabURL% 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" return "Failed"
} }
else, { else, {
Message = CheckCurrentTabForCurrentSite() passed successfully Message = CheckCurrentTabForCurrentSite() passed successfully
SaveOrPostProgress(Message:=Message,PostType:="ErrorLoggingTextFile,DiscordErrorLogging") SaveOrPostProgress(Message:=Message,PostType:="ErrorLoggingTextFile")
} }
} }
/* /*
@@ -226,8 +241,8 @@ NavigateFromBaseURLTo(URL,PageTitle := "TodoDeleteme"){
; extract Base URL from Full URL ; extract Base URL from Full URL
URLBase := ExtractBaseURL(URL) URLBase := ExtractBaseURL(URL)
Message = Checking for URLBase: %URLBase% within ChromeTabsURLArray ; Message = Checking for URLBase: %URLBase% within ChromeTabsURLArray
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging") ; SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
; msgbox % HasSubstringVal(ChromeTabsURLArray, URLBase) . "`n`n is the status of URLbase in ChromeTabsURLArray" ; msgbox % HasSubstringVal(ChromeTabsURLArray, URLBase) . "`n`n is the status of URLbase in ChromeTabsURLArray"
@@ -235,7 +250,7 @@ NavigateFromBaseURLTo(URL,PageTitle := "TodoDeleteme"){
if(!HasSubstringVal(ChromeTabsURLArray, URLBase)) if(!HasSubstringVal(ChromeTabsURLArray, URLBase))
{ {
; DevModeMsgBox("Creating new tab") ; 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") SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
try, run "%ChromeFilepath%" "%URL%" try, run "%ChromeFilepath%" "%URL%"
@@ -394,12 +409,12 @@ ActivateChromeTab(URL){
if(A_index < 3){ if(A_index < 3){
if(CurrentTabURL = StartingTabURL){ if(CurrentTabURL = StartingTabURL){
Message = Current Tab URL is THE SAME as Starting URL after %A_index% tab switches`nStuck on this tab? 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() CheckForAlerts()
} }
else, { else, {
Message = Current Tab URL is DIFFERENT from starting URL after %A_index% tab switches 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){ if(LastActiveTab = CurrentTabURL){
@@ -429,7 +444,7 @@ ActivateChromeTab(URL){
; / loop through tabs ; / loop through tabs
} }
Message = ActivateChromeTab function failed to activate tab for %urlBase% after looping through %NumberOfTabActivationLoops% 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" return "Failed"
} }
@@ -438,7 +453,7 @@ ActivateChromeTab(URL){
CheckForAlerts(){ CheckForAlerts(){
Message = Checking for Any Obstructing Alerts in Chrome Message = Checking for Any Obstructing Alerts in Chrome
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging") SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
status := 1 status := 1
try driver.SwitchToAlert() try driver.SwitchToAlert()
@@ -450,7 +465,7 @@ CheckForAlerts(){
if(status){ if(status){
; msgbox, alert found ; msgbox, alert found
; Message = Page Alert Found. Dismissing. ; 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") SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
try driver.switchToalert().accept() try driver.switchToalert().accept()
; try driver.switchToalert().dismiss() ; try driver.switchToalert().dismiss()
@@ -519,7 +534,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")){
@@ -655,6 +670,7 @@ Selenium_LoopToClickID(IDName,NumOfLoops:=1,SleepLength:=1000){
sleep, %SleepLength% sleep, %SleepLength%
Continue Continue
} }
MouseClicksSaved += 1
Return Return
} }
} }
@@ -670,6 +686,7 @@ Selenium_LoopToClickName(ElementName,NumOfLoops:=1,SleepLength:=1000){
sleep, %SleepLength% sleep, %SleepLength%
Continue Continue
} }
MouseClicksSaved += 1
Return Return
} }
} }
@@ -703,10 +720,28 @@ Selenium_LoopToSendValueByName(ElementName,NumOfLoops:=1,SleepLength:=1000,Strin
} }
} }
Selenium_LoopToSendValueToXpath(Xpath,NumOfLoops:=1,SleepLength:=1000,StringTextContent:=""){ Selenium_LoopToSendValueToXpath(Xpath,NumOfLoops:=1,SleepLength:=1000,StringTextContent:="",ClearElement:=0){
loop, %NumOfLoops% { loop, %NumOfLoops% {
; ToolTip, Loop attempt: %A_index%
try driver.FindElementByXPath(Xpath).sendKeys(StringTextContent) ; Click on "upload image" button if(ClearElement){
Loop, 3 { ; sometimes have to do it multiple times to make it trigger properly
Try PreviousValue := driver.findelementbyxpath(Xpath).Attribute("value") ;Xpath Value
try, driver.FindElementByXPath(Xpath).clear()
Try CurrentValue := driver.findelementbyxpath(Xpath).Attribute("value") ;Xpath Value
if(PreviousValue != CurrentValue){
break
}
sleep, 1000
; msgbox
}
}
try driver.FindElementByXPath(Xpath).sendKeys(StringTextContent) ; Input Text
catch e { catch e {
if(A_index = NumOfLoops){ if(A_index = NumOfLoops){
Return "Failed" Return "Failed"
@@ -729,6 +764,7 @@ Selenium_LoopToClickXpath(Xpath,NumOfLoops:=1,SleepLength:=1000){
sleep, %SleepLength% sleep, %SleepLength%
Continue Continue
} }
MouseClicksSaved += 1
Return Return
} }
} }
@@ -754,30 +790,96 @@ Selenium_LoopToClickXpathAndWaitForOpenWindow(Xpath,NumOfLoops:=1,SleepLength:=1
sleep, %SleepLength% sleep, %SleepLength%
Continue Continue
} }
MouseClicksSaved += 1
Return Return
} }
} }
Selenium_LoopToClearXpath(Xpath,NumOfLoops:=1,SleepLength:=1000){ Selenium_LoopToClearXpath(Xpath,NumberOfAttemps:=1,SleepLength:=1000){
loop, %NumOfLoops% { loop, %NumberOfAttemps% {
try driver.FindElementByXPath(Xpath).clear() try driver.FindElementByXPath(Xpath).clear()
catch e { catch e {
if(A_index = NumOfLoops){
Return "Failed" Return "Failed"
} }
sleep, %SleepLength% sleep, %SleepLength%
Continue
try, InerText := driver.findelementbyxpath(Xpath).Attribute("value")
; Msgbox % "InerText: " InerText
if(InerText = "")
return
if(A_index = NumberOfAttemps){
return "Failed after %NumberOfAttemps"
} }
Return
Continue
; Return
} }
} }
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 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 try URLOfLastErrorPage := driver.URL
} }
GetHTMLValueFromXpathOuterHTML(XPATH, HTMLElementName){
Try ElementOuterHTML := driver.findelementbyxpath(Xpath).Attribute("outerHTML") ;XPATH-ID & Tag
; try Clipboard := driver.findelementbyxpath(Xpath).Attribute("outerHTML") ;XPATH-ID & Tag
; Try MsgBox,,Element OuterHTML: `n, % driver.findelementbyxpath(Xpath).Attribute("outerHTML") ;XPATH-ID & Tag
; Match string between quotes following the HTMLELEMENTNAME
RegexStatement = %HTMLElementName%="([^"]+)"
; regexMatch := RegExMatch(ElementOuterHTML, "value=""([^""]+)""", match)
regexMatch := RegExMatch(ElementOuterHTML, RegexStatement, match)
if (regexMatch)
{
ElementValue := match1
; Msgbox % "PostURL: " PostURL
; Message = URL Pulled out from OuterHTML: %PostURL%
Return ElementValue
}
else {
Message = Failed to Pull out value from OuterHTML
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
Return "Failed"
}
}
;---\Selenium--- ;---\Selenium---
;------------------------------------------------ ;------------------------------------------------

197
Shared-GoTos.ahk Normal file
View File

@@ -0,0 +1,197 @@
; This #include needs to be at the bottom of the parent script
CheckForUpdates:
UpdateStartTime := A_TickCount ; start time
; The GUI buttons must have variable set to vUpdateAvailable and vChromeUpdateAvailable for button to get updated
; The following variables need to be set in the parent script
; GitReleasesAPIURL
; ChromeFilepath
Message = Checking for Updates
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
if(CheckForUpdates(GitReleasesAPIURL, ScriptVersion)){
GuiControl,,UpdateAvailable, Update Available!
}
; check for Post Scheduler Update
if(ScriptNameAcronym = "FVU"){
if(CheckForUpdates(PostSchedulerGitReleasesAPIURL, PostSchedulerVersion)){
GuiControl,,PostSchedulerUpdateAvailable, FPS Update Available!
}
}
if(CheckForChromeUpdates(ChromeFilepath)){
GuiControl,,ChromeUpdateAvailable, Chrome Update Available!
ChromeUpdateAvailable := 1
}
; calculate run time and convert to seconds
TimeToCheckforUpdates := round(((A_TickCount - UpdateStartTime) / 1000), 2)
Message = Update Check took %TimeToCheckforUpdates% seconds to complete
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
; Msgbox % "TimeToCheckforUpdates: " TimeToCheckforUpdates
; Msgbox % "URunTime: " URunTime
ToolTip
Return
; UpdatePostScheduler:
Return
UpdateChrome:
; if chroem doesn't exist, download it
if(ChromeFilepath = ""){
Status := DownloadLatestChromium()
if(Status)
GuiControl,,ChromeUpdateAvailable, Chrome Up-To-Date
Return
}
if(CheckForChromeUpdates = "")
Status := CheckForChromeUpdates(ChromeFilepath)
if(!status){
OnMessage(0x44, "OnMsgBoxConfirmChromiumOverwrite")
MsgBox 0x41, Already Up-to-Date, Yor current Chromium version is already up to date. `nDo you want to download and overwrite it?
OnMessage(0x44, "")
IfMsgBox OK, {
Return
} Else IfMsgBox Cancel, {
ToolTip
}
}
Status := DownloadLatestChromium()
if(Status)
GuiControl,,ChromeUpdateAvailable, Chrome Up-To-Date
Return
/*
*/
PasteClipboardToEditBox:
if(A_GuiControl = "PasteClipboardToSMPBody"){
GuiControl,,PostBody, %Clipboard%
}
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
OpenErrorLog:
run, %ErrorLoggingFilePath%
Return
OpenGiteaPage:
if(ScriptAbbreviatedName = "FLS")
URL = https://freedomain.dev/yuriy/livestream-scheduler
if(ScriptAbbreviatedName = "FVU")
URL = https://freedomain.dev/yuriy/video-uploader
if(ScriptAbbreviatedName = "FSMP")
URL = https://freedomain.dev/yuriy/social-media-poster
run, %URL%
Return
UpdatePostScheduler:
; Close any existing instances of the Post Scheduler
; Kill any active intances of the Post Scheduler so the .exe file can be overwriten
process, close, Freedomain Post Scheduler.exe
; Msgbox % "PostSchedulerGitReleasesAPIURL: " PostSchedulerGitReleasesAPIURL
data := URLDownloadToVar(PostSchedulerGitReleasesAPIURL)
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
exename := parsed.1.assets.1.name
exeURL := parsed.1.assets.1.browser_download_url
; Msgbox % "exename: " exename
; ExeName := StrReplace(exename, ".exe", "")
; UpdateExeName = %exename%.exe
UpdateExeFilepath = %A_ScriptDir%\%ExeName%
if(PostSchedulerVersion =< UpdateVersionNumber){
; IniWrite, 0, %SettingsIniFilepath%, %ScriptSettingsSection%, UpdateAvailable
MsgBox, You are Up-To-Date, There are no new updates to download.
; IniRead, UpdateAvailable, %SettingsIniFilepath%, %ScriptSettingsSection%, UpdateAvailable, 0
return
}
Changelog = %PostSchedulerVersion% --> %UpdateVersionNumber%`n`nChangelog:`n%Changelog%
OnMessage(0x44, "OnMsgBoxUpdateAvailable")
MsgBox 0x44, Update Available For %exename%, %Changelog%
OnMessage(0x44, "")
IfMsgBox Yes, {
Return
}
Else IfMsgBox No, {
SaveOrPostProgress(Message:="Downloading Update",PostType:="Tooltip,ErrorLoggingTextFile")
if(FileExist(UpdateExeFilepath)){
FileDelete, %UpdateExeFilepath%
if(ErrorLevel){
Message = Failed to Delete %UpdateExeFilepath%. `nPlease Close the process manually and try the update again.
MsgBox 0x10,, %Message%
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
Return
}
}
UrlDownloadToFile, %exeURL%, %UpdateExeFilepath%
run, "%UpdateExeFilepath%" "%A_ScriptFullPath%"
ToolTip
; ExitApp
}
return

View File

@@ -1,61 +1,21 @@
;---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){ URLDownloadToVar(url){
hObject:=ComObjCreate("WinHttp.WinHttpRequest.5.1") hObject:=ComObjCreate("WinHttp.WinHttpRequest.5.1")
hObject.Open("GET",url) Try, hObject.Open("GET",url)
catch e {
Message = Error Ocurred when trying to do GET Request using URLDownloadToVar to`n: %URL%
SaveOrPostProgress(Message:=Message,PostType:=",ErrorLoggingTextFile,ErrorSummaryVar")
}
try {
hObject.Send() hObject.Send()
}
catch e {
Message = Error Ocurred when trying to hObject.Send() with URLDownloadToVar Function
SaveOrPostProgress(Message:=Message,PostType:=",ErrorLoggingTextFile,ErrorSummaryVar")
; MsgBox, 4096, Error, Failed to connect to:`n`n%url%`n`nAre you connected to the internet? Or is the website down?`n`nDisable Auto Update Check to disable this message.
return ""
}
return hObject.ResponseText return hObject.ResponseText
} }

1
Update-Functions.ahk Normal file
View File

@@ -0,0 +1 @@
; Code migrated to Shared-GoTo's

View File

@@ -0,0 +1,98 @@
; https://www.autohotkey.com/boards/viewtopic.php?t=112391
; Usage:
; cred := CredRead("CREDENTIALNAME", NewlineInPassword := 1)
; Username := cred.username
; Password := cred.password
; msgbox % cred.username
; msgbox % cred.password
; Functions
;------------------------------------------------
CredWrite(name, username, password)
{
VarSetCapacity(cred, 24 + A_PtrSize * 7, 0)
cbPassword := StrLen(password)*2
NumPut(1 , cred, 4+A_PtrSize*0, "UInt") ; Type = CRED_TYPE_GENERIC
NumPut(&name , cred, 8+A_PtrSize*0, "Ptr") ; TargetName = name
NumPut(cbPassword, cred, 16+A_PtrSize*2, "UInt") ; CredentialBlobSize
NumPut(&password , cred, 16+A_PtrSize*3, "UInt") ; CredentialBlob
NumPut(3 , cred, 16+A_PtrSize*4, "UInt") ; Persist = CRED_PERSIST_ENTERPRISE (roam across domain)
NumPut(&username , cred, 24+A_PtrSize*6, "Ptr") ; UserName
return DllCall("Advapi32.dll\CredWriteW"
, "Ptr", &cred ; [in] PCREDENTIALW Credential
, "UInt", 0 ; [in] DWORD Flags
, "UInt") ; BOOL
}
CredDelete(name)
{
return DllCall("Advapi32.dll\CredDeleteW"
, "WStr", name ; [in] LPCWSTR TargetName
, "UInt", 1 ; [in] DWORD Type,
, "UInt", 0 ; [in] DWORD Flags
, "UInt") ; BOOL
}
CredRead(name,NewlineInUsername:=0, NewlineInPassword:=0)
{
DllCall("Advapi32.dll\CredReadW"
, "Str", name ; [in] LPCWSTR TargetName
, "UInt", 1 ; [in] DWORD Type = CRED_TYPE_GENERIC (https://learn.microsoft.com/en-us/windows/win32/api/wincred/ns-wincred-credentiala)
, "UInt", 0 ; [in] DWORD Flags
, "Ptr*", pCred ; [out] PCREDENTIALW *Credential
, "UInt") ; BOOL
if !pCred{
; Username
InputBox, Username, Input Username, Username not found. `nPlease Input Username for: `n--%name%--,,,,,,,,%Clipboard% ; , Prompt, HIDE, Width, Height, X, Y, Font, Timeout, Default]
if(ErrorLevel)
return
InputBox, Password, Input Password, Password not found. `nPlease Input Password for: `n--%name%--,,,,,,,,%Clipboard% ; , Prompt, HIDE, Width, Height, X, Y, Font, Timeout, Default]
if(ErrorLevel)
return
if !CredWrite(name, Username, Password)
MsgBox failed to write cred
else, { ; try reading the credential that was just saved
DllCall("Advapi32.dll\CredReadW"
, "Str", name ; [in] LPCWSTR TargetName
, "UInt", 1 ; [in] DWORD Type = CRED_TYPE_GENERIC (https://learn.microsoft.com/en-us/windows/win32/api/wincred/ns-wincred-credentiala)
, "UInt", 0 ; [in] DWORD Flags
, "Ptr*", pCred ; [out] PCREDENTIALW *Credential
, "UInt") ; BOOL
}
if !pCred{
msgbox, Failed to read cred. after writing it to Credential Manager.
return
}
}
name := StrGet(NumGet(pCred + 8 + A_PtrSize * 0, "UPtr"), 256, "UTF-16")
; append new line to end if requested
if(NewlineInUsername)
username := StrGet(NumGet(pCred + 24 + A_PtrSize * 6, "UPtr"), 256, "UTF-16") . "`n"
else,
username := StrGet(NumGet(pCred + 24 + A_PtrSize * 6, "UPtr"), 256, "UTF-16")
len := NumGet(pCred + 16 + A_PtrSize * 2, "UInt")
; append new line to end if requested
if(NewlineInPassword)
password := StrGet(NumGet(pCred + 16 + A_PtrSize * 3, "UPtr"), len/2, "UTF-16") . "`n"
else,
password := StrGet(NumGet(pCred + 16 + A_PtrSize * 3, "UPtr"), len/2, "UTF-16")
DllCall("Advapi32.dll\CredFree", "Ptr", pCred)
return {"name": name, "username": username, "password": password}
}
; Misc
;------------------------------------------------
; Escape::ExitApp

79
Zip.ahk Normal file
View 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 -------------------------------------