2016-11-18 3 views
0

[Code] 섹션의 Inno Setup FileCopy 명령에서 변수를 어떻게 사용할 수 있습니까?Inno 설치 디렉토리의 일부로 {app} 변수를 사용하는 FileCopy

`FileCopy(ExpandConstant('{app}\Backup\config.ini'),ExpandConstant('{app}\bin\config.ini'),False);` 

이 내가 사용하고 있지만 작동하지 ... 임 프로 시저 내부에서이를 사용하여 ... 그리고 [Files] 섹션에 Afterinstall:을 사용하여이 프로 시저를 호출하고있는 무슨이다.

[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

좀 더 코드를 게시 할 수 있습니까? 언제이 기능을 부르니? '{app}'설정 후입니까? 명확한 코드를 위해서는 ExpandConstant ('{app}') + '\ Backup \ config.ini'라고 부를 수 있습니다. 하지만 여전히 파일이 있는지 먼저 확인한 다음 복사 작업을 수행해야합니다. – RobeN

+0

@RobeN 코드를 추가하기 위해 게시물을 편집했습니다. 좀 봐 줄래? 감사! –

+2

코드가 정확합니다. "작동하지 않는 것"은 무엇을 의미합니까? 그것은 무엇을합니까? 'FileCopy' 함수는 무엇을 리턴합니까? 대상 디렉토리가 존재합니까? –

답변

1

FileCopy 함수는 디렉토리를 만들지 않습니다. 기존 디렉토리의 파일을 다른 기존 디렉토리에 복사합니다.

config.iniBackup 디렉토리에서 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; 
+0

nice .. 고마워. –