--- dao/DelphiScanner/Utils.pas 2015/09/03 14:27:21 2693 +++ dao/DelphiScanner/Utils.pas 2016/04/08 14:01:34 2996 @@ -3,7 +3,9 @@ interface uses Controls, - Graphics //TColor + Graphics, //TColor + IniFiles, + Windows //TFileTime ; type @@ -24,7 +26,15 @@ class function Sto_GetFmtFileVersion(const FileName: String = ''): String; + class function CheckUrl(url:string): boolean; + class function FileTime2DateTime(FileTime: TFileTime): TDateTime; + + class function GetComputerNameHelper() : String; + + class function GetCurrentUserName : string; + + class function URLEncode(const s : string) : string; end; @@ -33,10 +43,13 @@ uses StrUtils, Types, //TRect , - Windows, Messages, SysUtils, //IntToStr etc - Registry + Registry, + wininet, //CheckUrl + + HTTPApp //HTTPEncode + ; @@ -236,4 +249,88 @@ end; +class function TUtils.CheckUrl(url:string):boolean; +var + hSession, hfile: hInternet; + dwindex,dwcodelen :dword; + dwcode:array[1..20] of char; + res : pchar; +begin + if pos('http://',lowercase(url))=0 then + url := 'http://'+url; + Result := false; + hSession := InternetOpen('InetURL:/1.0', + INTERNET_OPEN_TYPE_PRECONFIG, + nil, + nil, + 0); + if assigned(hsession) then + begin + hfile := InternetOpenUrl(hsession, + pchar(url), + nil, + 0, + INTERNET_FLAG_RELOAD, + 0); + dwIndex := 0; + dwCodeLen := 10; + HttpQueryInfo(hfile, + HTTP_QUERY_STATUS_CODE, + @dwcode, + dwcodeLen, + dwIndex); + res := pchar(@dwcode); + result:= (res ='200') or (res ='302'); + if assigned(hfile) then + InternetCloseHandle(hfile); + InternetCloseHandle(hsession); + end; + +end; + + +class function TUtils.FileTime2DateTime(FileTime: TFileTime): TDateTime; +var + LocalFileTime: TFileTime; + SystemTime: TSystemTime; +begin + FileTimeToLocalFileTime(FileTime, LocalFileTime) ; + FileTimeToSystemTime(LocalFileTime, SystemTime) ; + Result := SystemTimeToDateTime(SystemTime) ; +end; + + +class function TUtils.GetComputerNameHelper : String; +var + buffer: array[0..255] of char; + size: dword; +begin + size := 256; + if GetComputerName(buffer, size) then + Result := buffer + else + Result := '' +end; + +class function TUtils.GetCurrentUserName : string; +const + cnMaxUserNameLen = 254; +var + sUserName : string; + dwUserNameLen : DWord; +begin + dwUserNameLen := cnMaxUserNameLen-1; + SetLength( sUserName, cnMaxUserNameLen ); + GetUserName(PChar( sUserName ),dwUserNameLen ); + SetLength( sUserName, dwUserNameLen ); + Result := sUserName; +end; + + +class function TUtils.URLEncode(const s : string) : string; +begin + result := HTTPEncode(s); +end; + + end.