OSDN Git Service

ギコナビ更新チェック&インストーラ保存の機能を追加
authorh677 <h677>
Tue, 23 Sep 2008 11:06:17 +0000 (11:06 +0000)
committerh677 <h677>
Tue, 23 Sep 2008 11:06:17 +0000 (11:06 +0000)
Giko.dfm
Giko.pas
GikoDataModule.dfm
GikoDataModule.pas
UpdateCheck.dfm [new file with mode: 0644]
UpdateCheck.pas [new file with mode: 0644]
gikoNavi.dpr
gikoNavi.res

index 5148a1a..43446d2 100644 (file)
--- a/Giko.dfm
+++ b/Giko.dfm
@@ -1,5 +1,5 @@
 object GikoForm: TGikoForm
-  Left = 304
+  Left = 241
   Top = 116
   HorzScrollBar.Visible = False
   VertScrollBar.Visible = False
@@ -7606,6 +7606,12 @@ object GikoForm: TGikoForm
       object N80: TMenuItem
         Action = GikoDM.NewBoardSearchAction
       end
+      object N84: TMenuItem
+        Caption = '-'
+      end
+      object UpdateGikonaviAction1: TMenuItem
+        Action = GikoDM.UpdateGikonaviAction
+      end
       object N7: TMenuItem
         Caption = '-'
       end
index 838d263..575b7be 100644 (file)
--- a/Giko.pas
+++ b/Giko.pas
@@ -420,6 +420,8 @@ type
     TaskTrayPopupMenu: TPopupMenu;
     Exit1: TMenuItem;
     N83: TMenuItem;
+    UpdateGikonaviAction1: TMenuItem;
+    N84: TMenuItem;
                                procedure FormCreate(Sender: TObject);
                procedure FormDestroy(Sender: TObject);
                procedure BrowserStatusTextChange(Sender: TObject;
index 589305c..9cbf0cf 100644 (file)
@@ -1377,6 +1377,12 @@ object GikoDM: TGikoDM
       OnExecute = DereferenceResActionExecute
       OnUpdate = DependActiveCntentLogActionUpdate
     end
+    object UpdateGikonaviAction: TAction
+      Category = #12501#12449#12452#12523
+      Caption = #12462#12467#12490#12499#26356#26032
+      Hint = #12462#12467#12490#12499#12398#26356#26032
+      OnExecute = UpdateGikonaviActionExecute
+    end
   end
   object ToobarImageList: TImageList
     Left = 44
index 67576b3..eb3c64e 100644 (file)
@@ -242,6 +242,7 @@ type
     ExtractSameIDAction: TAction;
     ShowTabListAction: TAction;
     DereferenceResAction: TAction;
+    UpdateGikonaviAction: TAction;
        procedure EditNGActionExecute(Sender: TObject);
        procedure ReloadActionExecute(Sender: TObject);
        procedure GoFowardActionExecute(Sender: TObject);
@@ -454,6 +455,7 @@ type
     procedure ExtractSameIDActionExecute(Sender: TObject);
     procedure ShowTabListActionExecute(Sender: TObject);
     procedure DereferenceResActionExecute(Sender: TObject);
+    procedure UpdateGikonaviActionExecute(Sender: TObject);
   private
        { Private \90é\8c¾ }
        procedure ClearResFilter;
@@ -508,7 +510,7 @@ uses
        GikoBayesian, About, ShellAPI,
        RoundName, RoundData, Menus, ListViewUtils,
        ThreadControl, GikoMessage, InputAssist,
-    DefaultFileManager, Forms, NewBoardURL;
+    DefaultFileManager, Forms, NewBoardURL, UpdateCheck;
 
 const
        MSG_ERROR : string = '\83G\83\89\81[';
@@ -4563,5 +4565,23 @@ begin
     end;
 end;
 
+procedure TGikoDM.UpdateGikonaviActionExecute(Sender: TObject);
+var
+    form : TUpdateCheckForm;
+       Msg: string;
+begin
+       if (EditorFormExists) then begin
+               Msg := '\83\8c\83X\83G\83f\83B\83^\82ð\91S\82Ä\95Â\82\82Ä\82­\82¾\82³\82¢';
+               MsgBox(GikoForm.Handle, Msg, MSG_ERROR, MB_OK or MB_ICONSTOP);
+               Exit;
+       end;
+    form := TUpdateCheckForm.Create(Self);
+    try
+        form.ShowModal;
+    finally
+        form.Release;
+    end;
+end;
+
 end.
 
diff --git a/UpdateCheck.dfm b/UpdateCheck.dfm
new file mode 100644 (file)
index 0000000..f6be24c
--- /dev/null
@@ -0,0 +1,73 @@
+object UpdateCheckForm: TUpdateCheckForm
+  Left = 331
+  Top = 160
+  Width = 492
+  Height = 247
+  Caption = #26356#26032#12481#12455#12483#12463
+  Color = clBtnFace
+  Font.Charset = SHIFTJIS_CHARSET
+  Font.Color = clWindowText
+  Font.Height = -12
+  Font.Name = #65325#65331' '#65328#12468#12471#12483#12463
+  Font.Style = []
+  OldCreateOrder = False
+  Position = poDesktopCenter
+  OnCreate = FormCreate
+  PixelsPerInch = 96
+  TextHeight = 12
+  object Panel1: TPanel
+    Left = 0
+    Top = 0
+    Width = 484
+    Height = 41
+    Align = alTop
+    TabOrder = 0
+    object UpdateButton: TButton
+      Left = 16
+      Top = 8
+      Width = 75
+      Height = 25
+      Caption = #23455#34892
+      TabOrder = 0
+      OnClick = UpdateButtonClick
+    end
+  end
+  object Panel2: TPanel
+    Left = 0
+    Top = 41
+    Width = 484
+    Height = 172
+    Align = alClient
+    Caption = 'Panel2'
+    TabOrder = 1
+    object ResultMemo: TMemo
+      Left = 1
+      Top = 1
+      Width = 482
+      Height = 170
+      Align = alClient
+      Lines.Strings = (
+        'ResultMemo')
+      TabOrder = 0
+    end
+  end
+  object IdHTTP: TIdHTTP
+    MaxLineAction = maException
+    AllowCookies = True
+    ProxyParams.BasicAuthentication = False
+    ProxyParams.ProxyPort = 0
+    Request.ContentLength = -1
+    Request.ContentRangeEnd = 0
+    Request.ContentRangeStart = 0
+    Request.Accept = 'text/html, */*'
+    Request.BasicAuthentication = False
+    Request.UserAgent = 'Mozilla/3.0 (compatible; Indy Library)'
+    HTTPOptions = [hoForceEncodeParams]
+    Left = 400
+    Top = 8
+  end
+  object IdAntiFreeze: TIdAntiFreeze
+    Left = 440
+    Top = 8
+  end
+end
diff --git a/UpdateCheck.pas b/UpdateCheck.pas
new file mode 100644 (file)
index 0000000..4d12e4d
--- /dev/null
@@ -0,0 +1,206 @@
+unit UpdateCheck;
+
+interface
+
+uses
+  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
+  Dialogs, IdAntiFreezeBase, IdAntiFreeze, IdBaseComponent, IdComponent,
+  IdTCPConnection, IdTCPClient, IdHTTP, StdCtrls, ExtCtrls;
+
+type
+  TUpdateCheckForm = class(TForm)
+    Panel1: TPanel;
+    Panel2: TPanel;
+    ResultMemo: TMemo;
+    UpdateButton: TButton;
+    IdHTTP: TIdHTTP;
+    IdAntiFreeze: TIdAntiFreeze;
+    procedure UpdateButtonClick(Sender: TObject);
+    procedure FormCreate(Sender: TObject);
+  private
+    { Private \90é\8c¾ }
+    function  GetDesktopDir:string;
+    function  GetDownloadFilePath(FileName: String): String;
+    function  CreateShortCut(FileName, Argment, SavePath :string):boolean;
+    procedure DonwloadUpdate(url: String);
+  public
+    { Public \90é\8c¾ }
+  end;
+
+var
+  UpdateCheckForm: TUpdateCheckForm;
+
+implementation
+uses
+    GikoSystem, NewBoard, Giko, IniFiles, MojuUtils, GikoDataModule,
+    ActiveX, ComObj, ShlObj;
+    
+{$R *.dfm}
+
+procedure TUpdateCheckForm.UpdateButtonClick(Sender: TObject);
+const
+       CHECK_URL = 'http://gikonavi.sourceforge.jp/updater/latest.txt';
+var
+    value : string;
+       ResStream: TMemoryStream;
+    downResult, current, newest: TStringList;
+begin
+    ResultMemo.Lines.Clear;
+    Screen.Cursor := crHourGlass;
+    UpdateButton.Enabled := False;
+
+    try
+        ResStream := TMemoryStream.Create;
+        try
+            TNewBoardDialog.InitHTTPClient(IdHTTP);
+            IdHTTP.Request.Referer := '';
+            IdHTTP.Request.AcceptEncoding := 'gzip';
+
+            IdHTTP.Request.CacheControl := 'no-cache';
+            IdHTTP.Request.CustomHeaders.Add('Pragma: no-cache');
+            IdHTTP.HandleRedirects := true;
+            downResult := TStringList.Create;
+            newest     := TStringList.Create;
+            current    := TStringList.Create;
+            IdAntiFreeze.Active := true;
+            try
+                try
+                    ResStream.Clear;
+                    IdHTTP.Get(CHECK_URL, ResStream);
+                    value := GikoSys.GzipDecompress(ResStream,
+                            IdHTTP.Response.ContentEncoding);
+                    downResult.Text := value;
+                    newest.Text := MojuUtils.CustomStringReplace(downResult.Values[ 'version' ],
+                                        '.', #10, false);
+                    current.Text := MojuUtils.CustomStringReplace(GikoSys.Version,
+                                        '.', #10, false);
+                    if newest.Count >= 2 then begin
+                        if ( StrToInt(current[1]) < StrToInt(newest[1]) ) or
+                           ( (StrToInt(current[1]) = StrToInt(newest[1]))) and
+                           ((StrToInt(current[2]) < StrToInt(newest[2])) ) 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' ]));
+                        end else begin
+                            ResultMemo.Lines.Add('\8d¡\82Ì\83M\83R\83i\83r\82ª\8dÅ\90V\82Å\82·\81B');
+                        end;
+                    end else begin
+                        ResultMemo.Lines.Add('\8d¡\82Ì\83M\83R\83i\83r\82ª\8dÅ\90V\82Å\82·\81B');
+                    end;
+                except
+                    on E: Exception do begin
+                        ResultMemo.Lines.Add(E.Message);
+                        {$IFDEF DEBUG}
+                        Writeln(IdHTTP.ResponseText);
+                        {$ENDIF}
+                    end;
+                end;
+            finally
+                current.free;
+                newest.free;
+                downResult.Free;
+                IdAntiFreeze.Active := false;
+            end;
+        finally
+            ResStream.Clear;
+            ResStream.Free;
+        end;
+    finally
+        UpdateButton.Enabled := True;
+        Screen.Cursor := crDefault;
+    end;
+
+end;
+
+//! \83A\83b\83v\83f\81[\83g\83_\83E\83\93\83\8d\81[\83h
+procedure TUpdateCheckForm.DonwloadUpdate(url: String);
+var
+    filename : String;
+    fileStrem: TFileStream;
+begin
+    filename := GetDownloadFilePath(Copy(url, LastDelimiter('/', url) + 1,  Length(url)));
+    fileStrem := TFileStream.Create(filename, fmCreate);
+    try
+        IdHTTP.Get(url, fileStrem);
+        ResultMemo.Lines.Add(
+            IdHttp.ResponseText + '(' + IntToStr(IdHttp.ResponseCode) + ')');
+        if CreateShortCut(
+            filename,
+            '/SP- /silent /noicons "/dir=' + GikoSys.GetAppDir + '"'
+            , 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');
+        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;
+
+    finally
+        fileStrem.Free;
+    end;
+end;
+//! \83_\83E\83\93\83\8d\81[\83h\82µ\82½\83t\83@\83C\83\8b\82Ì\95Û\91\83p\83X
+function  TUpdateCheckForm.GetDownloadFilePath(FileName: String): String;
+var
+    TempPath: array[0..MAX_PATH] of Char;
+begin
+    GetTempPath(MAX_PATH, TempPath);
+    Result := IncludeTrailingPathDelimiter(TempPath) + FileName;
+end;
+
+
+//! \83f\83X\83N\83g\83b\83v\82Ì\83p\83X\82ð\8eæ\93¾\82·\82é\8aÖ\90\94
+function  TUpdateCheckForm.GetDesktopDir:string;
+var
+    DeskTopPath: array[0..MAX_PATH] of Char;
+    pidl: PItemIDList;
+begin
+    SHGetSpecialFolderLocation(Application.Handle, CSIDL_DESKTOP, pidl);
+    SHGetPathFromIDList(pidl, DesktopPath);
+    Result := DesktopPath;
+end;
+
+//! \83V\83\87\81[\83g\83J\83b\83g\82ð\8dì\90¬\82·\82é\8aÖ\90\94
+function  TUpdateCheckForm.CreateShortCut(FileName, Argment, SavePath :string):boolean;
+//FileName\81c\83V\83\87\81[\83g\83J\83b\83g\82ð\8dì\90¬\82·\82é\83t\83@\83C\83\8b\96¼
+//SavePath\81c.lnk\83t\83@\83C\83\8b\82ð\8dì\90¬\82·\82é\83f\83B\83\8c\83N\83g\83\8a
+var
+    SL :IShelllink;
+    PF :IPersistFile;
+    wFileName :WideString;
+begin
+    Result :=false;
+    //IUnKnown\83I\83u\83W\83F\83N\83g\82ð\8dì\90¬\82µ\82Ä\81AIShellLink\82É\83L\83\83\83X\83g
+    SL :=CreateComObject(CLSID_ShellLink) as IShellLink;
+    //IPersistFile \82É\83L\83\83\83X\83g
+    PF :=SL as IPersistFile;
+
+    if (SL.SetPath(PChar(FileName)) <> NOERROR) then begin
+        Exit;
+    end;
+    if (SL.SetWorkingDirectory(PChar(ExtractFilePath(FileName)))
+                                   <> NOERROR ) then begin
+        Exit;
+    end;
+    if (SL.SetArguments(PChar(Argment)) <> NOERROR) then begin
+        Exit;
+    end;
+    if (SL.SetDescription(PChar('\83M\83R\83i\83r\8dX\90V')) <> NOERROR) then begin
+        Exit;
+    end;
+
+    //IPersistFile\82ÌSave\83\81\83\\83b\83h\82É\82ÍPWChar\8c^\82Ì\83p\83\89\83\81\81[\83^\82ª\95K\97v
+    wFileName :=SavePath +'\\83M\83R\83i\83r\8dX\90V.lnk';
+    //\83V\83\87\81[\83g\83J\83b\83g\82ð\8dì\90¬
+    if (PF.Save(PWChar(wFileName),True) <> NOERROR) then begin
+        Exit;
+    end;
+    Result :=true;
+end;
+
+//! Form\83R\83\93\83X\83g\83\89\83N\83^
+procedure TUpdateCheckForm.FormCreate(Sender: TObject);
+begin
+    ResultMemo.Lines.Clear;
+end;
+
+end.
index 7f89a4a..a575549 100644 (file)
@@ -80,7 +80,8 @@ uses
   ResPopupBrowser in 'ResPopupBrowser.pas',
   SkinFiles in 'SkinFiles.pas',
   NewBoardURL in 'NewBoardURL.pas' {NewBoardURLForm},
-  ExtPreviewDatamodule in 'ExtPreviewDatamodule.pas' {ExtPreviewDM: TDataModule};
+  ExtPreviewDatamodule in 'ExtPreviewDatamodule.pas' {ExtPreviewDM: TDataModule},
+  UpdateCheck in 'UpdateCheck.pas' {UpdateCheckForm};
 
 {$R *.RES}
 {$R gikoResource.res}
@@ -139,6 +140,7 @@ begin
   Application.CreateForm(TReplaceDM, ReplaceDM);
   Application.CreateForm(TExtPreviewDM, ExtPreviewDM);
   Application.CreateForm(TGikoForm, GikoForm);
+  Application.CreateForm(TUpdateCheckForm, UpdateCheckForm);
   Application.Run;
                ReleaseMutex(hMutex);
        end;
index 5035236..982f1d3 100644 (file)
Binary files a/gikoNavi.res and b/gikoNavi.res differ