Inno setup 从一个文件中读取修改的时间,并使用它设置整个目录中文件的时间

Inno setup 从一个文件中读取修改的时间,并使用它设置整个目录中文件的时间,inno-setup,last-modified,Inno Setup,Last Modified,在我的安装程序中,我从不存储时间/日期属性的归档文件中提取文件,因此提取文件时,上次修改的日期设置为当前日期。我想将其设置为存档文件的最后修改日期,但我不知道如何设置。我试着使用和中的代码片段,但虽然它并没有给出任何错误,但它在更改时间方面不起作用。需要更改文件夹中*的上次修改日期 另外,如果用户取消安装程序并开始回滚更改,我需要挂接到哪里才能删除这些文件?我已经在卸载删除中处理好了,但如果用户取消安装,则不会 编辑:忽略第二部分,我在这里发布后不久就发现了。通过检查卸载程序注册表项,将我自己的

在我的安装程序中,我从不存储时间/日期属性的归档文件中提取文件,因此提取文件时,上次修改的日期设置为当前日期。我想将其设置为存档文件的最后修改日期,但我不知道如何设置。我试着使用和中的代码片段,但虽然它并没有给出任何错误,但它在更改时间方面不起作用。需要更改文件夹中*的上次修改日期

另外,如果用户取消安装程序并开始回滚更改,我需要挂接到哪里才能删除这些文件?我已经在卸载删除中处理好了,但如果用户取消安装,则不会

编辑:忽略第二部分,我在这里发布后不久就发现了。通过检查卸载程序注册表项,将我自己的CleanUp()添加到DeinitializeSetup()

下面是我试图添加到的代码部分:

procedure VolExtract(VWorld: String);
var
  ResultCode: Integer;
  VPath: String;
begin
  // Files are extracted to {app}\VWorld\One, {app}\VWorld\Two, etc.
  VPath := ExpandConstant('{app}\' + VWorld);
  WizardForm.FilenameLabel.Caption := DriveLetter + VWorld + '\one.vol';
  if Exec(ExpandConstant('{tmp}\volextract.exe'), '"' + DriveLetter + VWorld + '\one.vol" "' + VPath + '"', '', SW_HIDE, ewWaitUntilTerminated, ResultCode) and (ResultCode = 0) then
  begin
    // Yep, it executed successfully
    WizardForm.FilenameLabel.Caption := DriveLetter + VWorld + '\two.vol';
    if Exec(ExpandConstant('{tmp}\volextract.exe'), '"' + DriveLetter + VWorld + '\two.vol" "' + VPath + '"', '', SW_HIDE, ewWaitUntilTerminated, ResultCode) and (ResultCode = 0) then
    begin
      // Next
      WizardForm.FilenameLabel.Caption := DriveLetter + VWorld + '\three.vol';
      if Exec(ExpandConstant('{tmp}\volextract.exe'), '"' + DriveLetter + VWorld + '\three.vol" "' + VPath + '"', '', SW_HIDE, ewWaitUntilTerminated, ResultCode) and (ResultCode = 0) then
      begin
        // Next
        WizardForm.FilenameLabel.Caption := DriveLetter + VWorld + '\four.vol';
        Exec(ExpandConstant('{tmp}\volextract.exe'), '"' + DriveLetter + VWorld + '\four.vol" "' + VPath + '"', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
      end;
    end;
  end;
  if ResultCode <> 0 then
  begin
    // Handle Fail
    CDFound := False;
    MsgBox(CustomMessage('FileErr'), mbInformation, MB_OK);
    WizardForm.Close;
  end;
end;
procedure-VolExtract(VWorld:String);
变量
结果代码:整数;
VPath:字符串;
开始
//文件被提取到{app}\VWorld\One、{app}\VWorld\Two等。
VPath:=ExpandConstant('{app}\'+VWorld);
WizardForm.FilenameLabel.Caption:=DriveLetter+VWorld+'\one.vol';
如果Exec(ExpandConstant('{tmp}\volextract.exe')、'''+DriveLetter+VWorld+'\one.vol''、'+VPath+'''、''、SW_HIDE、ewwaitunterminated、ResultCode)和(ResultCode=0),则
开始
//是的,它成功地执行了
WizardForm.FilenameLabel.Caption:=DriveLetter+VWorld+'\two.vol';
如果Exec(ExpandConstant('{tmp}\volextract.exe')、'''+DriveLetter+VWorld+'\two.vol''、'+VPath+''、''、SW_HIDE、ewwaitunterminated、ResultCode)和(ResultCode=0),则
开始
//下一个
WizardForm.FilenameLabel.Caption:=DriveLetter+VWorld+'\three.vol';
如果Exec(ExpandConstant('{tmp}\volextract.exe')、'''+DriveLetter+VWorld+'\three.vol''+VPath+''、''、SW_HIDE、ewwaitunterminated、ResultCode)和(ResultCode=0),则
开始
//下一个
WizardForm.FilenameLabel.Caption:=DriveLetter+VWorld+'\four.vol';
Exec(ExpandConstant('{tmp}\volextract.exe')、'''+DriveLetter+VWorld+'\four.vol''+VPath+''、''、SW_HIDE、ewwaitunterminated、ResultCode);
结束;
结束;
结束;
如果结果代码为0,则
开始
//处理失败
CDFound:=假;
MsgBox(CustomMessage('FileErr'),mbInformation,MB_OK);
向导窗体。关闭;
结束;
结束;

关于第二个问题,您可以删除在名为

Procedure CancelButtonClick(CurPageID: Integer; Var Cancel, Confirm: Boolean);
Begin
End;
正如chm中Pascal脚本:事件函数一节所述


关于第一个问题,我建议您使用inno setup[文件]部分,而不是从存档中提取。您可能会将此存档文件解压缩到本地文件夹中(因此,在编译之前,您可以将此本地文件夹添加到[files]。但我可能会误解您关于文件修改日期的命令。

要更改上次修改的时间(现在称之为LastWriteTime)对于某个文件的LastWriteTime之前指定目录中的所有文件,在提取文件后请使用以下代码。您可以按照本文上一版本的说明进行操作,但请注意,我在那里遇到了错误(混合时间参数和未使用的文件标志参数),但重点仍然是

还请注意,此代码适用于InnoSetup的ANSI版本。如果您需要在Unicode版本中使用此代码,则应将
CreateFile
函数导入定义为
CreateFileW
,而不是
CreateFileA
,或者使用本文中建议的技巧


取消按钮单击
可以将
确认
取消
参数设置为True,在本事件中的代码完成后,您将获得确认
退出设置?
对话框。因此,这不是正确的位置,因为您可以拒绝此确认对话框。是的,这是我对取消按钮的理解n已经单击了。在我最初发布此问题后不久,我就设法找到了这一部分,但还没有机会更新它。我在DeinitializeSetup()中添加了一个CleanUp()过程检查注册表中的卸载程序项。太好了!我现在就去试试,如果可行,我会继续并将其标记为答案。非常感谢:)
[code]
const
  OPEN_EXISTING = 3;  
  FILE_SHARE_WRITE = 2;
  GENERIC_WRITE = $40000000;
  INVALID_HANDLE_VALUE = 4294967295;

function CreateFile(lpFileName: string; dwDesiredAccess, dwShareMode,
  lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes: DWORD;
  hTemplateFile: THandle): THandle; 
  external 'CreateFileA@kernel32.dll stdcall';
function CloseHandle(hObject: THandle): BOOL; 
  external 'CloseHandle@kernel32.dll stdcall';
function SetFileTime(hFile: THandle; const lpCreationTime, lpLastAccessTime, 
  lpLastWriteTime: TFileTime): BOOL; 
  external 'SetFileTime@kernel32.dll stdcall';

function FileSetTime(const AFileName: string; const ACreationTime, 
  ALastAccessTime, ALastWriteTime: TFileTime): Boolean;
var
  FileHandle: THandle;
begin
  Result := False;
  FileHandle := CreateFile(AFileName, GENERIC_WRITE, FILE_SHARE_WRITE, 0,
    OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  if FileHandle <> INVALID_HANDLE_VALUE then
  try
    Result := SetFileTime(FileHandle, ACreationTime, ALastAccessTime, 
      ALastWriteTime);
  finally
    CloseHandle(FileHandle);
  end;
end; 

procedure ModifyLastWriteTime(const ASourceFile, ATargetFolder: string);
var
  FindRec: TFindRec;
  LastWriteTime: TFileTime;
begin
  if FindFirst(ASourceFile, FindRec) then
  begin
    LastWriteTime := FindRec.LastWriteTime;
    if FindFirst(ATargetFolder + '*.*', FindRec) then
    try
      repeat
        if (FindRec.Attributes and FILE_ATTRIBUTE_DIRECTORY) = 0 then
          FileSetTime(ATargetFolder + FindRec.Name, FindRec.CreationTime, 
            FindRec.LastAccessTime, LastWriteTime);
      until
        not FindNext(FindRec);
    finally
      FindClose(FindRec);
    end;
  end;
end;
ModifyLastWriteTime('c:\SourceFile.xxx', 'c:\TargetFolder\')