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