Inno Setup:重命名目录失败

时间:2014-11-21 18:57:54

标签: inno-setup

我尝试使用RenameFile功能重命名目录但没有成功。使用DirExists函数,我确认原始目录存在且新目录不存在。但仍然重命名失败。目录路径仅包含ASCII字符。我正在使用Inno Setup 5.5.5。尝试过Unicode和非Unicode版本。结果相同。代码是:

procedure CurStepChanged(CurStep: TSetupStep);
var
  NewFolder, BackupFolder: String;
begin
  NewFolder := LgtUserDirPage.Values[0];
  Log('NewFolder: ' + NewFolder);
  if (CurStep = ssInstall) and DirExists(NewFolder) and (pos('backup', WizardSelectedComponents(False)) > 0) then begin
    BackupFolder := NewFolder + '-backup'
    Log('BackupFolder: ' + BackupFolder);
    if DirExists(NewFolder) then Log('Found!');
    if not DirExists(BackupFolder) then Log('No backup!');
    if RenameFile(NewFolder, BackupFolder) then Log('Backup created!');
  end
  else if (CurStep = ssPostInstall) then begin
    if FileExists(BackupFolder + '\settings.lgt') then
      FileCopy(BackupFolder + '\settings.lgt', NewFolder + '\settings.lgt', False);
    if FileExists(BackupFolder + '\settings.logtalk') then
      FileCopy(BackupFolder + '\settings.logtalk', NewFolder + '\settings.logtalk', False)
  end
end;

调试输出为:

Setup application started
Setup version: Inno Setup version 5.5.5 (u)
Original Setup EXE: C:\Users\pmoura\Desktop\Output\logtalk-3.00.0-rc7.exe
Setup command line: /SL5="$3E0350,1739097,119296,C:\Users\pmoura\Desktop\Output\logtalk-3.00.0-rc7.exe" /SPAWNWND=$2D038A /NOTIFYWND=$220252 /DEBUGWND=$11027C 
Windows version: 6.1.7601 SP1  (NT platform: Yes)
64-bit Windows: Yes
Processor architecture: x64
User privileges: Administrative
64-bit install mode: No
Created temporary directory: C:\Users\pmoura\AppData\Local\Temp\is-JA0BI.tmp
NewFolder: C:\Users\pmoura\Documents\Logtalk
BackupFolder: C:\Users\pmoura\Documents\Logtalk-backup
Found!
No backup!

我从未得到Backup created!输出。执行只是从该行到程序结束。任何人都知道有任何理由可以解释重命名失败的原因吗?磁盘空间不是问题,顺便说一句。

1 个答案:

答案 0 :(得分:2)

发现问题。事实证明,RenameFile由于打开的shell而失败,因为我尝试重命名的目录中包含当前目录。在这些情况下,RenameFile似乎只返回false。指出问题的权限错误(代码)会更具启发性。

我现在更新了我的脚本,以便在RenameFile失败时警告用户,指出可能的原因。可以浏览更新代码here