| 1 | unit UMainForm;
|
|---|
| 2 |
|
|---|
| 3 | {$mode delphi}{$H+}
|
|---|
| 4 |
|
|---|
| 5 | interface
|
|---|
| 6 |
|
|---|
| 7 | uses
|
|---|
| 8 | Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,
|
|---|
| 9 | StdCtrls, Menus, ActnList, UModularSystem;
|
|---|
| 10 |
|
|---|
| 11 | type
|
|---|
| 12 |
|
|---|
| 13 | { TMainForm }
|
|---|
| 14 |
|
|---|
| 15 | TMainForm = class(TForm)
|
|---|
| 16 | published
|
|---|
| 17 | AModuleStart: TAction;
|
|---|
| 18 | AModuleStop: TAction;
|
|---|
| 19 | AModuleInstall: TAction;
|
|---|
| 20 | AModuleUninstall: TAction;
|
|---|
| 21 | AModuleUpdate: TAction;
|
|---|
| 22 | ActionList1: TActionList;
|
|---|
| 23 | ButtonUpdate: TButton;
|
|---|
| 24 | ButtonUninstall: TButton;
|
|---|
| 25 | ButtonInstall: TButton;
|
|---|
| 26 | ButtonUpdate1: TButton;
|
|---|
| 27 | ButtonUpdate2: TButton;
|
|---|
| 28 | ListViewModules: TListView;
|
|---|
| 29 | MenuItem1: TMenuItem;
|
|---|
| 30 | MenuItem2: TMenuItem;
|
|---|
| 31 | MenuItem3: TMenuItem;
|
|---|
| 32 | MenuItem4: TMenuItem;
|
|---|
| 33 | MenuItem5: TMenuItem;
|
|---|
| 34 | ModuleManager: TModuleManager;
|
|---|
| 35 | PopupMenu1: TPopupMenu;
|
|---|
| 36 | procedure AModuleStartExecute(Sender: TObject);
|
|---|
| 37 | procedure AModuleStopExecute(Sender: TObject);
|
|---|
| 38 | procedure ButtonInstallClick(Sender: TObject);
|
|---|
| 39 | procedure ButtonUninstallClick(Sender: TObject);
|
|---|
| 40 | procedure ButtonUpdateClick(Sender: TObject);
|
|---|
| 41 | procedure FormCreate(Sender: TObject);
|
|---|
| 42 | procedure FormDestroy(Sender: TObject);
|
|---|
| 43 | procedure FormShow(Sender: TObject);
|
|---|
| 44 | procedure ListViewModulesData(Sender: TObject; Item: TListItem);
|
|---|
| 45 | procedure ListViewModulesSelectItem(Sender: TObject; Item: TListItem;
|
|---|
| 46 | Selected: Boolean);
|
|---|
| 47 | private
|
|---|
| 48 | procedure RegisterModules;
|
|---|
| 49 | public
|
|---|
| 50 | procedure Log(Text: string);
|
|---|
| 51 | procedure RefreshList;
|
|---|
| 52 | end;
|
|---|
| 53 |
|
|---|
| 54 | const
|
|---|
| 55 | BoolText: array[Boolean] of string = ('No', 'Yes');
|
|---|
| 56 |
|
|---|
| 57 | var
|
|---|
| 58 | MainForm: TMainForm;
|
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 | implementation
|
|---|
| 62 |
|
|---|
| 63 | {$R *.lfm}
|
|---|
| 64 |
|
|---|
| 65 | uses
|
|---|
| 66 | UModuleUser, UModuleBase, UModuleACL, ULogForm;
|
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 | { TMainForm }
|
|---|
| 70 |
|
|---|
| 71 | procedure TMainForm.ListViewModulesData(Sender: TObject; Item: TListItem);
|
|---|
| 72 | begin
|
|---|
| 73 | if (Item.Index >= 0) and (Item.Index < ModuleManager.Modules.Count) then
|
|---|
| 74 | with TModule(ModuleManager.Modules[Item.Index]) do begin
|
|---|
| 75 | Item.Caption := Title;
|
|---|
| 76 | Item.Data := ModuleManager.Modules[Item.Index];
|
|---|
| 77 | Item.SubItems.Add(Identification);
|
|---|
| 78 | Item.SubItems.Add(Version);
|
|---|
| 79 | Item.SubItems.Add(BoolText[Installed]);
|
|---|
| 80 | Item.SubItems.Add(BoolText[Running]);
|
|---|
| 81 | Item.SubItems.Add(License);
|
|---|
| 82 | Item.SubItems.Add(StringReplace(Dependencies.Text, LineEnding, ', ', [rfReplaceAll]));
|
|---|
| 83 | Item.SubItems.Add(StringReplace(Description.Text, LineEnding, ', ', [rfReplaceAll]));
|
|---|
| 84 | end;
|
|---|
| 85 | end;
|
|---|
| 86 |
|
|---|
| 87 | procedure TMainForm.ListViewModulesSelectItem(Sender: TObject; Item: TListItem;
|
|---|
| 88 | Selected: Boolean);
|
|---|
| 89 | var
|
|---|
| 90 | Installed: Boolean;
|
|---|
| 91 | Running: Boolean;
|
|---|
| 92 | begin
|
|---|
| 93 | if Assigned(ListViewModules.Selected) then Installed := TModule(ListViewModules.Selected.Data).Installed;
|
|---|
| 94 | if Assigned(ListViewModules.Selected) then Running := TModule(ListViewModules.Selected.Data).Running;
|
|---|
| 95 | AModuleInstall.Enabled := Assigned(ListViewModules.Selected) and not Installed;
|
|---|
| 96 | AModuleUninstall.Enabled := Assigned(ListViewModules.Selected) and Installed;
|
|---|
| 97 | AModuleUpdate.Enabled := Assigned(ListViewModules.Selected) and Installed;
|
|---|
| 98 | AModuleStart.Enabled := Assigned(ListViewModules.Selected) and not Running;
|
|---|
| 99 | AModuleStop.Enabled := Assigned(ListViewModules.Selected) and Running;
|
|---|
| 100 | end;
|
|---|
| 101 |
|
|---|
| 102 | procedure TMainForm.RegisterModules;
|
|---|
| 103 | begin
|
|---|
| 104 | ModuleManager.RegisterModule(TModuleUser.Create(nil));
|
|---|
| 105 | ModuleManager.RegisterModule(TModuleBase.Create(nil));
|
|---|
| 106 | ModuleManager.RegisterModule(TModuleACL.Create(nil));
|
|---|
| 107 | end;
|
|---|
| 108 |
|
|---|
| 109 | procedure TMainForm.Log(Text: string);
|
|---|
| 110 | begin
|
|---|
| 111 | LogForm.Memo1.Lines.Add(Text);
|
|---|
| 112 | end;
|
|---|
| 113 |
|
|---|
| 114 | procedure TMainForm.RefreshList;
|
|---|
| 115 | begin
|
|---|
| 116 | ListViewModules.Items.Count := ModuleManager.Modules.Count;
|
|---|
| 117 | ListViewModules.Refresh;
|
|---|
| 118 | ListViewModulesSelectItem(ListViewModules, ListViewModules.Selected,
|
|---|
| 119 | Assigned(ListViewModules.Selected));
|
|---|
| 120 | end;
|
|---|
| 121 |
|
|---|
| 122 | procedure TMainForm.FormCreate(Sender: TObject);
|
|---|
| 123 | begin
|
|---|
| 124 | RegisterModules;
|
|---|
| 125 | end;
|
|---|
| 126 |
|
|---|
| 127 | procedure TMainForm.ButtonInstallClick(Sender: TObject);
|
|---|
| 128 | var
|
|---|
| 129 | ModuleList: TStringList;
|
|---|
| 130 | begin
|
|---|
| 131 | if Assigned(ListViewModules.Selected) then begin
|
|---|
| 132 | try
|
|---|
| 133 | ModuleList := TStringList.Create;
|
|---|
| 134 | TModule(ListViewModules.Selected.Data).EnumModulesInstall(ModuleList);
|
|---|
| 135 | if ModuleList.Count > 0 then begin
|
|---|
| 136 | if MessageDlg('These modules will be installed in addition to ' +
|
|---|
| 137 | TModule(ListViewModules.Selected.Data).Name + ': ' +
|
|---|
| 138 | StringReplace(ModuleList.Text, LineEnding, ', ', [rfReplaceAll]),
|
|---|
| 139 | mtConfirmation, [mbYes, mbNo], 0) = mrYes then
|
|---|
| 140 | TModule(ListViewModules.Selected.Data).Install;
|
|---|
| 141 | end else TModule(ListViewModules.Selected.Data).Install;
|
|---|
| 142 | finally
|
|---|
| 143 | ModuleList.Free;
|
|---|
| 144 | end;
|
|---|
| 145 | RefreshList;
|
|---|
| 146 | end;
|
|---|
| 147 | end;
|
|---|
| 148 |
|
|---|
| 149 | procedure TMainForm.AModuleStartExecute(Sender: TObject);
|
|---|
| 150 | var
|
|---|
| 151 | ModuleList: TStringList;
|
|---|
| 152 | begin
|
|---|
| 153 | if Assigned(ListViewModules.Selected) then begin
|
|---|
| 154 | try
|
|---|
| 155 | ModuleList := TStringList.Create;
|
|---|
| 156 | TModule(ListViewModules.Selected.Data).EnumModulesStart(ModuleList);
|
|---|
| 157 | if ModuleList.Count > 0 then begin
|
|---|
| 158 | if MessageDlg('These modules will be started in addition to ' +
|
|---|
| 159 | TModule(ListViewModules.Selected.Data).Name + ': ' +
|
|---|
| 160 | StringReplace(ModuleList.Text, LineEnding, ', ', [rfReplaceAll]),
|
|---|
| 161 | mtConfirmation, [mbYes, mbNo], 0) = mrYes then
|
|---|
| 162 | TModule(ListViewModules.Selected.Data).Start;
|
|---|
| 163 | end else TModule(ListViewModules.Selected.Data).Start;
|
|---|
| 164 | finally
|
|---|
| 165 | ModuleList.Free;
|
|---|
| 166 | end;
|
|---|
| 167 | RefreshList;
|
|---|
| 168 | end;
|
|---|
| 169 | end;
|
|---|
| 170 |
|
|---|
| 171 | procedure TMainForm.AModuleStopExecute(Sender: TObject);
|
|---|
| 172 | var
|
|---|
| 173 | ModuleList: TStringList;
|
|---|
| 174 | begin
|
|---|
| 175 | if Assigned(ListViewModules.Selected) then begin
|
|---|
| 176 | try
|
|---|
| 177 | ModuleList := TStringList.Create;
|
|---|
| 178 | TModule(ListViewModules.Selected.Data).EnumModulesStop(ModuleList);
|
|---|
| 179 | if ModuleList.Count > 0 then begin
|
|---|
| 180 | if MessageDlg('These modules will be stopped in addition to ' +
|
|---|
| 181 | TModule(ListViewModules.Selected.Data).Name + ': ' +
|
|---|
| 182 | StringReplace(ModuleList.Text, LineEnding, ', ', [rfReplaceAll]),
|
|---|
| 183 | mtConfirmation, [mbYes, mbNo], 0) = mrYes then
|
|---|
| 184 | TModule(ListViewModules.Selected.Data).Stop;
|
|---|
| 185 | end else TModule(ListViewModules.Selected.Data).Stop;
|
|---|
| 186 | finally
|
|---|
| 187 | ModuleList.Free;
|
|---|
| 188 | end;
|
|---|
| 189 |
|
|---|
| 190 | RefreshList;
|
|---|
| 191 | end;
|
|---|
| 192 | end;
|
|---|
| 193 |
|
|---|
| 194 | procedure TMainForm.ButtonUninstallClick(Sender: TObject);
|
|---|
| 195 | var
|
|---|
| 196 | ModuleList: TStringList;
|
|---|
| 197 | begin
|
|---|
| 198 | if Assigned(ListViewModules.Selected) then begin
|
|---|
| 199 | try
|
|---|
| 200 | ModuleList := TStringList.Create;
|
|---|
| 201 | TModule(ListViewModules.Selected.Data).EnumModulesUninstall(ModuleList);
|
|---|
| 202 | if ModuleList.Count > 0 then begin
|
|---|
| 203 | if MessageDlg('These modules will be uninstalled in addition to ' +
|
|---|
| 204 | TModule(ListViewModules.Selected.Data).Name + ': ' +
|
|---|
| 205 | StringReplace(ModuleList.Text, LineEnding, ', ', [rfReplaceAll]),
|
|---|
| 206 | mtConfirmation, [mbYes, mbNo], 0) = mrYes then
|
|---|
| 207 | TModule(ListViewModules.Selected.Data).Uninstall;
|
|---|
| 208 | end else TModule(ListViewModules.Selected.Data).Uninstall;
|
|---|
| 209 | finally
|
|---|
| 210 | ModuleList.Free;
|
|---|
| 211 | end;
|
|---|
| 212 |
|
|---|
| 213 | RefreshList;
|
|---|
| 214 | end;
|
|---|
| 215 | end;
|
|---|
| 216 |
|
|---|
| 217 | procedure TMainForm.ButtonUpdateClick(Sender: TObject);
|
|---|
| 218 | begin
|
|---|
| 219 | if Assigned(ListViewModules.Selected) then begin
|
|---|
| 220 | TModule(ListViewModules.Selected.Data).Upgrade;
|
|---|
| 221 | RefreshList;
|
|---|
| 222 | end;
|
|---|
| 223 | end;
|
|---|
| 224 |
|
|---|
| 225 | procedure TMainForm.FormDestroy(Sender: TObject);
|
|---|
| 226 | begin
|
|---|
| 227 | end;
|
|---|
| 228 |
|
|---|
| 229 | procedure TMainForm.FormShow(Sender: TObject);
|
|---|
| 230 | begin
|
|---|
| 231 | RefreshList;
|
|---|
| 232 | LogForm.Show;
|
|---|
| 233 | end;
|
|---|
| 234 |
|
|---|
| 235 | end.
|
|---|
| 236 |
|
|---|