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.