X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=UpdateCheck.pas;h=dd252727c65dedb11e656a2be6cb6736cfa50353;hb=refs%2Fheads%2Fmaster;hp=fe0fa4d282cef86f431390646b625c1784de2371;hpb=145a7b174f53df2972f30af26c58243b65a7570d;p=gikonavigoeson%2Fgikonavi.git diff --git a/UpdateCheck.pas b/UpdateCheck.pas index fe0fa4d..dd25272 100644 --- a/UpdateCheck.pas +++ b/UpdateCheck.pas @@ -5,7 +5,7 @@ interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, IdAntiFreezeBase, IdAntiFreeze, IdBaseComponent, IdComponent, - IdTCPConnection, IdTCPClient, IdHTTP, StdCtrls, ExtCtrls; + IdTCPConnection, IdTCPClient, IdHTTP, StdCtrls, ExtCtrls, Buttons; type TUpdateCheckForm = class(TForm) @@ -16,18 +16,27 @@ type IdHTTP: TIdHTTP; IdAntiFreeze: TIdAntiFreeze; NightBuildCheckButton: TButton; + CancelBitBtn: TBitBtn; procedure UpdateButtonClick(Sender: TObject); procedure FormCreate(Sender: TObject); procedure NightBuildCheckButtonClick(Sender: TObject); + procedure CancelBitBtnClick(Sender: TObject); private { Private éŒ¾ } + FExecPath : string; + FExecArgs : string; + FAllowshutdown : Boolean; + FCanceled : Boolean; function GetDesktopDir:string; function GetDownloadFilePath(FileName: String): String; function CreateShortCut(FileName, Argment, SavePath :string):boolean; procedure DonwloadUpdate(url: String); - procedure CheckUpdate(nightbuild :Boolean); + function CheckUpdate(nightbuild :Boolean): Boolean; public { Public éŒ¾ } + property ExecPath :String read FExecPath; + property ExecArgs :String read FExecArgs; + property Allowshutdown :Boolean read FAllowshutdown; end; var @@ -39,24 +48,56 @@ uses ActiveX, ComObj, ShlObj, GikoUtil; {$R *.dfm} - +//! ³‹K”Å procedure TUpdateCheckForm.UpdateButtonClick(Sender: TObject); begin - CheckUpdate(false); + if CheckUpdate(false) then begin + if GikoUtil.MsgBox(Handle, 'XV‚ª‚ ‚邽‚߃MƒRƒiƒr‚ðÄ‹N“®‚µ‚Ü‚·‚©H', 'I—¹Šm”F', + MB_YESNO or MB_ICONWARNING or MB_DEFBUTTON2) = ID_YES then begin + FAllowshutdown := True; + close; + end; + end; +end; +//! l’Œ”Å +procedure TUpdateCheckForm.NightBuildCheckButtonClick(Sender: TObject); +begin + if GikoUtil.MsgBox(Handle, '³Ž®ƒŠƒŠ[ƒX”Å‚Å‚Í‚ ‚è‚Ü‚¹‚ñ‚ª‚æ‚낵‚¢‚Å‚·‚©H', 'XVŠm”F', + MB_YESNO or MB_ICONWARNING or MB_DEFBUTTON2) = ID_YES then begin + if CheckUpdate(true) then begin + if GikoUtil.MsgBox(Handle, 'XV‚ª‚ ‚邽‚߃MƒRƒiƒr‚ðÄ‹N“®‚µ‚Ü‚·‚©H', 'I—¹Šm”F', + MB_YESNO or MB_ICONWARNING or MB_DEFBUTTON2) = ID_YES then begin + FAllowshutdown := True; + close; + end; + end; + end; end; + //! ƒAƒbƒvƒf[ƒg‘Ώۊm”F -procedure TUpdateCheckForm.CheckUpdate(nightbuild :Boolean); +function TUpdateCheckForm.CheckUpdate(nightbuild :Boolean): Boolean; const - CHECK_URL = 'http://gikonavi.sourceforge.jp/updater/latest.txt'; +{$IFDEF DEBUG} +// CHECK_URL = 'http://gikonavi.sourceforge.jp/updater/debug.txt'; + CHECK_URL = 'http://gikonavigoeson.sourceforge.jp/updater/debug.txt'; +{$ELSE} +// CHECK_URL = 'http://gikonavi.sourceforge.jp/updater/latest.txt'; + CHECK_URL = 'http://gikonavigoeson.sourceforge.jp/updater/latest.txt'; +{$ENDIF} var - value : string; + value, url : string; ResStream: TMemoryStream; downResult, current, newest: TStringList; newgiko: Boolean; begin + Result := false; + FExecPath := ''; + FExecArgs := ''; + FAllowshutdown := False; ResultMemo.Lines.Clear; Screen.Cursor := crHourGlass; UpdateButton.Enabled := False; + NightBuildCheckButton.Enabled := False; try ResStream := TMemoryStream.Create; @@ -67,6 +108,7 @@ begin IdHTTP.Request.CacheControl := 'no-cache'; IdHTTP.Request.CustomHeaders.Add('Pragma: no-cache'); + IdHTTP.ReadTimeout := 0; IdHTTP.HandleRedirects := true; downResult := TStringList.Create; newest := TStringList.Create; @@ -75,7 +117,13 @@ begin try try ResStream.Clear; + FCanceled := False; + CancelBitBtn.Enabled := True; IdHTTP.Get(CHECK_URL, ResStream); + CancelBitBtn.Enabled := False; + if (FCanceled) then begin + raise Exception.Create('ƒ_ƒEƒ“ƒ[ƒh‚ªƒLƒƒƒ“ƒZƒ‹‚³‚ê‚Ü‚µ‚½B'); + end; value := GikoSys.GzipDecompress(ResStream, IdHTTP.Response.ContentEncoding); downResult.Text := value; @@ -94,8 +142,10 @@ begin newgiko := false; // night build‚́Aƒrƒ‹ƒh”ԍ†‚¾‚¯‚Å”»’è‚·‚é if (nightbuild) then begin + url := downResult.Values[ 'n_url' ]; newgiko := StrToInt(current[3]) < StrToInt(newest[3]); end else begin + url := downResult.Values[ 'url' ]; newgiko := ( StrToInt(current[1]) < StrToInt(newest[1]) ) or ( (StrToInt(current[1]) = StrToInt(newest[1]))) and ((StrToInt(current[2]) < StrToInt(newest[2])) ); @@ -103,9 +153,9 @@ begin if (newgiko) then begin if GikoUtil.MsgBox(Handle, 'V‚µ‚¢ƒMƒRƒiƒr‚ª‚ ‚è‚Ü‚·Bƒ_ƒEƒ“ƒ[ƒh‚µ‚Ü‚·‚©H', 'XVŠm”F', MB_YESNO or MB_ICONWARNING or MB_DEFBUTTON2) = ID_YES then begin - - ResultMemo.Lines.Add('V‚µ‚¢ƒMƒRƒiƒr‚ª‚ ‚è‚Ü‚·Bƒ_ƒEƒ“ƒ[ƒh‚ðŠJŽn‚µ‚Ü‚·B' + downResult.Values[ 'url' ]); - DonwloadUpdate(Trim(downResult.Values[ 'url' ])); + ResultMemo.Lines.Add('V‚µ‚¢ƒMƒRƒiƒr‚ª‚ ‚è‚Ü‚·Bƒ_ƒEƒ“ƒ[ƒh‚ðŠJŽn‚µ‚Ü‚·B' + url); + DonwloadUpdate(Trim(url)); + Result := True; end; end else begin ResultMemo.Lines.Add('¡‚̃MƒRƒiƒr‚ªÅV‚Å‚·B'); @@ -132,6 +182,7 @@ begin ResStream.Free; end; finally + NightBuildCheckButton.Enabled := True; UpdateButton.Enabled := True; Screen.Cursor := crDefault; end; @@ -147,15 +198,20 @@ begin filename := GetDownloadFilePath(Copy(url, LastDelimiter('/', url) + 1, Length(url))); fileStrem := TFileStream.Create(filename, fmCreate); try + CancelBitBtn.Enabled := True; IdHTTP.Get(url, fileStrem); + CancelBitBtn.Enabled := False; + if (FCanceled) then begin + raise Exception.Create('ƒ_ƒEƒ“ƒ[ƒh‚ªƒLƒƒƒ“ƒZƒ‹‚³‚ê‚Ü‚µ‚½B'); + end; ResultMemo.Lines.Add( IdHttp.ResponseText + '(' + IntToStr(IdHttp.ResponseCode) + ')'); + FExecPath := filename; + FExecArgs := '/SP- /silent /noicons "/dir=' + GikoSys.GetAppDir + '"'; if CreateShortCut( - filename, - '/SP- /silent /noicons "/dir=' + GikoSys.GetAppDir + '"' - , GetDesktopDir) then begin + execPath, execArgs, GetDesktopDir) then begin ResultMemo.Lines.Add('ƒfƒXƒNƒgƒbƒv‚É"ƒMƒRƒiƒrXV"ƒVƒ‡[ƒgƒJƒbƒg‚ðì¬‚µ‚Ü‚µ‚½B'); - ResultMemo.Lines.Add('ƒMƒRƒiƒr‚ðI—¹‚µ‚āA"ƒMƒRƒiƒrXV"ƒVƒ‡[ƒgƒJƒbƒg‚ðƒ_ƒuƒ‹ƒNƒŠƒbƒN‚µ‚Ä‚­‚¾‚³‚¢B'); + // ResultMemo.Lines.Add('ƒMƒRƒiƒr‚ðI—¹‚µ‚āA"ƒMƒRƒiƒrXV"ƒVƒ‡[ƒgƒJƒbƒg‚ðƒ_ƒuƒ‹ƒNƒŠƒbƒN‚µ‚Ä‚­‚¾‚³‚¢B'); end else begin ResultMemo.Lines.Add('ƒfƒXƒNƒgƒbƒv‚ɃVƒ‡[ƒgƒJƒbƒg‚ðì¬‚Å‚«‚Ü‚¹‚ñ‚Å‚µ‚½B'); end; @@ -225,15 +281,30 @@ end; //! FormƒRƒ“ƒXƒgƒ‰ƒNƒ^ procedure TUpdateCheckForm.FormCreate(Sender: TObject); +var + CenterForm: TCustomForm; begin + CenterForm := TCustomForm(Owner); + if Assigned(CenterForm) then begin + Left := ((CenterForm.Width - Width) div 2) + CenterForm.Left; + Top := ((CenterForm.Height - Height) div 2) + CenterForm.Top; + end else begin + Left := (Screen.Width - Width) div 2; + Top := (Screen.Height - Height) div 2; + end; + ResultMemo.Lines.Clear; + FExecPath := ''; + FExecArgs := ''; + FAllowshutdown := False; end; - -procedure TUpdateCheckForm.NightBuildCheckButtonClick(Sender: TObject); +//! ƒLƒƒƒ“ƒZƒ‹ƒ{ƒ^ƒ“‰Ÿ‰º +procedure TUpdateCheckForm.CancelBitBtnClick(Sender: TObject); begin - if GikoUtil.MsgBox(Handle, '³Ž®ƒŠƒŠ[ƒX”Å‚Å‚Í‚ ‚è‚Ü‚¹‚ñ‚ª‚æ‚낵‚¢‚Å‚·‚©H', 'XVŠm”F', - MB_YESNO or MB_ICONWARNING or MB_DEFBUTTON2) = ID_YES then begin - CheckUpdate(true); + CancelBitBtn.Enabled := False; + FCanceled := True; + if IdHTTP.Connected then begin + IdHTTP.Disconnect; end; end;