2016-03-04 218 views
2

设置SetupLogging=yes内登录名创建一个文件:Inno Setup的指定安装

%TEMP%\安装日志YYYY-MM-DD#NNN.txt

有什么办法指定文件的名称?请注意,我知道我可以在安装结束时使用FileCopy对其进行重命名(How can I log Inno Setup installations?),但我只是想在开始时指定文件的名称,就像可以用开关/log=%TEMP%\ProductInstall.log完成一样。这可能吗?

回答

3

不,这是不可能的。 SetupLogging的日志文件名格式是硬编码的。

如果在命令行中指定/LOG=,并且如果不是,则使用/LOG=重新生成安装程序,所有您可以执行此操作来检查InitializeSetup

虽然这有点过分。

function ShellExecute(hwnd: HWND; lpOperation: string; lpFile: string; 
    lpParameters: string; lpDirectory: string; nShowCmd: Integer): THandle; 
    external '[email protected] stdcall'; 

function InitializeSetup(): Boolean; 
var 
    HasLog: Boolean; 
    Params: string; 
    I: Integer; 
    S: string; 
    RetVal: Integer; 
begin 
    HasLog := False; 
    Params := ''; 
    for I := 1 to ParamCount do 
    begin 
    S := ParamStr(I); 
    if CompareText(Copy(S, 1, 5), '/LOG=') = 0 then 
    begin 
     HasLog := True; 
     break; 
    end; 
    { Do not pass our /SL5 switch } 
    if CompareText(Copy(S, 1, 5), '/SL5=') = 0 then 
    begin 
     Params := Params + AddQuotes(S) + ' '; 
    end; 
    end; 

    Result := True; 
    if HasLog then 
    begin 
    Log('Log specified, continuing.'); 
    end 
    else 
    begin 
    { add selected language, so that user is not prompted again } 
    Params := Params + ' /LANG=' + ActiveLanguage; 
    { force logging } 
    Params := Params + ' /LOG="' + ExpandConstant('{%TEMP}\ProductInstall.log') + '"'; 
    Log(Format('Log file not specified, restarting setup with [%s]', [Params])); 
    RetVal := ShellExecute(0, '', ExpandConstant('{srcexe}'), Params, '', SW_SHOW); 
    Log(Format('Restarting setup returned [%d]', [RetVal])); 
    if RetVal > 32 then 
    begin 
     Log('Restart with logging succeeded, aborting this instance'); 
     Result := False; 
    end 
     else 
    begin 
     Log(Format('Restarting with logging failed [%s], keeping this instance', [ 
     SysErrorMessage(RetVal)])); 
    end; 
    end; 
end; 
+0

马丁,感谢您确认我的怀疑,并提出了解决方法,虽然如您所说,这有点矫枉过正。我想我会在安装结束时重命名该文件。 –