Getting the last modification date of a file in Inno Setup Pascal Script
I need to choose the most recently modified file in my instal开发者_如何学Golation script. It seems the Pascal scripting language has no GetFileDateTime
or similar, so I am resorting to:
function FileDateTime (FileID : string) : double ;
var
FindRec : TFindRec;
begin
Result := 0.00 ;
if (FindFirst (FileID, FindRec)) then
begin
try
Result := FindRec.LastWriteTime ; { gives type mismatch, naturally }
finally
FindClose (FindRec) ;
end ;
end ;
end ;
but I can't find any documentation on the format of LastWriteTime
. Ideally I want the datetime returned in a format that will make it relatively easy to display it, as I will need to write the equivalent of Delphi's FormatDateTime
as well. Inno Pascal has GetDateTimeString
but this only formats the current datetime, not an arbitrary datetime.
The documentation on the TFindRec
record in InnoSetup is here. It is very sparse, but I am almost confident that it has the exact same format as the corresponding structure in the Windows API.
Indeed, InnoSetup's FindFirst
function most likely corresponds to FindFirstFile
of the Windows API. Thus, the TFindRec
record corresponds to the WIN32_FIND_DATA
structure so that a TFileTime
record corresponds to a FILETIME
structure.
type
SYSTEMTIME = record
Year: WORD;
Month: WORD;
DayOfWeek: WORD;
Day: WORD;
Hour: WORD;
Minute: WORD;
Second: WORD;
Milliseconds: WORD;
end;
function FileTimeToSystemTime(
FileTime: TFileTime;
var SystemTime: SYSTEMTIME
): Boolean;
external 'FileTimeToSystemTime@kernel32.dll stdcall';
function GetModifiedFileDate(strFile : String) : Boolean;
var
FindRec: TFindRec;
SystemInfo: SYSTEMTIME;
begin
if FindFirst(strFile, FindRec) then begin
FileTimeToSystemTime( FindRec.LastWriteTime, SystemInfo);
end;
MsgBox(format('%4.4d-%2.2d-%2.2d', [SystemInfo.Year, SystemInfo.Month, SystemInfo.Day]), mbInformation, MB_OK);
end;
精彩评论