up

unit up;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  StdCtrls, ExtCtrls, RzPanel, IniFiles, RzStatus, IdHTTP, IdGlobal, Registry,
  rwIni;

type
  TUpdate = class(TObject)
  private
    xrwIni: TrwIni;
    GetVersion: TRzVersionInfo;
    httpGet: TIdHTTP;
  public
    function DownFiles: Boolean;
    function CompStr(Src, Dst: string): Boolean;
    function CheckVersion: Boolean;
    constructor Create; overload;
    destructor Destroy; override;
  end;

var
  xUpdate: TUpdate;

implementation

function TUpdate.CompStr(Src, Dst: string): Boolean;
var
  i: integer;
  iSrc: string;
  iDst: string;
begin
  Result := True;
  for i := 0 to 3 do
  begin
    iSrc := Copy(Src, 0, pos('.', Src) - 1);
    Src := Copy(Src, pos('.', Src) + 1, Length(Src) - pos('.', Src) + 1);
    if not (pos('.', Src) > 0) then iSrc := Src;
    iDst := Copy(Dst, 0, pos('.', Dst) - 1);
    Dst := Copy(Dst, pos('.', Dst) + 1, Length(Dst) - pos('.', Dst) + 1);
    if not (pos('.', Dst) > 0) then iDst := Dst;
    try
      if StrToInt(iSrc) < StrToInt(iDst) then
      begin
        Result := False;
        Break;
      end;
    except
      Result := False;
      Break;
    end;
  end;
end;

function TUpdate.DownFiles: Boolean;
var
  i, iFileHandle: integer;
  Version: string;
  AppIni: TiniFile;
  g_path: string;
  url: string;
  upgrade: string;
  files: TStrings;
  IniFile: TMemoryStream;
begin
  url := xrwIni.hkReadString('Server');
  if url = '' then url := 'http://www.big1163.com/';
  if Copy(url, Length(url), 1) <> '/' then url := url + '/';
  url := url + 'superform/';

  g_path := ExtractFilePath(application.ExeName);
  IniFile := TMemoryStream.Create;
  try
    httpGet.Get(url + 'update.ini', IniFile);
    IniFile.SaveToFile(g_path + 'update/update.ini');
  except
    Result := False;
    FreeAndNil(IniFile);
    Exit;
  end;

  try
    Files := TStringlist.Create;
    AppIni := TIniFile.Create(g_path + '/update/update.ini');
    AppIni.ReadSections(files);
    for i := 0 to files.Count - 1 do
    begin
      try
        if pos(uppercase('setup.exe'), uppercase(files[i])) > 0 then
        begin
          GetVersion.FilePath := g_path + ExtractFileName(Application.ExeName);
          version := GetVersion.FileVersion;
        end
        else
        begin
          GetVersion.FilePath := g_path + files[i];
          Version := GetVersion.FileVersion;
        end;
        if pos('Value', Version) > 0 then Version := '1.0.0.0';

        if CompStr(Version, Appini.ReadString(files[i], 'Ver', '1.0.0.1')) then
        begin
          Continue;
        end;
        IniFile.Clear;
        httpGet.Get(url + files[i], IniFile);
        IniFile.SaveToFile(g_path + 'update/' + files[i]);
      except

      end;
    end;

    FreeAndNil(IniFile);
{
    for i := 0 to files.Count - 1 do
    begin
      try
        if FileExists(g_path + 'update/' + files[i]) then
          DeleteFile(g_path + files[i]);
      except

      end;
    end;

    for i := 0 to files.Count - 1 do
    begin
      try
        if FileExists(g_path + 'update/' + files[i]) then
        begin
          if CopyFileTo(g_path + 'update/' + files[i], g_path + files[i]) then
            DeleteFile(g_path + 'update/' + files[i]);
        end;
      except

      end;
    end;
}   
  finally
    AppIni.free;
    files.Free;
  end;
end;

function TUpdate.CheckVersion: Boolean;
var
  i, iFileHandle: integer;
  Version: string;
  AppIni: TiniFile;
  g_path: string;
  url: string;
  upgrade: string;
  files: TStrings;
  IniFile: TMemoryStream;
begin
  url := xrwIni.hkReadString('Server');
  if url = '' then url := 'http://www.big1163.com/';
  if Copy(url, Length(url), 1) <> '/' then url := url + '/';
  url := url + 'superform/';

  g_path := ExtractFilePath(application.ExeName);
  IniFile := TMemoryStream.Create;
  try
    httpGet.Get(url + 'update.ini', IniFile);
    IniFile.SaveToFile(g_path + 'update/update.ini');
  except
    Result := False;
    FreeAndNil(IniFile);
    Exit;
  end;

  try
    Files := TStringlist.Create;
    AppIni := TIniFile.Create(g_path + '/update/update.ini');
    AppIni.ReadSections(files);
    for i := 0 to files.Count - 1 do
    begin
      try
        if pos(uppercase('setup.exe'), uppercase(files[i])) > 0 then
        begin
          GetVersion.FilePath := g_path + ExtractFileName(Application.ExeName);
          version := GetVersion.FileVersion;
        end
        else
        begin
          GetVersion.FilePath := g_path + files[i];
          Version := GetVersion.FileVersion;
        end;
        if pos('Value', Version) > 0 then Version := '1.0.0.0';
        if Appini.ReadString(files[i], 'Ver', '') = '' then Continue;
        if CompStr(Version, Appini.ReadString(files[i], 'Ver', '1.0.0.1')) then
        begin
          Continue;
        end;
        Result := True;
        Break;
      except

      end;
    end;
  finally
    AppIni.free;
    files.Free;
  end;
end;

constructor TUpdate.Create;
begin
  xrwIni := TrwIni.Create(nil);
  xrwIni.RegistryPath := '/Software/supermail/';
  GetVersion := TRzVersionInfo.Create(nil);
  httpGet := TIdHTTP.Create(nil);
  inherited Create;
end;

destructor TUpdate.Destroy;
begin
  xrwIni.Free;
  GetVersion.Free;
  httpGet.Free;
  inherited;
end;

end.

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值