Ignore:
Timestamp:
Oct 17, 2012, 1:21:41 PM (12 years ago)
Author:
chronos
Message:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • ModularSystem/UModularSystem.pas

    r428 r429  
    2222    FRunning: Boolean;
    2323    FInstalled: Boolean;
    24     Manager: TModuleManager;
     24    FManager: TModuleManager;
    2525    FVersion: string;
    2626    FIdentification: string;
     
    3434    procedure SetRunning(AValue: Boolean);
    3535  protected
    36     procedure BeforeStart; virtual;
    37     procedure AfterStart; virtual;
    38     procedure BeforeStop; virtual;
    39     procedure AfterStop; virtual;
     36    procedure DoStart; virtual;
     37    procedure DoStop; virtual;
     38    procedure DoInstall; virtual;
     39    procedure DoUninstall; virtual;
     40    procedure DoUpgrade; virtual;
    4041  public
    4142    API: TAPI;
    42     procedure Start; virtual;
    43     procedure Stop; virtual;
    44     procedure Install; virtual;
    45     procedure Uninstall; virtual;
    46     procedure Upgrade; virtual;
     43    procedure Start;
     44    procedure Stop;
     45    procedure Install;
     46    procedure Uninstall;
     47    procedure Upgrade;
    4748    procedure EnumModulesStart(ModuleList: TStringList);
    4849    procedure EnumModulesStop(ModuleList: TStringList);
     
    5657    property Enabled: Boolean read FEnabled write SetEnabled;
    5758  published
     59    property Manager: TModuleManager read FManager;
    5860    property Version: string read FVersion write FVersion;
    5961    property Identification: string read FIdentification write FIdentification;
     
    260262begin
    261263  Modules.Add(Module);
    262   Module.Manager := Self;
     264  Module.FManager := Self;
    263265  Module.API := API;
    264266  Module.Enabled := Enabled;
     
    310312  inherited;
    311313  Modules := TObjectList.Create;
     314  //Modules.OwnsObjects := False;
    312315end;
    313316
     
    316319  StopAll;
    317320  FreeAndNil(Modules);
    318   inherited Destroy;
     321  inherited;
    319322end;
    320323
     
    344347    RootKey := Context.RootKey;
    345348    for I := 0 to Modules.Count - 1 do
    346     with TModule(Modules[I]) do begin
     349    with TModule(Modules[I]) do
     350    if Enabled then begin
    347351      OpenKey(Context.Key + '\' + Identification, True);
    348352      WriteBool('Run', Running);
     
    361365end;
    362366
    363 procedure TModule.BeforeStart;
    364 begin
    365   if Running then Exit;
     367procedure TModule.DoStart;
     368begin
     369
     370end;
     371
     372procedure TModule.DoStop;
     373begin
     374
     375end;
     376
     377procedure TModule.DoInstall;
     378begin
     379
     380end;
     381
     382procedure TModule.DoUninstall;
     383begin
     384
     385end;
     386
     387procedure TModule.DoUpgrade;
     388begin
     389
     390end;
     391
     392procedure TModule.SetInstalled(AValue: Boolean);
     393begin
     394  if FInstalled = AValue then Exit;
     395  if AValue then Install else Uninstall;
     396end;
     397
     398procedure TModule.SetEnabled(AValue: Boolean);
     399begin
     400  if FEnabled = AValue then Exit;
     401  FEnabled := AValue;
     402  if not FEnabled and FInstalled then Uninstall;
     403end;
     404
     405procedure TModule.Start;
     406begin
     407  if not Enabled or Running then Exit;
    366408  if not Installed then Install;
    367409  Manager.StartDependencies(Identification, Dependencies);
    368 end;
    369 
    370 procedure TModule.AfterStart;
    371 begin
     410  DoStart;
    372411  FRunning := True;
    373412end;
    374413
    375 procedure TModule.BeforeStop;
     414procedure TModule.Stop;
    376415begin
    377416  if not Running then Exit;
    378417  FRunning := False;
    379418  Manager.StopDependencies(Identification);
    380 end;
    381 
    382 procedure TModule.AfterStop;
    383 begin
    384 end;
    385 
    386 procedure TModule.SetInstalled(AValue: Boolean);
    387 begin
    388   if FInstalled = AValue then Exit;
    389   if AValue then Install else Uninstall;
    390 end;
    391 
    392 procedure TModule.SetEnabled(AValue: Boolean);
    393 begin
    394   if FEnabled = AValue then Exit;
    395   FEnabled := AValue;
    396   if not FEnabled and FInstalled then Uninstall;
    397 end;
    398 
    399 procedure TModule.Start;
    400 begin
    401   BeforeStart;
    402   AfterStart;
    403 end;
    404 
    405 procedure TModule.Stop;
    406 begin
    407   BeforeStop;
    408   AfterStop;
     419  DoStop;
    409420end;
    410421
    411422procedure TModule.Install;
    412423begin
    413   if Installed then Exit;
     424  if not Enabled or Installed then Exit;
    414425  Manager.InstallDependencies(Identification, Dependencies);
    415426  FInstalled := True;
    416427  if Assigned(Manager.FOnModuleChange) then
    417428    Manager.FOnModuleChange(Manager, Self);
     429  DoInstall;
    418430end;
    419431
     
    424436  Manager.UninstallDependencies(Identification);
    425437  FInstalled := False;
     438  DoUninstall;
    426439  if Assigned(Manager.FOnModuleChange) then
    427440    Manager.FOnModuleChange(Manager, Self);
     
    430443procedure TModule.Upgrade;
    431444begin
    432   if not Running then Exit;
     445  if not Enabled or not Installed then Exit;
     446  if Running then try
     447    Stop;
     448    DoUpgrade;
     449  finally
     450    Start;
     451  end else DoUpgrade;
    433452end;
    434453
     
    474493begin
    475494  Running := False;
    476   Description.Free;
    477   Dependencies.Free;
    478   inherited Destroy;
     495  FreeAndNil(FDescription);
     496  FreeAndNil(FDependencies);
     497  inherited;
    479498end;
    480499
Note: See TracChangeset for help on using the changeset viewer.