1
2 var
3 wpAskConfDir: TInputDirWizardPage;
4
5 // Additional Elements on TargetDir wizard page
6 CheckSecondInstall: TCheckBox; // Also used by GetAppId
7 CheckSecondLabel: TLabel;
8
9 CfgLoadedFromDir: String; // The directory from which lazarus was uninstalled
10 CFGFileForLoadedFromDir: TStringList;
11 CFGPathForLoadedFromDir: String; // the PCP
12 CFGStateForLoadedFromDir: TCfgFileState;
13
14 Procedure ClearExistingConfigForFolder;
15 begin
16 CfgLoadedFromDir := '';
17 if CFGFileForLoadedFromDir <> nil then
18 CFGFileForLoadedFromDir.Clear;
19 CFGPathForLoadedFromDir := '';
20 CFGStateForLoadedFromDir := csNoFile;
21 end;
22
23 Procedure LoadExistingConfigForFolder(AFolder: String);
24 begin
25 CfgLoadedFromDir := AFolder;
26 LoadCFGFile(AFolder, CFGFileForLoadedFromDir);
27 CFGStateForLoadedFromDir := ParseCFGList(CFGFileForLoadedFromDir, CFGPathForLoadedFromDir);
28 end;
29
HasConfigLoadedFromDirnull30 function HasConfigLoadedFromDir(AFolder: String; FallBackToUninstallDir: Boolean): Boolean;
31 begin
32 Result := (CfgLoadedFromDir = AFolder) and
33 (CFGFileForLoadedFromDir <> nil) and
34 (CFGFileForLoadedFromDir.Count > 0); // only if content
35 if (not Result) and FallBackToUninstallDir then
36 Result := HasSavedConfigFromUninstall(AFolder);
37 end;
38
39 // Did the loadedconf contain a pcp?
HasPCPLoadedFromDirnull40 function HasPCPLoadedFromDir(AFolder: String; FallBackToUninstallDir: Boolean): Boolean;
41 begin
42 Result := False;
43 if HasConfigLoadedFromDir(AFolder, False) then
44 Result := CFGPathForLoadedFromDir <> ''
45 else
46 if FallBackToUninstallDir and HasSavedConfigFromUninstall(AFolder) then
47 Result := GetSavedPCPFromUninstall(AFolder) <> '';
48 end;
49
GetConfigLoadedFromDirnull50 function GetConfigLoadedFromDir(AFolder: String; FallBackToUninstallDir: Boolean): TStringList;
51 begin
52 Result := nil;
53 if HasConfigLoadedFromDir(AFolder, False) then
54 Result := CFGFileForLoadedFromDir
55 else
56 if FallBackToUninstallDir and HasSavedConfigFromUninstall(AFolder) then
57 Result := GetSavedConfigFromUninstall(AFolder);
58 end;
59
GetPCPLoadedFromDirnull60 function GetPCPLoadedFromDir(AFolder: String; FallBackToUninstallDir: Boolean): String;
61 begin
62 Result := '';
63 if HasConfigLoadedFromDir(AFolder, False) then
64 Result := CFGPathForLoadedFromDir
65 else
66 if FallBackToUninstallDir and HasSavedConfigFromUninstall(AFolder) then
67 Result := GetSavedPCPFromUninstall(AFolder);
68 end;
69
GetStateLoadedFromDirnull70 function GetStateLoadedFromDir(AFolder: String; FallBackToUninstallDir: Boolean): TCfgFileState;
71 begin
72 Result := csNoFile;
73 if HasConfigLoadedFromDir(AFolder, False) then
74 Result := CFGStateForLoadedFromDir
75 else
76 if FallBackToUninstallDir and HasSavedConfigFromUninstall(AFolder) then
77 Result := GetSavedStateFromUninstall(AFolder);
78 end;
79
80
81
82 Procedure AddSecondaryCheckBoxToTargetDirWizzard;
83 begin
84 if (CheckSecondInstall <> nil) then
85 exit;
86
87 WizardForm.DirEdit.Parent.Handle;
88
89 CheckSecondInstall := TCheckBox.Create(WizardForm);
90 AddComponentToPage(CheckSecondInstall, WizardForm.DirEdit, 10, 0, 1, 0);
91 CheckSecondInstall.Caption := CustomMessage('CheckSecondClick');
92
93 CheckSecondLabel := TLabel.Create(WizardForm);
94 AddComponentToPage(CheckSecondLabel, CheckSecondInstall, 10, 0, 1, -10);
95 CheckSecondLabel.AutoSize := False;
96 CheckSecondLabel.WordWrap := True;
97 CheckSecondLabel.Caption := CustomMessage('CheckSecondInfo');
98 end;
99
100 procedure CreateSecondaryConfFolderAndNameWizardPage;
101 begin
102 wpAskConfDir := CreateInputDirPage(
103 wpSelectDir,
104 CustomMessage('SecondConfCapt'),
105 CustomMessage('SecondConfCapt2'),
106 CustomMessage('SecondConfBody'),
107 False,
108 'laz_conf'
109 );
110 wpAskConfDir.Add(CustomMessage('FolderForConfig'));
111 end;
112
IsSecondaryCheckBoxCheckednull113 function IsSecondaryCheckBoxChecked: Boolean;
114 begin
115 Result := (CheckSecondInstall <> nil) and (CheckSecondInstall.Checked);
116 end;
117
118 Procedure CreateOrSaveConfigFile;
119 var
120 CfgFile: TStringList;
121 begin
122 if not (IsSecondaryCheckBoxChecked or IsSecondaryUpdate) then
123 exit;
124
125 if IsSecondaryCheckBoxChecked then begin
126 CfgFile := GetConfigLoadedFromDir(WizardDirValue, True);
127 if (GetPCPLoadedFromDir(WizardDirValue, True) <> SecondPCP) or (CfgFile = nil) then
128 CreateCFGFile(SecondPCP, CfgFile);
129
130 if (SecondPCP <> '') then
131 try
132 CfgFile.SaveToFile(AddBackslash(WizardDirValue) + 'lazarus.cfg')
133 ForceDirectories(SecondPCP);
134 except
135 MsgBox('Internal Error (1): Could not save CFG for secondary install', mbConfirmation, MB_OK);
136 end
137 else begin
138 MsgBox('Internal Error (2): Could not save CFG for secondary install', mbConfirmation, MB_OK);
139 end;
140 end
141
142 else
143 // NO checkbox.checked
144 if (DidRunUninstaller) and (IsSecondaryUpdate) and
145 (not FileExists(AddBackslash(WizardDirValue) + 'lazarus.cfg'))
146 then begin
147 // cfg was uninstalled / restore
148 CfgFile := GetConfigLoadedFromDir(WizardDirValue, True);
149
150 if (CfgFile <> nil) then
151 try
152 CfgFile.SaveToFile(AddBackslash(WizardDirValue) + 'lazarus.cfg')
153 except
154 MsgBox('Internal Error (3): Could not restore CFG for secondary install', mbConfirmation, MB_OK);
155 end
156 else
157 begin
158 MsgBox('Internal Error (5): Could not restore CFG for secondary install', mbConfirmation, MB_OK);
159 end;
160 end
161
162 else
163 // NO checkbox.checked
164 if (IsSecondaryUpdate) and
165 (not FileExists(AddBackslash(WizardDirValue) + 'lazarus.cfg'))
166 then begin
167 // where is the config gone ???????
168 MsgBox('Internal Error (4): Pre-Existing Configfile was removed?', mbConfirmation, MB_OK);
169 end
170 ;
171 end;
172
173