简体   繁体   English

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

[英]Inno Setup RenameFile and FileCopy inexplicably failing on some computers

My app has several gigabytes of image data which used to be stored in the {app} directory.我的应用程序有几千兆字节的图像数据,这些数据曾经存储在{app}目录中。 In the next update I need to move that picture data, as part of the Inno Setup installation, to the {commonappdata} directory in order to be a well behaved program.在下一次更新中,作为 Inno Setup 安装的一部分,我需要将该图片数据移动到{commonappdata}目录,以便成为一个表现良好的程序。

I created a procedure that attempts to move a directory full of images (identified by the InName parameter) by renaming it (for speed purposes).我创建了一个过程,它试图通过重命名(出于速度目的)来移动一个充满图像的目录(由InName参数标识)。 If that fails (ie if the directories were on different drives) then the procedure will copy the file and then delete the source.如果失败(即,如果目录位于不同的驱动器上),则该过程将复制文件,然后删除源。

All that works great on my computer and any computers I have access to, but for most other people it fails to rename the directory and then fails to copy it.所有这些在我的计算机和我可以访问的任何计算机上都运行良好,但对于大多数其他人来说,它无法重命名目录,然后无法复制它。 The procedure logs all of this so I know that the source and destination names are correct, but the RenameFile and FileCopy just fail without any explanation.该过程记录了所有这些,因此我知道源名称和目标名称是正确的,但是 RenameFile 和 FileCopy 只是失败而没有任何解释。

I'd really appreciate any thoughts anyone has as to why the RenameFile and FileCopy commands are failing on other people's computers but not mine.我真的很感激任何人对为什么RenameFileFileCopy命令在其他人的计算机上失败但不是我的计算机上的任何想法。 I've verified that they can copy the files using File Explorer without any issues (they're not read-only or anything like that).我已经验证他们可以使用文件资源管理器复制文件而没有任何问题(它们不是只读的或类似的东西)。

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;

Make sure the target directories do exist.确保目标目录确实存在。 Ie those like {commonappdata}\MyApp\images .即像{commonappdata}\MyApp\images这样的。

The RenameFile nor FileCopy functions won't create them for you. RenameFileFileCopy函数不会为您创建它们。


You can also check the GetLastError after the function fails.您也可以在 function 失败后检查GetLastError For a declaration, see Inno Setup FileExists unable to find existing file .有关声明,请参阅Inno Setup FileExists unable to find existing file

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM