2016-03-04 217 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

馬丁,感謝您確認我的懷疑,並提出瞭解決方法,雖然如您所說,這有點矯枉過正。我想我會在安裝結束時重命名該文件。 –