6 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
7 Dialogs, IdAntiFreezeBase, IdAntiFreeze, IdBaseComponent, IdComponent,
8 IdTCPConnection, IdTCPClient, IdHTTP, StdCtrls, ExtCtrls, Buttons;
11 TUpdateCheckForm = class(TForm)
15 UpdateButton: TButton;
17 IdAntiFreeze: TIdAntiFreeze;
18 NightBuildCheckButton: TButton;
19 CancelBitBtn: TBitBtn;
20 procedure UpdateButtonClick(Sender: TObject);
21 procedure FormCreate(Sender: TObject);
22 procedure NightBuildCheckButtonClick(Sender: TObject);
23 procedure CancelBitBtnClick(Sender: TObject);
28 FAllowshutdown : Boolean;
30 function GetDesktopDir:string;
31 function GetDownloadFilePath(FileName: String): String;
32 function CreateShortCut(FileName, Argment, SavePath :string):boolean;
33 procedure DonwloadUpdate(url: String);
34 function CheckUpdate(nightbuild :Boolean): Boolean;
37 property ExecPath :String read FExecPath;
38 property ExecArgs :String read FExecArgs;
39 property Allowshutdown :Boolean read FAllowshutdown;
43 UpdateCheckForm: TUpdateCheckForm;
47 GikoSystem, NewBoard, Giko, IniFiles, MojuUtils, GikoDataModule,
48 ActiveX, ComObj, ShlObj, GikoUtil;
52 procedure TUpdateCheckForm.UpdateButtonClick(Sender: TObject);
54 if CheckUpdate(false) then begin
55 if GikoUtil.MsgBox(Handle, '
\8dX
\90V
\82ª
\82 \82é
\82½
\82ß
\83M
\83R
\83i
\83r
\82ð
\8dÄ
\8bN
\93®
\82µ
\82Ü
\82·
\82©
\81H', '
\8fI
\97¹
\8am
\94F',
56 MB_YESNO or MB_ICONWARNING or MB_DEFBUTTON2) = ID_YES then begin
57 FAllowshutdown := True;
63 procedure TUpdateCheckForm.NightBuildCheckButtonClick(Sender: TObject);
65 if GikoUtil.MsgBox(Handle, '
\90³
\8e®
\83\8a\83\8a\81[
\83X
\94Å
\82Å
\82Í
\82 \82è
\82Ü
\82¹
\82ñ
\82ª
\82æ
\82ë
\82µ
\82¢
\82Å
\82·
\82©
\81H', '
\8dX
\90V
\8am
\94F',
66 MB_YESNO or MB_ICONWARNING or MB_DEFBUTTON2) = ID_YES then begin
67 if CheckUpdate(true) then begin
68 if GikoUtil.MsgBox(Handle, '
\8dX
\90V
\82ª
\82 \82é
\82½
\82ß
\83M
\83R
\83i
\83r
\82ð
\8dÄ
\8bN
\93®
\82µ
\82Ü
\82·
\82©
\81H', '
\8fI
\97¹
\8am
\94F',
69 MB_YESNO or MB_ICONWARNING or MB_DEFBUTTON2) = ID_YES then begin
70 FAllowshutdown := True;
77 //!
\83A
\83b
\83v
\83f
\81[
\83g
\91Î
\8fÛ
\8am
\94F
78 function TUpdateCheckForm.CheckUpdate(nightbuild :Boolean): Boolean;
81 // CHECK_URL = 'http://gikonavi.sourceforge.jp/updater/debug.txt';
82 CHECK_URL = 'http://gikonavigoeson.sourceforge.jp/updater/debug.txt';
84 // CHECK_URL = 'http://gikonavi.sourceforge.jp/updater/latest.txt';
85 CHECK_URL = 'http://gikonavigoeson.sourceforge.jp/updater/latest.txt';
89 ResStream: TMemoryStream;
90 downResult, current, newest: TStringList;
96 FAllowshutdown := False;
97 ResultMemo.Lines.Clear;
98 Screen.Cursor := crHourGlass;
99 UpdateButton.Enabled := False;
100 NightBuildCheckButton.Enabled := False;
103 ResStream := TMemoryStream.Create;
105 TNewBoardDialog.InitHTTPClient(IdHTTP);
106 IdHTTP.Request.Referer := '';
107 IdHTTP.Request.AcceptEncoding := 'gzip';
109 IdHTTP.Request.CacheControl := 'no-cache';
110 IdHTTP.Request.CustomHeaders.Add('Pragma: no-cache');
111 IdHTTP.ReadTimeout := 0;
112 IdHTTP.HandleRedirects := true;
113 downResult := TStringList.Create;
114 newest := TStringList.Create;
115 current := TStringList.Create;
116 IdAntiFreeze.Active := true;
121 CancelBitBtn.Enabled := True;
122 IdHTTP.Get(CHECK_URL, ResStream);
123 CancelBitBtn.Enabled := False;
124 if (FCanceled) then begin
125 raise Exception.Create('
\83_
\83E
\83\93\83\8d\81[
\83h
\82ª
\83L
\83\83\83\93\83Z
\83\8b\82³
\82ê
\82Ü
\82µ
\82½
\81B');
127 value := GikoSys.GzipDecompress(ResStream,
128 IdHTTP.Response.ContentEncoding);
129 downResult.Text := value;
130 if (nightbuild) then begin
131 ResultMemo.Lines.Add('
\8dÅ
\90V
\82Ìnight build
\82Í
\81A' + downResult.Values[ 'n_version' ]);
132 newest.Text := MojuUtils.CustomStringReplace(downResult.Values[ 'n_version' ],
135 ResultMemo.Lines.Add('
\8dÅ
\90V
\82Ì
\83M
\83R
\83i
\83r
\82Í
\81A' + downResult.Values[ 'version' ]);
136 newest.Text := MojuUtils.CustomStringReplace(downResult.Values[ 'version' ],
139 current.Text := MojuUtils.CustomStringReplace(GikoSys.Version,
141 if newest.Count >= 2 then begin
143 // night build
\82Í
\81A
\83r
\83\8b\83h
\94Ô
\8d\86\82¾
\82¯
\82Å
\94»
\92è
\82·
\82é
144 if (nightbuild) then begin
145 url := downResult.Values[ 'n_url' ];
146 newgiko := StrToInt(current[3]) < StrToInt(newest[3]);
148 url := downResult.Values[ 'url' ];
149 newgiko := ( StrToInt(current[1]) < StrToInt(newest[1]) ) or
150 ( (StrToInt(current[1]) = StrToInt(newest[1]))) and
151 ((StrToInt(current[2]) < StrToInt(newest[2])) );
153 if (newgiko) then begin
154 if GikoUtil.MsgBox(Handle, '
\90V
\82µ
\82¢
\83M
\83R
\83i
\83r
\82ª
\82 \82è
\82Ü
\82·
\81B
\83_
\83E
\83\93\83\8d\81[
\83h
\82µ
\82Ü
\82·
\82©
\81H', '
\8dX
\90V
\8am
\94F',
155 MB_YESNO or MB_ICONWARNING or MB_DEFBUTTON2) = ID_YES then begin
156 ResultMemo.Lines.Add('
\90V
\82µ
\82¢
\83M
\83R
\83i
\83r
\82ª
\82 \82è
\82Ü
\82·
\81B
\83_
\83E
\83\93\83\8d\81[
\83h
\82ð
\8aJ
\8en
\82µ
\82Ü
\82·
\81B' + url);
157 DonwloadUpdate(Trim(url));
161 ResultMemo.Lines.Add('
\8d¡
\82Ì
\83M
\83R
\83i
\83r
\82ª
\8dÅ
\90V
\82Å
\82·
\81B');
164 ResultMemo.Lines.Add('
\8d¡
\82Ì
\83M
\83R
\83i
\83r
\82ª
\8dÅ
\90V
\82Å
\82·
\81B');
167 on E: Exception do begin
168 ResultMemo.Lines.Add(E.Message);
170 Writeln(IdHTTP.ResponseText);
178 IdAntiFreeze.Active := false;
185 NightBuildCheckButton.Enabled := True;
186 UpdateButton.Enabled := True;
187 Screen.Cursor := crDefault;
192 //!
\83A
\83b
\83v
\83f
\81[
\83g
\83_
\83E
\83\93\83\8d\81[
\83h
193 procedure TUpdateCheckForm.DonwloadUpdate(url: String);
196 fileStrem: TFileStream;
198 filename := GetDownloadFilePath(Copy(url, LastDelimiter('/', url) + 1, Length(url)));
199 fileStrem := TFileStream.Create(filename, fmCreate);
201 CancelBitBtn.Enabled := True;
202 IdHTTP.Get(url, fileStrem);
203 CancelBitBtn.Enabled := False;
204 if (FCanceled) then begin
205 raise Exception.Create('
\83_
\83E
\83\93\83\8d\81[
\83h
\82ª
\83L
\83\83\83\93\83Z
\83\8b\82³
\82ê
\82Ü
\82µ
\82½
\81B');
207 ResultMemo.Lines.Add(
208 IdHttp.ResponseText + '(' + IntToStr(IdHttp.ResponseCode) + ')');
209 FExecPath := filename;
210 FExecArgs := '/SP- /silent /noicons "/dir=' + GikoSys.GetAppDir + '"';
212 execPath, execArgs, GetDesktopDir) then begin
213 ResultMemo.Lines.Add('
\83f
\83X
\83N
\83g
\83b
\83v
\82É"
\83M
\83R
\83i
\83r
\8dX
\90V"
\83V
\83\87\81[
\83g
\83J
\83b
\83g
\82ð
\8dì
\90¬
\82µ
\82Ü
\82µ
\82½
\81B');
214 // ResultMemo.Lines.Add('
\83M
\83R
\83i
\83r
\82ð
\8fI
\97¹
\82µ
\82Ä
\81A"
\83M
\83R
\83i
\83r
\8dX
\90V"
\83V
\83\87\81[
\83g
\83J
\83b
\83g
\82ð
\83_
\83u
\83\8b\83N
\83\8a\83b
\83N
\82µ
\82Ä
\82
\82¾
\82³
\82¢
\81B');
216 ResultMemo.Lines.Add('
\83f
\83X
\83N
\83g
\83b
\83v
\82É
\83V
\83\87\81[
\83g
\83J
\83b
\83g
\82ð
\8dì
\90¬
\82Å
\82«
\82Ü
\82¹
\82ñ
\82Å
\82µ
\82½
\81B');
223 //!
\83_
\83E
\83\93\83\8d\81[
\83h
\82µ
\82½
\83t
\83@
\83C
\83\8b\82Ì
\95Û
\91¶
\83p
\83X
224 function TUpdateCheckForm.GetDownloadFilePath(FileName: String): String;
226 TempPath: array[0..MAX_PATH] of Char;
228 GetTempPath(MAX_PATH, TempPath);
229 Result := IncludeTrailingPathDelimiter(TempPath) + FileName;
233 //!
\83f
\83X
\83N
\83g
\83b
\83v
\82Ì
\83p
\83X
\82ð
\8eæ
\93¾
\82·
\82é
\8aÖ
\90\94
234 function TUpdateCheckForm.GetDesktopDir:string;
236 DeskTopPath: array[0..MAX_PATH] of Char;
239 SHGetSpecialFolderLocation(Application.Handle, CSIDL_DESKTOP, pidl);
240 SHGetPathFromIDList(pidl, DesktopPath);
241 Result := DesktopPath;
244 //!
\83V
\83\87\81[
\83g
\83J
\83b
\83g
\82ð
\8dì
\90¬
\82·
\82é
\8aÖ
\90\94
245 function TUpdateCheckForm.CreateShortCut(FileName, Argment, SavePath :string):boolean;
246 //FileName
\81c
\83V
\83\87\81[
\83g
\83J
\83b
\83g
\82ð
\8dì
\90¬
\82·
\82é
\83t
\83@
\83C
\83\8b\96¼
247 //SavePath
\81c.lnk
\83t
\83@
\83C
\83\8b\82ð
\8dì
\90¬
\82·
\82é
\83f
\83B
\83\8c\83N
\83g
\83\8a
251 wFileName :WideString;
254 //IUnKnown
\83I
\83u
\83W
\83F
\83N
\83g
\82ð
\8dì
\90¬
\82µ
\82Ä
\81AIShellLink
\82É
\83L
\83\83\83X
\83g
255 SL :=CreateComObject(CLSID_ShellLink) as IShellLink;
256 //IPersistFile
\82É
\83L
\83\83\83X
\83g
257 PF :=SL as IPersistFile;
259 if (SL.SetPath(PChar(FileName)) <> NOERROR) then begin
262 if (SL.SetWorkingDirectory(PChar(ExtractFilePath(FileName)))
263 <> NOERROR ) then begin
266 if (SL.SetArguments(PChar(Argment)) <> NOERROR) then begin
269 if (SL.SetDescription(PChar('
\83M
\83R
\83i
\83r
\8dX
\90V')) <> NOERROR) then begin
273 //IPersistFile
\82ÌSave
\83\81\83\
\83b
\83h
\82É
\82ÍPWChar
\8c^
\82Ì
\83p
\83\89\83\81\81[
\83^
\82ª
\95K
\97v
274 wFileName :=SavePath +'\
\83M
\83R
\83i
\83r
\8dX
\90V.lnk';
275 //
\83V
\83\87\81[
\83g
\83J
\83b
\83g
\82ð
\8dì
\90¬
276 if (PF.Save(PWChar(wFileName),True) <> NOERROR) then begin
282 //! Form
\83R
\83\93\83X
\83g
\83\89\83N
\83^
283 procedure TUpdateCheckForm.FormCreate(Sender: TObject);
285 CenterForm: TCustomForm;
287 CenterForm := TCustomForm(Owner);
288 if Assigned(CenterForm) then begin
289 Left := ((CenterForm.Width - Width) div 2) + CenterForm.Left;
290 Top := ((CenterForm.Height - Height) div 2) + CenterForm.Top;
292 Left := (Screen.Width - Width) div 2;
293 Top := (Screen.Height - Height) div 2;
296 ResultMemo.Lines.Clear;
299 FAllowshutdown := False;
301 //!
\83L
\83\83\83\93\83Z
\83\8b\83{
\83^
\83\93\89\9f\89º
302 procedure TUpdateCheckForm.CancelBitBtnClick(Sender: TObject);
304 CancelBitBtn.Enabled := False;
306 if IdHTTP.Connected then begin