Make online programs upgrade information query with Delphi

zhaozj2021-02-08  194

More and more programs support online upgrade features, this article describes how to get upgrade information from the website. Here I mainly use the version information to detect if I need to download the upgrade version. The general principles are as follows: 1, place the information text to the website. 2. Use TNMHTTP to get text content from the website information text. 3. Analyze text parses required information. 4. The comparison program version provides upgrade information. First, let's place an information text to your own website. This text has its own file format, I defined the following format: [update] 1.79.9.25 http://delphibox.com /softm/3_update.zip 2002-9-25 [/ update] We can save it as an update.txt file, use the [] <> marker to classify information, here Contains program name, version, update date and download address. Here I am going uploaded to http://2ccc.com/Update.txt. Then we use TNMHTTP component to get the contents of this file from a Web site: function TForm1.GetUpdateText: String; begin NMHTTP1.InputFileMode: = FALSE; NMHTTP1.OutputFileMode: = FALSE; NMHTTP1.ReportLevel: = Status_Basic; NMHTTP1.Get ( 'http: / /2ccc.com/update.txt '); {Get Site Text} Result: = NMHTTP1.BODY; END; After obtaining text, we have to separate it, I use the following functions: Function TFORM1.AalyseUpdate : String; Var Update: tupdate: boolean; var Tmpstr, Ver: string; bEFORE, AFTER: STRING: String; {This function is used to separate strings in the middle of the two strings, for example .. ('delphiBox.com', 'delphi', '. CoM') => 'Box'.

VAR POS1, POS2: Word; Begin Pos1: = POS (Before, SRC) Length (Before); POS2: = POS (After, SRC); Result: = Copy (SRC, POS1, POS2-POS1); Begin Tmpstr: = CENTERSTR (Body, 'Update'); {Get Upgrade Information between Program Men} If Tmpstr = '' Then Result: = FALSE ELSE {Can't find this file upgrade information} Begin Ver: = centerstr (Tmpstr, '', ''); update.version: = SeparateVerstr (Ver); {Resolution version} Update.date.date:=stodate(Centerstr (TMPSTR, '', ' ')); {Analysis Date} Update.URL: = CENTERSTR (Tmpstr,' '); {Analytical Upgrade Address} Result: = True; End; End; Tupdate is my definition Information record format: TSIMpleversion = Record {Simplified version information} dwproductversionms: dWord; {Main version} dwproductVersionls: dword; {Acute version} end; tupdate = record {Upgrade information} Name: string [63]; {program name } Version: Tsimpleversion; {version} Date: Tdate; {Date} URL: ShortString; {Download address} end; {Download address} end; and the SeparateVerstr () function is the upgraded version of the upgrade version of the upgrade version of the information. (s: string): tsimpleversion; const separator = '.'; {II '.' split} var P, V1, V2, V3, V4: Word; Begin if longth (s) = 0 dam (SEPARATOR, S); V1: = STRTOINT (COPY (S, 1, P-1)); delete (s, 1, p); p: = POS (SEPARATOR, S); V2: = STRTOINT (COPY (S, 1, P-1)); delete (s, 1, p); p: = POS (Separator, s); v3: = start (COPY) S, 1, p-1); delete (s, 1, p); v4: = start (s); result.dwproductversionms: = V1 * $ 10000 v2; result.dwproductversionls: = v3 * $ 10000 v4; END The last thing to do is the version information of the comparison file, first get your own version, I use the following function: Function getBuildInfo (FNAME: STRING): Tsimpleversion; {Get itself version information} var verinfosize: DWORD;

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

New Post(0)