OSDN Git Service

・板一覧更新の処理メッセージを追加
[gikonavigoeson/gikonavi.git] / UpdateCheck.pas
index fe0fa4d..dd25272 100644 (file)
@@ -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 \90é\8c¾ }
+    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 \90é\8c¾ }
+    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}
-
+//! \90³\8bK\94Å
 procedure TUpdateCheckForm.UpdateButtonClick(Sender: TObject);
 begin
-    CheckUpdate(false);
+    if CheckUpdate(false) then begin
+        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',
+            MB_YESNO or MB_ICONWARNING or MB_DEFBUTTON2) = ID_YES then begin
+            FAllowshutdown := True;
+            close;
+        end;
+    end;
+end;
+//! \90l\92\8c\94Å
+procedure TUpdateCheckForm.NightBuildCheckButtonClick(Sender: TObject);
+begin
+    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',
+        MB_YESNO or MB_ICONWARNING or MB_DEFBUTTON2) = ID_YES then begin
+        if CheckUpdate(true) then begin
+            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',
+                MB_YESNO or MB_ICONWARNING or MB_DEFBUTTON2) = ID_YES then begin
+                FAllowshutdown := True;
+                close;
+            end;
+        end;
+    end;
 end;
+
 //! \83A\83b\83v\83f\81[\83g\91Î\8fÛ\8am\94F
-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('\83_\83E\83\93\83\8d\81[\83h\82ª\83L\83\83\83\93\83Z\83\8b\82³\82ê\82Ü\82µ\82½\81B');
+                    end;
                     value := GikoSys.GzipDecompress(ResStream,
                             IdHTTP.Response.ContentEncoding);
                     downResult.Text := value;
@@ -94,8 +142,10 @@ begin
                         newgiko := false;
                         // night build\82Í\81A\83r\83\8b\83h\94Ô\8d\86\82¾\82¯\82Å\94»\92è\82·\82é
                         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, '\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',
                                 MB_YESNO or MB_ICONWARNING or MB_DEFBUTTON2) = ID_YES then begin
-
-                                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' ]);
-                                DonwloadUpdate(Trim(downResult.Values[ 'url' ]));
+                                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);
+                                DonwloadUpdate(Trim(url));
+                                Result := True;
                             end;
                         end else begin
                             ResultMemo.Lines.Add('\8d¡\82Ì\83M\83R\83i\83r\82ª\8dÅ\90V\82Å\82·\81B');
@@ -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('\83_\83E\83\93\83\8d\81[\83h\82ª\83L\83\83\83\93\83Z\83\8b\82³\82ê\82Ü\82µ\82½\81B');
+        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('\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');
-            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');
+            // 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');
         end else begin
             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');
         end;
@@ -225,15 +281,30 @@ end;
 
 //! Form\83R\83\93\83X\83g\83\89\83N\83^
 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);
+//! \83L\83\83\83\93\83Z\83\8b\83{\83^\83\93\89\9f\89º
+procedure TUpdateCheckForm.CancelBitBtnClick(Sender: TObject);
 begin
-    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',
-        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;