OSDN Git Service

避難所版
[gikonavigoeson/gikonavi.git] / UpdateCheck.pas
index 6385a01..2495065 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,12 +78,14 @@ 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 : string;
+    value, url : string;
        ResStream: TMemoryStream;
     downResult, current, newest: TStringList;
     newgiko: Boolean;
@@ -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;
@@ -129,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])) );
@@ -138,9 +153,8 @@ 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
@@ -168,6 +182,7 @@ begin
             ResStream.Free;
         end;
     finally
+        NightBuildCheckButton.Enabled := True;
         UpdateButton.Enabled := True;
         Screen.Cursor := crDefault;
     end;
@@ -183,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;
@@ -267,5 +287,14 @@ begin
     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.