Added support for automatic updates through gitea API
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
; check for updates if the setting is enabled
|
||||
if(AutoUpdateCheck AND !UpdateAvailable AND !SkipUpdateCheckThisRun){
|
||||
CheckForUpdates()
|
||||
}
|
||||
|
||||
|
||||
;---Load Settings From Previous Post---
|
||||
;------Run Actions on Passed in Arguments-------
|
||||
;------------------------------------------------
|
||||
if(ErrorLoggingDirectory = "LastPost"){
|
||||
IniRead, ErrorLoggingDirectory, %SettingsIniFilepath%, %ScriptSettingsSection%, LastPost, %A_Space%
|
||||
}
|
||||
|
||||
; 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%
|
||||
}
|
||||
|
||||
; 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
|
||||
|
||||
|
||||
@@ -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, {
|
||||
UpdateAvailable := 1
|
||||
; 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)
|
||||
Message = Program Update Found
|
||||
SaveOrPostProgress(Message:=Message,PostType:="ErrorLoggingTextFile")
|
||||
; IniWrite, 1, %SettingsIniFilepath%, %ScriptSettingsSection%, UpdateAvailable
|
||||
; ToolTip
|
||||
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){
|
||||
; msgbox, update found!
|
||||
Message = Script Update Found
|
||||
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
|
||||
IniWrite, 1, %SettingsIniFilepath%, %ScriptSettingsSection%, UpdateAvailable
|
||||
|
||||
GuiControl,, UpdateAvailable, Update Available - Click to View
|
||||
}
|
||||
else, {
|
||||
Message = No Updates Found
|
||||
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
|
||||
IniWrite, 0, %SettingsIniFilepath%, %ScriptSettingsSection%, UpdateAvailable
|
||||
|
||||
}
|
||||
*/
|
||||
ToolTip
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
UpdateScript(){
|
||||
data := URLDownloadToVar(GitReleasesAPIURL)
|
||||
|
||||
parsed := JSON.Load(data)
|
||||
|
||||
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%
|
||||
|
||||
|
||||
; 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
|
||||
|
||||
Reference in New Issue
Block a user