2012-11-21 10 views
5

Próbuję zrobić niestandardowe pole wyboru na mojej niestandardowej stronie (ponieważ jest to instalator jednej strony), potrzebne jest tylko pole wyboru bez okien dialogowych lub nic, instalator, który próbuję skompilować jest bardzo liniowy i prosty.Jak mogę dodać CheckBox dla plików opcjonalnych podczas instalacji? (innosetup)

Chcę związać "FILE3.EXE" na checkboxie w następujący sposób: jeśli pole wyboru jest zaznaczone, skopiuj plik (FILE3.EXE) w DestDir, w przeciwnym razie, jeśli pole wyboru jest odznaczone, pomiń plik (FILE3.EXE) podczas instalacji .

Jest to kod, który kiedyś, oczywiście kod pole brakuje, bo nie jestem w stanie tego zrobić

[Files] 
Source: FILE1.EXE; DestDir: {app}; 
Source: FILE2.EXE; DestDir: {app}; 
Source: FILE3.EXE; DestDir: {app}; //OPTIONAL 

[Code] 
procedure ExitProcess(uExitCode: UINT); 
external '[email protected] stdcall'; 


var 
MainPage : TWizardPage; 
FolderToInstall : TEdit; 
InstallLocation : String; 


procedure CancelClick(Sender: TObject); 
begin 
if ExitSetupMsgBox then 
begin 
ExitProcess(0); 
end; 
end; 


procedure BrowseClick(Sender : TObject); 
var 
Dir : String; 

begin 
Dir := FolderToInstall.Text; 
if BrowseForFolder('Browse',Dir,false) then 
FolderToInstall.Text := Dir; 
WizardForm.DirEdit.Text := Dir; 
end; 


procedure InitializeWizard(); 
var 
LabelFolder : TLabel; 


MainPage := CreateCustomPage(wpWelcome,'',''); 
LabelFolder := TLabel.Create(MainPage); 
LabelFolder.Parent := WizardForm; 
LabelFolder.Top := 164; 
LabelFolder.Left := 6; 
LabelFolder.Caption := 'Directory:' 


FolderToInstall := TEdit.Create(MainPage); 
FolderToInstall.Parent := WizardForm; 
FolderToInstall.Top := 182; 
FolderToInstall.Left := 85; 
FolderToInstall.Width := 380; 
FolderToInstall.Text := WizardDirValue; 
FolderToInstall.ReadOnly := True; 
end; 
+1

Czy chcesz mieć kompletne niestandardowe rozwiązanie, czy też chcesz użyć już wbudowanej funkcjonalności dla tego podejścia? –

+0

Próbuję utworzyć niestandardowe pole wyboru na mojej niestandardowej stronie (ponieważ jest to instalator jednej strony), potrzebne jest tylko pole wyboru bez okien dialogowych lub coś innego, instalator, który próbuję skompilować jest bardzo liniowy i prosty – ApprenticeGeek

+1

Następnie utwórz pole wyboru i wykonaj funkcję niestandardową za pomocą parametru ['Check'] (http://jrsoftware.org/ishelp/topic_scriptcheck.htm#Check) w sekcji" Pliki ". Gdzie chcesz to pole wyboru? – TLama

Odpowiedz

10

Musisz dokonać Check funkcję, która będzie zwracać stan pola wyboru z sekcji [Code] skryptu . Coś takiego może robić, co chcesz, ale przed skryptem kodu bym cię skorygować w następujący:

  • użytku TNew ... klas skąd jesteś w stanie, więc w przypadku korzystania TNewEdit zamiast TEdit
  • użycie TWizardPage.Surface jako Parent jeśli chcesz mieć pewien element na stronie (tutaj nie jestem pewien, czy to jest twój zamiar, tylko wskazując na to uwagę :-) Format
  • kod, to nie musi być tak płaski

W poniższym przykładzie używałem Check funkcja nazywa InstallHelpFile dla warunkowego zainstalować pewnego pliku, w tym przypadku MyProg.chm. Funkcja Check działa po prostu; gdy zwrócisz True do funkcji, plik zostanie przetworzony, pomijany, gdy zwrócisz False.

[Setup] 
AppName=My Program 
AppVersion=1.5 
DefaultDirName={pf}\My Program 
OutputDir=userdocs:Inno Setup Examples Output 

[Files] 
Source: "MyProg.exe"; DestDir: "{app}" 
Source: "MyProg.chm"; DestDir: "{app}"; Check: InstallHelpFile; 

[Code] 
var 
    InstallHelpCheckBox: TNewCheckBox; 

procedure InitializeWizard; 
var 
    LabelFolder: TLabel; 
    MainPage: TWizardPage; 
    FolderToInstall: TNewEdit; 
begin 
    MainPage := CreateCustomPage(wpWelcome, '', ''); 
    LabelFolder := TLabel.Create(MainPage); 
    LabelFolder.Parent := WizardForm; 
    LabelFolder.Top := 164; 
    LabelFolder.Left := 6; 
    LabelFolder.Caption := 'Directory:' 

    FolderToInstall := TNewEdit.Create(MainPage); 
    FolderToInstall.Parent := MainPage.Surface; 
    FolderToInstall.Top := 182; 
    FolderToInstall.Left := 85; 
    FolderToInstall.Width := 380; 
    FolderToInstall.Text := WizardDirValue; 
    FolderToInstall.ReadOnly := True; 

    InstallHelpCheckBox := TNewCheckBox.Create(MainPage); 
    InstallHelpCheckBox.Parent := MainPage.Surface; 
    InstallHelpCheckBox.Top := FolderToInstall.Top + FolderToInstall.Height + 8; 
    InstallHelpCheckBox.Left := FolderToInstall.Left; 
    InstallHelpCheckBox.Width := FolderToInstall.Width; 
    InstallHelpCheckBox.Caption := 'Install help file'; 
end; 

function InstallHelpFile: Boolean; 
begin 
    // here is the Check function used above; if you return True to this 
    // function, the file will be installed, when False, the file won't 
    // be installed 
    Result := InstallHelpCheckBox.Checked; 
end; 
+0

WORKED WIELKI !!! – ApprenticeGeek

10

Nie trzeba ręcznie utworzyć wyboru za to. Standardowym sposobem, aby użytkownik mógł wybrać, co zainstalować, jest użycie sekcji skryptu w postaci [Types] i [Components].

Spójrz na skrypt Componens.iss znajdujący się w twoim folderze instalacyjnym \ examples.

; -- Components.iss -- 
; Demonstrates a components-based installation. 

; SEE THE DOCUMENTATION FOR DETAILS ON CREATING .ISS SCRIPT FILES! 

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

[Types] 
Name: "full"; Description: "Full installation" 
Name: "compact"; Description: "Compact installation" 
Name: "custom"; Description: "Custom installation"; Flags: iscustom 

[Components] 
Name: "program"; Description: "Program Files"; Types: full compact custom; Flags: fixed 
Name: "help"; Description: "Help File"; Types: full 
Name: "readme"; Description: "Readme File"; Types: full 
Name: "readme\en"; Description: "English"; Flags: exclusive 
Name: "readme\de"; Description: "German"; Flags: exclusive 

[Files] 
Source: "MyProg.exe"; DestDir: "{app}"; Components: program 
Source: "MyProg.chm"; DestDir: "{app}"; Components: help 
Source: "Readme.txt"; DestDir: "{app}"; Components: readme\en; Flags: isreadme 
Source: "Readme-German.txt"; DestName: "Liesmich.txt"; DestDir: "{app}"; Components: readme\de; Flags: isreadme 

[Icons] 
Name: "{group}\My Program"; Filename: "{app}\MyProg.exe" 

Na starcie instalator prezentuje to okno w kreatorze:

Components dialog

+2

@Globulorozzo Powiesz, że istotne informacje w twoim pytaniu, które chcą, aby każdy "widział w kodzie", nie jest zbyt dobry dla tych, którzy próbują ci pomóc! – jachguate

+0

@Globulorozzo I dlaczego nie ma edycji Twojego pytania? Czy powinniśmy to dla ciebie zrobić? :( –

0
// Create: 
for i := 0 to g_SetupX_Count do begin 
    WizardForm.ComponentsList.AddCheckBox(g_SetupX_Name[i], '', 0, g_SetupX_Active[i], true, false, false, nil); 
    g_SetupX_CompListIndex[i] := nextPosi; 
    nextPosi := nextPosi + 1; 
end; 

// Evaluate: 
for i := 0 to g_SetupX_Count do begin 
    g_SetupX_Active[i] := WizardForm.ComponentsList.Checked[g_SetupX_CompListIndex[i]]; 
end; 
Powiązane problemy