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

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

Loading…
Cancel
Save