Changeset 75 for trunk/Packages/ModularSystem/ModularSystem.pas
- Timestamp:
- Jun 4, 2024, 12:22:49 AM (5 months ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/ModularSystem/ModularSystem.pas
r74 r75 1 unit UModularSystem; 2 3 {$mode Delphi}{$H+} 1 unit ModularSystem; 4 2 5 3 interface 6 4 7 5 uses 8 Classes, SysUtils, URegistry, SpecializedList;6 Classes, SysUtils, RegistryEx, Generics.Collections; 9 7 10 8 type 11 9 TModuleManager = class; 12 10 TModule = class; 13 T ListModule= class;11 TModules = class; 14 12 15 13 TAPI = class(TComponent) 16 17 14 end; 18 15 … … 39 36 FLicense: string; 40 37 FAuthor: string; 41 FDependencies: T ListString;42 FDescription: T ListString;38 FDependencies: TStringList; 39 FDescription: TStringList; 43 40 FFileName: string; 44 41 FWebSite: string; … … 65 62 procedure Reinstall; 66 63 procedure Upgrade; 67 procedure EnumDependenciesCascade(ModuleList: T ListModule;64 procedure EnumDependenciesCascade(ModuleList: TModules; 68 65 Conditions: TModuleConditions = [mcAll]); 69 procedure EnumSuperiorDependenciesCascade(ModuleList: T ListModule;66 procedure EnumSuperiorDependenciesCascade(ModuleList: TModules; 70 67 Conditions: TModuleConditions = [mcAll]); 71 68 procedure SetInstalledState(Value: Boolean); … … 84 81 property License: string read FLicense write FLicense; 85 82 property Author: string read FAuthor write FAuthor; 86 property Dependencies: T ListStringread FDependencies write FDependencies;87 property Description: T ListStringread FDescription write FDescription;83 property Dependencies: TStringList read FDependencies write FDependencies; 84 property Description: TStringList read FDescription write FDescription; 88 85 property FileName: string read FFileName write FFileName; 89 86 property Category: string read FCategory write FCategory; … … 92 89 end; 93 90 94 { TListModule } 95 96 TListModule = class(TListObject) 97 private 91 { TModules } 92 93 TModules = class(TObjectList<TModule>) 98 94 public 99 95 procedure Perform(Actions: array of TModuleAction; Conditions: TModuleConditions = [mcAll]); 100 96 function FindByName(Name: string): TModule; 97 function GetNames: string; 101 98 end; 102 99 103 100 TModuleManagerOption = (moAutoInstallOnRun, moAuto); 104 101 TModuleManagerOptions = set of TModuleManagerOption; 102 105 103 { TModuleManager } 106 104 … … 114 112 procedure DoUpdate(Sender: TObject); 115 113 public 116 Modules: T ListModule; // TObjectList<TModule>114 Modules: TModules; 117 115 function ModuleRunning(Name: string): Boolean; 118 procedure EnumDependenciesCascade(Module: TModule; ModuleList: T ListModule;116 procedure EnumDependenciesCascade(Module: TModule; ModuleList: TModules; 119 117 Conditions: TModuleConditions = [mcAll]); 120 118 procedure EnumSuperiorDependenciesCascade(Module: TModule; 121 ModuleList: T ListModule; Conditions: TModuleConditions = [mcAll]);119 ModuleList: TModules; Conditions: TModuleConditions = [mcAll]); 122 120 procedure RegisterModule(Module: TModule); 123 121 procedure UnregisterModule(Module: TModule); … … 145 143 end; 146 144 147 { T ListModule}148 149 procedure T ListModule.Perform(Actions: array of TModuleAction;145 { TModules } 146 147 procedure TModules.Perform(Actions: array of TModuleAction; 150 148 Conditions: TModuleConditions = [mcAll]); 151 149 var … … 153 151 A: Integer; 154 152 begin 155 try156 BeginUpdate;157 153 for I := 0 to Count - 1 do 158 154 with TModule(Items[I]) do … … 173 169 if Actions[A] = maDisable then Disable; 174 170 end; 175 finally 176 EndUpdate; 177 end; 178 end; 179 180 function TListModule.FindByName(Name: string): TModule; 171 end; 172 173 function TModules.FindByName(Name: string): TModule; 181 174 var 182 175 I: Integer; … … 188 181 end; 189 182 183 function TModules.GetNames: string; 184 var 185 I: Integer; 186 begin 187 Result := ''; 188 for I := 0 to Count - 1 do 189 Result := Result + ', ' + Items[I].Identification; 190 Result := Copy(Result, 3, MaxInt); 191 end; 192 190 193 { TModuleManager } 191 194 … … 216 219 217 220 procedure TModuleManager.EnumDependenciesCascade(Module: TModule; 218 ModuleList: T ListModule; Conditions: TModuleConditions = [mcAll]);221 ModuleList: TModules; Conditions: TModuleConditions = [mcAll]); 219 222 var 220 223 DepModule: TModule; 224 DepModuleName: string; 221 225 I: Integer; 222 226 begin 223 227 for I := 0 to Module.Dependencies.Count - 1 do begin 224 DepModule := Modules.FindByName(Module.Dependencies[I]); 228 DepModuleName := Module.Dependencies[I]; 229 DepModule := Modules.FindByName(DepModuleName); 225 230 if Assigned(DepModule) then 226 231 with DepModule do begin … … 236 241 Self.EnumDependenciesCascade(DepModule, ModuleList); 237 242 end; 238 end else raise Exception.CreateFmt(SModuleNotFound, [ DepModule.Identification]);243 end else raise Exception.CreateFmt(SModuleNotFound, [Module.Dependencies[I], Module.Identification]); 239 244 end; 240 245 end; 241 246 242 247 procedure TModuleManager.EnumSuperiorDependenciesCascade(Module: TModule; 243 ModuleList: T ListModule; Conditions: TModuleConditions = [mcAll]);248 ModuleList: TModules; Conditions: TModuleConditions = [mcAll]); 244 249 var 245 250 I: Integer; … … 267 272 Module.FManager := Self; 268 273 Module.API := API; 269 Modules.Update;274 //Modules.Update; 270 275 end; 271 276 … … 273 278 begin 274 279 Modules.Remove(Module); 275 Modules.Update;280 //Modules.Update; 276 281 end; 277 282 … … 279 284 begin 280 285 inherited; 281 Modules := T ListModule.Create;286 Modules := TModules.Create; 282 287 Modules.OwnsObjects := False; 283 Modules.OnUpdate := DoUpdate;288 //Modules.OnUpdate := DoUpdate; 284 289 end; 285 290 … … 362 367 procedure TModule.Enable; 363 368 var 364 List: T ListModule;369 List: TModules; 365 370 begin 366 371 if Enabled then Exit; 367 372 FEnabled := True; 368 373 try 369 List := T ListModule.Create;374 List := TModules.Create; 370 375 List.OwnsObjects := False; 371 376 EnumDependenciesCascade(List, [mcNotEnabled]); … … 380 385 procedure TModule.Disable; 381 386 var 382 List: T ListModule;387 List: TModules; 383 388 begin 384 389 if not Enabled then Exit; … … 386 391 FEnabled := False; 387 392 try 388 List := T ListModule.Create;393 List := TModules.Create; 389 394 List.OwnsObjects := False; 390 395 EnumSuperiorDependenciesCascade(List, [mcEnabled]); … … 393 398 List.Free; 394 399 end; 395 Manager.Modules.Update;400 //Manager.Modules.Update; 396 401 end; 397 402 … … 418 423 procedure TModule.Start; 419 424 var 420 List: T ListModule;425 List: TModules; 421 426 StartTime: TDateTime; 422 427 begin … … 424 429 if not Installed then Install; // Auto install not installed modules 425 430 try 426 List := T ListModule.Create;431 List := TModules.Create; 427 432 List.OwnsObjects := False; 428 433 EnumDependenciesCascade(List, [mcNotRunning]); … … 435 440 FStartUpTime := Now - StartTime; 436 441 FRunning := True; 437 Manager.Modules.Update;442 //Manager.Modules.Update; 438 443 end; 439 444 440 445 procedure TModule.Stop; 441 446 var 442 List: T ListModule;447 List: TModules; 443 448 begin 444 449 if not Running then Exit; 445 450 FRunning := False; 446 451 try 447 List := T ListModule.Create;452 List := TModules.Create; 448 453 List.OwnsObjects := False; 449 454 EnumSuperiorDependenciesCascade(List, [mcRunning]); … … 453 458 end; 454 459 DoStop; 455 Manager.Modules.Update;460 //Manager.Modules.Update; 456 461 end; 457 462 … … 464 469 procedure TModule.Install; 465 470 var 466 List: T ListModule;471 List: TModules; 467 472 begin 468 473 if Installed then Exit; 469 474 try 470 List := T ListModule.Create;475 List := TModules.Create; 471 476 List.OwnsObjects := False; 472 477 EnumDependenciesCascade(List, [mcNotInstalled]); … … 478 483 DoInstall; 479 484 //Enable; // Auto enable installed module 480 Manager.Modules.Update;485 //Manager.Modules.Update; 481 486 end; 482 487 483 488 procedure TModule.Uninstall; 484 489 var 485 List: T ListModule;490 List: TModules; 486 491 begin 487 492 if not Installed then Exit; 488 493 if Enabled then Disable; // Auto disable uninstalled module 489 494 try 490 List := T ListModule.Create;495 List := TModules.Create; 491 496 List.OwnsObjects := False; 492 497 EnumSuperiorDependenciesCascade(List, [mcInstalled]); … … 497 502 FInstalled := False; 498 503 DoUninstall; 499 Manager.Modules.Update;504 //Manager.Modules.Update; 500 505 end; 501 506 … … 515 520 Start; 516 521 end else DoUpgrade; 517 Manager.Modules.Update;518 end; 519 520 procedure TModule.EnumDependenciesCascade(ModuleList: T ListModule;522 //Manager.Modules.Update; 523 end; 524 525 procedure TModule.EnumDependenciesCascade(ModuleList: TModules; 521 526 Conditions: TModuleConditions = [mcAll]); 522 527 begin … … 525 530 end; 526 531 527 procedure TModule.EnumSuperiorDependenciesCascade(ModuleList: T ListModule;532 procedure TModule.EnumSuperiorDependenciesCascade(ModuleList: TModules; 528 533 Conditions: TModuleConditions = [mcAll]); 529 534 begin … … 535 540 begin 536 541 FInstalled := Value; 537 Manager.Modules.Update;542 //Manager.Modules.Update; 538 543 end; 539 544 … … 541 546 begin 542 547 inherited; 543 Dependencies := T ListString.Create;544 Description := T ListString.Create;548 Dependencies := TStringList.Create; 549 Description := TStringList.Create; 545 550 end; 546 551
Note:
See TracChangeset
for help on using the changeset viewer.