选择数据库路径或让安装继续

时间:2015-01-13 12:09:08

标签: inno-setup

我尝试在InnoSetup做一些事情,但我做不到。我想让用户选择是安装数据库还是选择这个数据库的路径。

更具体地说,我会有一个包含我的2个组件的页面: "标准"和"服务器"

案例1: 如果用户选择"标准",则安装将继续正常并在本地安装数据库。

案例2: 如果用户选择" server",则下一页用于选择基本路径(例如网络共享),不要在本地安装数据库。

我从Inno Setup开始(特别是代码部分)我该怎么做?

这是我当前代码的一个示例,请注意我已尝试将互联网上的代码调整为我的问题,但不一定合适:

[Types]
Name: "standard"; Description: "Local Database";
Name: "server"; Description: "Server Database"; Flags: iscustom

[Components]
Name: "baselocal"; Description: "Standard Installation : install program and local database"; Types: standard; 
Name: "baseserver"; Description: "Installation with server database : install program and choose directory for database"; Types: server;

[Files]
Source: "Path\to\database\*"; DestDir: "{app}\{code:GetDir|0}"; Flags: ignoreversion recursesubdirs createallsubdirs; Components: standard

[Code]
// Database choice
var
  DirPage: TInputDirWizardPage;
  DirPageID: Integer;

function GetDir(Param: String): String;
begin
  Result := DirPage.Values[StrToInt(Param)];
end;

procedure InitializeWizard;
begin
  // create a directory input page
  DirPage := CreateInputDirPage(wpSelectComponents, 'Choix de la base', 'Caneco BT peut gérer une base sur un serveur ou en local. Veuillez indiquez le chemin de la base qui vous intéresse.', 'Dossier Base de Données', False, '');
  // add directory input page items
  DirPage.Add('Sélectionnez un chemin :');
  // assign default directories for the items from the previously stored data; if
  // there are no data stored from the previous installation, use default folders
  // of your choice
  DirPage.Values[0] := GetPreviousData('Directory1', ExpandConstant('{pf}\program\'));
  DirPageID := DirPage.ID;
end;

procedure RegisterPreviousData(PreviousDataKey: Integer);
begin
  // store chosen directories for the next run of the setup
  SetPreviousData(PreviousDataKey, 'Directory1', DirPage.Values[0]);
end;
// Skip page
function ShouldSkipPage(PageID: Integer): Boolean;
begin
  // initialize result to not skip any page (not necessary, but safer)
  Result := False;
  // if the page that is asked to be skipped is your custom page, then...
  if PageID = DirPageID then
    // if the component is not selected, skip the page
    Result := not IsComponentSelected('help');
end;

提前谢谢

1 个答案:

答案 0 :(得分:0)

我开始为零,因此尝试做这样的事情:

[code]
var
  ActionPage: TInputOptionWizardPage;
  DirPage: TInputDirWizardPage;
  DirPageID: Integer;

procedure InitializeWizard;
begin
  ActionPage := CreateInputOptionPage(wpWelcome,
    'Optional Actions Test', 'Which actions should be performed?',
    'Please select all optional actions you want to be performed, then click Next.',
    True, False);

  ActionPage.Add('Action 1');
  ActionPage.Add('Action 2');

  ActionPage.Values[0] := True;
  ActionPage.Values[1] := False;
end;

function NextButtonClick(CurPageID: Integer): Boolean;
begin
  Result := True;
  if CurPageID = ActionPage.ID then begin
    if ActionPage.Values[0] then
                begin
                  // create a directory input page
                  DirPage := CreateInputDirPage(wpSelectComponents, 'Choix de la base', 'Caneco BT peut gérer une base sur un serveur ou en local. Veuillez indiquez le chemin de la base qui vous intéresse.', 'Dossier Base de Données', False, '');
                  // add directory input page items
                  DirPage.Add('Sélectionnez un chemin :');
                  // assign default directories for the items from the previously stored data; if
                  // there are no data stored from the previous installation, use default folders
                  // of your choice
                  DirPage.Values[0] := GetPreviousData('Directory1', ExpandConstant('{pf}\program\'));
                  DirPageID := DirPage.ID;
                  exit;
                end;

    if ActionPage.Values[1] then
       MsgBox('Local Database', mbInformation, MB_OK);
       exit;
  end;
end;

那个工作(我非常高兴)但我有一个问题:

如果我选择" Action1"而且我要去" DirPage"页面然后我回去,选择"动作2" " DirPage"页面出现。

否则,如果我从开始选择" Action2"页面" DirPage"没有按预期显示。

为什么呢?我可以解决这个问题吗?