Changeset 395 for ModularSystem


Ignore:
Timestamp:
Jul 31, 2012, 3:58:07 PM (12 years ago)
Author:
chronos
Message:
  • Added: ModularSystem modules can be marked for installation.
  • Added: Relation to TAPI class where application specific interface should be implemented.
Location:
ModularSystem
Files:
5 deleted
1 edited

Legend:

Unmodified
Added
Removed
  • ModularSystem/UModularSystem.pas

    r394 r395  
    1010type
    1111  TModuleManager = class;
     12
     13  TAPI = class
     14
     15  end;
    1216
    1317  { TModule }
     
    1721    FInstalled: Boolean;
    1822    Manager: TModuleManager;
     23    procedure SetInstalled(AValue: Boolean);
    1924  public
    2025    Version: string;
     
    2530    Description: TStringList;
    2631    License: string;
     32    API: TAPI;
     33    MarkForInstall: Boolean;
    2734    procedure Install; virtual;
    2835    procedure Uninstall; virtual;
     
    3239    constructor Create; virtual;
    3340    destructor Destroy; override;
    34     property Installed: Boolean read FInstalled;
     41    property Installed: Boolean read FInstalled write SetInstalled;
    3542  end;
    3643
    3744  { TModuleManager }
    3845
    39   TModuleManager = class
     46  TModuleManager = class(TComponent)
     47  private
     48    FAPI: TAPI;
     49    procedure SetAPI(AValue: TAPI);
     50  public
    4051    Modules: TObjectList; // TObjectList<TModule>
    4152    function FindModuleByName(Name: string): TModule;
     
    4455    procedure EnumModulesInstall(Dependencies, ModuleList: TStringList);
    4556    procedure EnumModulesUninstall(ModuleName: string; ModuleList: TStringList);
    46     procedure RegisterModule(Module: TModule);
    47     constructor Create;
     57    procedure RegisterModule(Module: TModule; MarkForInstall: Boolean = False);
     58    procedure UnregisterModule(Module: TModule);
     59    procedure InstallMarked;
     60    procedure UninstallAll;
     61    constructor Create(AOwner: TComponent); override;
    4862    destructor Destroy; override;
     63    property API: TAPI read FAPI write SetAPI;
    4964  end;
    5065
     
    5671
    5772{ TModuleManager }
     73
     74procedure TModuleManager.SetAPI(AValue: TAPI);
     75var
     76  I: Integer;
     77begin
     78  if FAPI = AValue then Exit;
     79  FAPI := AValue;
     80  for I := 0 to Modules.Count - 1 do
     81    TModule(Modules[I]).API := FAPI;
     82end;
    5883
    5984function TModuleManager.FindModuleByName(Name: string): TModule;
     
    122147end;
    123148
    124 procedure TModuleManager.RegisterModule(Module: TModule);
     149procedure TModuleManager.RegisterModule(Module: TModule;
     150  MarkForInstall: Boolean = False);
    125151begin
    126152  Modules.Add(Module);
    127153  Module.Manager := Self;
    128 end;
    129 
    130 constructor TModuleManager.Create;
    131 begin
    132   Modules := TObjectList.Create
     154  Module.API := API;
     155  Module.MarkForInstall := MarkForInstall;
     156end;
     157
     158procedure TModuleManager.UnregisterModule(Module: TModule);
     159begin
     160  Modules.Remove(Module);
     161end;
     162
     163procedure TModuleManager.InstallMarked;
     164var
     165  I: Integer;
     166begin
     167  for I := 0 to Modules.Count - 1 do
     168  with TModule(Modules[I]) do
     169    if not Installed and MarkForInstall then Install;
     170end;
     171
     172procedure TModuleManager.UninstallAll;
     173var
     174  I: Integer;
     175begin
     176  for I := 0 to Modules.Count - 1 do
     177  with TModule(Modules[I]) do
     178    if Installed then Uninstall;
     179end;
     180
     181constructor TModuleManager.Create(AOwner: TComponent);
     182begin
     183  inherited;
     184  Modules := TObjectList.Create;
    133185end;
    134186
     
    140192
    141193{ TModule }
     194
     195procedure TModule.SetInstalled(AValue: Boolean);
     196begin
     197  if FInstalled = AValue then Exit;
     198  if AValue then Install else Uninstall;
     199end;
    142200
    143201procedure TModule.Install;
     
    180238destructor TModule.Destroy;
    181239begin
     240  Installed := False;
    182241  Description.Free;
    183242  Dependencies.Free;
Note: See TracChangeset for help on using the changeset viewer.