installation - Inno Setup RenameFile 和 FileCopy 在某些计算机上莫名其妙地失败
问题描述
我的应用程序有几千兆字节的图像数据,这些数据曾经存储在{app}
目录中。在下一次更新中,作为 Inno Setup 安装的一部分,我需要将该图片数据移动到{commonappdata}
目录中,以便成为一个表现良好的程序。
我创建了一个过程,该过程试图通过重命名(出于速度目的)来移动一个充满图像的目录(由InName
参数标识)。如果失败(即,如果目录位于不同的驱动器上),则该过程将复制文件,然后删除源。
所有这些在我的计算机和我可以访问的任何计算机上都运行良好,但对于大多数其他人来说,它无法重命名目录,然后无法复制它。该过程记录了所有这些,因此我知道源名称和目标名称是正确的,但是 RenameFile 和 FileCopy 只是失败而没有任何解释。
我真的很感激任何人对为什么RenameFile
andFileCopy
命令在其他人的计算机上失败但不是我的计算机上的任何想法。我已经验证他们可以使用文件资源管理器复制文件而没有任何问题(它们不是只读的或类似的东西)。
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;
解决方案
确保目标目录确实存在。即那些喜欢{commonappdata}\MyApp\images
.
RenameFile
norFileCopy
函数不会为您创建它们。
您还可以GetLastError
在功能失败后检查。有关声明,请参阅Inno Setup FileExists unable to find existing file。
推荐阅读
- sql - 重组表并检查值
- bash - 即使只有一个短语要替换,我如何使用 sed 替换整行?
- swift - Swift:动画 NSLayoutConstraint 不起作用
- javascript - 异步函数调用上的同步函数调用与“等待”的行为
- dafny - 断言、forall 和映射:通用量词不适用于映射
- c - 在某些情况下,链接器允许多个模块定义具有相同名称的全局符号?
- c# - System.TypeLoadException:'AndroidX.AppCompat.View.Menu.MenuItemImpl 类型的 VTable 设置失败'
- flutter - Flutter Gridview水平滚动
- python - 如何在python中用空格替换多个unicode换行符?
- javascript - 这是什么 ”?。” 在 JavaScript 中调用的功能?