Changeset 93 for trunk/Modules


Ignore:
Timestamp:
Sep 7, 2012, 10:31:31 PM (12 years ago)
Author:
chronos
Message:
  • Přidáno: Udržovní inforamce o instalovaných modulech v databázi.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Modules/System/UModuleSystem.pas

    r92 r93  
    66
    77uses
    8   Classes, SysUtils, UModularSystem;
     8  Classes, SysUtils, UModularSystem, SpecializedDictionary;
    99
    1010type
     
    1313
    1414  TModuleSystem = class(TModule)
     15  private
     16    procedure ModuleChange(Sender: TObject; Module: TModule);
    1517  public
    1618    constructor Create(Owner: TComponent); override;
     
    2123    procedure Uninstall; override;
    2224    procedure Upgrade; override;
     25    procedure UpdateModuleList;
    2326  end;
    2427
     
    3033
    3134{ TModuleSystem }
     35
     36procedure TModuleSystem.ModuleChange(Sender: TObject; Module: TModule);
     37var
     38  DbRows: TDbRows;
     39  Data: TDictionaryStringString;
     40begin
     41  try
     42    DbRows := TDbRows.Create;
     43    Data := TDictionaryStringString.Create;
     44    if Module.Installed then Data.Add('Installed', '1')
     45      else Data.Add('Installed', '0');
     46    Core.CommonDatabase.Update('SystemModule', Data, 'Name="' + Module.Identification + '"');
     47  finally
     48    Data.Free;
     49    DbRows.Free;
     50  end;
     51end;
    3252
    3353constructor TModuleSystem.Create(Owner: TComponent);
     
    4767
    4868procedure TModuleSystem.Start;
     69var
     70  DbRows: TDbRows;
     71  I: Integer;
     72  Module: TModule;
    4973begin
     74  try
     75    DbRows := TDbRows.Create;
     76    Core.CommonDatabase.Select(DbRows, 'SystemModule', 'Name, Installed');
     77    for I := 0 to DbRows.Count - 1 do
     78    with DbRows[I] do begin
     79      Module := Core.ModuleManager.FindModuleByName(Values['Name']);
     80      if Assigned(Module) then
     81        if Values['Installed'] = '1' then Module.SetInstalledState(True)
     82          else Module.SetInstalledState(False);
     83    end;
     84  finally
     85    DbRows.Free;
     86  end;
     87  Core.ModuleManager.OnModuleChange := ModuleChange;
    5088  inherited Start;
    5189end;
     
    5492begin
    5593  inherited Stop;
     94  Core.ModuleManager.OnModuleChange := nil;
    5695end;
    5796
     
    78117    DbRows.Free;
    79118  end;
     119  UpdateModuleList;
    80120  inherited Install;
    81121end;
     
    99139end;
    100140
     141procedure TModuleSystem.UpdateModuleList;
     142var
     143  DbRows: TDbRows;
     144  I: Integer;
     145  Index: Integer;
     146  Data: TDictionaryStringString;
     147begin
     148  try
     149    DbRows := TDbRows.Create;
     150    Data := TDictionaryStringString.Create;
     151
     152    Core.CommonDatabase.Select(DbRows, 'SystemModule', 'Name');
     153
     154    for I := 0 to Core.ModuleManager.Modules.Count - 1 do
     155    with TModule(Core.ModuleManager.Modules[I]) do begin
     156      Data.Clear;
     157      Data.Add('Name', Identification);
     158      Data.Add('Version', Version);
     159      Data.Add('License', License);
     160      Data.Add('Creator', Author);
     161      Data.Add('Description', Description.Text);
     162      Data.Add('Title', Title);
     163      Data.Add('Dependencies', Dependencies.Text);
     164      if Installed then Data.Add('Installed', '1')
     165        else Data.Add('Installed', '0');
     166
     167      Index := 0;
     168      while (Index < DbRows.Count) and (DbRows[Index].Values['Name'] <> Identification) do Inc(Index);
     169      if Index >= DbRows.Count then Core.CommonDatabase.Insert('SystemModule', Data)
     170        else Core.CommonDatabase.Update('SystemModule', Data, 'Name="' + Identification + '"');
     171    end;
     172  finally
     173    Data.Free;
     174    DbRows.Free;
     175  end;
     176end;
     177
    101178end.
    102179
Note: See TracChangeset for help on using the changeset viewer.