Inno-setup:将所有用户的选择存储在INI文件中

时间:2012-01-05 15:37:24

标签: inno-setup

我希望在安装到.INI文件期间存储用户做出的所有选择(或者如果用户没有更改它们的默认值)。我知道命令行选项/ LOADINF和/ SAVEINF,但我希望有一个类似的功能,而不依赖于命令行。这将用于在重新安装时保留设置,还可以定义一组设置(由管理员定义),以便在分散办公室的多个安装中使用。

感谢您的帮助

1 个答案:

答案 0 :(得分:0)

可以做你想要的。但是,您的[code]部分中需要相当数量的代码。几年前我做了类似的事情,但我只是在阅读INI。我从未写过INI文件。你应该能够使用SetIni *(SetIniString,SetIniBool等)函数写入它。您可以使用GetIni *函数读取INI文件。这是一个快速的样本,我把它放在一起,提出了一个想法:

; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "My Program"
#define MyAppVersion "1.5"
#define MyAppPublisher "My Company, Inc."
#define MyAppURL "http://www.example.com/"
#define MyAppExeName "MyProg.exe"

[Setup]
; NOTE: The value of AppId uniquely identifies this application.
; Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{4CCA332F-C69B-48DF-93B4-145EB88A1BCB}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={code:GetDefaultDir}
DefaultGroupName={#MyAppName}
OutputBaseFilename=setup
Compression=lzma
SolidCompression=yes

[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"

[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked

[Files]
Source: "C:\util\innosetup\Examples\MyProg.exe"; DestDir: "{app}"; Flags: ignoreversion
; NOTE: Don't use "Flags: ignoreversion" on any shared system files

[Icons]
Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon

[Run]
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, "&", "&&")}}"; Flags: nowait postinstall skipifsilent

[Code]
var 
FinishedInstall : boolean;

function GetDefaultDir(def: string): string;
var
sInstallPath : string;
bRes : boolean;

begin
  sInstallPath := GetIniString('Common', 'TargetDir', ExpandConstant('{pf}') + '\myApp', ExpandConstant('{src}') + '\myappsetup.INI');
  Result := sInstallPath;
end;

procedure CurStepChanged(CurStep: TSetupStep);
begin
  if CurStep = ssPostInstall then
     FinishedInstall := True;
end;

procedure DeinitializeSetup();
var
bIni : boolean;
begin
if FinishedInstall then
  bIni := SetIniString('Common', 'TargetDir',ExpandConstant('{app}'), ExpandConstant('{app}') + '\myappsetup.INI');
end;