The php script just sends two custom headers, one containing the version and the other is the location of the file to download.
PB:
Code: Select all
Structure VERSION_INFO
major.l
minor.l
release.l
EndStructure
Structure UPDATE_DATA
appdownload.s
appversion.l
EndStructure
InitNetwork()
Procedure DownloadLatestUpdate(source.s, destination.s, packageName.s)
; returns 1 on success, 0 error
Define.l download, e, text, ret = -1, font
download = OpenWindow(#PB_Any, 0, 0, 250, 90, "Updater", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
font = LoadFont(#PB_Any, "Arial", 12)
text = TextGadget(#PB_Any, 0, 30, 250, 90, "Attempting to download update...", #PB_Text_Center)
SetGadgetFont(text, FontID(font))
While e <> #PB_Event_CloseWindow
e = WaitWindowEvent(1)
If ret = -1
If ReceiveHTTPFile(source.s, destination.s + packageName.s)
SetGadgetText(text, "Downloaded update! Close this window to open file.") : ret = 1
Else
SetGadgetText(text, "Failed to retrieve update.") : ret = 0
EndIf
EndIf
Wend
If ret : RunProgram(packageName.s, "", destination.s) : EndIf
FreeGadget(text)
FreeFont(font)
CloseWindow(download)
ProcedureReturn ret
EndProcedure
Procedure GetLatestVersion(url.s, *updatedata.UPDATE_DATA)
; returns 0 on failure, 1 if only one header is found, and 2 on success
Define.s str, line
Define.l c, i, ret = 0
str.s = GetHTTPHeader(url.s)
c = CountString(str.s, Chr(10))
If c > 0 : For i = 1 To c
line.s = StringField(str.s, i, Chr(10))
If FindString(line.s, "AppDownload: ")
*updatedata\appdownload = StringField(line.s, 2, " ")
Debug *updatedata\appdownload
ret + 1
EndIf
If FindString(line.s, "AppVersion: ")
*updatedata\appversion = Val(StringField(line.s, 2, " "))
Debug *updatedata\appversion
ret + 1
EndIf
Next i : EndIf
ProcedureReturn ret
EndProcedure
Procedure ConvertVersion(*versioninfo.VERSION_INFO)
ProcedureReturn Val(Str(*versioninfo\major) + Str(*versioninfo\minor) + Str(*versioninfo\release))
EndProcedure
updateinfo.UPDATE_DATA
version.VERSION_INFO\major = 1
version\minor = 2
version\release = 29
urlToVersion.s = "http://mywebsite.com/apphomepage/index.php"
appPath.s = "C:\MyApp\"
If GetLatestVersion(urlToVersion, updateinfo) = 2
If updateinfo\appversion > ConvertVersion(version)
r = MessageRequester("Updater", "There is an update available!" + #LF$ + "Would you like to download it now?", #PB_MessageRequester_YesNo)
If r = #PB_MessageRequester_Yes
DownloadLatestUpdate(updateinfo\appdownload, appPath.s, "MyApp.zip")
EndIf
EndIf
EndIf
Code: Select all
<?PHP
header("AppVersion: 1230");
header("AppDownload: http://myapp.com/download.php?file=MyApp.zip");
?>
<!DOCTYPE html>
<html>
<head></head>
<body></body>
</html>