autohotkey-api-libraries/Gitea-API.ahk
2023-08-26 00:20:09 -04:00

81 lines
2.3 KiB
AutoHotkey

; GITEA Functions
;------------------------------------------------
CheckForUpdates(GitReleasesAPIURL){
; msgbox, checking for updates
Message = Checking For Updates
SaveOrPostProgress(Message,PostType:="ErrorLoggingTextFile")
data := URLDownloadToVar(GitReleasesAPIURL)
; Msgbox % "data: " data
parsed := JSON.Load(data)
UpdateVersionNumber := parsed.1.name
; Message = UpdateVersionNumber: %UpdateVersionNumber%
; DevModeMsgBox(Message)
if(ScriptVersion = UpdateVersionNumber OR ScriptVersion > UpdateVersionNumber){
ToolTip
return 0
}
else, {
UpdateAvailable := 1
; msgbox, update found!
Message = Program Update Found
SaveOrPostProgress(Message:=Message,PostType:="ErrorLoggingTextFile")
; IniWrite, 1, %SettingsIniFilepath%, %ScriptSettingsSection%, UpdateAvailable
; ToolTip
return 1
}
}
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%
if(ScriptVersion = UpdateVersionNumber){
; IniWrite, 0, %SettingsIniFilepath%, %ScriptSettingsSection%, UpdateAvailable
MsgBox, You are Up-To-Date
; IniRead, UpdateAvailable, %SettingsIniFilepath%, %ScriptSettingsSection%, UpdateAvailable, 0
return
}
Changelog = %ScriptVersion% --> %UpdateVersionNumber%`n%Changelog%
OnMessage(0x44, "OnMsgBoxUpdateAvailable")
MsgBox 0x44, Update Available, %Changelog%
OnMessage(0x44, "")
IfMsgBox Yes, {
Return
}
Else IfMsgBox No, {
SaveOrPostProgress(Message:="Downloading Update",PostType:="Tooltip,ErrorLoggingTextFile")
; Msgbox, downloading to: %A_ScriptDir%\%UpdateExeName%
UrlDownloadToFile, %exeURL%, %UpdateExeFilepath%
run, "%UpdateExeFilepath%" "%A_ScriptFullPath%"
ExitApp
}
return
}