安装空文件夹时访问 CurrentFileName 时出现 Inno Setup Runtime 错误
Inno Setup Runtime error while accessing CurrentFileName when installing an empty folder
我试图通过 Pascal 代码访问文件夹中的所有文件。当我遍历一个空文件夹时,出现以下错误:
Exception: Internal error; An attempt was made to call the "CurrentFileName" function from outside a "Check", "BeforeInstall" or "AfterInstall" event function belonging to a "[Files]" entry
我使用的代码:
[Files]
Source: ".D_Dlls\*"; DestDir: {app}D_Dlls; Flags: ignoreversion recursesubdirs createallsubdirs skipifsourcedoesntexist ; Check: FileBackup
[Code]
function FileBackup(): Boolean;
var FileName,Source,Target,TargetDir: String;
begin
Result := True;
Source := ExpandConstant(CurrentFileName);
end
比如说我的文件夹结构是这样的:
3D_Dlls
- Folder 1
- Folder 2 // Empty folder and it invokes the problem
- Folder 3
我认为这是 Inno Setup 中由 createallsubdirs
标志触发的错误。
指定标志后,Inno Setup 会收集一个单独的空目录列表,这些空目录需要在安装期间显式创建。当 "installing" 为空文件夹时,对 CurrentFileName
的调用就会失败。
解决方法:
如果可能,删除 createallsubdirs
标志。
相反,您可以使用 [Dirs]
section.
显式创建空目录
捕获异常:
function FileBackup: Boolean;
begin
Result := True;
try
Source := ExpandConstant(CurrentFileName);
except
Log(GetExceptionMessage);
end;
end;
我已经在 Inno Setup 新闻组上报告了这个问题,但此后新闻组被重置了。
I believe this is a bug in Inno Setup triggered by the createallsubdirs flag.
When the flag is specified, Inno Setup collects a separate list of
empty directories that needs to be explicitly created during
installation. When "installing" the empty folder, the call to
CurrentFileName simply fails.
Workarounds:
Remove the createallsubdirs flag, if possible.
Instead, you can explicitly create empty directories using [Dirs]
section.
Catch the exception:
谢谢马丁。我在这里遇到了同样的问题,我无法删除 'createallsubdirs' 标志,因为源是动态的,我不知道包含什么。在本例中,它有两个空目录。我得到同样的错误,查看日志:
- 开始安装过程。
- 试图从属于“[Files]”条目"Check"、"BeforeInstall" 或 "AfterInstall" 事件函数外部调用 "CurrentFilename" 函数
- 正在创建目录:C:\ (...)
try except 解决方案对我有用!
我试图通过 Pascal 代码访问文件夹中的所有文件。当我遍历一个空文件夹时,出现以下错误:
Exception: Internal error; An attempt was made to call the "CurrentFileName" function from outside a "Check", "BeforeInstall" or "AfterInstall" event function belonging to a "[Files]" entry
我使用的代码:
[Files]
Source: ".D_Dlls\*"; DestDir: {app}D_Dlls; Flags: ignoreversion recursesubdirs createallsubdirs skipifsourcedoesntexist ; Check: FileBackup
[Code]
function FileBackup(): Boolean;
var FileName,Source,Target,TargetDir: String;
begin
Result := True;
Source := ExpandConstant(CurrentFileName);
end
比如说我的文件夹结构是这样的:
3D_Dlls
- Folder 1
- Folder 2 // Empty folder and it invokes the problem
- Folder 3
我认为这是 Inno Setup 中由 createallsubdirs
标志触发的错误。
指定标志后,Inno Setup 会收集一个单独的空目录列表,这些空目录需要在安装期间显式创建。当 "installing" 为空文件夹时,对 CurrentFileName
的调用就会失败。
解决方法:
如果可能,删除
createallsubdirs
标志。相反,您可以使用
[Dirs]
section. 显式创建空目录
捕获异常:
function FileBackup: Boolean; begin Result := True; try Source := ExpandConstant(CurrentFileName); except Log(GetExceptionMessage); end; end;
我已经在 Inno Setup 新闻组上报告了这个问题,但此后新闻组被重置了。
I believe this is a bug in Inno Setup triggered by the createallsubdirs flag.
When the flag is specified, Inno Setup collects a separate list of empty directories that needs to be explicitly created during installation. When "installing" the empty folder, the call to CurrentFileName simply fails.
Workarounds:
Remove the createallsubdirs flag, if possible.
Instead, you can explicitly create empty directories using [Dirs] section.
Catch the exception:
谢谢马丁。我在这里遇到了同样的问题,我无法删除 'createallsubdirs' 标志,因为源是动态的,我不知道包含什么。在本例中,它有两个空目录。我得到同样的错误,查看日志:
- 开始安装过程。
- 试图从属于“[Files]”条目"Check"、"BeforeInstall" 或 "AfterInstall" 事件函数外部调用 "CurrentFilename" 函数
- 正在创建目录:C:\ (...)
try except 解决方案对我有用!