Inno Setup RenameFile 和 FileCopy 在某些计算机上莫名其妙地失败

Inno Setup RenameFile and FileCopy inexplicably failing on some computers

我的应用程序有几千兆字节的图像数据,这些数据以前存储在 {app} 目录中。在下一次更新中,我需要将该图片数据作为 Inno Setup 安装的一部分移动到 {commonappdata} 目录,以便成为一个运行良好的程序。

我创建了一个程序,试图通过重命名(出于速度目的)来移动充满图像的目录(由 InName 参数标识)。如果失败(即,如果目录位于不同的驱动器上),则该过程将复制文件,然后删除源文件。

所有这些在我的计算机和我可以访问的任何计算机上都运行良好,但对于大多数其他人来说,它无法重命名目录,然后无法复制它。该过程记录了所有这些,因此我知道源名称和目标名称是正确的,但 RenameFile 和 FileCopy 只是失败而没有任何解释。

对于 RenameFileFileCopy 命令为何在其他人的计算机上失败但在我的计算机上失败的任何想法,我将不胜感激。我已经验证他们可以使用文件资源管理器毫无问题地复制文件(它们不是只读的或类似的东西)。

Procedure MoveIt(InName: string);
var Sstr,Dstr: string;
begin
  Sstr:=ExpandConstant('{app}')+'\images\'+InName;
  Dstr:=ExpandConstant('{commonappdata}')+'\MyApp\images\'+InName;
  Log('Source: '+Sstr);
  Log('Destination: '+Dstr);
  if DirExists(Sstr) then
  begin
    OutputMsgMemoWizardPage.RichEditViewer.lines.add(InName+'...');
    if RenameFile(ExpandConstant('{app}')+'\images\'+InName,ExpandConstant('{commonappdata}')+'\MyApp\images\'+InName) then
    begin
      Log('Rename result=success');
      OutputMsgMemoWizardPage.RichEditViewer.lines[OutputMsgMemoWizardPage.RichEditViewer.lines.Count-1]:=InName+': success';
    end else
    begin
      Log('Rename result=Failed'); 
      if FileCopy(ExpandConstant('{app}')+'\images\'+InName,ExpandConstant('{commonappdata}')+'\MyApp\Folder images\'+InName,true) then
      begin
        Log('Copy result=success');
        OutputMsgMemoWizardPage.RichEditViewer.lines[OutputMsgMemoWizardPage.RichEditViewer.lines.Count-1]:=InName+': success';
        if DeleteFile(ExpandConstant('{app}')+'\images\'+InName) then
          Log('Delete result=success')
        else
        begin
          Log('Delete result=Failed');
          OutputMsgMemoWizardPage.RichEditViewer.lines.add(InName+
            '(Could not delete source directory)');
        end;
      end else
      begin
        Log('Copy result=Failed');
     OutputMsgMemoWizardPage.RichEditViewer.lines[OutputMsgMemoWizardPage.RichEditViewer.lines.Count-1]:=InName+': Failed';
      end;
    end
  end else Log('Source file not found');
end;

确保目标目录确实存在。 IE。像 {commonappdata}\MyApp\images.

这样的人

RenameFileFileCopy 函数不会为您创建它们。


您还可以查看 GetLastError after the function fails. For a declaration, see