/[projects]/dao/DelphiScanner/Utils.pas
ViewVC logotype

Diff of /dao/DelphiScanner/Utils.pas

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2682 by torben, Wed Aug 26 19:52:38 2015 UTC revision 2695 by torben, Thu Sep 3 14:40:49 2015 UTC
# Line 3  unit Utils; Line 3  unit Utils;
3  interface  interface
4  uses  uses
5    Controls,    Controls,
6    Graphics //TColor    Graphics, //TColor
7      IniFiles,
8      Windows //TFileTime
9    ;    ;
10    
11  type  type
# Line 20  type Line 22  type
22      class function TColorToHex(Color : TColor) : string;      class function TColorToHex(Color : TColor) : string;
23      class function HexToTColor(sColor : string) : TColor;      class function HexToTColor(sColor : string) : TColor;
24    
25        class function AdobeReaderExists(): Boolean;
26    
27        class function Sto_GetFmtFileVersion(const FileName: String = ''): String;
28    
29        class function CheckUrl(url:string): boolean;
30    
31        class function FileTime2DateTime(FileTime: TFileTime): TDateTime;
32    
33    
34    
35    
# Line 29  implementation Line 39  implementation
39    
40  uses StrUtils,  uses StrUtils,
41    Types, //TRect ,    Types, //TRect ,
   Windows,  
42    Messages,    Messages,
43    SysUtils //IntToStr etc    SysUtils, //IntToStr etc
44      Registry,
45      wininet   //CheckUrl
46    
47    ;    ;
48    
49  {  {
# Line 161  begin Line 173  begin
173  end;  end;
174    
175    
176    class function TUtils.AdobeReaderExists(): Boolean;
177    var
178      AReg: TRegistry;
179    begin
180      result:= false;
181      AReg := TRegistry.Create;
182      AReg.RootKey := HKEY_LOCAL_MACHINE;
183      if AReg.KeyExists('\SOFTWARE\Adobe\Acrobat Reader') then
184        result:= True;
185      AReg.Free;
186    end;
187    
188    
189    /// <summary>
190    ///   This function reads the file resource of "FileName" and returns
191    ///   the version number as formatted text.</summary>
192    /// <example>
193    ///   Sto_GetFmtFileVersion() = '4.13.128.0'
194    ///   Sto_GetFmtFileVersion('', '%.2d-%.2d-%.2d') = '04-13-128'
195    /// </example>
196    /// <remarks>If "Fmt" is invalid, the function may raise an
197    ///   EConvertError exception.</remarks>
198    /// <param name="FileName">Full path to exe or dll. If an empty
199    ///   string is passed, the function uses the filename of the
200    ///   running exe or dll.</param>
201    /// <param name="Fmt">Format string, you can use at most four integer
202    ///   values.</param>
203    /// <returns>Formatted version number of file, '' if no version
204    ///   resource found.</returns>
205    class function TUtils.Sto_GetFmtFileVersion(const FileName: String = ''): String;
206    var
207      sFileName: String;
208      iBufferSize: DWORD;
209      iDummy: DWORD;
210      pBuffer: Pointer;
211      pFileInfo: Pointer;
212      iVer: array[1..4] of Integer;
213    begin
214      // set default value
215      Result := '';
216      // get filename of exe/dll if no filename is specified
217      sFileName := Trim(FileName);
218      if (sFileName = '') then
219        sFileName := GetModuleName(HInstance);
220      // get size of version info (0 if no version info exists)
221      iBufferSize := GetFileVersionInfoSize(PChar(sFileName), iDummy);
222      if (iBufferSize > 0) then
223      begin
224        GetMem(pBuffer, iBufferSize);
225        try
226        // get fixed file info (language independent)
227        GetFileVersionInfo(PChar(sFileName), 0, iBufferSize, pBuffer);
228        VerQueryValue(pBuffer, '\', pFileInfo, iDummy);
229        // read version blocks
230        iVer[1] := HiWord(PVSFixedFileInfo(pFileInfo)^.dwFileVersionMS);
231        iVer[2] := LoWord(PVSFixedFileInfo(pFileInfo)^.dwFileVersionMS);
232        iVer[3] := HiWord(PVSFixedFileInfo(pFileInfo)^.dwFileVersionLS);
233        iVer[4] := LoWord(PVSFixedFileInfo(pFileInfo)^.dwFileVersionLS);
234        finally
235          FreeMem(pBuffer);
236        end;
237    
238        // format result string
239        Result := Format('%d.%d.%d.%d', [iVer[1], iVer[2], iVer[3], iVer[4]]);
240    
241      end;
242    end;
243    
244    
245    class function TUtils.CheckUrl(url:string):boolean;
246    var
247      hSession, hfile: hInternet;
248      dwindex,dwcodelen :dword;
249      dwcode:array[1..20] of char;
250      res : pchar;
251    begin
252      if pos('http://',lowercase(url))=0 then
253        url := 'http://'+url;
254      Result := false;
255      hSession := InternetOpen('InetURL:/1.0',
256                                INTERNET_OPEN_TYPE_PRECONFIG,
257                                nil,
258                                nil,
259                                0);
260      if assigned(hsession) then
261      begin
262        hfile := InternetOpenUrl(hsession,
263                                 pchar(url),
264                                 nil,
265                                 0,
266                                 INTERNET_FLAG_RELOAD,
267                                 0);
268        dwIndex := 0;
269        dwCodeLen := 10;
270        HttpQueryInfo(hfile,
271                      HTTP_QUERY_STATUS_CODE,
272                      @dwcode,
273                      dwcodeLen,
274                      dwIndex);
275        res := pchar(@dwcode);
276        result:= (res ='200') or (res ='302');
277        if assigned(hfile) then
278          InternetCloseHandle(hfile);
279        InternetCloseHandle(hsession);
280      end;
281    
282    end;
283    
284    
285    class function TUtils.FileTime2DateTime(FileTime: TFileTime): TDateTime;
286    var
287       LocalFileTime: TFileTime;
288       SystemTime: TSystemTime;
289    begin
290       FileTimeToLocalFileTime(FileTime, LocalFileTime) ;
291       FileTimeToSystemTime(LocalFileTime, SystemTime) ;
292       Result := SystemTimeToDateTime(SystemTime) ;
293    end;
294    
295    
296  end.  end.

Legend:
Removed from v.2682  
changed lines
  Added in v.2695

  ViewVC Help
Powered by ViewVC 1.1.20