1 | unit UCore;
|
---|
2 |
|
---|
3 | {$mode delphi}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | uses
|
---|
8 | Registry, Classes, SysUtils, FileUtil, USqlDatabase, URegistry, Forms,
|
---|
9 | UApplicationInfo, UCoolTranslator, UPersistentForm, UModularSystem,
|
---|
10 | UFormModuleList;
|
---|
11 |
|
---|
12 | type
|
---|
13 |
|
---|
14 | { TCore }
|
---|
15 |
|
---|
16 | TCore = class(TDataModule)
|
---|
17 | ApplicationInfo1: TApplicationInfo;
|
---|
18 | CoolTranslator1: TCoolTranslator;
|
---|
19 | Database: TSqlDatabase;
|
---|
20 | ModuleManager: TModuleManager;
|
---|
21 | procedure DataModuleCreate(Sender: TObject);
|
---|
22 | procedure DataModuleDestroy(Sender: TObject);
|
---|
23 | procedure ModuleManagerUpdate(Sender: TObject);
|
---|
24 | private
|
---|
25 | public
|
---|
26 | FormModuleList: TFormModuleList;
|
---|
27 | FormList: TForm;
|
---|
28 | PersistentForm: TPersistentForm;
|
---|
29 | RegistryContext: TRegistryContext;
|
---|
30 | procedure Init;
|
---|
31 | procedure Done;
|
---|
32 | procedure InitData;
|
---|
33 | procedure Connect;
|
---|
34 | procedure LoadFromRegistry(AContext: TRegistryContext);
|
---|
35 | procedure SaveToRegistry(AContext: TRegistryContext);
|
---|
36 | end;
|
---|
37 |
|
---|
38 | var
|
---|
39 | Core: TCore;
|
---|
40 |
|
---|
41 | implementation
|
---|
42 |
|
---|
43 | {$R *.lfm}
|
---|
44 |
|
---|
45 | uses
|
---|
46 | URegistredModules, UFormMain;
|
---|
47 |
|
---|
48 |
|
---|
49 | { TCore }
|
---|
50 |
|
---|
51 | procedure TCore.DataModuleCreate(Sender: TObject);
|
---|
52 | begin
|
---|
53 | PersistentForm := TPersistentForm.Create;
|
---|
54 | PersistentForm.RegistryContext := RegContext(HKEY(ApplicationInfo1.RegistryRoot),
|
---|
55 | ApplicationInfo1.RegistryKey + '\Forms');
|
---|
56 | RegistryContext := RegContext(HKEY(ApplicationInfo1.RegistryRoot), ApplicationInfo1.RegistryKey);
|
---|
57 | end;
|
---|
58 |
|
---|
59 | procedure TCore.DataModuleDestroy(Sender: TObject);
|
---|
60 | begin
|
---|
61 | FreeAndNil(PersistentForm);
|
---|
62 | end;
|
---|
63 |
|
---|
64 | procedure TCore.ModuleManagerUpdate(Sender: TObject);
|
---|
65 | begin
|
---|
66 | if Assigned(FormModuleList) then
|
---|
67 | FormModuleList.Reload;
|
---|
68 | FormMain.ReloadPages;
|
---|
69 | end;
|
---|
70 |
|
---|
71 | procedure TCore.Init;
|
---|
72 | begin
|
---|
73 | LoadFromRegistry(RegistryContext);
|
---|
74 |
|
---|
75 | try
|
---|
76 | ModuleManager.Modules.BeginUpdate;
|
---|
77 |
|
---|
78 | // Init modules
|
---|
79 | with TRegistryEx.Create do
|
---|
80 | try
|
---|
81 | Context := RegistryContext;
|
---|
82 | RegisterModules(ModuleManager);
|
---|
83 | if ReadBoolWithDefault('ModuleManagerInstalled', False) then
|
---|
84 | ModuleManager.LoadFromRegistry(RegContext(RegistryContext.RootKey, RegistryContext.Key + '\Modules'))
|
---|
85 | else begin
|
---|
86 | ModuleManager.Modules.Perform([maEnable]);
|
---|
87 | ModuleManager.SaveToRegistry(RegContext(RegistryContext.RootKey, RegistryContext.Key + '\Modules'));
|
---|
88 | WriteBool('ModuleManagerInstalled', True);
|
---|
89 | end;
|
---|
90 | finally
|
---|
91 | Free;
|
---|
92 | end;
|
---|
93 | ModuleManager.Modules.Perform([maStart], [mcEnabled]);
|
---|
94 | finally
|
---|
95 | ModuleManager.Modules.EndUpdate;
|
---|
96 | end;
|
---|
97 | end;
|
---|
98 |
|
---|
99 | procedure TCore.Done;
|
---|
100 | begin
|
---|
101 | SaveToRegistry(RegistryContext);
|
---|
102 | FormMain.Hide; // Speed up undocking with hidden main form
|
---|
103 | ModuleManager.SaveToRegistry(RegContext(RegistryContext.RootKey, RegistryContext.Key + '\Modules'));
|
---|
104 | if Assigned(FormModuleList) then FreeAndNil(FormModuleList);
|
---|
105 | ModuleManager.OnUpdate := nil;
|
---|
106 | UnregisterModules(ModuleManager);
|
---|
107 | end;
|
---|
108 |
|
---|
109 | procedure TCore.InitData;
|
---|
110 | var
|
---|
111 | DbRows: TDbRows;
|
---|
112 | begin
|
---|
113 | try
|
---|
114 | DbRows := TDbRows.Create;
|
---|
115 | Database.Query(DbRows, '');
|
---|
116 | finally
|
---|
117 | DbRows.Free;
|
---|
118 | end;
|
---|
119 | end;
|
---|
120 |
|
---|
121 | procedure TCore.Connect;
|
---|
122 | begin
|
---|
123 | Database.Connect;
|
---|
124 | end;
|
---|
125 |
|
---|
126 | procedure TCore.LoadFromRegistry(AContext: TRegistryContext);
|
---|
127 | begin
|
---|
128 | with TRegistryEx.Create do
|
---|
129 | try
|
---|
130 | Context := AContext;
|
---|
131 | Database.HostName := ReadStringWithDefault('HostName', 'localhost');
|
---|
132 | Database.Database := ReadStringWithDefault('Schema', 'dochazka');
|
---|
133 | Database.UserName := ReadStringWithDefault('UserName', 'dochazka');
|
---|
134 | Database.Password := ReadStringWithDefault('Password', '');
|
---|
135 | CoolTranslator1.Language := CoolTranslator1.Languages.SearchByCode(ReadStringWithDefault('Language', ''));
|
---|
136 | finally
|
---|
137 | Free;
|
---|
138 | end;
|
---|
139 | end;
|
---|
140 |
|
---|
141 | procedure TCore.SaveToRegistry(AContext: TRegistryContext);
|
---|
142 | begin
|
---|
143 | with TRegistryEx.Create do
|
---|
144 | try
|
---|
145 | Context := AContext;
|
---|
146 | WriteString('HostName', Database.HostName);
|
---|
147 | WriteString('Schema', Database.Database);
|
---|
148 | WriteString('UserName', Database.UserName);
|
---|
149 | WriteString('Password', Database.Password);
|
---|
150 | WriteString('Language', CoolTranslator1.Language.Code);
|
---|
151 | finally
|
---|
152 | Free;
|
---|
153 | end;
|
---|
154 | end;
|
---|
155 |
|
---|
156 | end.
|
---|
157 |
|
---|