2012년 4월 13일 금요일

컴포넌트 선택에 따라 특정페이지 나타나게

 

Help 컴포넌트 선택시 Password 입력창이 나타나도록.

[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program
DisableProgramGroupPage=yes
UninstallDisplayIcon={app}\MyProg.exe
OutputDir=userdocs:Inno Setup Examples Output

[Files]

[Components]
Name: "help"; Description: "help"
Name: "test"; Description: "test"

[Code]
//Since you need the password later in the installation, and not always, you can not use the standard setup password page.
// You will instead create your own page and insert it after the components selection page:
var
  PasswordPage: TInputQueryWizardPage;

procedure InitializeWizard();
begin
  PasswordPage := CreateInputQueryPage(wpSelectComponents,
    'Your caption goes here',
    'Your description goes here',
    'Your subcaption goes here');
  PasswordPage.Add(SetupMessage(msgPasswordEditLabel), True);
end;

//Note that this uses the translated password caption, you may need to make the other three strings translatable as well.
//Next you will need to hide that page if the user has not selected the component for installation:
function ShouldSkipPage(PageID: Integer): Boolean;
begin
  Result := False;
  if PageID = PasswordPage.ID then begin
    // show password page only if help file is selected for installation
    Result := not IsComponentSelected('help');
  end;
end;

//Finally you need to check the password, and prevent the user from going to the next page if the password is wrong:
function NextButtonClick(CurPageID: Integer): Boolean;
begin
  Result := True;
  if CurPageID = PasswordPage.ID then begin
    // stay on this page if password is wrong
    if PasswordPage.Edits[0].Text <> '1234' then begin
      MsgBox(SetupMessage(msgIncorrectPassword), mbError, MB_OK);
      Result := False;
    end;
  end;
end;

2012년 4월 10일 화요일

주 모니터의 해상도(Resolution)와 색상(BITSPIXEL)알아내기. User32.dll 이용

[Setup]
AppName=DisplayResoltution
AppVerName=DisplayResoltution
DefaultDirName=DisplayResoltution
DisableStartupPrompt=true
Uninstallable=false

[Code]
[Code]
function GetSystemMetrics (nIndex: Integer): Integer;
  external 'GetSystemMetrics@User32.dll stdcall setuponly';

Const
    SM_CXSCREEN = 0; // The enum-value for getting the width of the cient area for a full-screen window on the primary display monitor, in pixels.
    SM_CYSCREEN = 1; // The enum-value for getting the height of the client area for a full-screen window on the primary display monitor, in pixels.

function InitializeSetup(): Boolean;
  var
      hDC: Integer;
      xres: Integer;
      yres: Integer;
begin
    xres := GetSystemMetrics(SM_CXSCREEN);
    yres := GetSystemMetrics(SM_CYSCREEN); //vertical resolution

    MsgBox( 'Current resolution is ' + IntToStr(xres) +
        'x' + IntToStr(yres)
, mbInformation, MB_OK );

    Result := False;
end;

주 모니터의 해상도(Resolution)와 색상(BITSPIXEL)알아내기. GDI32.dll 이용

[Setup]
AppName=DisplayResoltution
AppVerName=DisplayResoltution
DefaultDirName=DisplayResoltution
DisableStartupPrompt=true
Uninstallable=false

[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}\My Program"; Filename: "{app}\MyProg.exe"; Parameters: {code:GetParams}


[Code]
// Functions to get BPP & resolution

function DeleteDC (hDC: Integer): Integer;
external 'DeleteDC@GDI32 stdcall';

function CreateDC (lpDriverName, lpDeviceName, lpOutput: String; lpInitData: Integer): Integer;
external 'CreateDCA@GDI32 stdcall';

function GetDeviceCaps (hDC, nIndex: Integer): Integer;
external 'GetDeviceCaps@GDI32 stdcall';

Const
    HORZRES = 8;    //horizontal resolution
    VERTRES = 10;   //vertical resolution
    BITSPIXEL = 12; //bits per pixel
    PLANES = 14;    //number of planes (color depth=bits_per_pixel*number_of_planes)
    ASPECTX =11;
    ASPECTY =11;
var
xres, yres, bpp, pl, tmp, xx, yy: Integer;

function InitializeSetup(): Boolean;
  var
      hDC: Integer;
begin

    //get resolution & BPP
    hDC := CreateDC('DISPLAY', '', '', 0 );
    pl := GetDeviceCaps(hDC, PLANES);
    bpp := GetDeviceCaps(hDC, BITSPIXEL);
    xres := GetDeviceCaps(hDC, HORZRES); //horizontal resolution
    yres := GetDeviceCaps(hDC, VERTRES); //vertical resolution
    xx := GetDeviceCaps(hDC, ASPECTX); //vertical resolution
    yy := GetDeviceCaps(hDC, ASPECTY); //vertical resolution
    tmp := DeleteDC(hDC);
    bpp := pl * bpp;   //color depth
   

    MsgBox( 'Current resolution is ' + IntToStr(xres) +
        'x' + IntToStr(yres) +
        ' and color depth is ' + IntToStr( bpp ) +  'left'
        , mbInformation, MB_OK );

    Result := false;
end;

function GetParams(def: string): string;
var
sTemp : string;
begin
  sTemp := 'xres=' + IntToStr(xres) + ' yres=' +IntToStr(yres);
  result := sTemp;
end;

Custom page

출처:http://stackoverflow.com/questions/4311995/inno-setup-custom-page

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

#define MyAppName "DXX-Rebirth"
#define MyAppName1 "D1X-Rebirth"
#define MyAppName2 "D2X-Rebirth"
#define MyAppVersion "0.57.0"
#define MyAppURL "http://www.dxx-rebirth.com/"
#define MyAppExeName "d1x-rebirth.exe"
#define MyAppExeName2 "d2x-rebirth.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={{DF665ED8-D2A7-490A-805F-6677EFFBAB40}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={pf}\{#MyAppName}
DefaultGroupName={#MyAppName}
OutputBaseFilename=Setup
Compression=lzma
SolidCompression=yes

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

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

[Types]
Name: "install"; Description: "DXX-Rebirth"; Flags: iscustom

[Components]
Name: "d1x"; Description: "D1X-Rebirth"; Types: install
Name: "d2x"; Description: "D2X-Rebirth"; Types: install

[Files]
;D1X Files

[Icons]

[Run]

[UninstallDelete]
Type: filesandordirs; Name: "{app}"

[Code]
// global vars
var
  SampleDataPage: TInputOptionWizardPage;
  DataDirPage: TInputDirWizardPage;
  DataDirPage1: TInputDirWizardPage;
  DataDirPage2: TInputDirWizardPage;


// custom wizard page setup, for data dir.
procedure InitializeWizard;
begin
  { Taken from CodeDlg.iss example script }
  { Create custom pages to show during install }

  SampleDataPage := CreateInputOptionPage(wpSelectComponents,
    'Install Descent Data', '',
    'Would you like to copy the Descent game files to your DXX-Rebirth installation?',
    True, False);
  SampleDataPage.Add('Yes copy the game files, missions, players, and savegames.');
  SampleDataPage.Add('Yes, but just copy the game files.');
  SampleDataPage.Add('No, I'+chr(39)+'ll copy the game files myself later.');

  SampleDataPage.Values[0] := True;

  DataDirPage := CreateInputDirPage(SampleDataPage.ID,
  'Descent Data Directory', '',
  'Please select the location where the original Descent files are installed.',
  False, '');
  DataDirPage.Add('Descent location.');
  DataDirPage.Add('Decent 2 location.');
  DataDirPage.Values[0] := ExpandConstant('{pf}\GOG.com\Descent and Descent 2\Descent');
  DataDirPage.Values[1] := ExpandConstant('{pf}\GOG.com\Descent and Descent 2\Descent 2');

  DataDirPage1 := CreateInputDirPage(SampleDataPage.ID,
  'Descent Data Directory', '',
  'Please select the location where the original Descent files are installed.',
  False, '');
  DataDirPage1.Add('');
  DataDirPage1.Values[0] := ExpandConstant('{pf}\GOG.com\Descent and Descent 2\Descent');

  DataDirPage2 := CreateInputDirPage(SampleDataPage.ID,
  'Descent Data Directory', '',
  'Please select the location where the original Descent 2 files are installed.',
  False, '');
  DataDirPage2.Add('Decent 2 location.');
  DataDirPage2.Values[0] := ExpandConstant('{pf}\GOG.com\Descent and Descent 2\Descent 2');

end;


function ShouldSkipPage(PageID: Integer): Boolean;
begin
  if (PageID = DataDirPage.ID) and (SampleDataPage.Values[2] = true) then
  begin
    Result := True
    exit;
  end;
  if (IsComponentSelected('d1x') = true) and (IsComponentSelected('d2x') = true) then
    begin
      if PageID = DataDirPage.ID then
      begin
        result := false;
        exit;
      end;
      if PageID = DataDirPage1.ID then
      begin
        result := true;
        exit;
      end;
      if PageID = DataDirPage2.ID then
      begin
        result := true;
        exit;
      end;
      exit;
    end;
    if (IsComponentSelected('d1x') = true) and (IsComponentSelected('d2x') = false) then
    begin
      if PageID = DataDirPage.ID then
      begin
        result := true;
        exit;
      end;
      if PageID = DataDirPage1.ID then
      begin
        result := false;
        exit;
      end;
      if PageID = DataDirPage2.ID then
      begin
        result := true;
        exit;
      end;
      exit;
    end;
    if (IsComponentSelected('d1x') = false) and (IsComponentSelected('d2x') = true) then
    begin
      if PageID = DataDirPage.ID then
      begin
        result := true;
        exit;
      end;
      if PageID = DataDirPage1.ID then
      begin
        result := true;
        exit;
      end;
      if PageID = DataDirPage2.ID then
      begin
        result := false;
        exit;
      end;
      exit;
    end
  else
  begin
  result := false;
  end;
end;

function NextButtonClick(CurPageID: Integer): Boolean;
begin
  if CurPageID = wpSelectComponents then
  begin
    if (IsComponentSelected('d1x') = false) and (IsComponentSelected('d2x') = false) then
      begin
        MsgBox('You didn'+chr(39)+'t select anything to install.', mbError, MB_OK);
        result := false;
        exit;
      end
      else
      result := true;
  end
  else
    result := true;
end;

function InstallAll(): Boolean;
begin
  { Return the value of the 'install' radiobutton }
  //MsgBox('InstallSampleData.', mbError, MB_OK);
  Result := SampleDataPage.Values[0];
end;

function Install(): Boolean;
begin
  { Return the value of the 'install' radiobutton }
  //MsgBox('InstallSampleData.', mbError, MB_OK);
  Result := SampleDataPage.Values[1];
end;

function DontInstall(): Boolean;
begin
  Result := SampleDataPage.Values[2];
end;

function DescentTwo(Param: String): String;
begin
if Assigned(DataDirPage) then
  begin
    if (IsComponentSelected('d1x') = true) and (IsComponentSelected('d2x') = true) then
    begin
      result := DataDirPage.Values[1];
    end;
    if (IsComponentSelected('d1x') = false) and (IsComponentSelected('d2x') = true) then
    begin
      result := DataDirPage.Values[0];
    end;
    if (IsComponentSelected('d1x') = true) and (IsComponentSelected('d2x') = false) then
    begin
      result := '';
    end;
  end
else
result := '';
end;

function Descent(Param: String): String;
begin
if Assigned(DataDirPage) then
  begin
    if (IsComponentSelected('d1x') = false) and (IsComponentSelected('d2x') = true) then
    begin
    result := '';
    end
    else
    begin
        result := DataDirPage.Values[0];
    end;
  end
  else  
   result := '';
  end;
end.

2012년 4월 6일 금요일

입력된 값과 입력한 key 값을 비교

입력된 값과 입력한 key 값을 비교해서 틀릴 경우 next 버튼 비활성화

[Setup]
AppName=My Program
AppVerName=My Program version 1.5
DefaultDirName={pf}\My Program
DisableProgramGroupPage = yes
UninstallDisplayIcon={app}\MyProg.exe
OutputDir=userdocs:Inno Setup Examples Output

[Files]
Source: "MyProg.exe"; DestDir: "{app}"; Flags: ignoreversion

[CustomMessages]
CustomForm_Caption=설정정보
CustomForm_Description=설정정보를 입력하세요.
CustomForm_Label1_Caption0=username:
CustomForm_Label2_Caption0=password:
CustomForm_Label3_Caption0=key:

[Code]
Var
Page: TWizardPage;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
  
procedure  EdtOnChange (Sender: TObject);

Var
MyEdit : TEdit;
  
   
begin
MyEdit := TEdit(Sender);
if MyEdit.Text = '78df5df222b526a341b2eeac0f64fb57' then
  WizardForm.NextButton.Enabled := true
Else
  WizardForm.NextButton.Enabled := false;
end;


procedure InitializeWizard;
Var
  CheckBox: TCheckBox;
begin
  Page := CreateCustomPage( wpWelcome, ExpandConstant('{cm:CustomForm_Caption}'), ExpandConstant('{cm:CustomForm_Description}') );


{ Label1 } Label1 := TLabel.Create(Page); with Label1 do begin Parent := Page.Surface; Caption := ExpandConstant('{cm:CustomForm_Label1_Caption0}'); Left := ScaleX(16); Top := ScaleY(24); Width := ScaleX(70); Height := ScaleY(13); end;

{ Label2 } Label2 := TLabel.Create(Page); with Label2 do begin Parent := Page.Surface; Caption := ExpandConstant('{cm:CustomForm_Label2_Caption0}'); Left := ScaleX(17); Top := ScaleY(56); Width := ScaleX(70); Height := ScaleY(13); end;

{ Label3 } Label3 := TLabel.Create(Page); with Label3 do begin Parent := Page.Surface; Caption := ExpandConstant('{cm:CustomForm_Label3_Caption0}'); Left := ScaleX(17); Top := ScaleY(88); Width := ScaleX(70); Height := ScaleY(13); end;

{ Edit1 } Edit1 := TEdit.Create(Page); with Edit1 do begin Parent := Page.Surface; Left := ScaleX(115); Top := ScaleY(24); Width := ScaleX(273); Height := ScaleY(21); TabOrder := 0; end;

{ Edit2 } Edit2 := TEdit.Create(Page); with Edit2 do begin Parent := Page.Surface; Left := ScaleX(115); Top := ScaleY(56); Width := ScaleX(273); Height := ScaleY(21); TabOrder := 1; end;

{ Edit3 } Edit3 := TEdit.Create(Page); with Edit3 do begin Parent := Page.Surface; Left := ScaleX(115); Top := ScaleY(88); Width := ScaleX(273); Height := ScaleY(21); TabOrder := 2; end;

Edit3.OnChange := @EdtOnChange;

end;

procedure CurPageChanged(CurPageID: Integer);
begin
If CurPageID = Page.ID Then
  WizardForm.NextButton.Enabled := false;
end;

check box

check box를 만들어준다.

[Setup]
AppName='Test Date Script'
AppVerName='Test Date Script'
DefaultDirName={pf}\test

[Code]

const
cCheckBox = false;
cRadioButton  = true;

var
  Opt : TInputOptionWizardPage;

function BoolToStr(Value : Boolean) : String;
begin
  if Value then
    result := 'true'
  else
    result := 'false';
end;

procedure ClickEvent(Sender : TObject);
var
Msg : String;
I   : Integer;
begin
   // Click Event, allowing inspection of the Values.
    Msg := 'The Following Items are Checked' +#10#13;
    Msg := Msg + 'Values[0]=' + BoolToStr(Opt.Values[0]) +#10#13;
    Msg := Msg + 'Values[1]=' + BoolToStr(Opt.Values[1]) +#10#13;
    Msg := Msg + 'Values[2]=' + BoolToStr(Opt.Values[2]);

    MsgBox(Msg,mbInformation,MB_OK);
end;
procedure InitializeWizard();
var
  I : Integer;
  ControlType : Boolean;
begin
  ControlType := cCheckBox;
  Opt := CreateInputOptionPage(1,'Caption','Desc','SubCaption',ControlType, false);
  Opt.Add('Test1');
  Opt.Add('Test2');
  Opt.Add('Test3');

  // Assign the Click Event.
  Opt.CheckListBox.OnClickCheck := @ClickEvent; 
end;

INI 파일 생성

사용자에게 Username과 Password를 입력 받아 INI 파일로 기록하는 방법입니다.

[AUTH]
USERNAME=이름
PASSWORD=password

형식으로 INI파일을 생성함.

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

[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={{82C8C949-44A8-49C4-8CED-8DD0ACD0DCCF}
AppName=My Program
AppVerName=My Program 1.5
AppPublisher=My Company, Inc.
AppPublisherURL=http://www.example.com/
AppSupportURL=http://www.example.com/
AppUpdatesURL=http://www.example.com/
DefaultDirName={pf}\My Program
DefaultGroupName=My Program
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: "MyProg.exe"; DestDir: "{app}"; Flags: ignoreversion

; NOTE: Don't use "Flags: ignoreversion" on any shared system files

[INI]
Filename: {app}\prefs.ini; Section: AUTH; Key: USERNAME; String: {code:GetUserName}
Filename: {app}\prefs.ini; Section: AUTH; Key: PASSWORD; String: {code:GetPassword}


[code]
var
AuthPage : TInputQueryWizardPage;

procedure InitializeWizard;
begin
AuthPage := CreateInputQueryPage(wpWelcome,
    'Account Information', 'Please enter your Account Information',
    '');
  AuthPage.Add('Username:', False);
  AuthPage.Add('Password:', True);
end;

function AuthForm_NextButtonClick(Page: TWizardPage): Boolean;
begin
  Result := True;
end;

function GetUserName(Param: String): string;
begin
result := AuthPage.Values[0];
end;

function GetPassword(Param: String): string;
begin
result := AuthPage.Values[1];
end;