/[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 2693 by torben, Thu Sep 3 14:27:21 2015 UTC revision 2996 by torben, Fri Apr 8 14:01:34 2016 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 24  type Line 26  type
26    
27      class function Sto_GetFmtFileVersion(const FileName: String = ''): String;      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        class function GetComputerNameHelper() : String;
34    
35        class function GetCurrentUserName : string;
36    
37        class function URLEncode(const s : string) : string;
38    
39    
40    end;    end;
# Line 33  implementation Line 43  implementation
43    
44  uses StrUtils,  uses StrUtils,
45    Types, //TRect ,    Types, //TRect ,
   Windows,  
46    Messages,    Messages,
47    SysUtils, //IntToStr etc    SysUtils, //IntToStr etc
48    Registry    Registry,
49      wininet,   //CheckUrl
50    
51      HTTPApp //HTTPEncode
52    
53    
54    ;    ;
55    
# Line 236  begin Line 249  begin
249  end;  end;
250    
251    
252    class function TUtils.CheckUrl(url:string):boolean;
253    var
254      hSession, hfile: hInternet;
255      dwindex,dwcodelen :dword;
256      dwcode:array[1..20] of char;
257      res : pchar;
258    begin
259      if pos('http://',lowercase(url))=0 then
260        url := 'http://'+url;
261      Result := false;
262      hSession := InternetOpen('InetURL:/1.0',
263                                INTERNET_OPEN_TYPE_PRECONFIG,
264                                nil,
265                                nil,
266                                0);
267      if assigned(hsession) then
268      begin
269        hfile := InternetOpenUrl(hsession,
270                                 pchar(url),
271                                 nil,
272                                 0,
273                                 INTERNET_FLAG_RELOAD,
274                                 0);
275        dwIndex := 0;
276        dwCodeLen := 10;
277        HttpQueryInfo(hfile,
278                      HTTP_QUERY_STATUS_CODE,
279                      @dwcode,
280                      dwcodeLen,
281                      dwIndex);
282        res := pchar(@dwcode);
283        result:= (res ='200') or (res ='302');
284        if assigned(hfile) then
285          InternetCloseHandle(hfile);
286        InternetCloseHandle(hsession);
287      end;
288    
289    end;
290    
291    
292    class function TUtils.FileTime2DateTime(FileTime: TFileTime): TDateTime;
293    var
294       LocalFileTime: TFileTime;
295       SystemTime: TSystemTime;
296    begin
297       FileTimeToLocalFileTime(FileTime, LocalFileTime) ;
298       FileTimeToSystemTime(LocalFileTime, SystemTime) ;
299       Result := SystemTimeToDateTime(SystemTime) ;
300    end;
301    
302    
303    class function TUtils.GetComputerNameHelper : String;
304    var
305      buffer: array[0..255] of char;
306      size: dword;
307    begin
308      size := 256;
309      if GetComputerName(buffer, size) then
310        Result := buffer
311      else
312        Result := ''
313    end;
314    
315    class function TUtils.GetCurrentUserName : string;
316    const
317      cnMaxUserNameLen = 254;
318    var
319      sUserName     : string;
320      dwUserNameLen : DWord;
321    begin
322      dwUserNameLen := cnMaxUserNameLen-1;
323      SetLength( sUserName, cnMaxUserNameLen );
324      GetUserName(PChar( sUserName ),dwUserNameLen );
325      SetLength( sUserName, dwUserNameLen );
326      Result := sUserName;
327    end;
328    
329    
330    class function TUtils.URLEncode(const s : string) : string;
331    begin
332      result := HTTPEncode(s);
333    end;
334    
335    
336  end.  end.

Legend:
Removed from v.2693  
changed lines
  Added in v.2996

  ViewVC Help
Powered by ViewVC 1.1.20