-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFrameAboutMe.pas
More file actions
626 lines (536 loc) · 17.3 KB
/
FrameAboutMe.pas
File metadata and controls
626 lines (536 loc) · 17.3 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
unit FrameAboutMe;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ComCtrls, Vcl.StdCtrls,
Vcl.ExtCtrls, System.NetEncoding, System.Hash, Vcl.Imaging.pngimage,
Vcl.Clipbrd, System.IOUtils, FireDAC.Stan.Intf,
FireDAC.Stan.Option, FireDAC.Stan.Error, FireDAC.UI.Intf, FireDAC.Phys.Intf,
FireDAC.Stan.Def, FireDAC.Stan.Pool, FireDAC.Stan.Async, FireDAC.Phys,
FireDAC.Phys.SQLite, FireDAC.Phys.SQLiteDef, FireDAC.Stan.ExprFuncs,
FireDAC.VCLUI.Wait, FireDAC.Phys.SQLiteWrapper.Stat, Data.DB,
FireDAC.Comp.Client, FireDAC.Stan.Param, FireDAC.DatS, FireDAC.DApt.Intf,
FireDAC.DApt, FireDAC.Comp.DataSet, uAntiTamperPackage, uBasicProtection;
type
// 打赏地址类型
TDonationAddressType = (datWechat, datAlipay, datBTC, datUSDT, datAboutMe);
// 图像映射记录类型(修复E2169:不能在字段处定义匿名record)
TImageMapping = record
Key: string;
Image: TImage;
AddressLabel: TLabel;
DefaultAddress: string;
end;
{ MigrateEncryptedImages implementation moved to implementation section }
TFrameAboutMe = class(TFrame)
pcAboutMe: TPageControl;
tsWechat: TTabSheet;
tsAlipay: TTabSheet;
tsBTC: TTabSheet;
tsUSDT: TTabSheet;
tsAboutMe: TTabSheet;
// 微信页面
imgWechat: TImage;
lblWechatTip: TLabel;
lblWechatAddress: TLabel;
// 支付宝页面
imgAlipay: TImage;
lblAlipayTip: TLabel;
lblAlipayAddress: TLabel;
// BTC页面
imgBTC: TImage;
lblBTCTip: TLabel;
lblBTCAddress: TLabel;
btnCopyBTC: TButton;
// USDT页面
imgUSDT: TImage;
lblUSDTTip: TLabel;
lblUSDTAddress: TLabel;
btnCopyUSDT: TButton;
// 关于我页面
imgAboutMe: TImage;
lblAboutMeTip: TLabel;
lblMachineCode: TLabel;
lblMachineCodeValue: TLabel;
FDConnection1: TFDConnection;
FDPhysSQLiteDriverLink1: TFDPhysSQLiteDriverLink;
FDTable1: TFDTable;
procedure btnCopyBTCClick(Sender: TObject);
procedure btnCopyUSDTClick(Sender: TObject);
procedure lblMachineCodeValueClick(Sender: TObject);
procedure pcAboutMeDrawTab(Control: TCustomTabControl; TabIndex: Integer;
const Rect: TRect; Active: Boolean);
private
// 字段应在方法之前声明,避免E2169
FInitTimer: TTimer;
FImageMappings: array[0..4] of TImageMapping;
// 日志与内部方法
procedure Log(const Msg: string);
procedure InitializeDataManager;
procedure MigrateEncryptedImages; // 迁移旧加密数据为固定口令方案
procedure LoadAndDisplayImages;
procedure InitializeImageMappings;
procedure EnsureDefaultImagesPresent;
procedure OnInitTimerTimer(Sender: TObject);
function GetProjectRootPath: string;
// UI更新
procedure CopyAddressToClipboard(const Address: string; const AddressName: string);
function GenerateMachineCode: string;
procedure UpdateMachineCodeDisplay;
public
constructor Create(AOwner: TComponent); override;
procedure AfterConstruction; override;
destructor Destroy; override;
procedure ManualInitialize;
// 公共接口
procedure RotateToNextPage;
function GetCurrentPageIndex: Integer;
procedure SetActivePage(PageIndex: Integer);
end;
implementation
{$R *.dfm}
procedure TFrameAboutMe.Log(const Msg: string);
var
LogFileName: string;
Writer: TStreamWriter;
begin
try
LogFileName := GetProjectRootPath + 'aboutme_debug.log';
Writer := TStreamWriter.Create(LogFileName, True, TEncoding.UTF8);
try
Writer.WriteLine(Format('[%s] %s', [DateTimeToStr(Now), Msg]));
finally
Writer.Free;
end;
except
// 静默失败,防止日志记录本身导致崩溃
end;
end;
constructor TFrameAboutMe.Create(AOwner: TComponent);
var
LogFile: TextFile;
begin
inherited Create(AOwner);
Log('FrameAboutMe.Create 开始执行');
// 设置PageControl的OnDrawTab事件
pcAboutMe.OwnerDraw := True;
pcAboutMe.OnDrawTab := pcAboutMeDrawTab;
// 更新机器码显示
UpdateMachineCodeDisplay;
Log('基本设置完成,创建Timer');
// 创建延迟初始化Timer
FInitTimer := TTimer.Create(Self);
FInitTimer.Interval := 1000; // 1秒后初始化
FInitTimer.OnTimer := OnInitTimerTimer;
FInitTimer.Enabled := True;
Log('FrameAboutMe.Create 完成');
end;
procedure TFrameAboutMe.AfterConstruction;
begin
inherited AfterConstruction;
// 不在这里初始化,等待主窗体手动调用
end;
procedure TFrameAboutMe.ManualInitialize;
begin
// 手动初始化方法,由主窗体调用
InitializeDataManager;
EnsureDefaultImagesPresent;
LoadAndDisplayImages;
end;
procedure TFrameAboutMe.OnInitTimerTimer(Sender: TObject);
var
LogFile: TextFile;
begin
// 停止Timer
FInitTimer.Enabled := False;
Log('Timer触发,开始延迟初始化');
// 执行延迟初始化
InitializeDataManager;
EnsureDefaultImagesPresent;
LoadAndDisplayImages;
Log('延迟初始化完成');
end;
destructor TFrameAboutMe.Destroy;
begin
// 设计时组件会自动释放,无需手动释放
inherited;
end;
procedure TFrameAboutMe.InitializeDataManager;
var
LogFile: TextFile;
LogFileName: string;
DatabasePath: string;
begin
try
LogFileName := GetProjectRootPath + 'aboutme_debug.log';
// 启动时强制清空日志文件(截断为0字节)
try
TFile.WriteAllText(LogFileName, '');
except
// 忽略清空日志的异常
end;
Log('InitializeDataManager started');
Log('Project root directory: ' + GetProjectRootPath);
// 设置动态数据库路径
DatabasePath := GetProjectRootPath + 'MoveC.db';
Log('Setting database path: ' + DatabasePath);
// 检查数据库文件是否存在
if not TFile.Exists(DatabasePath) then
begin
Log('Database file does not exist: ' + DatabasePath);
raise Exception.Create('Database file not found');
end;
// 设置数据库连接字符串
Log('Setting up database connection');
FDConnection1.Params.Values['Database'] := DatabasePath;
// Note: Password is not set here as encryption is handled at application level
// 绑定表到 images(防止设计时指向错误的表)
FDTable1.Connection := FDConnection1;
FDTable1.TableName := 'images';
// 检查设计时数据库组件状态
Log('Checking design-time database components:');
Log(' FDConnection1.Connected: ' + BoolToStr(FDConnection1.Connected, True));
Log(' FDTable1.Active: ' + BoolToStr(FDTable1.Active, True));
Log(' Database path: ' + FDConnection1.Params.Values['Database']);
Log(' FDTable1.TableName: ' + FDTable1.TableName);
// 如果连接未激活,尝试激活
if not FDConnection1.Connected then
begin
Log('Attempting to activate database connection');
try
FDConnection1.Connected := True;
Log('Database connection activated successfully');
except
on E: Exception do
begin
Log('Database connection activation failed: ' + E.Message);
raise;
end;
end;
end;
// 如果表未激活,尝试激活
if not FDTable1.Active then
begin
Log('Attempting to activate data table');
try
FDTable1.Active := True;
Log('Data table activated successfully');
except
on E: Exception do
begin
Log('Data table activation failed: ' + E.Message);
raise;
end;
end;
end;
// 在加载图像前执行一次性迁移(将旧加密改为“仅固定口令”方案)
MigrateEncryptedImages;
// 初始化图像映射数组
InitializeImageMappings;
// 自愈:确保默认5张图像存在
EnsureDefaultImagesPresent;
except
on E: Exception do
begin
// 记录错误但不中断程序
Log('InitializeDataManager failed: ' + E.Message);
end;
end;
end;
function TFrameAboutMe.GetProjectRootPath: string;
var
CurrentPath: string;
TestPath: string;
SearchCount: Integer;
begin
// 获取当前程序路径
CurrentPath := ExtractFilePath(ParamStr(0));
SearchCount := 0;
// 向上查找项目根目录,直到找到MoveC.db文件
while (CurrentPath <> '') and (SearchCount < 5) do
begin
TestPath := IncludeTrailingPathDelimiter(CurrentPath) + 'MoveC.db';
if TFile.Exists(TestPath) then
begin
Result := IncludeTrailingPathDelimiter(CurrentPath);
Exit;
end;
// 向上一级目录
CurrentPath := ExtractFilePath(ExcludeTrailingPathDelimiter(CurrentPath));
Inc(SearchCount);
end;
// 如果没找到,使用程序当前目录
Result := ExtractFilePath(ParamStr(0));
end;
procedure TFrameAboutMe.MigrateEncryptedImages;
begin
// 迁移功能已废弃,不再需要兼容旧加密方式
// 所有图像应使用ImportImages工具重新导入
end;
procedure TFrameAboutMe.EnsureDefaultImagesPresent;
begin
// 已禁用:不再从 Assets 插入任何默认图像
Exit;
end;
procedure TFrameAboutMe.InitializeImageMappings;
var
LogFile: TextFile;
LogFileName: string;
begin
LogFileName := GetProjectRootPath + 'aboutme_debug.log';
Log('开始初始化图像映射数组');
Log('验证Image控件分配状态:');
Log(Format(' imgWechat: %s (地址: %p)', [BoolToStr(Assigned(imgWechat), True), Pointer(imgWechat)]));
Log(Format(' imgAlipay: %s (地址: %p)', [BoolToStr(Assigned(imgAlipay), True), Pointer(imgAlipay)]));
Log(Format(' imgBTC: %s (地址: %p)', [BoolToStr(Assigned(imgBTC), True), Pointer(imgBTC)]));
Log(Format(' imgUSDT: %s (地址: %p)', [BoolToStr(Assigned(imgUSDT), True), Pointer(imgUSDT)]));
Log(Format(' imgAboutMe: %s (地址: %p)', [BoolToStr(Assigned(imgAboutMe), True), Pointer(imgAboutMe)]));
Log('Frame状态检查:');
Log(Format(' Frame.Parent: %s', [BoolToStr(Assigned(Parent), True)]));
Log(Format(' Frame.Visible: %s', [BoolToStr(Visible, True)]));
Log(Format(' Frame.ComponentCount: %d', [ComponentCount]));
FImageMappings[0].Key := 'wechat';
FImageMappings[0].Image := imgWechat;
FImageMappings[0].AddressLabel := lblWechatAddress;
FImageMappings[0].DefaultAddress := '微信收款码';
FImageMappings[1].Key := 'alipay';
FImageMappings[1].Image := imgAlipay;
FImageMappings[1].AddressLabel := lblAlipayAddress;
FImageMappings[1].DefaultAddress := '支付宝收款码';
FImageMappings[2].Key := 'btc';
FImageMappings[2].Image := imgBTC;
FImageMappings[2].AddressLabel := lblBTCAddress;
FImageMappings[2].DefaultAddress := 'BTC地址';
FImageMappings[3].Key := 'usdt';
FImageMappings[3].Image := imgUSDT;
FImageMappings[3].AddressLabel := lblUSDTAddress;
FImageMappings[3].DefaultAddress := 'USDT地址';
FImageMappings[4].Key := 'aboutme';
FImageMappings[4].Image := imgAboutMe;
FImageMappings[4].AddressLabel := nil;
FImageMappings[4].DefaultAddress := '';
Log('图像映射数组初始化完成');
end;
procedure TFrameAboutMe.LoadAndDisplayImages;
var
I: Integer;
AddressText: string;
begin
Log('开始加载和显示图像');
try
for I := 0 to High(FImageMappings) do
begin
Log(Format('处理图像 %d: %s', [I, FImageMappings[I].Key]));
if FDTable1.Active and Assigned(FImageMappings[I].Image) then
begin
try
// 使用 TAntiTamperPackage.LoadSecureImage 统一处理解密和校验
// 该方法内部处理 AES-256 解密、SHA-256 校验和 HMAC 校验
if TAntiTamperPackage.LoadSecureImage(
FDTable1,
FImageMappings[I].Key,
FImageMappings[I].Image,
AddressText) then
begin
Log(Format('图像加载成功: %s', [FImageMappings[I].Key]));
// 设置地址标签
if Assigned(FImageMappings[I].AddressLabel) then
begin
if AddressText <> '' then
FImageMappings[I].AddressLabel.Caption := AddressText
else
FImageMappings[I].AddressLabel.Caption := FImageMappings[I].DefaultAddress;
end;
end
else
begin
Log(Format('图像加载失败或未找到: %s', [FImageMappings[I].Key]));
end;
except
on E: Exception do
Log(Format('处理图像时异常: %s - %s', [FImageMappings[I].Key, E.Message]));
end;
end
else
begin
Log(Format('数据表未激活或Image控件未分配: %s', [FImageMappings[I].Key]));
end;
end;
except
on E: Exception do
Log(Format('LoadAndDisplayImages顶层异常: %s', [E.Message]));
end;
end;
// 旧方法已删除
// 旧方法已删除
// SaveImageToDebugFolder方法已删除
procedure TFrameAboutMe.btnCopyBTCClick(Sender: TObject);
var
BTCAddress: string;
AddressField: TField;
begin
if FDTable1.Active then
begin
if FDTable1.Locate('image_key', 'btc', []) then
begin
AddressField := FDTable1.FieldByName('address_text');
if not AddressField.IsNull and (AddressField.AsString <> '') then
BTCAddress := AddressField.AsString
else
BTCAddress := 'BTC地址未配置';
end
else
BTCAddress := 'BTC记录未找到';
CopyAddressToClipboard(BTCAddress, 'BTC地址');
end
else
CopyAddressToClipboard('数据库未连接', 'BTC地址');
end;
procedure TFrameAboutMe.btnCopyUSDTClick(Sender: TObject);
var
USDTAddress: string;
AddressField: TField;
begin
if FDTable1.Active then
begin
if FDTable1.Locate('image_key', 'usdt', []) then
begin
AddressField := FDTable1.FieldByName('address_text');
if not AddressField.IsNull and (AddressField.AsString <> '') then
USDTAddress := AddressField.AsString
else
USDTAddress := 'USDT地址未配置';
end
else
USDTAddress := 'USDT记录未找到';
CopyAddressToClipboard(USDTAddress, 'USDT地址');
end
else
CopyAddressToClipboard('数据库未连接', 'USDT地址');
end;
procedure TFrameAboutMe.CopyAddressToClipboard(const Address: string; const AddressName: string);
begin
try
Clipboard.AsText := Address;
// 地址已复制到剪贴板
except
on E: Exception do
// 复制失败,但不显示错误
end;
end;
procedure TFrameAboutMe.RotateToNextPage;
var
NextIndex: Integer;
begin
NextIndex := (pcAboutMe.ActivePageIndex + 1) mod pcAboutMe.PageCount;
pcAboutMe.ActivePageIndex := NextIndex;
end;
function TFrameAboutMe.GetCurrentPageIndex: Integer;
begin
Result := pcAboutMe.ActivePageIndex;
end;
procedure TFrameAboutMe.SetActivePage(PageIndex: Integer);
begin
if (PageIndex >= 0) and (PageIndex < pcAboutMe.PageCount) then
begin
pcAboutMe.ActivePageIndex := PageIndex;
end;
end;
function TFrameAboutMe.GenerateMachineCode: string;
var
ComputerName: array[0..MAX_COMPUTERNAME_LENGTH] of Char;
Size: DWORD;
HashValue: string;
begin
try
Size := SizeOf(ComputerName);
if GetComputerName(ComputerName, Size) then
begin
HashValue := THashSHA2.GetHashString(string(ComputerName) + IntToStr(GetTickCount64), SHA256);
Result := Copy(HashValue, 1, 16).ToUpper;
Result := Copy(Result, 1, 4) + '-' + Copy(Result, 5, 4) + '-' +
Copy(Result, 9, 4) + '-' + Copy(Result, 13, 4);
end
else
Result := 'ERROR-GENE-RATE-CODE';
except
Result := 'ERROR-GENE-RATE-CODE';
end;
end;
procedure TFrameAboutMe.UpdateMachineCodeDisplay;
begin
try
lblMachineCodeValue.Caption := GenerateMachineCode;
lblMachineCodeValue.Hint := '点击复制机器码到剪贴板';
except
lblMachineCodeValue.Caption := 'ERROR-DISPLAY';
end;
end;
procedure TFrameAboutMe.lblMachineCodeValueClick(Sender: TObject);
begin
try
Clipboard.AsText := lblMachineCodeValue.Caption;
ShowMessage('机器码已复制到剪贴板: ' + lblMachineCodeValue.Caption);
except
on E: Exception do
begin
ShowMessage('复制机器码失败: ' + E.Message);
end;
end;
end;
procedure TFrameAboutMe.pcAboutMeDrawTab(Control: TCustomTabControl; TabIndex: Integer;
const Rect: TRect; Active: Boolean);
var
TabControl: TPageControl;
Canvas: TCanvas;
TabRect: TRect;
TextRect: TRect;
TabText: string;
ActiveColor, InactiveColor, TextColor: TColor;
begin
TabControl := Control as TPageControl;
Canvas := TabControl.Canvas;
TabRect := Rect;
// 设置颜色
ActiveColor := $FF6B35; // 橙色高亮
InactiveColor := clBtnFace;
TextColor := clWindowText;
// 绘制tab背景
if Active then
begin
Canvas.Brush.Color := ActiveColor;
Canvas.Pen.Color := ActiveColor;
Canvas.FillRect(TabRect);
Canvas.Pen.Color := RGB(255, 255, 255);
Canvas.Pen.Width := 2;
Canvas.MoveTo(TabRect.Left, TabRect.Top);
Canvas.LineTo(TabRect.Right, TabRect.Top);
end
else
begin
Canvas.Brush.Color := InactiveColor;
Canvas.Pen.Color := InactiveColor;
Canvas.FillRect(TabRect);
end;
// 绘制tab文本
if (TabIndex >= 0) and (TabIndex < TabControl.PageCount) then
begin
TabText := TabControl.Pages[TabIndex].Caption;
Canvas.Brush.Style := bsClear;
Canvas.Font.Color := TextColor;
if Active then
begin
Canvas.Font.Style := [fsBold];
Canvas.Font.Color := clWhite;
end
else
begin
Canvas.Font.Style := [];
end;
TextRect := TabRect;
DrawText(Canvas.Handle, PChar(TabText), Length(TabText), TextRect,
DT_CENTER or DT_VCENTER or DT_SINGLELINE);
end;
end;
// LogMessage方法已删除
end.