Ignore:
Timestamp:
Jun 4, 2024, 12:22:49 AM (5 months ago)
Author:
chronos
Message:
  • Modified: Removed U prefix from unit names.
  • Modified: Updated Common package.
File:
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/Packages/ModularSystem/ModularSystem.pas

    r74 r75  
    1 unit UModularSystem;
    2 
    3 {$mode Delphi}{$H+}
     1unit ModularSystem;
    42
    53interface
    64
    75uses
    8   Classes, SysUtils, URegistry, SpecializedList;
     6  Classes, SysUtils, RegistryEx, Generics.Collections;
    97
    108type
    119  TModuleManager = class;
    1210  TModule = class;
    13   TListModule = class;
     11  TModules = class;
    1412
    1513  TAPI = class(TComponent)
    16 
    1714  end;
    1815
     
    3936    FLicense: string;
    4037    FAuthor: string;
    41     FDependencies: TListString;
    42     FDescription: TListString;
     38    FDependencies: TStringList;
     39    FDescription: TStringList;
    4340    FFileName: string;
    4441    FWebSite: string;
     
    6562    procedure Reinstall;
    6663    procedure Upgrade;
    67     procedure EnumDependenciesCascade(ModuleList: TListModule;
     64    procedure EnumDependenciesCascade(ModuleList: TModules;
    6865      Conditions: TModuleConditions = [mcAll]);
    69     procedure EnumSuperiorDependenciesCascade(ModuleList: TListModule;
     66    procedure EnumSuperiorDependenciesCascade(ModuleList: TModules;
    7067      Conditions: TModuleConditions = [mcAll]);
    7168    procedure SetInstalledState(Value: Boolean);
     
    8481    property License: string read FLicense write FLicense;
    8582    property Author: string read FAuthor write FAuthor;
    86     property Dependencies: TListString read FDependencies write FDependencies;
    87     property Description: TListString read FDescription write FDescription;
     83    property Dependencies: TStringList read FDependencies write FDependencies;
     84    property Description: TStringList read FDescription write FDescription;
    8885    property FileName: string read FFileName write FFileName;
    8986    property Category: string read FCategory write FCategory;
     
    9289  end;
    9390
    94   { TListModule }
    95 
    96   TListModule = class(TListObject)
    97   private
     91  { TModules }
     92
     93  TModules = class(TObjectList<TModule>)
    9894  public
    9995    procedure Perform(Actions: array of TModuleAction; Conditions: TModuleConditions = [mcAll]);
    10096    function FindByName(Name: string): TModule;
     97    function GetNames: string;
    10198  end;
    10299
    103100  TModuleManagerOption = (moAutoInstallOnRun, moAuto);
    104101  TModuleManagerOptions = set of TModuleManagerOption;
     102
    105103  { TModuleManager }
    106104
     
    114112    procedure DoUpdate(Sender: TObject);
    115113  public
    116     Modules: TListModule; // TObjectList<TModule>
     114    Modules: TModules;
    117115    function ModuleRunning(Name: string): Boolean;
    118     procedure EnumDependenciesCascade(Module: TModule; ModuleList: TListModule;
     116    procedure EnumDependenciesCascade(Module: TModule; ModuleList: TModules;
    119117      Conditions: TModuleConditions = [mcAll]);
    120118    procedure EnumSuperiorDependenciesCascade(Module: TModule;
    121       ModuleList: TListModule; Conditions: TModuleConditions = [mcAll]);
     119      ModuleList: TModules; Conditions: TModuleConditions = [mcAll]);
    122120    procedure RegisterModule(Module: TModule);
    123121    procedure UnregisterModule(Module: TModule);
     
    145143end;
    146144
    147 { TListModule }
    148 
    149 procedure TListModule.Perform(Actions:  array of TModuleAction;
     145{ TModules }
     146
     147procedure TModules.Perform(Actions:  array of TModuleAction;
    150148  Conditions: TModuleConditions = [mcAll]);
    151149var
     
    153151  A: Integer;
    154152begin
    155   try
    156     BeginUpdate;
    157153  for I := 0 to Count - 1 do
    158154  with TModule(Items[I]) do
     
    173169      if Actions[A] = maDisable then Disable;
    174170    end;
    175   finally
    176     EndUpdate;
    177   end;
    178 end;
    179 
    180 function TListModule.FindByName(Name: string): TModule;
     171end;
     172
     173function TModules.FindByName(Name: string): TModule;
    181174var
    182175  I: Integer;
     
    188181end;
    189182
     183function TModules.GetNames: string;
     184var
     185  I: Integer;
     186begin
     187  Result := '';
     188  for I := 0 to Count - 1 do
     189    Result := Result + ', ' + Items[I].Identification;
     190  Result := Copy(Result, 3, MaxInt);
     191end;
     192
    190193{ TModuleManager }
    191194
     
    216219
    217220procedure TModuleManager.EnumDependenciesCascade(Module: TModule;
    218   ModuleList: TListModule; Conditions: TModuleConditions = [mcAll]);
     221  ModuleList: TModules; Conditions: TModuleConditions = [mcAll]);
    219222var
    220223  DepModule: TModule;
     224  DepModuleName: string;
    221225  I: Integer;
    222226begin
    223227  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);
    225230    if Assigned(DepModule) then
    226231    with DepModule do begin
     
    236241          Self.EnumDependenciesCascade(DepModule, ModuleList);
    237242        end;
    238     end else raise Exception.CreateFmt(SModuleNotFound, [DepModule.Identification]);
     243    end else raise Exception.CreateFmt(SModuleNotFound, [Module.Dependencies[I], Module.Identification]);
    239244  end;
    240245end;
    241246
    242247procedure TModuleManager.EnumSuperiorDependenciesCascade(Module: TModule;
    243   ModuleList: TListModule; Conditions: TModuleConditions = [mcAll]);
     248  ModuleList: TModules; Conditions: TModuleConditions = [mcAll]);
    244249var
    245250  I: Integer;
     
    267272  Module.FManager := Self;
    268273  Module.API := API;
    269   Modules.Update;
     274  //Modules.Update;
    270275end;
    271276
     
    273278begin
    274279  Modules.Remove(Module);
    275   Modules.Update;
     280  //Modules.Update;
    276281end;
    277282
     
    279284begin
    280285  inherited;
    281   Modules := TListModule.Create;
     286  Modules := TModules.Create;
    282287  Modules.OwnsObjects := False;
    283   Modules.OnUpdate := DoUpdate;
     288  //Modules.OnUpdate := DoUpdate;
    284289end;
    285290
     
    362367procedure TModule.Enable;
    363368var
    364   List: TListModule;
     369  List: TModules;
    365370begin
    366371  if Enabled then Exit;
    367372  FEnabled := True;
    368373  try
    369     List := TListModule.Create;
     374    List := TModules.Create;
    370375    List.OwnsObjects := False;
    371376    EnumDependenciesCascade(List, [mcNotEnabled]);
     
    380385procedure TModule.Disable;
    381386var
    382   List: TListModule;
     387  List: TModules;
    383388begin
    384389  if not Enabled then Exit;
     
    386391  FEnabled := False;
    387392  try
    388     List := TListModule.Create;
     393    List := TModules.Create;
    389394    List.OwnsObjects := False;
    390395    EnumSuperiorDependenciesCascade(List, [mcEnabled]);
     
    393398    List.Free;
    394399  end;
    395   Manager.Modules.Update;
     400  //Manager.Modules.Update;
    396401end;
    397402
     
    418423procedure TModule.Start;
    419424var
    420   List: TListModule;
     425  List: TModules;
    421426  StartTime: TDateTime;
    422427begin
     
    424429  if not Installed then Install;  // Auto install not installed modules
    425430  try
    426     List := TListModule.Create;
     431    List := TModules.Create;
    427432    List.OwnsObjects := False;
    428433    EnumDependenciesCascade(List, [mcNotRunning]);
     
    435440  FStartUpTime := Now - StartTime;
    436441  FRunning := True;
    437   Manager.Modules.Update;
     442  //Manager.Modules.Update;
    438443end;
    439444
    440445procedure TModule.Stop;
    441446var
    442   List: TListModule;
     447  List: TModules;
    443448begin
    444449  if not Running then Exit;
    445450  FRunning := False;
    446451  try
    447     List := TListModule.Create;
     452    List := TModules.Create;
    448453    List.OwnsObjects := False;
    449454    EnumSuperiorDependenciesCascade(List, [mcRunning]);
     
    453458  end;
    454459  DoStop;
    455   Manager.Modules.Update;
     460  //Manager.Modules.Update;
    456461end;
    457462
     
    464469procedure TModule.Install;
    465470var
    466   List: TListModule;
     471  List: TModules;
    467472begin
    468473  if Installed then Exit;
    469474  try
    470     List := TListModule.Create;
     475    List := TModules.Create;
    471476    List.OwnsObjects := False;
    472477    EnumDependenciesCascade(List, [mcNotInstalled]);
     
    478483  DoInstall;
    479484  //Enable; // Auto enable installed module
    480   Manager.Modules.Update;
     485  //Manager.Modules.Update;
    481486end;
    482487
    483488procedure TModule.Uninstall;
    484489var
    485   List: TListModule;
     490  List: TModules;
    486491begin
    487492  if not Installed then Exit;
    488493  if Enabled then Disable; // Auto disable uninstalled module
    489494  try
    490     List := TListModule.Create;
     495    List := TModules.Create;
    491496    List.OwnsObjects := False;
    492497    EnumSuperiorDependenciesCascade(List, [mcInstalled]);
     
    497502  FInstalled := False;
    498503  DoUninstall;
    499   Manager.Modules.Update;
     504  //Manager.Modules.Update;
    500505end;
    501506
     
    515520    Start;
    516521  end else DoUpgrade;
    517   Manager.Modules.Update;
    518 end;
    519 
    520 procedure TModule.EnumDependenciesCascade(ModuleList: TListModule;
     522  //Manager.Modules.Update;
     523end;
     524
     525procedure TModule.EnumDependenciesCascade(ModuleList: TModules;
    521526  Conditions: TModuleConditions = [mcAll]);
    522527begin
     
    525530end;
    526531
    527 procedure TModule.EnumSuperiorDependenciesCascade(ModuleList: TListModule;
     532procedure TModule.EnumSuperiorDependenciesCascade(ModuleList: TModules;
    528533  Conditions: TModuleConditions = [mcAll]);
    529534begin
     
    535540begin
    536541  FInstalled := Value;
    537   Manager.Modules.Update;
     542  //Manager.Modules.Update;
    538543end;
    539544
     
    541546begin
    542547  inherited;
    543   Dependencies := TListString.Create;
    544   Description := TListString.Create;
     548  Dependencies := TStringList.Create;
     549  Description := TStringList.Create;
    545550end;
    546551
Note: See TracChangeset for help on using the changeset viewer.