簡體   English   中英

如何登錄 Inno Setup 安裝?

[英]How can I log Inno Setup installations?

Inno Setup 具有命令行參數/LOG="filename" 我可以在 Inno Setup 腳本中指定日志文件名,以便稍后將其包含在錯誤報告中嗎?

您可以設置SetupLogging選項 ( SetupLogging=yes ),然后將以下代碼集成到您的腳本中以將日志復制到某處。

procedure CurStepChanged(CurStep: TSetupStep);
var
  logfilepathname, logfilename, newfilepathname: string;
begin
  logfilepathname := ExpandConstant('{log}');
  logfilename := ExtractFileName(logfilepathname);
  newfilepathname := ExpandConstant('{app}\') + logfilename;

  if CurStep = ssDone then
  begin
    FileCopy(logfilepathname, newfilepathname, false);
  end;
end; 

按照 Lars 的評論,我使用了DeinitializeSetup()過程,但我也更改了新文件路徑以使用{src}常量將日志文件復制到運行安裝程序的目錄,而不是{app}常量,后者可能如果用戶取消安裝,則 / 可能不會被創建:

// Called just before Setup terminates. Note that this function is called even if the user exits Setup before anything is installed.
procedure DeinitializeSetup();
var
  logfilepathname, logfilename, newfilepathname: string;
begin
  logfilepathname := ExpandConstant('{log}');
  logfilename := ExtractFileName(logfilepathname);
  // Set the new target path as the directory where the installer is being run from
  newfilepathname := ExpandConstant('{src}\') + logfilename;

  FileCopy(logfilepathname, newfilepathname, false);
end; 

擴展 JasonMcF 的示例...檢查是否創建了卸載程序以查看安裝是否成功完成。

// Called just before Setup terminates.
// Note that this function is called even if the user exits Setup before anything is installed.
procedure DeinitializeSetup();
var
    unInstaller, logFilePath, logFileName, newFilePath: string;
begin
    unInstaller := ExpandConstant('{uninstallexe}');

    logFilePath := ExpandConstant('{log}');
    logFileName := ExtractFileName(logFilePath);
  
    if FileExists(unInstaller) then
    begin
        // uninstaller exists, setup was finished successfully, copy log to app directory
        newFilePath := ExpandConstant('{app}\') + logFileName;
    end
        else
    begin
        // setup didn't finish successfully, copy log to src directory
        newFilePath := ExpandConstant('{src}\') + logFileName;
    end;

    Log('DeinitializeSetup');
    Log('- unInstaller:' + unInstaller);
    Log('- logFilePath:' + logFilePath);
    Log('- newFilePath:' + newFilePath);

    FileCopy(logFilePath, newFilePath, false);
end;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM