-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMainUnit.pas
More file actions
800 lines (684 loc) · 24.9 KB
/
MainUnit.pas
File metadata and controls
800 lines (684 loc) · 24.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
unit MainUnit;
interface
uses
Winapi.Windows, Winapi.Messages, Winapi.ShellAPI,
System.SysUtils, System.Variants, System.Classes, System.Win.Registry,
System.Generics.Collections, System.Generics.Defaults,
Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Menus, Vcl.StdCtrls,
Vcl.ExtCtrls, Vcl.Buttons,
Autorun.Manager,
AutoUpdate, AutoUpdate.Scheduler,
Core.Startup,
Core.Language, Core.Language.Controls,
Core.UI, Core.UI.Controls, Core.UI.Notifications,
Desktop,
Mouse.Mac,
Sensitivity.Window,
Tray.Notify.Window, Tray.Notify.Controls,
Versions, Versions.Info, Versions.Helpers,
Helpers.License;
const
REG_Key = 'Software\Mouse MAC';
REG_ID = 'ID';
REG_Version = 'Version';
REG_AutoUpdateEnable = 'AutoUpdateEnable';
REG_AutoUpdateLastCheck = 'AutoUpdateLastCheck';
REG_AutoUpdateSkipVersion = 'AutoUpdateSkipVersion';
REG_Language = 'Language';
REG_LanguageId = 'LanguageId';
REG_Enable = 'Enable';
REG_Invert = 'Invert';
REG_VerticalSensitivity = 'VerticalSensitivity';
REG_HorizontalSensitivity = 'HorizontalSensitivity';
REG_HorizontalScrollOnShiftDown = 'HorizontalScrollOnShiftDown';
type
TConfig = record
ID: TAppID;
AutoUpdateEnable: Boolean;
AutoUpdateLastCheck: TDateTime;
AutoUpdateSkipVersion: TVersion;
Enable: Boolean;
Invert: Boolean;
HorizontalScrollOnShiftDown: Boolean;
VerticalSensitivity: Double;
HorizontalSensitivity: Double;
end;
TUIInfo = (UIInfoHide, UIInfoSN);
type
TMouseExForm = class(TTrayNotifyWindow)
PanelTop: TPanel;
PanelBottom: TPanel;
PanelConfig: TPanel;
ImageIcon: TImage;
LabelAppName: TLabel;
LabelAppInfo: TLabel;
LabelConfig: TLabel;
CheckBoxEnable: TCheckBox;
CheckBoxInvert: TCheckBox;
CheckBoxHorizontalScrollWithShift: TCheckBox;
TrayMenuAutoUpdate: TMenuItem;
TrayMenuAutoUpdateEnable: TMenuItem;
TrayMenuAutoUpdateCheck: TMenuItem;
PopupMenuTray: TPopupMenu;
TrayMenuMouse: TMenuItem;
TrayMenuEnable: TMenuItem;
TrayMenuAutorun: TMenuItem;
TrayMenuListboxSmoothScrolling: TMenuItem;
TrayMenuHorizontalScrollOnShiftDown: TMenuItem;
TrayMenuSensitivity: TMenuItem;
TrayMenuWebsite: TMenuItem;
TrayMenuLicense: TMenuItem;
TrayMenuClose: TMenuItem;
TrayMenuSeparator1: TMenuItem;
TrayMenuSeparator2: TMenuItem;
TrayMenuSeparator3: TMenuItem;
TrayMenuSeparator4: TMenuItem;
TrayMenuLanguage: TMenuItem;
TrayMenuLanguageSystem: TMenuItem;
TrayMenuSeparator5: TMenuItem;
LinkGridPanel: TGridPanel;
Link: TStaticText;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormDeactivate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure LabelAppInfoClick(Sender: TObject);
procedure LinkClick(Sender: TObject);
procedure TrayMenuMouseClick(Sender: TObject);
procedure TrayMenuEnableClick(Sender: TObject);
procedure TrayMenuAutorunClick(Sender: TObject);
procedure TrayMenuAutoUpdateEnableClick(Sender: TObject);
procedure TrayMenuAutoUpdateCheckClick(Sender: TObject);
procedure TrayMenuLanguageItemClick(Sender: TObject);
procedure TrayMenuHorizontalScrollOnShiftDownClick(Sender: TObject);
procedure TrayMenuSensitivityClick(Sender: TObject);
procedure TrayMenuListboxSmoothScrollingClick(Sender: TObject);
procedure TrayMenuWebsiteClick(Sender: TObject);
procedure TrayMenuLicenseClick(Sender: TObject);
procedure TrayMenuCloseClick(Sender: TObject);
procedure CheckBoxEnableClick(Sender: TObject);
procedure CheckBoxInvertClick(Sender: TObject);
procedure CheckBoxHorizontalScrollWithShiftClick(Sender: TObject);
procedure TrayNotifyUpdateAvalible(Sender: TObject; Value: Integer);
procedure TrayNotifyUpdateFail(Sender: TObject; Value: Integer);
protected
procedure LoadIcon; override;
procedure Loadlocalization;
procedure LoadAvailableLocalizetions;
function DefaultConfig: TConfig;
function LoadConfig: TConfig;
procedure SaveConfig(Conf: TConfig);
procedure SaveCurrentConfig;
procedure DeleteConfig;
private
LockerAutorun: ILocker;
LockerSaveConfig: ILocker;
LockerMouseMac: ILocker;
LockerInvert: ILocker;
LockerHorizontalScrollOnShiftDown: ILocker;
LockerUIEffects: ILocker;
LockerListboxSmoothScrolling: ILocker;
FUIInfo: TUIInfo;
AutoUpdateScheduler: TAutoUpdateScheduler;
procedure SetUIInfo(const Value: TUIInfo);
procedure AutorunManagerAutorun(Sender: TObject; Enable: Boolean);
procedure OpenConfigMouse;
procedure MouseMacStateChange(Sender: TObject; State: Boolean);
procedure MouseMacInvertChange(Sender: TObject; State: Boolean);
procedure MouseMacHorizontalScrollOnShiftDownChange(Sender: TObject; State: Boolean);
procedure DesktopManagerUIEffects(Sender: TObject; Capable: Boolean; State: Boolean);
procedure DesktopManagerListboxSmoothScrolling(Sender: TObject; Capable: Boolean; State: Boolean);
procedure AutoUpdateSchedulerInCheck(Sender: TObject);
procedure AutoUpdateSchedulerChecked(Sender: TObject);
procedure AutoUpdateSchedulerSaveLastCheck(Sender: TObject; Time: TDateTime);
procedure AutoUpdateSchedulerInstalling(Sender: TObject);
procedure AutoUpdateSchedulerSkip(Sender: TObject; Version: TVersion);
procedure AutoUpdateSchedulerAvalible(Sender: TObject; Version: TVersion);
public
property UIInfo: TUIInfo read FUIInfo write SetUIInfo;
end;
var
MouseExForm: TMouseExForm;
implementation
{$R *.dfm}
procedure TMouseExForm.FormCreate(Sender: TObject);
var
Conf: TConfig;
begin
// Инициализация флагов обновления данных
LockerAutorun := TLocker.Create;
LockerSaveConfig := TLocker.Create;
LockerMouseMac := TLocker.Create;
LockerInvert := TLocker.Create;
LockerHorizontalScrollOnShiftDown := TLocker.Create;
LockerUIEffects := TLocker.Create;
LockerListboxSmoothScrolling := TLocker.Create;
// Загрузка конфигурации
Conf := LoadConfig;
// Инициализация интерфейса
Link.LinkMode := True;
PanelTop.Shape := psBottomLine;
PanelTop.Style := tfpsHeader;
PanelConfig.Shape := psBottomLine;
PanelConfig.Style := tfpsBody;
PanelBottom.Style := tfpsLinkArea;
LabelAppName.Caption := TVersionInfo.ProductName;
CheckBoxEnable.AutoSize := True;
CheckBoxInvert.AutoSize := True;
CheckBoxHorizontalScrollWithShift.AutoSize := True;
UIInfo := Low(UIInfo);
LabelAppInfo.Font.Name := Font.Name;
LabelAppInfo.Font.Size := Font.Size;
LabelConfig.Font.Name := Font.Name;
LabelConfig.Font.Size := Font.Size;
if IsWindows10OrGreater then begin
with PanelTop do Height := Height - 3;
with LabelAppName do Top := Top - 3;
with LabelAppInfo do Top := Top - 3;
with ImageIcon do Top := Top - 3;
end;
// Инициализация трея
TrayIcon.PopupMenu := PopupMenuTray;
TrayIcon.Icon := Application.Icon.Handle;
// Инициализация Notification
TNotificationService.Notification := TrayNotification;
// Инициализация автозагрузки
AutorunManager.OnAutorun := AutorunManagerAutorun;
// Инициализация TMouseMac
TMouseMac.OnStateChange := MouseMacStateChange;
TMouseMac.OnInvertChange := MouseMacInvertChange;
TMouseMac.OnHorizontalScrollOnShiftDownChange := MouseMacHorizontalScrollOnShiftDownChange;
TMouseMac.Invert := Conf.Invert;
TMouseMac.Enable := Conf.Enable;
TMouseMac.HorizontalScrollOnShiftDown := Conf.HorizontalScrollOnShiftDown;
TMouseMac.VerticalSensitivity := Conf.VerticalSensitivity;
TMouseMac.HorizontalSensitivity := Conf.HorizontalSensitivity;
// Инициализация TDesktopManager
TDesktopManager.OnUIEffects := DesktopManagerUIEffects;
TDesktopManager.OnListboxSmoothScrolling := DesktopManagerListboxSmoothScrolling;
// Инициализация AutoUpdateScheduler
AutoUpdateScheduler := TAutoUpdateScheduler.Create(TLang[40],
Conf.AutoUpdateLastCheck, Conf.AutoUpdateSkipVersion, Conf.ID);
AutoUpdateScheduler.OnInCheck := AutoUpdateSchedulerInCheck;
AutoUpdateScheduler.OnChecked := AutoUpdateSchedulerChecked;
AutoUpdateScheduler.OnSaveLastCheck := AutoUpdateSchedulerSaveLastCheck;
AutoUpdateScheduler.OnInstalling := AutoUpdateSchedulerInstalling;
AutoUpdateScheduler.OnSkip := AutoUpdateSchedulerSkip;
AutoUpdateScheduler.OnAvalible := AutoUpdateSchedulerAvalible;
AutoUpdateScheduler.Enable := Conf.AutoUpdateEnable;
TrayMenuAutoUpdateEnable.Checked := AutoUpdateScheduler.Enable;
// Загрузка локализации
LoadAvailableLocalizetions;
Loadlocalization;
// Отображение иконки в трее
TrayIcon.Visible := True;
// Исправление отсутствующего значка при автозапуске через планировщик задач
TrayIcon.Update(30000);
case AutoUpdateScheduler.StartupUpdateStatus of
susComplete: TrayNotification.Notify(Format(TLang[45], [TVersionInfo.FileVersion.ToString]));
susFail: TrayNotification.Notify(Format(TLang[46], [TVersionInfo.FileVersion.ToString]), [nfError], TrayNotifyUpdateFail);
end;
end;
procedure TMouseExForm.FormDestroy(Sender: TObject);
begin
if WindowCreated and not LockerSaveConfig.IsLocked then
SaveCurrentConfig;
AutoUpdateScheduler.Free;
TMouseMac.Enable := False;
end;
procedure TMouseExForm.FormDeactivate(Sender: TObject);
begin
UIInfo:= Low(UIInfo);
end;
procedure TMouseExForm.FormShow(Sender: TObject);
begin
PanelConfig.Realign;
end;
{$REGION 'TMouseExForm Events'}
procedure TMouseExForm.LabelAppInfoClick(Sender: TObject);
begin
if UIInfo = High(UIInfo) then
UIInfo := Low(UIInfo)
else
UIInfo := Succ(UIInfo);
end;
procedure TMouseExForm.LinkClick(Sender: TObject);
begin
OpenConfigMouse;
end;
procedure TMouseExForm.CheckBoxEnableClick(Sender: TObject);
begin
if LockerMouseMac.IsLocked then Exit;
TMouseMac.Enable := (Sender as TCheckBox).Checked;
end;
procedure TMouseExForm.CheckBoxInvertClick(Sender: TObject);
begin
if LockerInvert.IsLocked then Exit;
TMouseMac.Invert := (Sender as TCheckBox).Checked;
end;
procedure TMouseExForm.CheckBoxHorizontalScrollWithShiftClick(Sender: TObject);
begin
if LockerHorizontalScrollOnShiftDown.IsLocked then Exit;
TMouseMac.HorizontalScrollOnShiftDown := (Sender as TCheckBox).Checked;
end;
procedure TMouseExForm.TrayMenuMouseClick(Sender: TObject);
begin
OpenConfigMouse;
end;
procedure TMouseExForm.TrayMenuEnableClick(Sender: TObject);
begin
if LockerMouseMac.IsLocked then Exit;
TMouseMac.Enable := (Sender as TMenuItem).Checked;
end;
procedure TMouseExForm.TrayMenuAutorunClick(Sender: TObject);
begin
if LockerAutorun.IsLocked then Exit;
AutorunManager.SetAutorunEx((Sender as TMenuItem).Checked);
SetForegroundWindow(TrayIcon.Handle);
end;
procedure TMouseExForm.TrayMenuAutoUpdateEnableClick(Sender: TObject);
begin
AutoUpdateScheduler.Enable := (Sender as TMenuItem).Checked;
end;
procedure TMouseExForm.TrayMenuAutoUpdateCheckClick(Sender: TObject);
begin
AutoUpdateScheduler.Check(True);
end;
procedure TMouseExForm.TrayMenuLanguageItemClick(Sender: TObject);
var
NewLanguageId, LastEffectiveLanguageId: LANGID;
StartUpInfo : TStartUpInfo;
ProcessInfo : TProcessInformation;
begin
if (Sender is TLanguageMenuItem) then
NewLanguageId := (Sender as TLanguageMenuItem).Localization.LanguageId
else
NewLanguageId := 0;
if TLang.LanguageId = NewLanguageId then Exit;
LastEffectiveLanguageId := TLang.EffectiveLanguageId;
TLang.LanguageId := NewLanguageId;
if LastEffectiveLanguageId = TLang.EffectiveLanguageId then Exit;
Loadlocalization;
SaveCurrentConfig;
TMutexLocker.Unlock;
TrayIcon.Visible := False;
ZeroMemory(@StartUpInfo, SizeOf(StartUpInfo));
StartUpInfo.cb := SizeOf(StartUpInfo);
if not CreateProcess(LPCTSTR(Application.ExeName), nil, nil, nil, True,
GetPriorityClass(GetCurrentProcess), nil, nil, StartUpInfo, ProcessInfo) then
begin
TMutexLocker.Lock;
TrayIcon.Visible := True;
Exit;
end;
LockerSaveConfig.Lock;
try
Application.Terminate;
finally
CloseHandle(ProcessInfo.hProcess);
CloseHandle(ProcessInfo.hThread);
ExitProcess(0);
end;
end;
procedure TMouseExForm.TrayMenuHorizontalScrollOnShiftDownClick(
Sender: TObject);
begin
if LockerHorizontalScrollOnShiftDown.IsLocked then Exit;
TMouseMac.HorizontalScrollOnShiftDown := (Sender as TMenuItem).Checked;
end;
procedure TMouseExForm.TrayMenuSensitivityClick(Sender: TObject);
begin
TSensitivityWindow.Open;
end;
procedure TMouseExForm.TrayMenuListboxSmoothScrollingClick(Sender: TObject);
begin
if LockerListboxSmoothScrolling.IsLocked then Exit;
TDesktopManager.ListboxSmoothScrolling := (Sender as TMenuItem).Checked;
end;
procedure TMouseExForm.TrayMenuWebsiteClick(Sender: TObject);
begin
ShellExecute(Handle, 'open', LPTSTR(TLang[12]), nil, nil, SW_RESTORE);
end;
procedure TMouseExForm.TrayMenuLicenseClick(Sender: TObject);
begin
TLicense.Open;
end;
procedure TMouseExForm.TrayMenuCloseClick(Sender: TObject);
begin
Close;
end;
procedure TMouseExForm.TrayNotifyUpdateAvalible(Sender: TObject;
Value: Integer);
begin
SetForegroundWindow(TrayIcon.Handle);
AutoUpdateScheduler.Check(True);
end;
procedure TMouseExForm.TrayNotifyUpdateFail(Sender: TObject; Value: Integer);
begin
ShellExecute(Handle, 'open', LPTSTR(TLang.GetString(12)), nil, nil, SW_RESTORE);
end;
{$ENDREGION}
{$REGION 'TMouseMac Event'}
procedure TMouseExForm.MouseMacStateChange(Sender: TObject; State: Boolean);
begin
LockerMouseMac.Lock;
try
CheckBoxEnable.Checked := State;
TrayMenuEnable.Checked := State;
CheckBoxInvert.Enabled := State;
if State then
TrayIcon.Hint := TLang[1] + sLineBreak + TLang[4]
else
TrayIcon.Hint := TLang[1] + sLineBreak + TLang[5];
LoadIcon;
finally
LockerMouseMac.Unlock;
end;
end;
procedure TMouseExForm.MouseMacInvertChange(Sender: TObject; State: Boolean);
begin
LockerInvert.Lock;
try
CheckBoxInvert.Checked := State;
finally
LockerInvert.Unlock;
end;
end;
procedure TMouseExForm.MouseMacHorizontalScrollOnShiftDownChange(
Sender: TObject; State: Boolean);
begin
LockerHorizontalScrollOnShiftDown.Lock;
try
TrayMenuHorizontalScrollOnShiftDown.Checked := State;
CheckBoxHorizontalScrollWithShift.Checked := State;
finally
LockerHorizontalScrollOnShiftDown.Unlock;
end;
end;
{$ENDREGION}
{$REGION 'TDesktopManager Event'}
procedure TMouseExForm.DesktopManagerUIEffects(Sender: TObject; Capable,
State: Boolean);
begin
LockerUIEffects.Lock;
try
if Capable then
TrayMenuListboxSmoothScrolling.Enabled := State;
finally
LockerUIEffects.Unlock;
end;
end;
procedure TMouseExForm.DesktopManagerListboxSmoothScrolling(Sender: TObject;
Capable, State: Boolean);
begin
LockerListboxSmoothScrolling.Lock;
try
TrayMenuListboxSmoothScrolling.Visible := Capable;
TrayMenuListboxSmoothScrolling.Checked := State;
finally
LockerListboxSmoothScrolling.Unlock;
end;
end;
{$ENDREGION}
{$REGION 'AutoUpdateScheduler Event'}
procedure TMouseExForm.AutoUpdateSchedulerChecked(Sender: TObject);
begin
TrayMenuAutoUpdateCheck.Enabled := True
end;
procedure TMouseExForm.AutoUpdateSchedulerInCheck(Sender: TObject);
begin
TrayMenuAutoUpdateCheck.Enabled := False;
end;
procedure TMouseExForm.AutoUpdateSchedulerInstalling(Sender: TObject);
begin
SaveCurrentConfig;
TrayIcon.Visible := False;
Application.Terminate;
ExitProcess(0);
end;
procedure TMouseExForm.AutoUpdateSchedulerSaveLastCheck(Sender: TObject;
Time: TDateTime);
begin
SaveCurrentConfig;
end;
procedure TMouseExForm.AutoUpdateSchedulerSkip(Sender: TObject;
Version: TVersion);
begin
SaveCurrentConfig;
end;
procedure TMouseExForm.AutoUpdateSchedulerAvalible(Sender: TObject;
Version: TVersion);
begin
TrayNotification.Notify(Format(TLang[44], [Version.ToString]), TrayNotifyUpdateAvalible);
end;
{$ENDREGION}
procedure TMouseExForm.AutorunManagerAutorun(Sender: TObject; Enable: Boolean);
begin
LockerAutorun.Lock;
try
TrayMenuAutorun.Checked := Enable;
finally
LockerAutorun.Unlock;
end;
end;
procedure TMouseExForm.OpenConfigMouse;
begin
WinExec('Control.exe main.cpl', SW_RESTORE);
end;
procedure TMouseExForm.LoadIcon;
begin
if TMouseMac.Enable then
Application.Icon.Handle := LoadIconW(HInstance, 'RIcon_Enable')
else
Application.Icon.Handle := LoadIconW(HInstance, 'RIcon_Disable');
ImageIcon.Picture.Assign(Application.Icon);
TrayIcon.Icon := Application.Icon.Handle;
end;
procedure TMouseExForm.Loadlocalization;
function GetInternationalization(Index: Integer): string;
var
NonLocalized: string;
begin
Result := TLang[Index];
NonLocalized := TLang.GetString(Index, TLang.DefaultLang);
if Result <> NonLocalized then
Result := Result + ' (' + NonLocalized + ')';
end;
begin
LabelAppName.Caption := TLang[1];
LabelConfig.Caption := TLang[2];
CheckBoxEnable.Caption := TLang[3];
CheckBoxInvert.Caption := TLang[7];
CheckBoxHorizontalScrollWithShift.Caption := TLang[30]; // Горизонтальная прокрутка с клавишей Shift
Link.Caption := TLang[8];
TrayMenuMouse.Caption := TLang[8];
TrayMenuEnable.Caption := TLang[3];
TrayMenuAutorun.Caption := TLang[6];
TrayMenuWebsite.Caption := TLang[11];
TrayMenuLicense.Caption := TLang[224]; // License
TrayMenuClose.Caption := TLang[9];
TrayMenuListboxSmoothScrolling.Caption := TLang[22]; // Гладкое прокручивание списков
TrayMenuHorizontalScrollOnShiftDown.Caption := TLang[30]; // Горизонтальная прокрутка с клавишей Shift
TrayMenuSensitivity.Caption := TLang[31]; // Sensitivity setting
TrayMenuAutoUpdate.Caption := TLang[41]; // Automatic updates
TrayMenuAutoUpdateEnable.Caption := TLang[42]; // Turn on automatic updates
TrayMenuAutoUpdateCheck.Caption := TLang[43]; // Check for Updates
TrayMenuLanguage.Caption := GetInternationalization(150);
TrayMenuLanguageSystem.Caption := GetInternationalization(151);
if TMouseMac.Enable then
TrayIcon.Hint := TLang[1] + sLineBreak + TLang[4]
else
TrayIcon.Hint := TLang[1] + sLineBreak + TLang[5];
TrayIcon.BalloonTitle := TLang[1]; // MouseMAC
TrayNotification.Title := TLang[1]; // MouseMAC
end;
procedure TMouseExForm.LoadAvailableLocalizetions;
var
AvailableLocalizations: TAvailableLocalizations;
Localization: TAvailableLocalization;
MenuItem: TMenuItem;
begin
AvailableLocalizations := TLang.GetAvailableLocalizations(0);
AvailableLocalizations.Sort(TComparer<TAvailableLocalization>.Construct(
function(const Left, Right: TAvailableLocalization): Integer
begin
Result := string.Compare(
Left.Value,
Right.Value,
[coLingIgnoreCase],
MAKELCID(TLang.LanguageId, SORT_DEFAULT));
end
));
try
for Localization in AvailableLocalizations do
begin
MenuItem := TLanguageMenuItem.Create(PopupMenuTray, Localization);
MenuItem.OnClick := TrayMenuLanguageItemClick;
MenuItem.Checked := Localization.LanguageId = TLang.LanguageId;
TrayMenuLanguage.Add(MenuItem);
end;
TrayMenuLanguageSystem.Checked := TLang.LanguageId = 0;
finally
AvailableLocalizations.Free;
end;
end;
procedure TMouseExForm.SetUIInfo(const Value: TUIInfo);
const
VerFmt = '%0:s: %1:s %2:s';
begin
FUIInfo := Value;
case Value of
UIInfoSN: begin
LabelAppInfo.Visible := True;
LabelAppInfo.Caption := Format(VerFmt,
[TLang[10], string(TVersionInfo.FileVersion), TVersionInfo.BinaryTypeAsShortString]);
end;
else begin
LabelAppInfo.Visible := False;
end;
end;
end;
{$REGION 'Config'}
function TMouseExForm.DefaultConfig: TConfig;
begin
Result.ID := TAutoUpdateScheduler.NewID;
Result.AutoUpdateEnable := True;
Result.AutoUpdateLastCheck := 0;
Result.AutoUpdateSkipVersion := TVersion.Empty;
Result.Enable:= True;
Result.Invert:= False;
Result.HorizontalScrollOnShiftDown:= False;
Result.VerticalSensitivity := TMouseMac.DefaultVerticalSensitivity;
Result.HorizontalSensitivity := TMouseMac.DefaultHorizontalSensitivity;
end;
function TMouseExForm.LoadConfig: TConfig;
var
Default: TConfig;
Registry: TRegistry;
function ReadBoolDef(const Name: string; const Def: Boolean): Boolean;
begin
if Registry.ValueExists(Name) then
Result := Registry.ReadBool(Name)
else
Result := Def;
end;
function ReadIntegerDef(const Name: string; const Def: Integer): Integer;
begin
if Registry.ValueExists(Name) then
Result := Registry.ReadInteger(Name)
else
Result := Def;
end;
function ReadDoubleDef(const Name: string; const Def: Double): Double;
begin
if Registry.ValueExists(Name) then
Result := Registry.ReadFloat(Name)
else
Result := Def;
end;
function ReadStringDef(const Name: string; const Def: string): string;
begin
if Registry.ValueExists(Name) then
Result := Registry.ReadString(Name)
else
Result := Def;
end;
begin
Default := DefaultConfig;
Registry := TRegistry.Create;
try
Registry.RootKey := HKEY_CURRENT_USER;
if not Registry.KeyExists(REG_Key) then Exit(Default);
if not Registry.OpenKeyReadOnly(REG_Key) then Exit(Default);
// Read config
Result.ID := ReadIntegerDef(REG_ID, Default.ID);
Result.AutoUpdateEnable := ReadBoolDef(REG_AutoUpdateEnable, Default.AutoUpdateEnable);
Result.AutoUpdateLastCheck := StrToDateTimeDef(ReadStringDef(REG_AutoUpdateLastCheck, ''), Default.AutoUpdateLastCheck);
Result.AutoUpdateSkipVersion := ReadStringDef(REG_AutoUpdateSkipVersion, Default.AutoUpdateSkipVersion);
Result.Enable:= ReadBoolDef(REG_Enable, Default.Enable);
Result.Invert:= ReadBoolDef(REG_Invert, Default.Invert);
Result.HorizontalScrollOnShiftDown:= ReadBoolDef(REG_HorizontalScrollOnShiftDown, Default.HorizontalScrollOnShiftDown);
Result.VerticalSensitivity:= ReadDoubleDef(REG_VerticalSensitivity, Default.VerticalSensitivity);
Result.HorizontalSensitivity:= ReadDoubleDef(REG_HorizontalSensitivity, Default.HorizontalSensitivity);
// end read config
Registry.CloseKey;
finally
Registry.Free;
end;
end;
procedure TMouseExForm.SaveConfig(Conf: TConfig);
var
Registry: TRegistry;
begin
Registry := TRegistry.Create;
try
Registry.RootKey := HKEY_CURRENT_USER;
if Registry.OpenKey(REG_Key, True) then begin
// Write config
Registry.WriteInteger(REG_ID, Conf.ID);
Registry.WriteString(REG_Version, TVersionInfo.FileVersion); // Last version
Registry.WriteInteger(REG_LanguageId, TLang.LanguageId);
Registry.WriteBool(REG_AutoUpdateEnable, Conf.AutoUpdateEnable);
Registry.WriteString(REG_AutoUpdateLastCheck, DateTimeToStr(Conf.AutoUpdateLastCheck));
Registry.WriteString(REG_AutoUpdateSkipVersion, Conf.AutoUpdateSkipVersion);
Registry.WriteBool(REG_Enable, Conf.Enable);
Registry.WriteBool(REG_Invert, Conf.Invert);
Registry.WriteBool(REG_HorizontalScrollOnShiftDown, Conf.HorizontalScrollOnShiftDown);
Registry.WriteFloat(REG_VerticalSensitivity, Conf.VerticalSensitivity);
Registry.WriteFloat(REG_HorizontalSensitivity, Conf.HorizontalSensitivity);
// end write config
Registry.CloseKey;
end;
finally
Registry.Free;
end;
end;
procedure TMouseExForm.SaveCurrentConfig;
var
Conf: TConfig;
begin
Conf.ID := AutoUpdateScheduler.ID;
Conf.AutoUpdateEnable := AutoUpdateScheduler.Enable;
Conf.AutoUpdateLastCheck := AutoUpdateScheduler.LastCheck;
Conf.AutoUpdateSkipVersion := AutoUpdateScheduler.SkipVersion;
Conf.Enable := TMouseMac.Enable;
Conf.Invert := TMouseMac.Invert;
Conf.HorizontalScrollOnShiftDown := TMouseMac.HorizontalScrollOnShiftDown;
Conf.VerticalSensitivity := TMouseMac.VerticalSensitivity;
Conf.HorizontalSensitivity := TMouseMac.HorizontalSensitivity;
SaveConfig(Conf);
end;
procedure TMouseExForm.DeleteConfig;
var
Registry: TRegistry;
begin
Registry := TRegistry.Create;
try
Registry.RootKey := HKEY_CURRENT_USER;
Registry.DeleteKey(REG_Key);
finally
Registry.Free;
end;
end;
{$ENDREGION}
end.