Added support for automatic updates through gitea API

main
Yuriy 2 years ago
parent 5af097f8ec
commit 0e872711f0

@ -26,11 +26,13 @@ Menu, Tray, Default, Reload wLast Post
global ScriptName
global ScriptVersion
global FullScriptName
global UpdateAvailable
global UpdateVersionNumber
;---Notes/Extra Info/#Includes------------------------------------------------------
ScriptName = Freedomain Social Media Poster
ScriptVersion = 2.70
ScriptVersion = 2.72
FullScriptName := ScriptName . " " . ScriptVersion
;---ToDo---
@ -150,7 +152,7 @@ if(PauseBetweenPosts){
}
IniRead, UpdateAvailable, %SettingsIniFilepath%, %ScriptSettingsSection%, UpdateAvailable, %A_Space%
; IniRead, UpdateAvailable, %SettingsIniFilepath%, %ScriptSettingsSection%, UpdateAvailable, %A_Space%
IniRead, TotalPostsPosted, %SettingsIniFilepath%, %ScriptSettingsSection%, TotalPostsPosted,0
IniRead, TotalRunTime, %SettingsIniFilepath%, %ScriptSettingsSection%, TotalRunTime, 0
@ -182,26 +184,30 @@ IniWrite, %ProgramExeFilepath%, %SettingsIniFilepath%, %ScriptSettingsSection%,
IniWrite, %ScriptVersion%, %SettingsIniFilepath%, %ScriptSettingsSection%, ScriptVersion
; Download Program Updater
if(!FileExist(FreedomainProgramUpdaterFilepath)){
; TooltipThis("Downloading Program Updater")
; UrlDownloadToFile, %FreedomainProgramUpdaterURL%, %FreedomainProgramUpdaterFilepath%
; ToolTip
;------Run Actions on Passed in Arguments-------
;------------------------------------------------
if(ErrorLoggingDirectory = "LastPost"){
IniRead, ErrorLoggingDirectory, %SettingsIniFilepath%, %ScriptSettingsSection%, LastPost, %A_Space%
}
; check for updates if the setting is enabled
if(AutoUpdateCheck AND !UpdateAvailable AND !SkipUpdateCheckThisRun){
CheckForUpdates()
}
; if passed argument is .exe file, then script has just been udpated and we need to move the old version
if(InStr(ErrorLoggingDirectory,ScriptName, and InStr(ErrorLoggingDirectory,".exe"))){
; create backups folder if it doesn't exist
BackupsFolder = %LibFolder%\Backups\%ErrorLoggingDirectory%
if(!FileExist(BackupsFolder)){
FileCreateDir, %BackupsFolder%
}
;---Load Settings From Previous Post---
;------------------------------------------------
if(ErrorLoggingDirectory = "LastPost"){
IniRead, ErrorLoggingDirectory, %SettingsIniFilepath%, %ScriptSettingsSection%, LastPost, %A_Space%
; move old version to backups folder, overwrite if name conflict
FileMove, %ErrorLoggingDirectory%, %BackupsFolder%\*, 1
MsgBox,,Update Successful, Previous version was backed up to: %BackupsFolder%
}
if(StrLen(ErrorLoggingDirectory) > 5){ ; if argument was passed in, read contents from that directory
SkipUpdateCheckThisRun := 1
@ -314,6 +320,13 @@ if(TestingMode){ ; Easy testing for Yuriy
}
; check for updates if the setting is enabled
if(AutoUpdateCheck AND !SkipUpdateCheckThisRun){
CheckForUpdates()
}
;---GUI Variables---
;------------------------------------------------
TooltipXPosition := Round((A_ScreenWidth / 2) - (A_ScreenWidth / 10)) ; Center Tooltip on the screen and a bit to the left
@ -402,7 +415,7 @@ Gui, Add, Button,xp+%Marginspace% yp+35 w%EditBoxThirdsWidth% h30 gSaveAsTemplat
Gui, Add, Button,x+%MarginSpace% w%EditBoxThirdsWidth% h30 gLoadTemplate, Load Template
Gui, Add, Button, x+%MarginSpace% w%EditBoxThirdsWidth% h30 gLoadLastPost, Load Last Post
if(UpdateAvailable)
Gui, Add, Button, x%MarginSpaceDoubled% y+%MarginSpace% w%EditBoxHalfWidths% h30 gUpdateScript vUpdateAvailable, Program Update Available
Gui, Add, Button, x%MarginSpaceDoubled% y+%MarginSpace% w%EditBoxHalfWidths% h30 gUpdateScript vUpdateAvailable, Update Available: %UpdateVersionNumber%
else,
Gui, Add, Button, x%MarginSpaceDoubled% y+%MarginSpace% w%EditBoxHalfWidths% h30 gUpdateScript vUpdateAvailable, Program is Up-to-Date
@ -1303,7 +1316,7 @@ loop, 5 {
try status := driver.executeScript(js)
if(Status)
continue
continue
sleep, 1000
}

@ -39,99 +39,65 @@ CheckForUpdates(){
parsed := JSON.Load(data)
Version := parsed.1.name
UpdateVersionNumber := parsed.1.name
; msgbox, Version: %Version%`nScriptVersion: %ScriptVersion%
if(ScriptVersion = Version){
if(ScriptVersion = UpdateVersionNumber){
ToolTip
return
}
else, {
; msgbox, update found!
; Message = Program Update Found
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
IniWrite, 1, %SettingsIniFilepath%, %ScriptSettingsSection%, UpdateAvailable
; GuiControl,, UpdateAvailable, Update Available - Click to View
}
; return
; @todo DELETE the rest of this.
/*
Msgbox % "Version: " Version
ChangeLog := parsed.1.body
exename := parsed.1.assets.1.name
exeURL := parsed.1.assets.1.browser_download_url
Msgbox % "exeURL: " exeURL
Msgbox % "exename: " exename
if(True)
return
; Msgbox % "FreedomScriptsChangelogURL: " FreedomScriptsChangelogURL
; Msgbox % "ChangelogIniFilepath: " ChangelogIniFilepath
; Msgbox % "ScriptSettingsSectio: " ScriptSettingsSection
; Msgbox % "SettingsIniFilepath: " SettingsIniFilepath
UpdateAvailable := 1
; msgbox, update found!
Message = Program Update Found
SaveOrPostProgress(Message:=Message,PostType:="ErrorLoggingTextFile")
; IniWrite, 1, %SettingsIniFilepath%, %ScriptSettingsSection%, UpdateAvailable
; ToolTip
return
}
UrlDownloadToFile, %FreedomScriptsChangelogURL%, %ChangelogIniFilepath%
if(ErrorLevel){
Message = Failed to Download Changelog
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
Return
}
IniRead, UpdateVersion, %ChangelogIniFilepath%, %ScriptSettingsSection%, ScriptVersion, %A_Space%
if(UpdateVersion = ""){
ToolTip
; MsgBox, update version is blank.
Return
}
if(ScriptVersion != UpdateVersion){
; msgbox, update found!
Message = Script Update Found
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
IniWrite, 1, %SettingsIniFilepath%, %ScriptSettingsSection%, UpdateAvailable
UpdateScript(){
data := URLDownloadToVar(GitReleasesAPIURL)
GuiControl,, UpdateAvailable, Update Available - Click to View
}
else, {
Message = No Updates Found
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
IniWrite, 0, %SettingsIniFilepath%, %ScriptSettingsSection%, UpdateAvailable
parsed := JSON.Load(data)
}
*/
ToolTip
return
}
UpdateVersionNumber := parsed.1.name
ChangeLog := parsed.1.body
exename := parsed.1.assets.1.name
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", "")
UpdateExeName = %exename% %UpdateVersionNumber%.exe
UpdateExeFilepath = %A_ScriptDir%\%UpdateExeName%
UpdateScript(){
; Msgbox % "ChangelogIniFilepath: " ChangelogIniFilepath
; Msgbox % "ScriptSettingsSection: " ScriptSettingsSection
IniRead, Changelog, %ChangelogIniFilepath%, %ScriptSettingsSection%, Changelog, %A_Space%
Changelog := StrReplace(Changelog, "--", "`n-")
; IniRead, Changelog, %ChangelogIniFilepath%, %ScriptSettingsSection%, Changelog, %A_Space%
; Changelog := StrReplace(Changelog, "--", "`n-")
IniRead, UpdateVersion, %ChangelogIniFilepath%, %ScriptSettingsSection%, ScriptVersion, %A_Space%
; IniRead, UpdateVersion, %ChangelogIniFilepath%, %ScriptSettingsSection%, ScriptVersion, %A_Space%
if(ScriptVersion = UpdateVersion){
IniWrite, 0, %SettingsIniFilepath%, %ScriptSettingsSection%, UpdateAvailable
if(ScriptVersion = UpdateVersionNumber){
; IniWrite, 0, %SettingsIniFilepath%, %ScriptSettingsSection%, UpdateAvailable
MsgBox, You are Up-To-Date
; IniRead, UpdateAvailable, %SettingsIniFilepath%, %ScriptSettingsSection%, UpdateAvailable, 0
return
}
Changelog = %ScriptVersion% -> %UpdateVersion%`n`n-%Changelog%
Changelog = %ScriptVersion% --> %UpdateVersionNumber%`n%Changelog%
OnMessage(0x44, "OnMsgBoxUpdateAvailable")
MsgBox 0x44, Update Available, %Changelog%
@ -140,8 +106,10 @@ UpdateScript(){
IfMsgBox Yes, {
Return
} Else IfMsgBox No, {
run, "%FreedomainProgramUpdaterFilepath%" "%ScriptSettingsSection%"
; Return
SaveOrPostProgress(Message:="Downloading Update",PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
Msgbox, downloading to: %A_ScriptDir%\%UpdateExeName%
UrlDownloadToFile, %exeURL%, %UpdateExeFilepath%
run, %UpdateExeFilepath% %A_ScriptFullPath%
ExitApp
}
return

Loading…
Cancel
Save