1 | unit UCore;
|
---|
2 |
|
---|
3 | {$mode delphi}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | uses
|
---|
8 | Classes, SysUtils, FileUtil, UCoolTranslator, UDebugLog, USystem, Registry,
|
---|
9 | USqlDatabase, UFormLoginProfile, URegistry, UPDClient;
|
---|
10 |
|
---|
11 | type
|
---|
12 |
|
---|
13 | { TCore }
|
---|
14 |
|
---|
15 | TCore = class(TDataModule)
|
---|
16 | CoolTranslator1: TCoolTranslator;
|
---|
17 | DebugLog1: TDebugLog;
|
---|
18 | procedure CoolTranslator1Translate(Sender: TObject);
|
---|
19 | procedure DataModuleCreate(Sender: TObject);
|
---|
20 | procedure DataModuleDestroy(Sender: TObject);
|
---|
21 | procedure SqlDatabase1LogQuery(Sender: TObject; Text: string);
|
---|
22 | private
|
---|
23 | procedure LoadFromRegistry;
|
---|
24 | procedure SaveToRegistry;
|
---|
25 | { private declarations }
|
---|
26 | public
|
---|
27 | LastUserName: string;
|
---|
28 | LastProfile: Integer;
|
---|
29 | LastPassword: string;
|
---|
30 | RememberPassword: Boolean;
|
---|
31 | Profiles: TProfileList;
|
---|
32 | RegistryKey: string;
|
---|
33 | RegistryRootKey: HKEY;
|
---|
34 | System: TChronisBase;
|
---|
35 | end;
|
---|
36 |
|
---|
37 | var
|
---|
38 | Core: TCore;
|
---|
39 |
|
---|
40 |
|
---|
41 | implementation
|
---|
42 |
|
---|
43 | uses
|
---|
44 | UModuleSystem, UModuleUser, UApplicationInfo;
|
---|
45 |
|
---|
46 | {$R *.lfm}
|
---|
47 |
|
---|
48 | { TCore }
|
---|
49 |
|
---|
50 | procedure TCore.DataModuleCreate(Sender: TObject);
|
---|
51 | begin
|
---|
52 | Profiles := TProfileList.Create;
|
---|
53 | RegistryRootKey := HKEY_CURRENT_USER;
|
---|
54 | RegistryKey := '\Software\' + ApplicationInfo.CompanyName + '\' +
|
---|
55 | ApplicationInfo.Name;
|
---|
56 | LoadFromRegistry;
|
---|
57 | System := TChronisBase.Create;
|
---|
58 | //TChronisClientMySQL(System.Client).Database := SqlDatabase1;
|
---|
59 | System.Modules.RegisterModule(TModuleSystem);
|
---|
60 | System.ModuleSystem := TModuleSystem(System.Modules.Last);
|
---|
61 | System.Modules.RegisterModule(TModuleUser);
|
---|
62 |
|
---|
63 | {$IFDEF DEBUG}
|
---|
64 | DebugLog1.WriteToFileEnable := True;
|
---|
65 | {$ENDIF}
|
---|
66 | end;
|
---|
67 |
|
---|
68 | procedure TCore.CoolTranslator1Translate(Sender: TObject);
|
---|
69 | begin
|
---|
70 | UFormLoginProfile.UpdateTranslation;
|
---|
71 | end;
|
---|
72 |
|
---|
73 | procedure TCore.DataModuleDestroy(Sender: TObject);
|
---|
74 | begin
|
---|
75 | SaveToRegistry;
|
---|
76 | FreeAndNil(System);
|
---|
77 | FreeAndNil(Profiles);
|
---|
78 | end;
|
---|
79 |
|
---|
80 | procedure TCore.SqlDatabase1LogQuery(Sender: TObject; Text: string);
|
---|
81 | begin
|
---|
82 | DebugLog1.Add('', Text);
|
---|
83 | end;
|
---|
84 |
|
---|
85 | procedure TCore.LoadFromRegistry;
|
---|
86 | begin
|
---|
87 | with TRegistryEx.Create do
|
---|
88 | try
|
---|
89 | RootKey := RegistryRootKey;
|
---|
90 | OpenKey(RegistryKey, True);
|
---|
91 | LastProfile := ReadIntegerWithDefault('LastConnectProfile', -1);
|
---|
92 | LastUserName := ReadStringWithDefault('LastUserName', 'admin');
|
---|
93 | LastPassword := ReadStringWithDefault('LastPassword', '');
|
---|
94 | RememberPassword := ReadBoolWithDefault('RememberPassword', False);
|
---|
95 | finally
|
---|
96 | Free;
|
---|
97 | end;
|
---|
98 | end;
|
---|
99 |
|
---|
100 | procedure TCore.SaveToRegistry;
|
---|
101 | begin
|
---|
102 | with TRegistryEx.Create do
|
---|
103 | try
|
---|
104 | RootKey := RegistryRootKey;
|
---|
105 | OpenKey(RegistryKey, True);
|
---|
106 | WriteInteger('LastConnectProfile', LastProfile);
|
---|
107 | WriteString('LastUserName', LastUserName);
|
---|
108 | if RememberPassword then WriteString('LastPassword', LastPassword)
|
---|
109 | else WriteString('LastPassword', '');
|
---|
110 | WriteBool('RememberPassword', RememberPassword);
|
---|
111 | finally
|
---|
112 | Free;
|
---|
113 | end;
|
---|
114 | end;
|
---|
115 |
|
---|
116 |
|
---|
117 | end.
|
---|
118 |
|
---|