Date: 02-16-2022
Return to Index
Date/Time: 2010-05-27 : 11:14:52
created by gbSnippets
'In the snippet "Online Update - Check For Updates", found in this library, you'll find the
'code to put in your app to be able to utilize the following application, which I call gbUpdate.
'In general, your original app downloads a new version of itself from a server. It calls gbUpdate and
'then closes itself. gbUpdate removes the old EXE and installs the new EXE, then starts
'the new EXE.
'When calling gbUpdate, your application passes command line data consisting of the application's
'name, size, and position. gbUpdate locates/resizes itself relative to your application.
'Primary Code:
'This code confirms that the command line used to call gbUpdate has valid data - a valid file
'called myapp.new, the original file called myapp.exe, and legal dialog dimensions.
Function VerifyCommandLineAndFiles(x as long, y as long, w as long, h as long) As Long
'get the five parameters from command line used to start gbUpdate
AppName$ = Command$(1) : x = Val(Command$(2)) : y = Val(Command$(3)) : w = Val(Command$(4)) : h = Val(Command$(5))
'verify that needed files .new/.exe are present, check validity of passed size/location arguments
If IsFile(Exe.Path$ + AppName$ + ".exe") = %False Then
MsgBox "Invalid application specified! gbUpdate closing. ", %MB_Ok + %MB_IconExclamation, AppName$ + " Online Update"
ElseIf IsFile(Exe.Path$ + AppName$ + ".new") = %False Then
MsgBox "Application update file missing! gbUpdate closing. ", %MB_Ok + %MB_IconExclamation, AppName$ + " Online Update"
ElseIf x<=10 Or y<=10 Or w<=10 Or h<=10 Then
MsgBox "Invalid application data specified! gbUpdate closing. ", %MB_Ok + %MB_IconExclamation, AppName$ + " Online Update"
Else
Function = 1
End If
End Function
'This additional code is used in the gbUpdate Callback function to install/run the new app
Case %WM_Command
Select Case CB.Ctl
Case %IdOk
'renames the old EXE as .old, then renames the downloaded file from .NEW to .EXE
If IsFile(Exe.Path$ + AppName$ + ".exe.old") Then Kill Exe.Path$ + AppName$ + ".exe.old"
Name Exe.Path$ + AppName$ + ".exe" As Exe.Path$ + AppName$ + ".exe.old"
Name Exe.Path$ + AppName$ + ".new" As Exe.Path$ + AppName$ + ".exe"
Dialog End hDlg
End Select
Case %WM_Destroy
Control Get Check hDlg, %IDCheckBox To iResult
If iResult = 1 Then pid??? = Shell (Exe.Path$ + AppName$ + ".exe") 'runs
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
#Resource "gbonlineupdate.pbr"
%IDLabel = 500 : %IDCheckBox = 501 : %IDImage = 502
Global hDlg As DWord, AppName$
Function PBMain() As Long
Local x As Long, y As Long, h As Long, w As Long
If VerifyCommandLineAndFiles(x,y,w,h) = 0 Then Exit Function
Dialog New Pixels, 0, AppName$ + " Online Update",x+w/2-150,y+h/2-75,300,150, %WS_OverlappedWindow To hDlg
Dialog Set Icon hDlg, "logo"
Control Add Image, hDlg, %IDImage, "gbupdate", 20, 10, 265, 70, %WS_Border
Control Add Label, hDlg, %IDLabel, "Ready to install " + AppName$ + ". Continue?", 20,90,270,20, %SS_Center
Control Add Button, hDlg, %IdOk,"Ok", 30,115,30,25
Control Add Button, hDlg, %IdCancel,"Cancel", 70,115,50,25
Control Add Checkbox, hDlg, %IDCheckBox,"Start on exit", 150,115,150,20
Control Set Check hDlg, %IDCheckBox, 1 'optional (start on exit)
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Dim pid???, iResult As Long
Select Case CB.Msg
Case %WM_Command
Select Case CB.Ctl
Case %IdOk
If IsFile(Exe.Path$ + AppName$ + ".exe.old") Then Kill Exe.Path$ + AppName$ + ".exe.old"
Name Exe.Path$ + AppName$ + ".exe" As Exe.Path$ + AppName$ + ".exe.old"
Name Exe.Path$ + AppName$ + ".new" As Exe.Path$ + AppName$ + ".exe"
Dialog End hDlg
Case %IdCancel
Dialog End hDlg
End Select
Case %WM_Destroy
Control Get Check hDlg, %IDCheckBox To iResult
If iResult = 1 Then pid??? = Shell (Exe.Path$ + AppName$ + ".exe")
End Select
End Function
Function VerifyCommandLineAndFiles(x as long, y as long, w as long, h as long) As Long
'get the five parameters from command line used to start gbUpdate
AppName$ = Command$(1) : x = Val(Command$(2)) : y = Val(Command$(3)) : w = Val(Command$(4)) : h = Val(Command$(5))
If IsFile(Exe.Path$ + AppName$ + ".exe") = %False Then
MsgBox "Invalid application specified! gbUpdate closing. ", %MB_Ok + %MB_IconExclamation, AppName$ + " Online Update"
ElseIf IsFile(Exe.Path$ + AppName$ + ".new") = %False Then
MsgBox "Application update file missing! gbUpdate closing. ", %MB_Ok + %MB_IconExclamation, AppName$ + " Online Update"
ElseIf x<=0 Or y<=0 Or w<=0 Or h<=0 Then
MsgBox "Invalid application data specified! gbUpdate closing. ", %MB_Ok + %MB_IconExclamation, AppName$ + " Online Update"
Else
Function = 1
End If
End Function
'gbs_00051
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm