UP

zhaozj2021-02-16  66

Unit Up;

Interface

Uses Windows, Messages, Sysutils, Variants, Classes, Graphics, Controls, Forms, Stdctrls, Extctrls, Rzpanel, INIFILES, RZSTATUS, IDHTTTP, 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 Not 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)

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 = '' TEN 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);

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; 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')) The begin Continue; end; inIfile.clear; httpget.get (URL Files [i], inIfile; inIfile .Savetofile (g_path 'update /' files [i]); Except

END;

Freeandnil; {for i: = 0 to FILES.COUNT - 1 Do Begin Try if FileExists (g_path 'Update /' Files [i]) Then Deletefile (g_path files [i]); eXcePtend;

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

FINALLY Appini.Free; Files.Free; 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 = '' TEN 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; 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 ')) The begin Continue; End; Result: = true; Break; Excendnd ; "Fatabase.free; end;

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

DeStructor Tupdate.destroy; begin xrwini.free; getVersion.free; httpget.free; inherited;

End.

转载请注明原文地址:https://www.9cbs.com/read-17406.html

New Post(0)