OSDN Git Service

・板一覧更新の処理メッセージを追加
[gikonavigoeson/gikonavi.git] / UpdateCheck.pas
index b2b7469..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,14 +16,17 @@ 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;
@@ -75,9 +78,11 @@ end;
 function TUpdateCheckForm.CheckUpdate(nightbuild :Boolean): Boolean;
 const
 {$IFDEF DEBUG}
-       CHECK_URL = 'http://gikonavi.sourceforge.jp/updater/debug.txt';
+//     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://gikonavi.sourceforge.jp/updater/latest.txt';
+       CHECK_URL = 'http://gikonavigoeson.sourceforge.jp/updater/latest.txt';
 {$ENDIF}
 var
     value, url : string;
@@ -92,6 +97,7 @@ begin
     ResultMemo.Lines.Clear;
     Screen.Cursor := crHourGlass;
     UpdateButton.Enabled := False;
+    NightBuildCheckButton.Enabled := False;
 
     try
         ResStream := TMemoryStream.Create;
@@ -102,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;
@@ -110,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;
@@ -169,6 +182,7 @@ begin
             ResStream.Free;
         end;
     finally
+        NightBuildCheckButton.Enabled := True;
         UpdateButton.Enabled := True;
         Screen.Cursor := crDefault;
     end;
@@ -184,7 +198,12 @@ 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;
@@ -262,11 +281,31 @@ 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;
+//! \83L\83\83\83\93\83Z\83\8b\83{\83^\83\93\89\9f\89º
+procedure TUpdateCheckForm.CancelBitBtnClick(Sender: TObject);
+begin
+    CancelBitBtn.Enabled := False;
+    FCanceled := True;
+    if IdHTTP.Connected then begin
+        IdHTTP.Disconnect;
+    end;
+end;
 
 end.