⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 checkfornewversion.pas

📁 防火墙DELPHI代码 防火墙DELPHI代码
💻 PAS
字号:
//iSafer.CheckForNewVersion.pas (C) 2004 DoDucTruong, Truong2D@Yahoo.com
unit CheckForNewVersion;

interface

uses
  Classes, SysUtils, IdHTTP, windows, forms;

type
  THtmlLoader = class(TThread)
  protected
    procedure Execute; override;
  public
  end;

  procedure CheckForNewUpdates();
  procedure Shell32Bit(JobToDo:String;booWait: BOOL);
var
  strMyVersion:string;

implementation

uses
  wininet;

procedure CheckForNewUpdates();
var
  htmlLoader: THtmlLoader;
begin
  try
    htmlLoader:= THtmlLoader.Create(True);
    htmlLoader.FreeOnTerminate:=True;
    htmlLoader.Resume;
  finally
  end;
end;

//Shell a program [and wait until it finishes]
procedure Shell32Bit(JobToDo:String; booWait: BOOL);
var
    RetVal:Cardinal;
    pi:PROCESS_INFORMATION;
    si:STARTUPINFO;
Begin
  FillMemory(@si, sizeof( si ), 0 );
  si.dwFlags:=STARTF_USESHOWWINDOW;
  si.wShowWindow:=SW_HIDE;
  si.cb := sizeof(STARTUPINFO);
  CreateProcess(nil,Pchar(JobToDo), nil, nil, False, CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS, nil,nil, si,pi);
  if booWait then
    repeat
      //Get the status of the process
      GetExitCodeProcess(pi.hProcess, RetVal);
    until RetVal <> STILL_ACTIVE;
End;

function FileVersion(const FileName: String;
  const Fmt: String = '%0.4d.%0.4d.%0.4d.%0.4d'): String;
var
  iBufferSize: DWORD;
  iDummy: DWORD;
  pBuffer: Pointer;
  pFileInfo: Pointer;
  iVer: Array[1..4] of Word;
begin
  // set default value
  Result := '9999.9999.9999.9999';
  // get size of version info (0 if no version info exists)
  iBufferSize := GetFileVersionInfoSize(PChar(FileName), iDummy);
  if (iBufferSize > 0) then
  begin
    GetMem(pBuffer, iBufferSize);
    try
    // get fixed file info
    GetFileVersionInfo(PChar(FileName), 0, iBufferSize, pBuffer);
    VerQueryValue(pBuffer, '\', pFileInfo, iDummy);
    // read version blocks
    iVer[1] := HiWord(PVSFixedFileInfo(pFileInfo)^.dwFileVersionMS);
    iVer[2] := LoWord(PVSFixedFileInfo(pFileInfo)^.dwFileVersionMS);
    iVer[3] := HiWord(PVSFixedFileInfo(pFileInfo)^.dwFileVersionLS);
    iVer[4] := LoWord(PVSFixedFileInfo(pFileInfo)^.dwFileVersionLS);
    finally
      FreeMem(pBuffer);
    end;
    // format result string
    Result := Format(Fmt, [iVer[1], iVer[2], iVer[3], iVer[4]]);
  end;
end;

//Perform a simple check about the new version.
procedure THtmlLoader.Execute;
var
  http: TIdHTTP;
  strLatestVersion:string;
begin
  http:=TIdHTTP.Create(nil);
  try
    try
      Http.Request.UserAgent := 'User-Agent: NULL';
      strLatestVersion := Http.Get('http://winsockfirewall.sourceforge.net/latest-ver.htm');

      strMyVersion:= FileVersion(Application.ExeName);
      if (strlen(Pchar(strLatestVersion))=strlen('9999.9999.9999.9999')) and (pos('.',strLatestVersion)=5) then if strLatestVersion > strMyVersion then begin
        If MessageBox(0,'There is a new version of iSafer, do you want to check it out?','iSafer',MB_ICONINFORMATION or MB_YESNO)=IDYES then
          Shell32Bit('explorer.exe http://winsockfirewall.sourceforge.net/latestversion.htm',False);
      end;
    except
      on E: Exception do strLatestVersion := Pchar('Error: ' + E.Message);
    end;
  finally
    Http.Disconnect;
    Http.Free;
  end;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -