2012-01-05 39 views
0

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

感谢您的帮助

回答

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; 
+0

谢谢Mirtheil,我从中得到了一些好主意。但是,为了使用它,我需要确切地知道哪些事件过程会让我在实​​际安装开始之前访问用户选择。另外,如何访问标准对话框上的用户选项(如应用程序目录或组)。 – LittleFish 2012-01-06 08:50:58

+0

我上面给出的示例将设置应用程序目录。您可以通过为设置常量{groupname}的“DefaultGroupName”执行类似的代码,将其应用于程序组。大多数标准对话框以各种常量存储信息。 – mirtheil 2012-01-06 12:26:48

相关问题