如何在FileCopy
部分的Inno Setup [Code]
命令中使用变量?
`FileCopy(ExpandConstant('{app}\Backup\config.ini'),ExpandConstant('{app}\bin\config.ini'),False);`
这就是我正在使用但似乎无法正常工作......我在一个程序中使用它...并使用Afterinstall:
部分中的[Files]
调用此程序。
[Files]
Source: "C:\dev\bin\config.ini"; DestDir: "{app}\bin\"; Flags: ignoreversion recursesubdirs createallsubdirs; Tasks: Steam; AfterInstall: RunOtherInstaller;
[Code]
procedure RunOtherInstaller;
var
Path: String;
ErrorCode: Integer;
begin
if (RegQueryStringValue(HKEY_LOCAL_MACHINE, 'Software\Valve\Steam', 'InstallPath', Path)) and (FileExists(Path + '\Steam.exe')) then
begin
//ShellExec('', ExpandConstant('"' + Path + '\Steam.exe' + '"'), 'steam://','', SW_SHOW, ewNoWait, ErrorCode);
Exec(ExpandConstant(Path + '\Steam.exe'), 'steam://', '', SW_SHOWNORMAL, ewNoWait, ErrorCode)
end
else
begin
MsgBox('Steam not found', mbError, MB_OK);
FileCopy(ExpandConstant('{app}\Backup\config.ini'),ExpandConstant('{app}\bin\config.ini'),False);
end
end;
答案 0 :(得分:1)
FileCopy
函数不会创建目录。它只是将文件从现有目录复制到其他现有目录。
您尝试将config.ini
从Backup
目录复制到bin
目录。
我已经更改了对steam://
的调用,并举例说明了如何运行Sang-Froid游戏(无论如何都可以更改它),然后我添加了一些示例检查。如果由于Config.ini或目标目录丢失而无法执行复制操作,最后会有FileCopy
函数,并附带消息检查。
[Files]
Source: "C:\dev\bin\config.ini"; DestDir: "{app}\bin\"; Flags: ignoreversion recursesubdirs createallsubdirs; Tasks: Steam; AfterInstall: RunOtherInstaller;
[Code]
procedure RunOtherInstaller;
var
Path: String;
ErrorCode: Integer;
begin
if (RegQueryStringValue(HKEY_LOCAL_MACHINE, 'Software\Valve\Steam', 'InstallPath', Path)) and (FileExists(Path + '\Steam.exe')) then
begin
//proper call for Steam:// - this sample tries to run Sang-Froid - Tales of Werewolves
ShellExec('', 'steam://rungameid/227220', '', '', SW_SHOW, ewNoWait, ErrorCode);
//your EXEC
//Exec(ExpandConstant(Path + '\Steam.exe'), 'steam://', '', SW_SHOWNORMAL, ewNoWait, ErrorCode)
end
else
begin
MsgBox('Steam not found', mbError, MB_OK);
//just some checks
MsgBox(ExpandConstant('{app}'), mbError, MB_OK);
if DirExists(ExpandConstant('{app}') + '\bin') then
MsgBox('''bin'' directory Exists', mbError, MB_OK)
else
MsgBox('''bin'' directory does not Exist!', mbError, MB_OK);
if DirExists(ExpandConstant('{app}') + '\Backup') then
MsgBox('''Backup'' directory Exists', mbError, MB_OK)
else
MsgBox('''Backup'' directory does not Exist!', mbError, MB_OK);
//end of checks
//check if Source file exists, check if destination directory exists
if FileExists(ExpandConstant('{app}') + '\Backup\config.ini') and DirExists(ExpandConstant('{app}') + '\bin') then begin
FileCopy(ExpandConstant('{app}') + '\Backup\config.ini',ExpandConstant('{app}') + '\bin\config.ini',False);
end
else begin
MsgBox('Either ''Config.ini'' file or ''bin'' directory does not Exist!', mbError, MB_OK);
end;
end
end;