Inno设置:不调用所有功能

时间:2014-12-31 16:06:25

标签: inno-setup

我是Inno安装程序安装程序的新手。 我正在努力实现以下目标并遇到麻烦...

1)选择数据库类型 - MS-SQL或Oracle

的选项

2)根据以上选择检查ms-sql或Oracle客户端驱动程序的ODBC驱动程序

3)获取数据库主机,用户名和密码

4)如果ms-sql使用上面的信息创建一个DSN条目。

当我运行安装程序时,我没有选择数据库类型(#1)的选项,也没有调用该函数来检查驱动程序(#2)。

感谢任何帮助。

提前感谢。

[Setup]
AppName=ODBC_Check
AppVerName=ODBC_Check
DefaultDirName={pf}\ODBC_Check
DisableStartupPrompt=true
SetupLogging=true

Compression=lzma/Max
SolidCompression=yes
Uninstallable=no


[INI]
;Filename: "{app}\DB_Params.ps1"; Section: "DB_PARAMS"; Key: "$DB_TYPE"; String: """{code:DBType.Values}"""
Filename: "{app}\DB_Params.ps1"; Section: "DB_PARAMS"; Key: "$DB_HOSTNAME"; String: """{code:GetDBValues|Database Host Name or IP Address}"""
Filename: "{app}\DB_Params.ps1"; Section: "DB_PARAMS"; Key: "$DB_USERNAME"; String: """{code:GetDBValues|Database User Name}"""
Filename: "{app}\DB_Params.ps1"; Section: "DB_PARAMS"; Key: "$DB_PASSWORD"; String: """{code:GetDBValues|Database User Password}"""


[Code]
var
  UserPage: TInputQueryWizardPage;
  DBSelectionPage: TInputOptionWizardPage;      
  DBParametersPage: TInputQueryWizardPage;  


procedure InitializeWizard;
begin
    UserPage := CreateInputQueryPage(wpWelcome,
    'Personal Information', 'Who are you?',
    'Please specify your name and the company for whom you work, then click Next.');
    UserPage.Add('Name:', False);
    UserPage.Add('Company:', False);


    DBSelectionPage := CreateInputOptionPage(UserPage.ID,
    'Database Selection', 'Database Type to use?',
    'Please select only one Databae type to use, then click Next.',
    True, True);
    DBSelectionPage.Add('MS-SQL');
    DBSelectionPage.Add('Oracle');


    DBParametersPage := CreateInputQueryPage(DBSelectionPage.ID,
    'Database Connection Information', 'Please enter the Database Host, Username and Password.',
    '');
    DBParametersPage.Add('Database Host Name or IP Address', False);
    DBParametersPage.Add('Database User Name', FALSE);
    DBParametersPage.Add('Database User Password', TRUE);


    UserPage.Values[0] := GetPreviousData('Name', ExpandConstant('{sysuserinfoname}'));
    UserPage.Values[1] := GetPreviousData('Company', ExpandConstant('{sysuserinfoorg}'));


  case GetPreviousData('DBSelectionMode', '') of
    'mssql': DBSelectionPage.SelectedValueIndex := 0;
    'oracle': DBSelectionPage.SelectedValueIndex := 1;
  else
    DBSelectionPage.SelectedValueIndex := 0;
  end;
 end;



procedure RegisterPreviousData(PreviousDataKey: Integer);
var
  DBSelectionMode: String;
begin
  SetPreviousData(PreviousDataKey, 'Name', UserPage.Values[0]);
  SetPreviousData(PreviousDataKey, 'Company', UserPage.Values[1]);

  SetPreviousData(PreviousDataKey, 'Database Host Name or IP Address', DBParametersPage.Values[0]);
  SetPreviousData(PreviousDataKey, 'Database User Name', DBParametersPage.Values[1]);
  SetPreviousData(PreviousDataKey, 'Database User Password', DBParametersPage.Values[2]);


  case DBSelectionPage.SelectedValueIndex of
    0: DBSelectionMode := 'mssql';
    1: DBSelectionMode := 'oracle';
  end;
  SetPreviousData(PreviousDataKey, 'DBSelectionMode', DBSelectionMode);
end;


function NextButtonClick(CurPageID: Integer): Boolean;
var
  ErrorCode: Integer;
  ODBCDriverInstalled : Boolean;
  ORADriverInstalled : Boolean;
  Result1 : Boolean;


begin
 Result := True;

  if CurPageID = DBSelectionPage.ID then begin
    if DBSelectionPage.Values[0] then begin
      ODBCDriverInstalled := RegKeyExists(HKLM,'SOFTWARE\ODBC\ODBCINST.INI\SQL Server Native Client 11.0');
      if ODBCDriverInstalled then
        begin
        Result := true;
        end else
          begin
        Result1 := MsgBox('This setup requires the ODBC Driver to connect to the Database. Please download and install. Do you want to download the ODBC Driver now?',
        mbConfirmation, MB_YESNO) = idYes;
          if Result1 =false then
            begin
            Result:=false;
            MsgBox('Setup cannot continue without MS-SQL ODBC Driver. Please install appropriate ODBC driver and re-run the DB Setup Assistant. You can safely choose "Cancel" to exit.', mbInformation, MB_OK);
          end else
        begin
        Result1:=false;
        ShellExec('open',
          'http://download.microsoft.com/download/a/a/c/aac39226-8825-44ce-90e3-bf8203e74006/dotnetfx.exe',
          '','',SW_SHOWNORMAL,ewNoWait,ErrorCode);
      end;
  end;

  end else begin
  Result := True;
  if CurPageID = DBSelectionPage.ID then begin
    if DBSelectionPage.Values[1] then
  ORADriverInstalled := RegKeyExists(HKLM,'SOFTWARE\ODBC\ODBCINST.INI\ORACLE');
  if ORADriverInstalled then
  begin
    Result := true;
  end else
     begin
      Result1 := MsgBox('This setup requires the ORACLE Driver to connect to the Database. Please download and install. Do you want to download the ORACLE Driver now?',
        mbConfirmation, MB_YESNO) = idYes;
      if Result1 =false then
      begin
        Result:=false;
        MsgBox('Setup cannot continue without ORACLE Driver. Please install appropriate ORACLE driver and re-run the DB Setup Assistant. You can safely choose "Cancel" to exit.', mbInformation, MB_OK);
      end else
      begin
        Result1:=false;
        ShellExec('open',
          'http://Oracle.com',
          '','',SW_SHOWNORMAL,ewNoWait,ErrorCode);
      end;
      end;
    end;
  end;

end else begin
  if CurPageID = UserPage.ID then begin
    if UserPage.Values[0] = '' then begin
      MsgBox('You must enter your name.', mbError, MB_OK);
      Result := False;
  end;

  end else if CurPageID = DBParametersPage.ID then begin
    if DBParametersPage.Values[0] = '' then begin
      MsgBox('You must enter the Database Server Name or IP.', mbError, MB_OK);
      Result := False;

  end else if CurPageID = DBParametersPage.ID then begin
    if DBParametersPage.Values[1] = '' then begin
      MsgBox('You must enter the Database Username.', mbError, MB_OK);
      Result := False;

  end else if CurPageID = DBParametersPage.ID then begin
    if DBParametersPage.Values[2] = '' then begin
      MsgBox('You must enter the Database Password.', mbError, MB_OK);
      Result := False;
  end;
 end;
end;

//end else 
//begin
   // Result := True;
     if (CurPageId = wpSelectDir) and not FileExists(ExpandConstant('{app}\config.xlsx')) then begin
        MsgBox('Please select the correct Config Directory', mbError, MB_OK);
        Result := False;
        exit;
    end;
end;
end;
end;


function GetUser(Param: String): String;
begin
  if Param = 'Name' then
    Result := UserPage.Values[0]
  else if Param = 'Company' then
    Result := UserPage.Values[1];
end;


function GetDBValues(Param: String): String;
begin
  if Param = 'Database Host Name or IP Address' then
    Result := DBParametersPage.Values[0]
  else if Param = 'Database User Name' then
    Result := DBParametersPage.Values[1]
  else if Param = 'Database User Password' then
    Result := DBParametersPage.Values[2];
end;

// End of Script 

0 个答案:

没有答案