6 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
7 Dialogs, IdAntiFreezeBase, IdAntiFreeze, IdBaseComponent, IdComponent,
8 IdTCPConnection, IdTCPClient, IdHTTP, StdCtrls, ExtCtrls;
11 TUpdateCheckForm = class(TForm)
15 UpdateButton: TButton;
17 IdAntiFreeze: TIdAntiFreeze;
18 NightBuildCheckButton: TButton;
19 procedure UpdateButtonClick(Sender: TObject);
20 procedure FormCreate(Sender: TObject);
21 procedure NightBuildCheckButtonClick(Sender: TObject);
26 FAllowshutdown : Boolean;
27 function GetDesktopDir:string;
28 function GetDownloadFilePath(FileName: String): String;
29 function CreateShortCut(FileName, Argment, SavePath :string):boolean;
30 procedure DonwloadUpdate(url: String);
31 function CheckUpdate(nightbuild :Boolean): Boolean;
34 property ExecPath :String read FExecPath;
35 property ExecArgs :String read FExecArgs;
36 property Allowshutdown :Boolean read FAllowshutdown;
40 UpdateCheckForm: TUpdateCheckForm;
44 GikoSystem, NewBoard, Giko, IniFiles, MojuUtils, GikoDataModule,
45 ActiveX, ComObj, ShlObj, GikoUtil;
49 procedure TUpdateCheckForm.UpdateButtonClick(Sender: TObject);
51 if CheckUpdate(false) then begin
52 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',
53 MB_YESNO or MB_ICONWARNING or MB_DEFBUTTON2) = ID_YES then begin
54 FAllowshutdown := True;
60 procedure TUpdateCheckForm.NightBuildCheckButtonClick(Sender: TObject);
62 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',
63 MB_YESNO or MB_ICONWARNING or MB_DEFBUTTON2) = ID_YES then begin
64 if CheckUpdate(true) then begin
65 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',
66 MB_YESNO or MB_ICONWARNING or MB_DEFBUTTON2) = ID_YES then begin
67 FAllowshutdown := True;
74 //!
\83A
\83b
\83v
\83f
\81[
\83g
\91Î
\8fÛ
\8am
\94F
75 function TUpdateCheckForm.CheckUpdate(nightbuild :Boolean): Boolean;
78 CHECK_URL = 'http://gikonavi.sourceforge.jp/updater/debug.txt';
80 CHECK_URL = 'http://gikonavi.sourceforge.jp/updater/latest.txt';
84 ResStream: TMemoryStream;
85 downResult, current, newest: TStringList;
91 FAllowshutdown := False;
92 ResultMemo.Lines.Clear;
93 Screen.Cursor := crHourGlass;
94 UpdateButton.Enabled := False;
97 ResStream := TMemoryStream.Create;
99 TNewBoardDialog.InitHTTPClient(IdHTTP);
100 IdHTTP.Request.Referer := '';
101 IdHTTP.Request.AcceptEncoding := 'gzip';
103 IdHTTP.Request.CacheControl := 'no-cache';
104 IdHTTP.Request.CustomHeaders.Add('Pragma: no-cache');
105 IdHTTP.HandleRedirects := true;
106 downResult := TStringList.Create;
107 newest := TStringList.Create;
108 current := TStringList.Create;
109 IdAntiFreeze.Active := true;
113 IdHTTP.Get(CHECK_URL, ResStream);
114 value := GikoSys.GzipDecompress(ResStream,
115 IdHTTP.Response.ContentEncoding);
116 downResult.Text := value;
117 if (nightbuild) then begin
118 ResultMemo.Lines.Add('
\8dÅ
\90V
\82Ìnight build
\82Í
\81A' + downResult.Values[ 'n_version' ]);
119 newest.Text := MojuUtils.CustomStringReplace(downResult.Values[ 'n_version' ],
122 ResultMemo.Lines.Add('
\8dÅ
\90V
\82Ì
\83M
\83R
\83i
\83r
\82Í
\81A' + downResult.Values[ 'version' ]);
123 newest.Text := MojuUtils.CustomStringReplace(downResult.Values[ 'version' ],
126 current.Text := MojuUtils.CustomStringReplace(GikoSys.Version,
128 if newest.Count >= 2 then begin
130 // night build
\82Í
\81A
\83r
\83\8b\83h
\94Ô
\8d\86\82¾
\82¯
\82Å
\94»
\92è
\82·
\82é
131 if (nightbuild) then begin
132 newgiko := StrToInt(current[3]) < StrToInt(newest[3]);
134 newgiko := ( StrToInt(current[1]) < StrToInt(newest[1]) ) or
135 ( (StrToInt(current[1]) = StrToInt(newest[1]))) and
136 ((StrToInt(current[2]) < StrToInt(newest[2])) );
138 if (newgiko) then begin
139 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',
140 MB_YESNO or MB_ICONWARNING or MB_DEFBUTTON2) = ID_YES then begin
142 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' + downResult.Values[ 'url' ]);
143 DonwloadUpdate(Trim(downResult.Values[ 'url' ]));
147 ResultMemo.Lines.Add('
\8d¡
\82Ì
\83M
\83R
\83i
\83r
\82ª
\8dÅ
\90V
\82Å
\82·
\81B');
150 ResultMemo.Lines.Add('
\8d¡
\82Ì
\83M
\83R
\83i
\83r
\82ª
\8dÅ
\90V
\82Å
\82·
\81B');
153 on E: Exception do begin
154 ResultMemo.Lines.Add(E.Message);
156 Writeln(IdHTTP.ResponseText);
164 IdAntiFreeze.Active := false;
171 UpdateButton.Enabled := True;
172 Screen.Cursor := crDefault;
177 //!
\83A
\83b
\83v
\83f
\81[
\83g
\83_
\83E
\83\93\83\8d\81[
\83h
178 procedure TUpdateCheckForm.DonwloadUpdate(url: String);
181 fileStrem: TFileStream;
183 filename := GetDownloadFilePath(Copy(url, LastDelimiter('/', url) + 1, Length(url)));
184 fileStrem := TFileStream.Create(filename, fmCreate);
186 IdHTTP.Get(url, fileStrem);
187 ResultMemo.Lines.Add(
188 IdHttp.ResponseText + '(' + IntToStr(IdHttp.ResponseCode) + ')');
189 FExecPath := filename;
190 FExecArgs := '/SP- /silent /noicons "/dir=' + GikoSys.GetAppDir + '"';
192 execPath, execArgs, GetDesktopDir) then begin
193 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');
194 // 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');
196 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');
203 //!
\83_
\83E
\83\93\83\8d\81[
\83h
\82µ
\82½
\83t
\83@
\83C
\83\8b\82Ì
\95Û
\91¶
\83p
\83X
204 function TUpdateCheckForm.GetDownloadFilePath(FileName: String): String;
206 TempPath: array[0..MAX_PATH] of Char;
208 GetTempPath(MAX_PATH, TempPath);
209 Result := IncludeTrailingPathDelimiter(TempPath) + FileName;
213 //!
\83f
\83X
\83N
\83g
\83b
\83v
\82Ì
\83p
\83X
\82ð
\8eæ
\93¾
\82·
\82é
\8aÖ
\90\94
214 function TUpdateCheckForm.GetDesktopDir:string;
216 DeskTopPath: array[0..MAX_PATH] of Char;
219 SHGetSpecialFolderLocation(Application.Handle, CSIDL_DESKTOP, pidl);
220 SHGetPathFromIDList(pidl, DesktopPath);
221 Result := DesktopPath;
224 //!
\83V
\83\87\81[
\83g
\83J
\83b
\83g
\82ð
\8dì
\90¬
\82·
\82é
\8aÖ
\90\94
225 function TUpdateCheckForm.CreateShortCut(FileName, Argment, SavePath :string):boolean;
226 //FileName
\81c
\83V
\83\87\81[
\83g
\83J
\83b
\83g
\82ð
\8dì
\90¬
\82·
\82é
\83t
\83@
\83C
\83\8b\96¼
227 //SavePath
\81c.lnk
\83t
\83@
\83C
\83\8b\82ð
\8dì
\90¬
\82·
\82é
\83f
\83B
\83\8c\83N
\83g
\83\8a
231 wFileName :WideString;
234 //IUnKnown
\83I
\83u
\83W
\83F
\83N
\83g
\82ð
\8dì
\90¬
\82µ
\82Ä
\81AIShellLink
\82É
\83L
\83\83\83X
\83g
235 SL :=CreateComObject(CLSID_ShellLink) as IShellLink;
236 //IPersistFile
\82É
\83L
\83\83\83X
\83g
237 PF :=SL as IPersistFile;
239 if (SL.SetPath(PChar(FileName)) <> NOERROR) then begin
242 if (SL.SetWorkingDirectory(PChar(ExtractFilePath(FileName)))
243 <> NOERROR ) then begin
246 if (SL.SetArguments(PChar(Argment)) <> NOERROR) then begin
249 if (SL.SetDescription(PChar('
\83M
\83R
\83i
\83r
\8dX
\90V')) <> NOERROR) then begin
253 //IPersistFile
\82ÌSave
\83\81\83\
\83b
\83h
\82É
\82ÍPWChar
\8c^
\82Ì
\83p
\83\89\83\81\81[
\83^
\82ª
\95K
\97v
254 wFileName :=SavePath +'\
\83M
\83R
\83i
\83r
\8dX
\90V.lnk';
255 //
\83V
\83\87\81[
\83g
\83J
\83b
\83g
\82ð
\8dì
\90¬
256 if (PF.Save(PWChar(wFileName),True) <> NOERROR) then begin
262 //! Form
\83R
\83\93\83X
\83g
\83\89\83N
\83^
263 procedure TUpdateCheckForm.FormCreate(Sender: TObject);
265 ResultMemo.Lines.Clear;
268 FAllowshutdown := False;