Repository navigation
Expand file tree
/
Copy pathUnit1.cpp
More file actions
3473 lines (2829 loc) · 110 KB
/
Copy pathUnit1.cpp
File metadata and controls
3473 lines (2829 loc) · 110 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
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//===========================================================================
/*
アタッシェケース(AttachéCase)
Copyright (c) 2002-2018, Mitsuhiro Hibara ( http://hibara.org )
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the following
conditions are met:
・Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
・Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
・Neither the name of the "HIBARA.ORG" nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
//===========================================================================
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
#if __CODEGEARC__ < 0x640
#pragma link "HTMLHelpViewer"
#else
#pragma link "Vcl.HTMLHelpViewer"
#endif
TForm1 *Form1;
TDragAndDrop *DragAndDropTarget;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
int i;
//サイドメニューグラフィック
bmpSideMenu = new Graphics::TBitmap;
bmpSideMenu->Canvas->Brush->Style = bsClear;
//アプリケーションタイトル
this->Caption = Application->Title;
//ページコントロールのタブを非表示に
PageControl1->Align = alClient;
for (i = 0; i < PageControl1->PageCount; i++) {
PageControl1->Pages[i]->TabVisible = false;
}
//メインパネル表示
PageControl1->ActivePageIndex = 0;
PaintBoxMain->Align = alClient;
PaintBoxEncrypt->Align = alClient;
PaintBoxConfirm->Align = alClient;
PaintBoxDecrypt->Align = alClient;
//動作設定インスタンスの作成
opthdl = new TAttacheCaseOptionHandle();
//動作設定のINIファイルパス
String IniFilePath = "";
//処理するファイルリスト
FileList = new TStringList;
//削除するファイルリスト
DeleteFileList = new TStringList;
lblMain->Caption = LoadResourceString(&Msgunit1::_DRAG_AND_DROP_HERE);
txtEncryptPassword->EditLabel->Caption = LoadResourceString(&Msgunit1::_INPUT_PASSWORD);
chkExeFileOut->Caption = LoadResourceString(&Msgunit1::_CHECK_BOX_EXEFILE_OUT);
txtPasswordConfirm->EditLabel->Caption = LoadResourceString(&Msgunit1::_CONFIRM_PASSWORD);
chkExeFileOutConf->Caption = LoadResourceString(&Msgunit1::_CHECK_BOX_EXEFILE_OUT);
txtDecryptPassword->EditLabel->Caption = LoadResourceString(&Msgunit1::_INPUT_DECRYPT_PASSWORD);
chkDeleteSourceData->Caption = LoadResourceString(&Msgunit1::_CHECK_BOX_DELETE_SOURCE_DATA);
chkDeleteSourceDataConf->Caption = chkDeleteSourceData->Caption;
chkDeleteAtcData->Caption = LoadResourceString(&Msgunit1::_CHECK_BOX_DELETE_ATC_DATA);
lblStatus->Caption = "-";
lblMsg->Caption = "-";
lblProgressPercentNum->Caption = "- %";
//サイドバーメニューキャプション
SideBarCaption[1] = LoadResourceString(&Msgunit1::_SIDEBAR_CAPTION_ENCRYPT);
SideBarCaption[2] = LoadResourceString(&Msgunit1::_SIDEBAR_CAPTION_DECRYPT);
SideBarCaption[4] = LoadResourceString(&Msgunit1::_SIDEBAR_CAPTION_OPTION);
SideBarCaptionPosX[1] = PaintBoxMenu->Width/2 - PaintBoxMenu->Canvas->TextWidth(SideBarCaption[1])/2;
SideBarCaptionPosX[2] = PaintBoxMenu->Width/2 - PaintBoxMenu->Canvas->TextWidth(SideBarCaption[2])/2;
SideBarCaptionPosX[4] = PaintBoxMenu->Width/2 - PaintBoxMenu->Canvas->TextWidth(SideBarCaption[4])/2;
//-----------------------------------
//ダイアログ周り
//-----------------------------------
//'暗号化するファイルを開く'
OpenDialogEncrypt->Title = LoadResourceString(&Msgunit1::_DIALOG_OPEN_FILES_FOR_ENCRYPTION_TITLE);
//'すべてのファイル(*.*)|*.*'
OpenDialogEncrypt->Filter = LoadResourceString(&Msgunit1::_DIALOG_OPEN_FILES_FOR_ENCRYPTION_FILTER);
//'復号するアタッシェケースファイルを開く'
OpenDialogDecrypt->Title = LoadResourceString(&Msgunit1::_DIALOG_OPEN_FILES_FOR_DECRYPTION_TITLE);
//'アタッシェケースファイル(*.atc)|*.atc|すべてのファイル(*.*)|*.*';
OpenDialogDecrypt->Filter = LoadResourceString(&Msgunit1::_DIALOG_OPEN_FILES_FOR_DECRYPTION_FINTER);
//'暗号化されたアタッシェケースファイル名の入力';
SaveDialog1->Title = LoadResourceString(&Msgunit1::_DIALOG_SAVE_FILES_FOR_ENCRYPTION_TITLE);
//'アタッシェケースファイル(*.atc)|*.atc|実行形式ファイル(*.exe)|(*.exe)|すべてのファイル(*.*)|*.*';
SaveDialog1->Filter = LoadResourceString(&Msgunit1::_DIALOG_SAVE_FILES_FOR_ENCRYPTION_FILTER);
//-----------------------------------
//動作設定を読み込む
//-----------------------------------
// コマンドライン引数がある
if ( ParamCount() > 0){
opthdl->LoadOptionDataFromParamString(FileList);
//ファイルリストがあれば、その同ディレクトリにINIファイルがあるか?
for (i = 0; i < FileList->Count; i++) {
if ( DirectoryExists(FileList->Strings[i]) == true ){
//フォルダならその中にあるファイル
IniFilePath = IncludeTrailingPathDelimiter(FileList->Strings[i])+INI_FILE_NAME;
}
else {
//ファイルなら同じディレクトリから
IniFilePath = IncludeTrailingPathDelimiter(ExtractFileDir(FileList->Strings[i]))+INI_FILE_NAME;
}
if (FileExists(IniFilePath) == true) {
break;
}
}
if (FileExists(IniFilePath) == false ) {
//カレントディレクトリに設定INIファイルがあるか?
IniFilePath = IncludeTrailingPathDelimiter(GetCurrentDir())+INI_FILE_NAME;
if ( FileExists(IniFilePath) == false ){
//なければ本体ディレクトリから、なければレジストリから読み込む
IniFilePath = IncludeTrailingPathDelimiter(ExtractFileDir(Application->ExeName))+INI_FILE_NAME;
opthdl->LoadOptionData(IniFilePath);
}
}
//もう一度、その上からコマンドライン引数を上書きする
opthdl->LoadOptionDataFromParamString(FileList);
}
else{
//-----------------------------------
// INIファイルがあればそこから、
// なければレジストリから読み込む
//-----------------------------------
//カレントディレクトリに設定INIファイルがあるか?
IniFilePath = IncludeTrailingPathDelimiter(GetCurrentDir())+INI_FILE_NAME;
if ( FileExists(IniFilePath) == true ){
opthdl->LoadOptionData(IniFilePath);
}
else{
//なければ本体ディレクトリから、なければレジストリから読み込む
IniFilePath = IncludeTrailingPathDelimiter(ExtractFileDir(Application->ExeName))+INI_FILE_NAME;
opthdl->LoadOptionData(IniFilePath);
}
}
//-----------------------------------
//各コンポーネントの配置
//-----------------------------------
SetFormComponent(NULL);
//-----------------------------------
//ウィンドウポジション
//-----------------------------------
this->Width = opthdl->FormWidth;
this->Height = opthdl->FormHeight;
this->Top = opthdl->FormTop;
this->Left = opthdl->FormLeft;
//-----------------------------------
//タスクトレイにアイコンを表示する
if (opthdl->fTaskTrayIcon == true) {
TrayIcon1->Visible = true;
}
else{
TrayIcon1->Visible = false;
}
//-----------------------------------
//サイドメニューを描画する
//-----------------------------------
PaintSideMenu();
//-----------------------------------
//ドラッグ&ドロップクラス
//-----------------------------------
Form1->Show();
//FormをShow()してからでないと呼び出せない
OleInitialize(NULL);
DragAndDropTarget = new TDragAndDrop(Form1);
DragAndDropTarget->FilesDragOver = FilesDragOver;
DragAndDropTarget->FilesDragLeave = FilesDragLeave;
DragAndDropTarget->FilesDragEnd = FilesDragEnd;
RegisterDragDrop(Form1->Handle, (IDropTarget*)DragAndDropTarget);
//コマンドライン引数にファイルが投げ込まれてきている
if ( FileList->Count > 0 ) {
//フォルダ内のファイルは個別に暗号化/復号する
if (opthdl->fFilesOneByOne == true ) {
ExpandFileList(FileList);
}
//暗号化/復号処理を自動判定し実行する
DoExecute(FileList);
}
else{
//メインパネルを通常表示
PageControlActiveSheet(TabSheetMain);
}
//-----------------------------------
//フォームの状態
//-----------------------------------
//最小化
if ( opthdl->WinStyle == 1 ) {
this->WindowState = wsMinimized;
}
//最大化
else if ( opthdl->WinStyle == 2 ) {
this->WindowState = wsMaximized;
}
else{
this->WindowState = wsNormal;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
//
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormDestroy(TObject *Sender)
{
//-----------------------------------
//ウィンドウポジションなどを記憶する
//-----------------------------------
opthdl->FormWidth = this->Width;
opthdl->FormHeight = this->Height;
opthdl->FormTop = this->Top;
opthdl->FormLeft = this->Left;
if ( this->WindowState == wsMinimized ){ //最小化
opthdl->WinStyle = 1;
}
else if ( Form1->WindowState == wsMaximized ){ //最大化
opthdl->WinStyle = 2;
}
else{
opthdl->WinStyle = 0;
}
//全設定を保存する
opthdl->SaveOptionData();
delete opthdl;
delete DeleteFileList; //削除するファイルリスト
delete FileList; //処理するファイルリスト
//-----------------------------------
//OLEドラッグ&ドロップの後始末
//-----------------------------------
RevokeDragDrop(Form1->Handle);
DragAndDropTarget->Release();
OleUninitialize();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormShow(TObject *Sender)
{
//
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift)
{
if (Key == VK_ESCAPE) {
Close();
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormResize(TObject *Sender)
{
//-----------------------------------
//各コンポーネントの配置
//-----------------------------------
SetFormComponent(Sender);
//-----------------------------------
//各メニューアイコンの位置・描画
//-----------------------------------
const int posX = 22;
//「オプション」
ptSideMenu[4].x = posX;
ptSideMenu[4].y = PaintBoxMenu->Height - 72;
// 分割線
ptSideMenu[3].x = posX;
ptSideMenu[3].y = ptSideMenu[4].y - 30;
// 中央配置
ptSideMenu[0].x = posX;
ptSideMenu[0].y = PaintBoxMenu->Height/2 - 36;
//「暗号化」
ptSideMenu[1].x = posX;
ptSideMenu[1].y = 16;
//「復号する」
ptSideMenu[2].x = posX;
ptSideMenu[2].y = ptSideMenu[1].y + 90;
//サイドメニューを再描画する
PaintSideMenu();
}
//---------------------------------------------------------------------------
//ジェスチャ(タッチ)イベント
//---------------------------------------------------------------------------
void __fastcall TForm1::FormGesture(TObject *Sender, const TGestureEventInfo &EventInfo,
bool &Handled)
{
int PosX, PosY;
switch(EventInfo.GestureID){
//igZoom
case 259:
Handled = true;
if(EventInfo.Flags.Contains(gfBegin) == true){ //ズーム開始
//基準座標を保存
TouchFormStartPos.x = (int)EventInfo.Location.x;
TouchFormStartPos.y = (int)EventInfo.Location.y;
TouchFormWidth = Form1->Width;
TouchFormHeight = Form1->Height;
}
else if (EventInfo.Flags.Contains(gfInertia) == true ){ //イナーシャ中
}
else if ( EventInfo.Flags.Contains(gfEnd) == true ){ //ズーム終了
TouchFormStartPos = TPoint(0,0);
TouchFormWidth = Form1->Width;
TouchFormHeight = Form1->Height;
}
else{
PosX = TouchFormStartPos.x - (int)EventInfo.Location.x;
PosY = TouchFormStartPos.y - (int)EventInfo.Location.y;
//フォームをそれに伴って拡大縮小する
Form1->Width = TouchFormWidth - PosX*2;
Form1->Height = TouchFormHeight - PosY*2;
}
break;
default:
break;
}//switch;
}
//---------------------------------------------------------------------------
//フォーム内コンポーネントを配置する
//---------------------------------------------------------------------------
void __fastcall TForm1::SetFormComponent(TObject *Sender)
{
//-----------------------------------
//デスクトップで最前面にウィンドウを表示するか
//-----------------------------------
if ( opthdl->fWindowForeground == true ){
this->FormStyle = fsStayOnTop;
}
else{
this->FormStyle = fsNormal;
}
//-----------------------------------
//メインパネル
//-----------------------------------
lblMain->Left = TabSheetMain->Width/2 - lblMain->Width/2;
lblMain->Top = TabSheetMain->Height/2 - lblMain->Height/2 - 32;
//-----------------------------------
//暗号化パスワード入力パネル
//-----------------------------------
txtEncryptPassword->Left = 24;
txtEncryptPassword->Top = TabSheetInputEncPass->Height/2 - txtEncryptPassword->Height;
txtEncryptPassword->Width = TabSheetInputEncPass->Width - txtEncryptPassword->Left*2;
//チェックボックス
chkExeFileOut->Top = txtEncryptPassword->BoundsRect.Bottom + 8;
chkExeFileOut->Left = txtEncryptPassword->Left;
chkExeFileOut->Width = txtEncryptPassword->Width;
chkDeleteSourceData->Left = chkExeFileOut->Left;
chkDeleteSourceData->Top = chkExeFileOut->BoundsRect.Bottom + 8;
//各ボタン
cmdEncryptPasswordCancel->Top = chkDeleteSourceData->BoundsRect.Bottom + 8;
cmdEncryptPasswordCancel->Left = chkExeFileOut->BoundsRect.Right - cmdEncryptPasswordCancel->Width;
cmdEncryptPasswordOK->Top = cmdEncryptPasswordCancel->Top;
cmdEncryptPasswordOK->Left = cmdEncryptPasswordCancel->Left - cmdEncryptPasswordOK->Width - 8;
//戻るボタン
imgBackFromInputEncPass->Picture = imgBackNormal->Picture;
//-----------------------------------
//暗号化パスワード再確認パネル
//-----------------------------------
txtPasswordConfirm->Left = 24;
txtPasswordConfirm->Top = TabSheetInputEncPassConfirm->Height/2 - txtPasswordConfirm->Height;
txtPasswordConfirm->Width = TabSheetInputEncPassConfirm->Width - txtPasswordConfirm->Left*2;
//チェックボックス
chkExeFileOutConf->Top = txtPasswordConfirm->BoundsRect.Bottom + 8;
chkExeFileOutConf->Left = txtPasswordConfirm->Left;
chkExeFileOutConf->Width = txtPasswordConfirm->Width;
chkDeleteSourceDataConf->Left = chkExeFileOutConf->Left;
chkDeleteSourceDataConf->Top = chkExeFileOutConf->BoundsRect.Bottom + 8;
//各ボタン
cmdConfirmCancel->Top = chkDeleteSourceDataConf->BoundsRect.Bottom + 8;
cmdConfirmCancel->Left = chkExeFileOutConf->BoundsRect.Right - cmdConfirmCancel->Width;
cmdConfirmOK->Top = cmdConfirmCancel->Top;
cmdConfirmOK->Left = cmdConfirmCancel->Left - cmdConfirmOK->Width - 8;
//戻るボタン
imgBackFromInputEncPassConfirm->Picture = imgBackNormal->Picture;
//-----------------------------------
//復号パスワード入力パネル
//-----------------------------------
txtDecryptPassword->Left = 24;
txtDecryptPassword->Top = TabSheetInputDecPass->Height/2 - txtDecryptPassword->Height;
txtDecryptPassword->Width = TabSheetInputDecPass->Width - txtDecryptPassword->Left*2;
//「暗号化ファイルを削除する」チェックボックス
chkDeleteAtcData->Top = txtDecryptPassword->BoundsRect.Bottom + 8;
chkDeleteAtcData->Left = txtDecryptPassword->Left;
chkDeleteAtcData->Width = txtDecryptPassword->Width;
//各ボタン
cmdDecryptPasswordCancel->Top = chkDeleteAtcData->BoundsRect.Bottom + 8;
cmdDecryptPasswordCancel->Left = txtDecryptPassword->BoundsRect.Right - cmdDecryptPasswordCancel->Width;
cmdDecryptPasswordOK->Top = cmdDecryptPasswordCancel->Top;
cmdDecryptPasswordOK->Left = cmdDecryptPasswordCancel->Left - cmdDecryptPasswordOK->Width - 8;
//戻るボタン
imgBackFromInputDecPass->Picture = imgBackNormal->Picture;
//-----------------------------------
//実行パネル
//-----------------------------------
ProgressBar1->Left = 24;
ProgressBar1->Top = TabSheetExecute->Height/2 - ProgressBar1->Height;
ProgressBar1->Width =TabSheetExecute->Width - ProgressBar1->Left*2;
lblMsg->Left = ProgressBar1->Left;
lblMsg->Top = ProgressBar1->Top - lblMsg->Height*2 - 8;
lblProgressPercentNum->Top = ProgressBar1->Top + ProgressBar1->Height + 8;
lblProgressPercentNum->Left =
ProgressBar1->Left + ProgressBar1->Width/2 - lblProgressPercentNum->Width/2;
lblStatus->Left = ProgressBar1->Left;
lblStatus->Top = lblMsg->Top - lblStatus->Height - 8;
cmdCancel->Top = ProgressBar1->BoundsRect.Bottom + 8;
cmdCancel->Left = ProgressBar1->BoundsRect.Right - cmdCancel->Width;
//戻るボタン
imgBackFromExecute->Picture = imgBackNormal->Picture;
if (TimerEncrypt->Enabled == false && TimerDecrypt->Enabled == false && TimerDelete->Enabled == false) {
imgBackFromExecute->Visible = true;
}
else{
imgBackFromExecute->Visible = false;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::PaintBoxMainMouseEnter(TObject *Sender)
{
//点線枠を表示する
#define DOT_HEIGHT 4
#define DOT_WIDTH 4
int PosX, PosY;
this->Canvas->Pen->Color = TColor(RGB(200,200,200));
this->Canvas->Brush->Color = TColor(RGB(200,200,200));
//水平線を描画
PosY = PageControl1->BoundsRect.bottom;
for (PosX = (PageControl1->BoundsRect.left - DOT_WIDTH); PosX < this->Width; PosX+=24) {
this->Canvas->Rectangle(PosX, 0, PosX+16, DOT_HEIGHT); //Top
this->Canvas->Rectangle(PosX, PosY, PosX+16, PosY+DOT_HEIGHT); //Bottom
}
//垂直線を描画
for (PosY = 0; PosY < this->Height; PosY+=24) {
this->Canvas->Rectangle(PageControl1->Left-DOT_WIDTH, PosY, PageControl1->Left+DOT_WIDTH, PosY+16);
this->Canvas->Rectangle(PageControl1->BoundsRect.right, PosY, PosX+DOT_WIDTH, PosY+16);
}
//ドロップ矢印
PaintBoxMain->Canvas->Draw(
PaintBoxMain->Width/2-imgArrow->Width/2, lblMain->BoundsRect.Bottom+8,
imgArrow->Picture->Icon);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::PaintBoxMainMouseLeave(TObject *Sender)
{
//点線枠をクリア
this->Canvas->Brush->Color = clBtnFace;
this->Canvas->FillRect(Rect(0, 0, this->Width, this->Height));
//ドロップ矢印をクリア
TRect rc = TRect(lblMain->Left, lblMain->BoundsRect.Bottom,
lblMain->BoundsRect.Right, lblMain->BoundsRect.Bottom+imgArrow->Height+8);
PaintBoxMain->Canvas->Brush->Color = clWhite;
PaintBoxMain->Canvas->FillRect(rc);
//サイドバーメニューを再描画しておく
PaintBoxMenuPaint(Sender);
}
//---------------------------------------------------------------------------
// PaintBoxをドラッグしてフォームを移動する
//---------------------------------------------------------------------------
void __fastcall TForm1::PaintBoxMainMouseDown(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
ReleaseCapture();
SendMessage(this->Handle, WM_SYSCOMMAND, SC_MOVE | 2, 0);
}
//---------------------------------------------------------------------------
// DragOver イベントのコールバック関数
//---------------------------------------------------------------------------
void __fastcall TForm1::FilesDragOver(POINTL ptl)
{
int px, py, pr, pb;
TRect rcResult;
TRect rcMouse = TRect(ptl.x-1, ptl.y-1, ptl.x+1, ptl.y+1); //マウス位置
TRect rcTarget;
//-----------------------------------
// メインパネル
//-----------------------------------
if ( PageControl1->ActivePage == TabSheetMain ) {
this->Color = TColor(RGB(80,80,80));
DragAndDropTarget->DropImageType = DROPIMAGE_COPY;
}
//-----------------------------------
// パスワード入力パネル
//-----------------------------------
else if ( PageControl1->ActivePage == TabSheetInputEncPass ) {
//パスワードファイルを許可する
if ( opthdl->fAllowPassFile == true ) {
DragAndDropTarget->fMultipleFilesOk = false;
DragAndDropTarget->DropImageType = DROPIMAGE_COPY;
//パスワード入力ボックス
px = txtEncryptPassword->Left;
py = txtEncryptPassword->Top;
pr = txtEncryptPassword->BoundsRect.Right;
pb = txtEncryptPassword->BoundsRect.Bottom;
rcTarget = Rect(ClientToScreen(TPoint(px, py)), ClientToScreen(TPoint(pr, pb)));
if (IntersectRect(rcResult, rcMouse, rcTarget) == true ) {
txtEncryptPassword->Color = TColor(0xDBEBF7); //オレンジ色
}
else{
txtEncryptPassword->Color = clBtnFace;
}
}
else{
DragAndDropTarget->DropImageType = DROPIMAGE_NONE;
}
}
//-----------------------------------
// パスワード再確認パネル
//-----------------------------------
else if ( PageControl1->ActivePage == TabSheetInputEncPassConfirm ) {
//パスワードファイルを許可する
if ( opthdl->fAllowPassFile == true ) {
DragAndDropTarget->fMultipleFilesOk = false;
DragAndDropTarget->DropImageType = DROPIMAGE_COPY;
//パスワード入力ボックス
px = txtPasswordConfirm->Left;
py = txtPasswordConfirm->Top;
pr = txtPasswordConfirm->BoundsRect.Right;
pb = txtPasswordConfirm->BoundsRect.Bottom;
rcTarget = Rect(ClientToScreen(TPoint(px, py)), ClientToScreen(TPoint(pr, pb)));
if (IntersectRect(rcResult, rcMouse, rcTarget) == true ) {
txtPasswordConfirm->Color = TColor(0x99ccff); //より濃いオレンジ色
}
else{
txtPasswordConfirm->Color = TColor(0xDBEBF7); //オレンジ色に戻す
}
}
else{
DragAndDropTarget->DropImageType = DROPIMAGE_NONE;
}
}
//-----------------------------------
// 復号パスワード入力パネル
//-----------------------------------
else if ( PageControl1->ActivePage == TabSheetInputDecPass ) {
//パスワードファイルを許可する
if ( opthdl->fAllowPassFile == true ) {
DragAndDropTarget->fMultipleFilesOk = false;
DragAndDropTarget->DropImageType = DROPIMAGE_COPY;
//パスワード入力ボックス
px = txtDecryptPassword->Left;
py = txtDecryptPassword->Top;
pr = txtDecryptPassword->BoundsRect.Right;
pb = txtDecryptPassword->BoundsRect.Bottom;
rcTarget = Rect(ClientToScreen(TPoint(px, py)), ClientToScreen(TPoint(pr, pb)));
if (IntersectRect(rcResult, rcMouse, rcTarget) == true ) {
txtDecryptPassword->Color = TColor(0xDBEBF7); //オレンジ色
}
else{
txtDecryptPassword->Color = clBtnFace;
}
}
else{
DragAndDropTarget->DropImageType = DROPIMAGE_NONE;
}
}
//-----------------------------------
// 実行中パネル
//-----------------------------------
else if ( PageControl1->ActivePage == TabSheetExecute ) {
//実行中はドロップを受け付けない
DragAndDropTarget->DropImageType = DROPIMAGE_NONE;
}
}
//---------------------------------------------------------------------------
// DragLeave イベントのコールバック関数
//---------------------------------------------------------------------------
void __fastcall TForm1::FilesDragLeave(void)
{
//-----------------------------------
// メインパネル
//-----------------------------------
if ( PageControl1->ActivePage == TabSheetMain ) {
//メインフォーム
this->Color = clBtnFace;
}
//-----------------------------------
// パスワード入力パネル
//-----------------------------------
else if ( PageControl1->ActivePage == TabSheetInputEncPass ) {
txtEncryptPassword->Color = clBtnFace;
}
//-----------------------------------
// パスワード再確認パネル
//-----------------------------------
else if ( PageControl1->ActivePage == TabSheetInputEncPassConfirm ) {
txtPasswordConfirm->Color = TColor(0xDBEBF7); //オレンジ色に戻す
}
//-----------------------------------
// 復号パスワード入力パネル
//-----------------------------------
else if ( PageControl1->ActivePage == TabSheetInputDecPass ) {
txtDecryptPassword->Color = clBtnFace;
}
//-----------------------------------
// 実行中パネル
//-----------------------------------
else if ( PageControl1->ActivePage == TabSheetExecute ) {
}
}
//---------------------------------------------------------------------------
// DragEnd イベントのコールバック関数
//---------------------------------------------------------------------------
void __fastcall TForm1::FilesDragEnd(POINTL ptl, String FileListText)
{
int px, py, pr, pb;
TRect rcResult;
TRect rcMouse = TRect(ptl.x-1, ptl.y-1, ptl.x+1, ptl.y+1); //マウス位置
TRect rcTarget;
String MsgText;
String SHA1HashPassword = "";
TStringList *DropFileList = new TStringList;
DropFileList->Text = FileListText;
//再確認用のパスワードハッシュ
AnsiString TempPasswordFileHeader;
AnsiString TempPasswordFileHash;
//-----------------------------------
// メインパネル
//-----------------------------------
if ( PageControl1->ActivePage == TabSheetMain ) {
//メインフォーム
this->Color = clBtnFace;
//ドラッグ&ドロップされたファイルリストを取得する
FileList->Text = FileListText;
//-----------------------------------
//暗号化/復号処理を自動判定し実行する
//-----------------------------------
if (FileList->Count > 0) {
Form1->Caption = ExtractFileName(FileList->Strings[0]) + " - " + Application->Title;
//フォルダ内のファイルは個別に暗号化/復号する
if (opthdl->fFilesOneByOne == true ) {
ExpandFileList(FileList);
}
DoExecute(FileList);
}
}
//-----------------------------------
// パスワード入力パネル
//-----------------------------------
else if ( PageControl1->ActivePage == TabSheetInputEncPass ) {
txtEncryptPassword->Color = clBtnFace;
//パスワードファイルを許可する
if ( opthdl->fAllowPassFile == true ) {
DragAndDropTarget->fMultipleFilesOk = false;
DragAndDropTarget->DropImageType = DROPIMAGE_COPY;
//パスワード入力ボックス
px = txtEncryptPassword->Left;
py = txtEncryptPassword->Top;
pr = txtEncryptPassword->BoundsRect.Right;
pb = txtEncryptPassword->BoundsRect.Bottom;
rcTarget = Rect(ClientToScreen(TPoint(px, py)), ClientToScreen(TPoint(pr, pb)));
if (IntersectRect(rcResult, rcMouse, rcTarget) == true && DropFileList->Count > 0) {
PasswordFilePath = DropFileList->Strings[0];
txtEncryptPassword->Text = PasswordFilePath;
//'パスワードに以下のファイルのハッシュ値が入力されました'
BalloonHint1->Title = LoadResourceString(&Msgunit1::_BALLOON_HINT_PASSWORD_HASH_TITLE);
//そのファイルパスを表示する
BalloonHint1->Description = DropFileList->Strings[0];
BalloonHint1->ShowHint(txtEncryptPassword->ClientToScreen(CenterPoint(txtEncryptPassword->ClientRect)));
txtEncryptPassword->SetFocus();
txtEncryptPassword->SelectAll();
}
}
else{
DragAndDropTarget->DropImageType = DROPIMAGE_NONE;
}
}
//-----------------------------------
// パスワード再確認パネル
//-----------------------------------
else if ( PageControl1->ActivePage == TabSheetInputEncPassConfirm ) {
txtPasswordConfirm->Color = TColor(0xDBEBF7); //オレンジ色に戻す
//パスワードファイルを許可する
if ( opthdl->fAllowPassFile == true ) {
DragAndDropTarget->fMultipleFilesOk = false;
DragAndDropTarget->DropImageType = DROPIMAGE_COPY;
//パスワード入力ボックス
px = txtPasswordConfirm->Left;
py = txtPasswordConfirm->Top;
pr = txtPasswordConfirm->BoundsRect.Right;
pb = txtPasswordConfirm->BoundsRect.Bottom;
rcTarget = Rect(ClientToScreen(TPoint(px, py)), ClientToScreen(TPoint(pr, pb)));
if (IntersectRect(rcResult, rcMouse, rcTarget) == true && DropFileList->Count > 0) {
ConfirmPasswordFilePath = DropFileList->Strings[0];
txtPasswordConfirm->Text = ConfirmPasswordFilePath;
cmdConfirmOKClick((TObject*)0);
}
}
else{
DragAndDropTarget->DropImageType = DROPIMAGE_NONE;
}
}
//-----------------------------------
// 復号パスワード入力パネル
//-----------------------------------
else if ( PageControl1->ActivePage == TabSheetInputDecPass ) {
txtDecryptPassword->Color = clBtnFace;
//パスワードファイルを許可する
if ( opthdl->fAllowPassFile == true ) {
DragAndDropTarget->fMultipleFilesOk = false;
DragAndDropTarget->DropImageType = DROPIMAGE_COPY;
//パスワード入力ボックス
px = txtDecryptPassword->Left;
py = txtDecryptPassword->Top;
pr = txtDecryptPassword->BoundsRect.Right;
pb = txtDecryptPassword->BoundsRect.Bottom;
rcTarget = Rect(ClientToScreen(TPoint(px, py)), ClientToScreen(TPoint(pr, pb)));
if (IntersectRect(rcResult, rcMouse, rcTarget) == true && DropFileList->Count > 0) {
//パスワードファイル
PasswordFilePath = DropFileList->Strings[0];
txtDecryptPassword->Text = PasswordFilePath;
cmdDecryptPasswordOKClick((TObject*)0);
}
}
else{
DragAndDropTarget->DropImageType = DROPIMAGE_NONE;
}
}
//-----------------------------------
// 実行中パネル
//-----------------------------------
else if ( PageControl1->ActivePage == TabSheetExecute ) {
}
delete DropFileList;
}
//---------------------------------------------------------------------------
//ファイルの判別を行った後に処理を分けて実行
//---------------------------------------------------------------------------
void __fastcall TForm1::DoExecute(TStringList *ExeFileList)
{
int i;
String MsgText;
String FilePath;
int FileVersion;
//-----------------------------------
// 処理内容
//-----------------------------------
// 1:暗号化(TYPE_CRYPT_ENCRYPT),
// 2:復号(TYPE_CRYPT_DECRYPT)
// -1:エラー(TYPE_CRYPT_ERROR)
// int CryptTypeNum = 0;
int res;
TForm* dlgconf;
TButton *btn;
TFileStream *fs;
char token[17];
ZeroMemory(token, 17);
FileListPosition = 0;
RetryAtcFilePath = "";
RetryNum = 0;
//同名ファイルはすべて上書きして暗号化する(ダイアログで「すべてはい」を選択 = true)
fOverwirteYesToAll = false;
//削除するファイルリストのクリア
DeleteFileList->Clear();
DelFileTotalSize = 0;
//-----------------------------------
//暗号/復号処理かを問い合わせる
//-----------------------------------
if ( opthdl->fAskEncDecode == true ) {
//'ドラッグ&ドロップされたファイルまたはフォルダーをどのように処理しますか?'
MsgText = LoadResourceString(&Msgunit1::_MSG_CONFIRM_ENCRYPT_OR_DECRYPT)+"\n"+
ExeFileList->Strings[0];
if ( ExeFileList->Count > 1) {
MsgText = MsgText + "\n..." + IntToStr(ExeFileList->Count) + " files.";
}
dlgconf = CreateMessageDialog(MsgText, mtConfirmation, TMsgDlgButtons()<<mbYes<<mbNo<<mbCancel, mbCancel);
dlgconf->Caption = LoadResourceString(&Msgunit1::_MSG_CAPTION_CONFIRMATION); //'確認'
//ボタン名をそれぞれ書き換える
btn = (TButton*)dlgconf->FindComponent("Yes"); //'暗号化する(&E)'
btn->Caption = LoadResourceString(&Msgunit1::_BUTTON_CAPTION_ENCRYPTION);
btn = (TButton*)dlgconf->FindComponent("No"); //'復号する(&D)'
btn->Caption = LoadResourceString(&Msgunit1::_BUTTON_CAPTION_DECRYPTION);
btn = (TButton*)dlgconf->FindComponent("Cancel"); //'キャンセル(&C)'
btn->Caption = LoadResourceString(&Msgunit1::_BUTTON_CAPTION_CANCEL);
dlgconf->ParentWindow = Form1->Handle;
res = dlgconf->ShowModal();
delete dlgconf;
//-----------------------------------
//暗号化
if (res == mrYes) {
CryptTypeNum = TYPE_CRYPT_ENCRYPT;
}
//-----------------------------------
//復号