--- dao/DelphiScanner/Utils.pas 2015/08/27 12:31:30 2685 +++ dao/DelphiScanner/Utils.pas 2015/09/03 14:31:39 2694 @@ -22,6 +22,10 @@ class function AdobeReaderExists(): Boolean; + class function Sto_GetFmtFileVersion(const FileName: String = ''): String; + + class function CheckUrl(url:string): boolean; + @@ -34,7 +38,8 @@ Windows, Messages, SysUtils, //IntToStr etc - Registry + Registry, + wininet //CheckUrl ; @@ -177,4 +182,100 @@ AReg.Free; end; + +/// +/// This function reads the file resource of "FileName" and returns +/// the version number as formatted text. +/// +/// Sto_GetFmtFileVersion() = '4.13.128.0' +/// Sto_GetFmtFileVersion('', '%.2d-%.2d-%.2d') = '04-13-128' +/// +/// If "Fmt" is invalid, the function may raise an +/// EConvertError exception. +/// Full path to exe or dll. If an empty +/// string is passed, the function uses the filename of the +/// running exe or dll. +/// Format string, you can use at most four integer +/// values. +/// Formatted version number of file, '' if no version +/// resource found. +class function TUtils.Sto_GetFmtFileVersion(const FileName: String = ''): String; +var + sFileName: String; + iBufferSize: DWORD; + iDummy: DWORD; + pBuffer: Pointer; + pFileInfo: Pointer; + iVer: array[1..4] of Integer; +begin + // set default value + Result := ''; + // get filename of exe/dll if no filename is specified + sFileName := Trim(FileName); + if (sFileName = '') then + sFileName := GetModuleName(HInstance); + // get size of version info (0 if no version info exists) + iBufferSize := GetFileVersionInfoSize(PChar(sFileName), iDummy); + if (iBufferSize > 0) then + begin + GetMem(pBuffer, iBufferSize); + try + // get fixed file info (language independent) + GetFileVersionInfo(PChar(sFileName), 0, iBufferSize, pBuffer); + VerQueryValue(pBuffer, '\', pFileInfo, iDummy); + // read version blocks + iVer[1] := HiWord(PVSFixedFileInfo(pFileInfo)^.dwFileVersionMS); + iVer[2] := LoWord(PVSFixedFileInfo(pFileInfo)^.dwFileVersionMS); + iVer[3] := HiWord(PVSFixedFileInfo(pFileInfo)^.dwFileVersionLS); + iVer[4] := LoWord(PVSFixedFileInfo(pFileInfo)^.dwFileVersionLS); + finally + FreeMem(pBuffer); + end; + + // format result string + Result := Format('%d.%d.%d.%d', [iVer[1], iVer[2], iVer[3], iVer[4]]); + + end; +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; + end.