22 |
|
|
23 |
class function AdobeReaderExists(): Boolean; |
class function AdobeReaderExists(): Boolean; |
24 |
|
|
25 |
|
class function Sto_GetFmtFileVersion(const FileName: String = ''): String; |
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
179 |
AReg.Free; |
AReg.Free; |
180 |
end; |
end; |
181 |
|
|
182 |
|
|
183 |
|
/// <summary> |
184 |
|
/// This function reads the file resource of "FileName" and returns |
185 |
|
/// the version number as formatted text.</summary> |
186 |
|
/// <example> |
187 |
|
/// Sto_GetFmtFileVersion() = '4.13.128.0' |
188 |
|
/// Sto_GetFmtFileVersion('', '%.2d-%.2d-%.2d') = '04-13-128' |
189 |
|
/// </example> |
190 |
|
/// <remarks>If "Fmt" is invalid, the function may raise an |
191 |
|
/// EConvertError exception.</remarks> |
192 |
|
/// <param name="FileName">Full path to exe or dll. If an empty |
193 |
|
/// string is passed, the function uses the filename of the |
194 |
|
/// running exe or dll.</param> |
195 |
|
/// <param name="Fmt">Format string, you can use at most four integer |
196 |
|
/// values.</param> |
197 |
|
/// <returns>Formatted version number of file, '' if no version |
198 |
|
/// resource found.</returns> |
199 |
|
class function TUtils.Sto_GetFmtFileVersion(const FileName: String = ''): String; |
200 |
|
var |
201 |
|
sFileName: String; |
202 |
|
iBufferSize: DWORD; |
203 |
|
iDummy: DWORD; |
204 |
|
pBuffer: Pointer; |
205 |
|
pFileInfo: Pointer; |
206 |
|
iVer: array[1..4] of Integer; |
207 |
|
begin |
208 |
|
// set default value |
209 |
|
Result := ''; |
210 |
|
// get filename of exe/dll if no filename is specified |
211 |
|
sFileName := Trim(FileName); |
212 |
|
if (sFileName = '') then |
213 |
|
sFileName := GetModuleName(HInstance); |
214 |
|
// get size of version info (0 if no version info exists) |
215 |
|
iBufferSize := GetFileVersionInfoSize(PChar(sFileName), iDummy); |
216 |
|
if (iBufferSize > 0) then |
217 |
|
begin |
218 |
|
GetMem(pBuffer, iBufferSize); |
219 |
|
try |
220 |
|
// get fixed file info (language independent) |
221 |
|
GetFileVersionInfo(PChar(sFileName), 0, iBufferSize, pBuffer); |
222 |
|
VerQueryValue(pBuffer, '\', pFileInfo, iDummy); |
223 |
|
// read version blocks |
224 |
|
iVer[1] := HiWord(PVSFixedFileInfo(pFileInfo)^.dwFileVersionMS); |
225 |
|
iVer[2] := LoWord(PVSFixedFileInfo(pFileInfo)^.dwFileVersionMS); |
226 |
|
iVer[3] := HiWord(PVSFixedFileInfo(pFileInfo)^.dwFileVersionLS); |
227 |
|
iVer[4] := LoWord(PVSFixedFileInfo(pFileInfo)^.dwFileVersionLS); |
228 |
|
finally |
229 |
|
FreeMem(pBuffer); |
230 |
|
end; |
231 |
|
|
232 |
|
// format result string |
233 |
|
Result := Format('%d.%d.%d.%d', [iVer[1], iVer[2], iVer[3], iVer[4]]); |
234 |
|
|
235 |
|
end; |
236 |
|
end; |
237 |
|
|
238 |
|
|
239 |
end. |
end. |