-
Notifications
You must be signed in to change notification settings - Fork 0
/
UpdateUnit.pas
127 lines (113 loc) · 3.53 KB
/
UpdateUnit.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
unit UpdateUnit;
interface
function IsConnectedToInternet: Boolean;
procedure CheckforUpdates;
const
INTERNET_CONNECTION_MODEM = 1;
INTERNET_CONNECTION_LAN = 2;
INTERNET_CONNECTION_PROXY = 4;
INTERNET_CONNECTION_MODEM_BUSY = 8;
implementation
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Classes,
Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.FileCtrl,
ToolWin, ComCtrls, ImgList, Menus, ShellAPI, ExtCtrls, ShlObj, URLMon,
ExtDlgs, Buttons, ActiveX, SkinHint, SkinData, DynamicSkinForm,
SkinCtrls, SkinPrinter, SkinMenus, SkinBoxCtrls, spSkinShellCtrls,
spMessages, SkinTabs, spButtonGroup, SkinExCtrls,
WUpdate,
WhatsNewFr, MainFr;
function InternetGetConnectedState(lpdwFlags: LPDWORD;
dwReserved: DWORD): BOOL; stdcall; external 'WININET.DLL';
function IsConnectedToInternet: Boolean;
var
dwConnectionTypes: Integer;
begin
try
dwConnectionTypes := INTERNET_CONNECTION_MODEM +
INTERNET_CONNECTION_LAN +
INTERNET_CONNECTION_PROXY;
if InternetGetConnectedState(@dwConnectionTypes, 0) then
Result := true
else
Result := false;
except
Result := false;
end;
end;
function Whatsnew : Boolean;
var
WhatsNewFrm : TWhatsNewFrm;
begin
WhatsNewFrm := TWhatsNewFrm.Create(nil);
try
WhatsNewFrm.ShowModal;
if FileExists('c:\DSSAT47\Tools\WeatherAnalogue\whatsnewwa.txt') then
DeleteFile('c:\DSSAT47\Tools\WeatherAnalogue\whatsnewwa.txt');
case WhatsNewFrm.ModalResult of
mrOk : result := true;
mrCancel : result := false;
end;
finally
WhatsNewFrm.Free;
end;
end;
procedure CheckforUpdates;
var
WebUpdate1: TWebUpdate;
begin
try
try
WebUpdate1 := TWebUpdate.Create(nil);
If IsConnectedToInternet Then
begin
WebUpdate1.FTPPassive := true;
WebUpdate1.Port := 21;
WebUpdate1.UpdateType := ftpUpdate;
WebUpdate1.ShowDownloadProgress := true;
WebUpdate1.Host := '6f7.a92.myftpupload.com';
WebUpdate1.UserID := 'dssatupdater';
WebUpdate1.Password := 'xpm#sawk6Jlwf';
Webupdate1.FTPDirectory := 'waupdate';
WebUpdate1.URL := 'ftp://6f7.a92.myftpupload.com/waupdate/version.INF';
WebUpdate1.TimeOut := 180000;
if WebUpdate1.NewVersionAvailable then
begin
if MainForm.spSkinMessage1.MessageDlg ('There is a new version of WeatherAnalogue is available.'+chr(13)+
'Would you like to update?', mtConfirmation, [mbYes, mbNo], 0) = MrNo
then
//Close
Exit
else
begin
if whatsnew then
begin
if MainForm.spSkinMessage1.MessageDlg ('Download update file(s)?', mtConfirmation, [mbYes, mbNo], 0) = MrYes
then
WebUpdate1.DoUpdate(true)
else
exit;
end
else
exit;
end;
end
else
begin
MainForm.spSkinMessage1.MessageDlg('No new version of WeatherAnalogue is available!', mtInformation,
[mbOk], 0);
end;
end
else
MainForm.spSkinMessage1.MessageDlg('No Internet connection!', mtInformation, [mbOk], 0);
except
begin
MainForm.spSkinMessage1.MessageDlg('Error connecting FTP site!', mtError, [mbOk], 0);
exit;
end;
end;
finally
WebUpdate1.Free;
end;
end;
end.