-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPPC_COM2.C
More file actions
4655 lines (4156 loc) · 125 KB
/
Copy pathPPC_COM2.C
File metadata and controls
4655 lines (4156 loc) · 125 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
/*-----------------------------------------------------------------------------
Paper Plane cUI コマンド処理
-----------------------------------------------------------------------------*/
#include "WINAPI.H"
#include <shlobj.h>
#include "PPX.H"
#include "VFS.H"
#include "PPC_STRU.H"
#include "PPC_FUNC.H"
#include "PPCOMBO.H"
#include "PPC_DD.H"
#include "sha.h"
#pragma hdrstop
#define DSET_SEPARATOR 1
const TCHAR Str_X_dlf[] = T("X_dlf");
const TCHAR Str_X_dsst[] = T("X_dsst");
const TCHAR StrDsetCancel[] = MES_DSCA;
const TCHAR StrDsetForce[] = MES_DSFO;
const TCHAR StrDsetDefault[] = MES_DSHO;
const TCHAR StrDsetThisPath[] = MES_DSTP;
const TCHAR StrDsetThisBranch[] = MES_DSTL;
const TCHAR StrDsetArchive[] = MES_DSTA;
const TCHAR StrDsetListfile[] = MES_DSTF;
const TCHAR StrDsetPathSeparate[] = MES_DSTS;
const TCHAR StrDsetTemporality[] = MES_DSTE;
const TCHAR StrDsetDirmode[] = MES_DSTD;
const TCHAR StrDsetEdit[] = MES_EDIT;
const TCHAR StrDsetSave[] = MES_SAVE;
const TCHAR StrDsetThumbMag[] = MES_DSMA;
const TCHAR StrDsetThumbMini[] = MES_DSMI;
const TCHAR StrDsetSlowMode[] = MES_DSSM;
const TCHAR StrDsetWatchDirModified[] = MES_DSWM;
const TCHAR StrDsetCacheView[] = MES_DSCV;
const TCHAR StrDsetAsyncRead[] = MES_DSAR;
const TCHAR StrDsetSaveDisk[] = MES_DSSD;
const TCHAR StrDsetSaveEveryTime[] = MES_DSSE;
const TCHAR cStrAuxBase[] = T("base");
const TCHAR cStrAuxSep[] = T(" %; ");
const TCHAR cStrRegTsClient[] = T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\SessionInfo");
const TCHAR cStrRegTsTarget[] = T("Target");
const TCHAR cStrRegWslPath[] = T("SYSTEM\\CurrentControlSet\\Services\\P9NP\\NetworkProvider");
const TCHAR cStrRegWslTarget[] = T("TriggerStartPrefix");
const struct PopStringList SortPopStringList[] = {
{DSET_SEPARATOR, NULL},
{CRID_SORT_TEMP, StrDsetTemporality},
{CRID_SORT_REGID, StrDsetForce},
{CRID_SORT_THIS_PATH, StrDsetThisPath},
{CRID_SORT_THIS_BRANCH, StrDsetThisBranch},
{0, NULL},
};
const struct PopStringList DispPopStringList1[] = {
{CRID_VIEWFORMAT_CANCEL, StrDsetCancel},
{DSET_SEPARATOR, NULL},
{CRID_VIEWFORMAT_EDIT, StrDsetEdit},
{0, NULL},
};
const struct PopStringList DispPopStringList2[] = {
{DSET_SEPARATOR, NULL},
{CRID_VIEWFORMAT_MAG_THUMBS, StrDsetThumbMag},
{CRID_VIEWFORMAT_MINI_THUMBS, StrDsetThumbMini},
{0, NULL},
};
const struct PopStringList DispPopStringList3[] = {
{DSET_SEPARATOR, NULL},
{CRID_VIEWFORMAT_THIS_PATH, StrDsetThisPath},
{CRID_VIEWFORMAT_THIS_BRANCH, StrDsetThisBranch},
{CRID_VIEWFORMAT_REGID, StrDsetDefault},
{0, NULL},
};
const struct PopStringList DispDiroptStringList[] = {
{DSET_SEPARATOR, NULL},
{CRID_DIROPT_TEMP, StrDsetTemporality},
{CRID_DIROPT_THIS_PATH, StrDsetThisPath},
{CRID_DIROPT_THIS_BRANCH, StrDsetThisBranch},
{0, NULL},
};
enum {
CM_RENAME = 1, CM_CRC32, CM_MD5, CM_SHA1, CM_SHA224, CM_SHA256,
CM_FTYPE, CM_HARDLINKS, CM_LINKEDPATH,
CM_OWNER, CM_INFOTIP,
// ここまで CommentsMenu で一括
CM_CMPHASH, CM_CLEAR,
CM_WINHASH, CM_WINHASH_MAX = 0xfff,
CM_EXT = 0x1000, // 必ず最後
// CM_MEMOEX0
};
const TCHAR *CommentsMenu[] = {
MES_TCME,
MES_TC32,
MES_TCM5,
MES_TCS1,
MES_TC22,
MES_TC25,
MES_TCFC,
MES_TCHL,
MES_TCLP,
MES_TCOW,
MES_TCIT,
NULL
};
const TCHAR Pastemode_Link[] = T("MakeShortCut");
const TCHAR StrInvokePasteLink[] = T("pastelink");
const TCHAR StrInvokePaste[] = T("paste");
const TCHAR StrInvokeExplorer1[] = T("E"); // Ver 4.90未満(Win98/4.0まで)
const TCHAR StrInvokeExplorer2[] = T("X"); // Ver 4.90以上(WinMe/2000~Vista)
const TCHAR StrInvokeExplorer3[] = T("P"); // Ver 6.1以上(Win7以降)
const TCHAR StrInvokeExplorer4[] = T("O"); // Win10以降
#define MAXSORTITEM 23
const BYTE DescendingSortTable[MAXSORTITEM + 1] = {
8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7, 16, 18, 17, 19, 21, 20, 23, 22};
XC_SORT nosort_xc = {{{-1, -1, -1, 0x7f}}, FILEATTRMASK_DIR_FILES, SORTE_DEFAULT_VALUE};
struct DirOptionMenuDataStruct {
const TCHAR *CommandName;
const TCHAR *MenuItemName;
const TCHAR *IconShowModeList[DSETI_OVLSINGLE + 2];
};
const TCHAR StrIcon_OverlaySafety[] = MES_DSIA;
const TCHAR StrIcon_Blank[] = MES_DSIB;
const TCHAR StrIcon_Frame[] = MES_DSIF;
const TCHAR StrIcon_OverlayNocache[] = MES_DSIH;
const TCHAR StrIcon_Info[] = MES_DSII;
const TCHAR StrIcon_Normal[] = MES_DSIN;
const TCHAR StrIcon_Overlay[] = MES_DSIO;
const TCHAR StrIcon_Simple[] = MES_DSIS;
const TCHAR StrIcon_Through[] = MES_DSIT;
const TCHAR StrIcon_NoShow[] = MES_DSIW;
const struct DirOptionMenuDataStruct DirOptionMenuData_Info =
{ T("infoicon"), MES_DSIL,
{ StrIcon_Through, StrIcon_NoShow, StrIcon_Blank, StrIcon_Frame,
StrIcon_Simple, StrIcon_Normal,
StrIcon_Overlay, StrIcon_OverlayNocache, StrIcon_OverlaySafety
}
};
const struct DirOptionMenuDataStruct DirOptionMenuData_Entry =
{ T("entryicon"), MES_DSEI,
{ StrIcon_Through, StrIcon_Info, T("[?]"), NULL,
StrIcon_Simple, StrIcon_Normal,
StrIcon_Overlay, StrIcon_OverlayNocache, StrIcon_OverlaySafety
}
};
LPARAM CommonCustTickID = 0; // K_Lcust 時に繰り返し再カスタマイズしないようにするためのID
//============================================= 表示ディレクトリ操作
// 「:」に移動し、希望カーソル位置を指定する
void FixRootEntryCursor(PPC_APPINFO *cinfo)
{
switch ( cinfo->path[0] ){
case '\\': {
TCHAR *sep1, *sep2;
sep1 = FindPathSeparator(cinfo->path + 2);
if ( sep1 != NULL ){
if ( *(sep1 + 1) != '\0' ){ // \\pcname\share
sep2 = FindPathSeparator(sep1 + 1);
if ( sep2 != NULL ){ // \\pcname\share\...
*sep2 = '\0';
}
tstrcpy(cinfo->Jfname, cinfo->path);
break;
}
}
tstrcpy(cinfo->Jfname, T("\\\\"));
break;
}
case '#':
tstrcpy(cinfo->Jfname, T("#:"));
break;
default:
thprintf(cinfo->Jfname, TSIZEOF(cinfo->Jfname), T("%c:"), cinfo->path[0]);
break;
}
ChangePath(cinfo, T(":"), CHGPATH_SETABSPATH);
}
// ルートディレクトリへ移動する
void PPC_RootDir(PPC_APPINFO *cinfo)
{
TCHAR *p, *q;
int mode;
TCHAR pathbuf[VFPS], newpath[VFPS];
if ( TinyCheckCellEdit(cinfo) ) return;
if ( cinfo->UnpackFix ) OffArcPathMode(cinfo);
if ( cinfo->UseArcPathMask != ARCPATHMASK_OFF ){ // 書庫内
if ( cinfo->ArcPathMaskDepth > cinfo->MinArcPathMaskDepth ){
SetPPcDirPos(cinfo);
while ( cinfo->ArcPathMaskDepth > cinfo->MinArcPathMaskDepth ){
tstrcpy(pathbuf, cinfo->ArcPathMask);
p = VFSFindLastEntry(cinfo->ArcPathMask);
*p = '\0';
cinfo->ArcPathMaskDepth--;
}
// 「..」にカーソルが当たるように調整
cinfo->e.cellN = 0;
MaskEntryMain(cinfo, &cinfo->mask, pathbuf);
SetCaption(cinfo);
return;
}
}
tstrcpy(newpath, cinfo->path);
p = VFSGetDriveType(newpath, &mode, NULL);
if ( p == NULL ) return; // 既にroot
if ( IsTrue(cinfo->ChdirLock) ){ // ロック
if ( VFSFullPath(pathbuf, T("\\"), newpath) != NULL ){
PPCuiWithPathForLock(cinfo, pathbuf);
return;
}
}
if ( IsTrue(cinfo->ModifyComment) ){
WriteComment(cinfo, cinfo->CommentFile);
}
SavePPcDir(cinfo, FALSE);
if ( cinfo->OrgPath[0] != '\0' ){ // 書庫内書庫/検索結果なら元のパスへ
ChangePath(cinfo, cinfo->OrgPath, CHGPATH_SETABSPATH);
cinfo->OrgPath[0] = '\0';
}
DxSetMotion(cinfo->DxDraw, DXMOTION_Root);
#ifdef USESLASHPATH
if ( (*p == '/') && (*(p + 1) != '\0') ){
*(p + 1) = '\0';
ChangePath(cinfo, newpath, CHGPATH_SETABSPATH);
read_entry(cinfo, RENTRY_READ);
return;
}
#endif
if ( *p == '\\' ) p++;
if ( *p ){
if ( mode == VFSPT_UNC ){ // UNC は共有ルートを求める
q = FindPathSeparator(p); // PC名をスキップ
if ( q != NULL ){
TCHAR *r;
q++;
r = FindPathSeparator(q); // 共有名をスキップ
if ( r != NULL ){
*r = '\0';
if ( *(r + 1) != '\0' ) p = r + 1;
}
}
}
} else{
p = newpath;
}
if ( p == newpath ){ // 既にrootに移動済み
if ( *p == ':' ) return; // 「:」に移動済み
ChangePath(cinfo, newpath, CHGPATH_SETABSPATH);
FixRootEntryCursor(cinfo);
read_entry(cinfo, RENTRY_JUMPNAME | RENTRY_JUMPNAME_INC);
} else{
q = FindPathSeparator(p);
if ( q != NULL ) *q = '\0';
tstrcpy(cinfo->Jfname, p);
*p = '\0';
ChangePath(cinfo, newpath, CHGPATH_SETABSPATH);
read_entry(cinfo, RENTRY_JUMPNAME);
}
}
//=============================================================================
// 親ディレクトリへ移動する
void PPC_UpDir(PPC_APPINFO *cinfo)
{
TCHAR *p;
TCHAR pathbuf[VFPS], newpath[VFPS];
if ( TinyCheckCellEdit(cinfo) ) return;
if ( cinfo->UnpackFix ) OffArcPathMode(cinfo);
if ( cinfo->UseArcPathMask != ARCPATHMASK_OFF ){ // 書庫内
cinfo->ArcPathMaskDepth--;
if ( cinfo->ArcPathMaskDepth >= cinfo->MinArcPathMaskDepth ){
TCHAR *last;
SetPPcDirPos(cinfo);
tstrcpy(pathbuf, cinfo->ArcPathMask);
last = FindBothLastEntry(cinfo->ArcPathMask);
if ( *last == '\0' ) last = cinfo->ArcPathMask;
*last = '\0';
// 「..」にカーソルが当たるように調整
cinfo->e.cellN = 0;
MaskEntryMain(cinfo, &cinfo->mask, pathbuf);
SetCaption(cinfo);
return;
}
}
if ( IsTrue(cinfo->ChdirLock) ){ // ロック
if ( VFSFullPath(pathbuf, T(".."), cinfo->path) != NULL ){
PPCuiWithPathForLock(cinfo, pathbuf);
return;
}
}
if ( IsTrue(cinfo->ModifyComment) ){
WriteComment(cinfo, cinfo->CommentFile);
}
SavePPcDir(cinfo, FALSE);
if ( cinfo->OrgPath[0] != '\0' ){ // 書庫内書庫/検索結果なら元のパスへ
ChangePath(cinfo, cinfo->OrgPath, CHGPATH_SETABSPATH);
cinfo->OrgPath[0] = '\0';
if ( cinfo->e.Dtype.mode == VFSDT_LFILE ){
DxSetMotion(cinfo->DxDraw, DXMOTION_UpDir);
read_entry(cinfo, RENTRY_READ);
return;
}
}
tstrcpy(newpath, cinfo->path);
if ( tstrchr(newpath, '/') != NULL ){ // http:// など
p = VFSGetDriveType(newpath, NULL, NULL);
if ( p == NULL ) return; // 既にroot
if ( *p == '/' ) p++;
if ( *p == '\0' ){ // root→drive list
if ( !(GetCustXDword(Str_X_dlf, NULL, 0) & XDLF_UPDIRJUMP) ){
tstrcpy(cinfo->Jfname, newpath);
ChangePath(cinfo, T(":"), CHGPATH_SETABSPATH);
} else{
return;
}
} else{ // subdir
for ( ; ; ){
TCHAR *q;
q = tstrchr(p, '/');
if ( q == NULL ){
tstrcpy(cinfo->Jfname, p);
if ( p > (newpath + 1) ) p--;
*p = '\0';
break;
}
// http の時は ~/dir/ の形式にする
if ( (cinfo->e.Dtype.mode == VFSDT_HTTP) && (*(q + 1) == '\0') ){
*p = '\0';
break;
}
p = q + 1;
}
}
} else{ // GNC等
p = VFSFindLastEntry(newpath);
if ( (*p != '\0') &&
(((GetDriveRoot(newpath) - 1) <= p) || !(GetCustXDword(Str_X_dlf, NULL, 0) & XDLF_UPDIRJUMP)) ){ // subdir
tstrcpy(cinfo->Jfname, p + (*p == '\\'));
*p = '\0';
} else{ // root
if ( (newpath[0] != ':') &&
!(GetCustXDword(Str_X_dlf, NULL, 0) & XDLF_UPDIRJUMP) ){
ChangePath(cinfo, newpath, CHGPATH_SETABSPATH);
FixRootEntryCursor(cinfo);
read_entry(cinfo, RENTRY_JUMPNAME | RENTRY_JUMPNAME_INC);
}
return;
}
}
DxSetMotion(cinfo->DxDraw, DXMOTION_UpDir);
ChangePath(cinfo, newpath, CHGPATH_SETABSPATH);
read_entry(cinfo, RENTRY_JUMPNAME);
}
BOOL USEFASTCALL CheckComma(const TCHAR **param)
{
if ( SkipSpace(param) == ',' ){
(*param)++;
return TRUE;
}
return FALSE;
}
BOOL LoadLs(LOADSETTINGS_MOD *ls, const TCHAR *path)
{
ls->cust.dset.flags = ls->cust.dset.deflags = 0;
ls->cust.dset.infoicon = ls->cust.dset.cellicon = DSETI_DEFAULT;
ls->cust.dset.sort.mode.block = -1;
ls->cust.dset.sort.atr = FILEATTRMASK_DIR_FILES;
ls->cust.dset.sort.option = SORTE_DEFAULT_VALUE;
ls->cust.buf[0] = '\0';
ls->buf = (LOADSETTINGS_CUST *)GetCustValue(StrXC_dset, path, &ls->cust, sizeof(ls->cust));
if ( ls->buf == NULL ){
ls->buf = &ls->cust;
return FALSE;
}
if ( ls->buf != &ls->cust ){ // 別バッファを取ったときは、別バッファから反映
ls->cust.dset = ls->buf->dset;
}
return TRUE;
}
void SaveLs(LOADSETTINGS_MOD *ls, const TCHAR *path)
{
// 何か変更点がある設定があれば保存する
if ( ls->cust.dset.flags || ls->cust.dset.deflags ||
(ls->cust.dset.infoicon != DSETI_DEFAULT) ||
(ls->cust.dset.cellicon != DSETI_DEFAULT) ||
(ls->cust.dset.sort.mode.dat[0] >= 0) ||
(ls->buf->buf[0] != '\0') ){
if ( ls->buf == NULL ){
ls->buf = &ls->cust;
}else if ( ls->buf != &ls->cust ){ // 別バッファに反映
ls->buf->dset = ls->cust.dset;
}
SetCustTable(StrXC_dset, path, ls->buf, sizeof(XC_DSET) + TSTRSIZE(ls->buf->buf));
} else{
DeleteCustTable(StrXC_dset, path, 0);
}
}
void FreeLs(LOADSETTINGS_MOD *ls)
{
if ( (ls->buf != &ls->cust ) && (ls->buf != NULL) ){
ProcHeapFree(ls->buf);
}
}
int tstrlenAddQ(const TCHAR *param)
{
int count = 0;
for (;;){
TCHAR chr;
chr = *param++;
if ( chr == '\0' ) return count;
if ( chr == '\"' ) count++;
count++;
}
}
void SetNewXdir(const TCHAR *path, const TCHAR *header, const TCHAR *param)
{
TCHAR *dstp;
const TCHAR *srcp;
size_t headsize;
size_t oldbufsize;
LOADSETTINGS_MOD ls;
LOADSETTINGS_CUST *newbuf;
if ( path == NULL ) return; // MaskEntry, path = NULL のとき用
LoadLs(&ls, path);
headsize = TSTRLENGTH(header);
oldbufsize = (ls.buf != &ls.cust) ? HeapSize(hProcessHeap, 0, ls.buf) : 0;
newbuf = (LOADSETTINGS_CUST *)HeapAlloc(hProcessHeap, 0, oldbufsize + headsize + (tstrlenAddQ(param) + 8) * sizeof(TCHAR)); // 8 は、空白区切り、" x 2分
if ( newbuf == NULL ){
FreeLs(&ls);
return;
}
srcp = ls.buf->buf;
dstp = newbuf->buf;
while ( SkipSpace(&srcp) != '\0' ){
TCHAR *headtop;
headtop = dstp;
for ( ;; ){ // 1項目分(header:"~")を保存
UTCHAR chr;
chr = (UTCHAR)*srcp++;
if ( chr <= ' ' ){ // 区切り
if ( chr == '\0' ) srcp--;
*dstp++ = ' ';
break;
}
*dstp++ = chr;
if ( chr != '\"' ) continue;
// 「"」処理
for ( ;; ){
chr = (UTCHAR)*srcp++;
if ( chr < ' ' ){ // 閉じないまま末端
if ( chr == '\0' ) srcp--;
*dstp++ = '\"';
*dstp++ = ' ';
break;
}
*dstp++ = chr;
if ( chr != '\"' ) continue;
break;
}
}
if ( memcmp(headtop, header, headsize) == 0 ){ // 同名項目の場合は破棄
dstp = headtop;
}
}
if ( param[0] != '\0' ){ // 新項目を追加
dstp = tstpcpy(dstp, header);
*dstp++ = '\"';
for ( ;; ){
UTCHAR chr;
chr = (UTCHAR)*param++;
if ( chr == '\0' ) break;
*dstp++ = chr;
if ( chr != '\"' ) continue;
*dstp++ = chr;
}
*dstp++ = '\"';
}
*dstp = '\0';
FreeLs(&ls); // 旧ls->buf を破棄
ls.buf = newbuf;
SaveLs(&ls, path);
FreeLs(&ls);
}
//-----------------------------------------------------------------------------
BOOL AppendMenuPopString(HMENU hMenu, const struct PopStringList *list)
{
BOOL settab;
TCHAR buf[VFPS];
const TCHAR *str;
buf[0] = '\0';
GetMenuString(hMenu, 0, buf, VFPS, MF_BYPOSITION);
settab = (tstrchr(buf, '\t') != NULL) ? TRUE : FALSE;
while ( list->id ){
if ( list->id == DSET_SEPARATOR ){
AppendMenu(hMenu, MF_SEPARATOR, 0, NULL);
} else{
str = MessageText(list->string);
if ( settab ){
buf[0] = '\t';
tstrcpy(buf + 1, str);
str = buf;
}
AppendMenuString(hMenu, list->id, str);
}
list++;
}
return settab;
}
void GetSetPath(PPC_APPINFO *cinfo, TCHAR *setpath, int mode, int offset, HMENU hMenu)
{
if ( mode == (offset + DSMD_THIS_PATH) ){
LoadSetting_FixThisPath(setpath, cinfo->path);
} else if ( mode == (offset + DSMD_THIS_BRANCH) ){
LoadSetting_FixThisBranch(setpath, cinfo->path);
} else if ( mode == (offset + DSMD_ARCHIVE) ){
tstrcpy(setpath, StrArchiveMode);
} else if ( mode == (offset + DSMD_LISTFILE) ){
tstrcpy(setpath, StrListfileMode);
} else{ // DSMD_PATHL
GetMenuString(hMenu, offset + DSMD_PATH_BRANCH, setpath, VFPS, MF_BYCOMMAND);
if ( setpath[0] == '\t' ){
memmove(setpath, (BYTE *)(TCHAR *)(setpath + 1), TSTROFF(tstrlen(setpath) + 1 - 1));
}
}
}
void LoadSortOpt(LPCTSTR *param, XC_SORT *xc)
{
const TCHAR *p;
int i = 1;
p = *param;
xc->mode.block = -1; // 0-3 をまとめて -1
if ( SkipSpace(&p) == '\0' ){ // 指定無し
xc->atr = xc->option = 0;
return;
}
xc->mode.dat[0] = (char)GetNumber(&p);
CheckComma(&p);
xc->atr = GetNumber(&p);
CheckComma(&p);
xc->option = GetNumber(&p);
while ( IsTrue(CheckComma(&p)) ){
xc->mode.dat[i] = (char)xc->atr;
xc->atr = xc->option;
xc->option = GetNumber(&p);
i++;
if ( i >= 4 ) break;
}
*param = p;
}
// 現在使用中のソート項目をチェック
void SortMenuCheck(HMENU hMenu, const TCHAR *str, int indexmax, XC_SORT *xc, int descending_sort)
{
MENUITEMINFO minfo;
int index = CRID_SORT, checkindex = 0, detailindex = 0;
XC_SORT des_xc;
XC_SORT tmpxc;
if ( descending_sort ){ // 降順指定時なら降順化した内容を用意する
des_xc = *xc;
if ( (des_xc.mode.dat[0] >= 0) && (des_xc.mode.dat[0] <= MAXSORTITEM) ){
des_xc.mode.dat[0] = DescendingSortTable[des_xc.mode.dat[0]];
}
}
minfo.cbSize = sizeof(minfo);
for ( ; index < indexmax; str += tstrlen(str) + 1, index++ ){
if ( *str == '\0' ){
detailindex = index;
continue;
}
if ( *str == MENUNAMEID_SIG ){
str += TSIZEOF(MENUNAMEID);
index--;
continue;
}
if ( (*str == 'a') || (*str == 'd') ){ // ascending / descending指定
minfo.fMask = MIIM_STATE | MIIM_ID;
minfo.fState = descending_sort ? (MFS_ENABLED | MFS_CHECKED) : MFS_ENABLED;
minfo.wID = CRID_SORT_DESCENDING;
if ( *str == 'a' ){
minfo.fState ^= MFS_CHECKED;
minfo.wID = CRID_SORT_ASCENDING;
}
// ↓ID 変更後はここで調整。
SetMenuItemInfo(hMenu, minfo.wID, MF_BYCOMMAND, &minfo);
// ID 変更前は後ろのSetMenuItemInfoで調整。
} else{ // 通常のソート指定
minfo.fMask = MIIM_STATE;
LoadSortOpt(&str, &tmpxc);
if ( (memcmp(xc, &tmpxc, sizeof(XC_SORT)) == 0) ||
(descending_sort && !memcmp(&des_xc, &tmpxc, sizeof(XC_SORT))) ){
checkindex = index;
minfo.fState = MFS_ENABLED | MFS_CHECKED;
} else{
minfo.fState = MFS_ENABLED;
}
}
SetMenuItemInfo(hMenu, index, MF_BYCOMMAND, &minfo);
}
if ( (checkindex == 0) && (xc->mode.dat[0] >= 0) && (detailindex != 0) ){
minfo.fMask = MIIM_STATE;
minfo.fState = MFS_ENABLED | MFS_CHECKED;
SetMenuItemInfo(hMenu, detailindex, MF_BYCOMMAND, &minfo);
}
}
int FindSortSetting(PPC_APPINFO *cinfo, TCHAR *findpath)
{
TCHAR path[VFPS], *p;
LOADSETTINGS_TMP ls;
int mode = CRID_SORT_NOMODE;
// 全指定
ls.dset.sort.mode.dat[0] = -1;
LoadSettingMain(&ls, T("*"));
if ( ls.dset.sort.mode.dat[0] >= 0 ){
tstrcpy(findpath, T("*"));
mode = CRID_SORT_PATH_BRANCH;
}
// ドライブ限定
tstrcpy(path, cinfo->path);
p = VFSGetDriveType(path, NULL, NULL);
if ( p != NULL ){
TCHAR backup;
if ( *p == '\\' ) p++;
backup = *p;
*p = '\0';
ls.dset.sort.mode.dat[0] = -1;
LoadSettingMain(&ls, path);
if ( ls.dset.sort.mode.dat[0] >= 0 ){
tstrcpy(findpath, path);
mode = CRID_SORT_PATH_BRANCH;
}
*p = backup;
} else{
p = path;
}
// 下層パス
if ( *p != '\0' ){
for ( ; ; ){ // 途中
TCHAR backup, *q;
q = FindPathSeparator(p);
if ( q == NULL ) break;
p = q + 1;
backup = *p;
*p = '\0';
ls.dset.sort.mode.dat[0] = -1;
LoadSettingMain(&ls, path);
if ( ls.dset.sort.mode.dat[0] >= 0 ){
tstrcpy(findpath, path);
mode = CRID_SORT_PATH_BRANCH;
}
*p = backup;
}
// 最終層の更に下層指定
p += tstrlen(p);
*p = '\\';
*(p + 1) = '\0';
ls.dset.sort.mode.dat[0] = -1;
LoadSettingMain(&ls, path);
if ( ls.dset.sort.mode.dat[0] >= 0 ){
tstrcpy(findpath, path);
mode = CRID_SORT_THIS_BRANCH;
}
// 最終層
*p = '\0';
ls.dset.sort.mode.dat[0] = -1;
LoadSettingMain(&ls, path);
if ( ls.dset.sort.mode.dat[0] >= 0 ){
tstrcpy(findpath, path);
mode = CRID_SORT_THIS_PATH;
}
}
// Archive
if ( (cinfo->e.Dtype.mode == VFSDT_UN) ||
(cinfo->e.Dtype.mode == VFSDT_SUSIE) ||
(cinfo->e.Dtype.mode == VFSDT_ARCFOLDER) ||
(cinfo->e.Dtype.mode == VFSDT_CABFOLDER) ||
(cinfo->e.Dtype.mode == VFSDT_LZHFOLDER) ||
(cinfo->e.Dtype.mode == VFSDT_ZIPFOLDER) ){
ls.dset.sort.mode.dat[0] = -1;
LoadSettingMain(&ls, StrArchiveMode);
if ( ls.dset.sort.mode.dat[0] >= 0 ){
tstrcpy(findpath, StrArchiveMode);
mode = CRID_SORT_ARCHIVE;
}
}
// Listfile
if ( cinfo->e.Dtype.mode == VFSDT_LFILE ){
ls.dset.sort.mode.dat[0] = -1;
LoadSettingMain(&ls, StrListfileMode);
if ( ls.dset.sort.mode.dat[0] >= 0 ){
tstrcpy(findpath, StrListfileMode);
mode = CRID_SORT_LISTFILE;
}
}
return mode;
}
HMENU AddPPcSortMenu(PPC_APPINFO *cinfo, HMENU hMenu, ThSTRUCT *PopupTbl, DWORD *mmmode, DWORD *sid, DWORD sortmode, const TCHAR *path)
{
DWORD id = CRID_SORT;
BOOL settab;
TCHAR setpath[VFPS];
DWORD newmmmode;
hMenu = PP_AddMenu(&cinfo->info,
cinfo->info.hWnd, hMenu, &id, T("MC_sort"), PopupTbl);
if ( hMenu == NULL ) return NULL;
setpath[0] = '\t';
newmmmode = FindSortSetting(cinfo, setpath + 1);
if ( newmmmode == CRID_SORT_NOMODE ){
GetCustData(Str_X_dsst, &X_dsst, sizeof(X_dsst));
newmmmode = X_dsst[0] + CRID_SORTEX;
}
settab = AppendMenuPopString(hMenu, SortPopStringList);
if ( newmmmode == CRID_SORT_PATH_BRANCH ){
if ( (sortmode == CRID_SORT_PATH_BRANCH) && (path != NULL) && (path[0] != '\0') ){
tstrcpy(setpath, path);
}
}else{
setpath[1] = '*';
setpath[2] = '\0';
}
AppendMenuString(hMenu, CRID_SORT_PATH_BRANCH, settab ? setpath : setpath + 1);
if ( (cinfo->e.Dtype.mode == VFSDT_LFILE) || (sortmode == CRID_SORT_LISTFILE) ){
AppendMenuString(hMenu, CRID_SORT_LISTFILE, StrDsetListfile);
}
if ( (cinfo->e.Dtype.mode == VFSDT_UN) ||
(cinfo->e.Dtype.mode == VFSDT_SUSIE) ||
(cinfo->e.Dtype.mode == VFSDT_ARCFOLDER) ||
(cinfo->e.Dtype.mode == VFSDT_CABFOLDER) ||
(cinfo->e.Dtype.mode == VFSDT_LZHFOLDER) ||
(cinfo->e.Dtype.mode == VFSDT_ZIPFOLDER) ||
(sortmode == CRID_SORT_ARCHIVE) ){
tstrcpy(settab ? setpath + 1 : setpath, MessageText(StrDsetArchive));
AppendMenuString(hMenu, CRID_SORT_ARCHIVE, setpath);
}
if ( sortmode != 0 ){ // \[S] 保持設定が有効なら強制設定にする
if ( sortmode >= CRID_SORTEX ){
newmmmode = sortmode;
} else if ( cinfo->XC_sort.mode.dat[0] >= 0 ){
newmmmode = CRID_SORT_REGID;
}
} else{ // [S] 一時設定
newmmmode = CRID_SORTEX + X_dsst[1];
}
CheckMenuRadioItem(hMenu, CRID_SORT_TEMP, CRID_SORT_MODELAST - 1, newmmmode, MF_BYCOMMAND);
if ( mmmode != NULL ){
*mmmode = newmmmode;
*sid = id;
}
return hMenu;
}
void SaveSortSetting(PPC_APPINFO *cinfo, int mode, const TCHAR *path, XC_SORT *xc)
{
switch ( mode ){
case CRID_SORT_TEMP: // 一時設定
if ( xc->mode.dat[0] == -1 ){
xc->mode.block = 0xffffff00 + 19; // まとめて -1
xc->atr = 0;
xc->option = 0;
}
break;
case CRID_SORT_NOMODE:
case CRID_SORT_REGID: // 強制設定
cinfo->XC_sort = *xc;
SetCustTable(T("XC_sort"), cinfo->RegCID + 1, xc, sizeof(XC_SORT));
break;
// case CRID_SORT_THIS_PATH: // パス設定
// case CRID_SORT_THIS_BRANCH: // 下層設定
// case CRID_SORT_PATH_BRANCH:
// case CRID_SORT_ARCHIVE:
default:
if ( cinfo->XC_sort.mode.dat[0] >= 0 ){
// 保持ソートが使われていたら、解除する
cinfo->XC_sort.mode.dat[0] = -1;
SetCustTable(T("XC_sort"), cinfo->RegCID + 1, &cinfo->XC_sort, sizeof(XC_SORT));
}
// setpath は、PPcTrackPopupMenu の前で準備済み
{
LOADSETTINGS_MOD ls;
LoadLs(&ls, path);
ls.cust.dset.sort = *xc;
SaveLs(&ls, path);
FreeLs(&ls);
}
break;
}
}
BOOL PPC_SortMenu(PPC_APPINFO *cinfo, XC_SORT *xc, DWORD sortmode, const TCHAR *path)
{
BOOL result = FALSE;
DWORD id;
DWORD index, mmmode;
const TCHAR *p;
HMENU hMenu;
ThSTRUCT PopupTbl; // 処理内容
TCHAR setpath[VFPS];
BOOL descending_sort = FALSE;
XC_SORT tmpxc;
if ( TinyCheckCellEdit(cinfo) ) return FALSE;
ThInit(&PopupTbl);
if ( sortmode == CRID_SORT_DESCENDING ) descending_sort = 1;
hMenu = AddPPcSortMenu(cinfo, NULL, &PopupTbl, &mmmode, &id, sortmode, path);
if ( hMenu != NULL ){
for ( ; ; ){
switch ( mmmode ){ // モード切替
case CRID_SORT_TEMP:
tmpxc = nosort_xc;
break;
case CRID_SORT_REGID:
tmpxc = cinfo->XC_sort;
break;
case CRID_SORT_THIS_PATH:
case CRID_SORT_THIS_BRANCH:
case CRID_SORT_PATH_BRANCH:
case CRID_SORT_ARCHIVE:
case CRID_SORT_LISTFILE: {
LOADSETTINGS_MOD ls;
GetSetPath(cinfo, setpath, mmmode, CRID_SORTEX, hMenu);
LoadLs(&ls, setpath);
tmpxc = ls.cust.dset.sort;
FreeLs(&ls);
break;
}
default:
tmpxc = *xc;
break;
}
if ( (sortmode >= CRID_SORT) && (sortmode < CRID_SORTEX) ){
index = sortmode;
break;
}
SortMenuCheck(hMenu, (TCHAR *)PopupTbl.bottom, id, &tmpxc, descending_sort);
index = PPcTrackPopupMenu(cinfo, hMenu);
if ( index == CRID_SORT_ASCENDING ){
descending_sort = 0;
continue;
}
if ( index == CRID_SORT_DESCENDING ){
descending_sort ^= 1;
continue;
}
if ( (index < CRID_SORT_TEMP) || (index >= CRID_SORT_MODELAST) ){
break;
}
mmmode = index;
CheckMenuRadioItem(hMenu, CRID_SORT_TEMP, CRID_SORT_MODELAST - 1, mmmode, MF_BYCOMMAND);
}
DestroyMenu(hMenu);
} else{
mmmode = sortmode ? CRID_SORT_REGID : CRID_SORT_TEMP;
index = CRID_SORT; // 登録メニューがないので詳細指定を用意しておく
ThAddString(&PopupTbl, NilStr);
tmpxc = *xc;
}
while ( index ){
GetMenuDataMacro2(p, &PopupTbl, index - CRID_SORT);
if ( p == NULL ) break; // 異常値
if ( *p == '\0' ){ // 空欄…編集
PPCSORTDIALOGPARAM psdp;
psdp.cinfo = cinfo;
psdp.xc = &tmpxc;
if ( PPxDialogBoxParam(hInst, MAKEINTRESOURCE(IDD_SORT),
cinfo->info.hWnd, SortDlgBox, (LPARAM)&psdp) <= 0 ){
break;
}
*xc = tmpxc;
} else if ( *p == 'r' ){ // react
*xc = cinfo->sort_last;
} else{ // 一般
char modedat;
LoadSortOpt(&p, xc);
modedat = xc->mode.dat[0];
if ( descending_sort && (modedat >= 0) && (modedat <= MAXSORTITEM) ){
xc->mode.dat[0] = DescendingSortTable[modedat];
}
}
SaveSortSetting(cinfo, mmmode, setpath, xc);
result = TRUE;
break;
}
ThFree(&PopupTbl);
return result;
}
//-----------------------------------------------------------------------------
void PPC_SortMain(PPC_APPINFO *cinfo, XC_SORT *xc)
{
const TCHAR *filename;
filename = CEL(cinfo->e.cellN).f.cFileName;
CellSort(cinfo, xc);
if ( cinfo->hHeaderWnd != NULL ) FixHeader(cinfo);
cinfo->DrawTargetFlags = DRAWT_ALL;
InvalidateRect(cinfo->info.hWnd, NULL, FALSE);
if ( XC_acsr[1] ){
FindCell(cinfo, filename);
} else{
MoveCellCsr(cinfo, 0, NULL);
}
}
//-----------------------------------------------------------------------------
// ソート
ERRORCODE SortKeyCommand(PPC_APPINFO *cinfo, DWORD sortmode, const TCHAR *path)
{
XC_SORT xc;
xc = cinfo->XC_sort;
if ( PPC_SortMenu(cinfo, &xc, sortmode, path) == FALSE ) return ERROR_CANCELLED;
if ( (sortmode == CRID_SORT_PATH_BRANCH) && (path != NULL) && (path[0] != '\0') ){
return NO_ERROR; // -"path" 指定の時はソートしない
}
PPC_SortMain(cinfo, &xc);
return NO_ERROR;
}
//-----------------------------------------------------------------------------