-
-
Notifications
You must be signed in to change notification settings - Fork 43
/
filelist.cpp
1948 lines (1743 loc) · 73.3 KB
/
filelist.cpp
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
/*=============================================================================
*
* ファイル一覧
*
===============================================================================
/ Copyright (C) 1997-2007 Sota. All rights reserved.
/
/ Redistribution and use in source and binary forms, with or without
/ modification, are permitted provided that the following conditions
/ are met:
/
/ 1. Redistributions of source code must retain the above copyright
/ notice, this list of conditions and the following disclaimer.
/ 2. 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.
/
/ THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 "common.h"
#include <sys/stat.h>
#include "OleDragDrop.h"
#include "filelist.h"
#define BUF_SIZE 256
#define CF_CNT 2
#define WM_DRAGDROP (WM_APP + 100)
#define WM_GETDATA (WM_APP + 101)
#define WM_DRAGOVER (WM_APP + 102)
/*===== プロトタイプ =====*/
static LRESULT CALLBACK FileListCommonWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
static void DispFileList2View(HWND hWnd, std::vector<FILELIST>& files);
static void AddListView(HWND hWnd, int Pos, std::wstring const& Name, int Type, LONGLONG Size, FILETIME *Time, int Attr, std::wstring const& Owner, int Link, int InfoExist, int ImageId);
static int MakeRemoteTree1(std::wstring const& Path, std::wstring const& Cur, std::vector<FILELIST>& Base, int *CancelCheckWork);
static int MakeRemoteTree2(std::wstring& Path, std::wstring const& Cur, std::vector<FILELIST>& Base, int *CancelCheckWork);
static void CopyTmpListToFileList(std::vector<FILELIST>& Base, std::vector<FILELIST> const& List);
static std::optional<std::vector<std::variant<FILELIST, std::string>>> GetListLine(int Num);
static bool MakeLocalTree(fs::path const& path, std::vector<FILELIST>& Base);
static void AddFileList(FILELIST const& Pkt, std::vector<FILELIST>& Base);
static int AskFilterStr(std::wstring const& file, int Type);
extern std::wstring FilterStr;
// 外部アプリケーションへドロップ後にローカル側のファイル一覧に作業フォルダが表示されるバグ対策
extern int SuppressRefresh;
// ローカル側自動更新
extern HANDLE ChangeNotification;
/*===== ローカルなワーク =====*/
static HWND hWndListLocal = NULL;
static HWND hWndListRemote = NULL;
static WNDPROC ListViewProc;
static std::vector<FILELIST> localFileList, remoteFileList;
static HIMAGELIST ListImg = NULL;
// ファイルアイコン表示対応
static HIMAGELIST ListImgFileIcon = NULL;
static auto FindStr = L"*"s; /* 検索文字列 */
static int Dragging = NO;
// 特定の操作を行うと異常終了するバグ修正
static POINT DropPoint;
static int StratusMode; /* 0=ファイル, 1=ディレクトリ, 2=リンク */
// リモートファイルリスト (2007.9.3 yutaka)
static std::vector<FILELIST> remoteFileListBase;
static std::vector<FILELIST> remoteFileListBaseNoExpand;
static fs::path remoteFileDir;
template<class Fn>
static inline bool FindFile(fs::path const& fileName, Fn&& fn) {
auto result = false;
WIN32_FIND_DATAW data;
if (auto handle = FindFirstFileW(fileName.c_str(), &data); handle != INVALID_HANDLE_VALUE) {
result = true;
do {
if (DispIgnoreHide == YES && (data.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN))
continue;
if (std::wstring_view const filename{ data.cFileName }; filename == L"."sv || filename == L".."sv)
continue;
// TODO: temporary round time, see #318 and #322.
auto const rounded = ((uint64_t)data.ftLastWriteTime.dwHighDateTime << 32 | data.ftLastWriteTime.dwLowDateTime) / 10000000 * 10000000;
data.ftLastWriteTime = { DWORD(rounded), DWORD(rounded >> 32) };
result = fn(data);
} while (result && FindNextFileW(handle, &data));
FindClose(handle);
} else
Error(L"FindFirstFileW()"sv);
return result;
}
// ファイルリストウインドウを作成する
int MakeListWin() {
WNDCLASSEXW wc{ sizeof(WNDCLASSEXW) };
if (!GetClassInfoExW(GetFtpInst(), WC_LISTVIEWW, &wc))
return FFFTP_FAIL;
ListViewProc = wc.lpfnWndProc;
wc.lpfnWndProc = FileListCommonWndProc;
wc.lpszClassName = WC_LISTVIEWW L"Ex";
if (RegisterClassExW(&wc) == 0)
return FFFTP_FAIL;
ListImg = ImageList_LoadImageW(GetFtpInst(), MAKEINTRESOURCEW(dirattr_bmp), 16, 9, RGB(255, 0, 0), IMAGE_BITMAP, 0);
/*===== ローカル側のリストビュー =====*/
hWndListLocal = CreateWindowExW(WS_EX_CLIENTEDGE, WC_LISTVIEWW L"Ex", nullptr, WS_CHILD | WS_VISIBLE | LVS_REPORT | LVS_SHOWSELALWAYS, 0, AskToolWinHeight() * 2, LocalWidth, ListHeight, GetMainHwnd(), 0, GetFtpInst(), nullptr);
if (!hWndListLocal)
return FFFTP_FAIL;
constexpr std::tuple<int, int> columnsLocal[] = {
{ LVCFMT_LEFT, IDS_MSGJPN038 },
{ LVCFMT_LEFT, IDS_MSGJPN039 },
{ LVCFMT_RIGHT, IDS_MSGJPN040 },
{ LVCFMT_LEFT, IDS_MSGJPN041 },
};
for (int i = 0; auto [fmt, resourceId] : columnsLocal) {
auto text = GetString(resourceId);
LVCOLUMNW column{ LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM, fmt, LocalTabWidth[i], data(text), 0, i };
SendMessageW(hWndListLocal, LVM_INSERTCOLUMNW, i++, (LPARAM)&column);
}
/*===== ホスト側のリストビュー =====*/
hWndListRemote = CreateWindowExW(WS_EX_CLIENTEDGE, WC_LISTVIEWW L"Ex", nullptr, WS_CHILD | WS_VISIBLE | LVS_REPORT | LVS_SHOWSELALWAYS, LocalWidth + SepaWidth, AskToolWinHeight() * 2, RemoteWidth, ListHeight, GetMainHwnd(), 0, GetFtpInst(), nullptr);
if (!hWndListRemote)
return FFFTP_FAIL;
constexpr std::tuple<int, int> columnsRemote[] = {
{ LVCFMT_LEFT, IDS_MSGJPN042 },
{ LVCFMT_LEFT, IDS_MSGJPN043 },
{ LVCFMT_RIGHT, IDS_MSGJPN044 },
{ LVCFMT_LEFT, IDS_MSGJPN045 },
{ LVCFMT_LEFT, IDS_MSGJPN046 },
{ LVCFMT_LEFT, IDS_MSGJPN047 },
};
for (int i = 0; auto [fmt, resourceId] : columnsRemote) {
auto text = GetString(resourceId);
LVCOLUMNW column{ LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM, fmt, RemoteTabWidth[i], data(text), 0, i };
SendMessageW(hWndListRemote, LVM_INSERTCOLUMNW, i++, (LPARAM)&column);
}
return FFFTP_SUCCESS;
}
// ファイルリストウインドウを削除
void DeleteListWin() noexcept {
if(hWndListLocal != NULL)
DestroyWindow(hWndListLocal);
if(hWndListRemote != NULL)
DestroyWindow(hWndListRemote);
return;
}
// ローカル側のファイルリストのウインドウハンドルを返す
HWND GetLocalHwnd() noexcept {
return hWndListLocal;
}
// ホスト側のファイルリストのウインドウハンドルを返す
HWND GetRemoteHwnd() noexcept {
return(hWndListRemote);
}
static void doTransferRemoteFile(void)
{
// すでにリモートから転送済みなら何もしない。(2007.9.3 yutaka)
if (!empty(remoteFileListBase))
return;
// 特定の操作を行うと異常終了するバグ修正
while(1)
{
MSG msg;
if(PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessageW(&msg);
}
else if(AskTransferNow() == NO)
break;
Sleep(10);
}
std::vector<FILELIST> FileListBase;
MakeSelectedFileList(WIN_REMOTE, YES, NO, FileListBase, &CancelFlg);
std::vector<FILELIST> FileListBaseNoExpand;
MakeSelectedFileList(WIN_REMOTE, NO, NO, FileListBaseNoExpand, &CancelFlg);
// set temporary folder
auto LocDir = AskLocalCurDir();
auto tmp = tempDirectory() / L"file";
if (auto const created = !fs::create_directory(tmp); !created) {
// 既存のファイルを削除する
for (auto const& f : FileListBase)
fs::remove(tmp / f.Name);
}
// 外部アプリケーションへドロップ後にローカル側のファイル一覧に作業フォルダが表示されるバグ対策
SuppressRefresh = 1;
// ダウンロード先をテンポラリに設定
SetLocalDirHist(tmp);
// FFFTPにダウンロード要求を出し、ダウンロードの完了を待つ。
PostMessageW(GetMainHwnd(), WM_COMMAND, MAKEWPARAM(MENU_DOWNLOAD, 0), 0);
// 特定の操作を行うと異常終了するバグ修正
while(1)
{
MSG msg;
if (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) {
TranslateMessage(&msg);
DispatchMessageW(&msg);
} else {
// 転送スレッドが動き出したら抜ける。
if (AskTransferNow() == YES)
break;
}
Sleep(10);
}
// 特定の操作を行うと異常終了するバグ修正
while(1)
{
MSG msg;
if(PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessageW(&msg);
}
else if(AskTransferNow() == NO)
break;
Sleep(10);
}
// ダウンロード先を元に戻す
SetLocalDirHist(LocDir);
SetCurrentDirAsDirHist();
// 外部アプリケーションへドロップ後にローカル側のファイル一覧に作業フォルダが表示されるバグ対策
SuppressRefresh = 0;
GetLocalDirForWnd();
remoteFileListBase = std::move(FileListBase);
remoteFileListBaseNoExpand = std::move(FileListBaseNoExpand);
remoteFileDir = std::move(tmp);
}
// テンポラリのファイルおよびフォルダを削除する。
void doDeleteRemoteFile(void)
{
if (std::error_code ec; !empty(remoteFileListBase)) {
fs::remove_all(remoteFileDir, ec);
remoteFileListBase.clear();
}
remoteFileListBaseNoExpand.clear();
}
// yutaka
// cf. http://www.nakka.com/lib/
/* ドロップファイルの作成 */
static HDROP CreateDropFileMem(std::vector<fs::path> const& filenames) {
// 構造体の後ろに続くファイル名のリスト(ファイル名\0ファイル名\0ファイル名\0\0)
std::wstring extra;
for (auto const& filename : filenames) {
extra += filename;
extra += L'\0';
}
extra += L'\0';
if (auto drop = (HDROP)GlobalAlloc(GHND, sizeof(DROPFILES) + size(extra) * sizeof(wchar_t))) {
if (auto dropfiles = static_cast<DROPFILES*>(GlobalLock(drop))) {
*dropfiles = { sizeof(DROPFILES), {}, false, true };
std::copy(begin(extra), end(extra), reinterpret_cast<wchar_t*>(dropfiles + 1));
GlobalUnlock(drop);
return drop;
}
GlobalFree(drop);
}
return 0;
}
// OLE D&Dを開始する
// (2007.8.30 yutaka)
static void doDragDrop(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
POINT pt;
// テンポラリをきれいにする (2007.9.3 yutaka)
doDeleteRemoteFile();
/* ドラッグ&ドロップの開始 */
CLIPFORMAT clipFormat = CF_HDROP;
OleDragDrop::DoDragDrop(hWnd, WM_GETDATA, WM_DRAGOVER, &clipFormat, 1, DROPEFFECT_COPY | DROPEFFECT_MOVE | DROPEFFECT_LINK);
// ドロップ先のアプリに WM_LBUTTONUP を飛ばす。
// 特定の操作を行うと異常終了するバグ修正
// GetCursorPos(&pt);
pt = DropPoint;
ScreenToClient(hWnd, &pt);
PostMessageW(hWnd,WM_LBUTTONUP,0,MAKELPARAM(pt.x,pt.y));
// ドロップ先が他プロセスかつカーソルが自プロセスのドロップ可能なウィンドウ上にある場合の対策
EnableWindow(GetMainHwnd(), TRUE);
}
// ファイル一覧ウインドウの共通メッセージ処理
static LRESULT CALLBACK FileListCommonWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
static POINT DragPoint;
static HWND hWndDragStart;
static int RemoteDropFileIndex = -1;
static int DragFirstTime = NO;
int Win = WIN_LOCAL;
HWND hWndDst = hWndListRemote;
HWND hWndHistEdit = GetLocalHistEditHwnd();
if (hWnd == hWndListRemote) {
Win = WIN_REMOTE;
hWndDst = hWndListLocal;
hWndHistEdit = GetRemoteHistEditHwnd();
}
switch (message) {
case WM_CREATE: {
auto const result = CallWindowProcW(ListViewProc, hWnd, message, wParam, lParam);
SendMessageW(hWnd, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_FULLROWSELECT | LVS_EX_LABELTIP, LVS_EX_FULLROWSELECT | LVS_EX_LABELTIP);
if (ListFont)
SendMessageW(hWnd, WM_SETFONT, (WPARAM)ListFont, MAKELPARAM(TRUE, 0));
SendMessageW(hWnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)ListImg);
return result;
}
case WM_SYSKEYDOWN:
if (wParam == 'D') { // Alt+D
SetFocus(hWndHistEdit);
return 0;
}
break;
case WM_KEYDOWN:
if (wParam == 0x09) {
SetFocus(hWndDst);
return 0;
}
break;
case WM_SETFOCUS:
SetFocusHwnd(hWnd);
MakeButtonsFocus();
DispCurrentWindow(Win);
DispSelectedSpace();
break;
case WM_KILLFOCUS:
MakeButtonsFocus();
DispCurrentWindow(-1);
break;
case WM_DROPFILES:
if (!AskUserOpeDisabled())
if (Dragging != YES) { // ドラッグ中は処理しない。ドラッグ後にWM_LBUTTONDOWNが飛んでくるため、そこで処理する。
if (hWnd == hWndListRemote) {
if (AskConnecting() == YES)
UploadDragProc(wParam);
} else if (hWnd == hWndListLocal)
ChangeDirDropFileProc(wParam);
}
DragFinish((HDROP)wParam);
return 0;
case WM_LBUTTONDOWN:
if (AskUserOpeDisabled())
return 0;
if (Dragging == YES)
return 0;
DragFirstTime = NO;
GetCursorPos(&DropPoint);
SetFocus(hWnd);
DragPoint = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
hWndDragStart = hWnd;
break;
case WM_LBUTTONUP:
if (AskUserOpeDisabled())
return 0;
if (Dragging == YES) {
Dragging = NO;
ReleaseCapture();
POINT Point = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
ClientToScreen(hWnd, &Point);
auto hWndPnt = WindowFromPoint(Point);
if (hWndPnt == hWndDst) { // local <-> remote
if (hWndPnt == hWndListRemote)
PostMessageW(GetMainHwnd(), WM_COMMAND, MAKEWPARAM(MENU_UPLOAD, 0), 0);
else if (hWndPnt == hWndListLocal)
PostMessageW(GetMainHwnd(), WM_COMMAND, MAKEWPARAM(MENU_DOWNLOAD, 0), 0);
} else if (hWndDragStart == hWndListRemote && hWndPnt == hWndListRemote && RemoteDropFileIndex != -1) { // remote <-> remoteの場合は、サーバでのファイルの移動を行う。(2007.9.5 yutaka)
ListView_SetItemState(hWnd, RemoteDropFileIndex, 0, LVIS_DROPHILITED);
MoveRemoteFileProc(RemoteDropFileIndex);
}
}
break;
case WM_DRAGDROP:
if (DragFirstTime == NO)
doDragDrop(hWnd, message, wParam, lParam);
DragFirstTime = YES;
return TRUE;
case WM_GETDATA: // ファイルのパスをD&D先のアプリへ返す (yutaka)
switch (wParam) {
case CF_HDROP: { /* ファイル */
std::vector<FILELIST> FileListBase, FileListBaseNoExpand;
fs::path PathDir;
// 特定の操作を行うと異常終了するバグ修正
GetCursorPos(&DropPoint);
auto hWndPnt = WindowFromPoint(DropPoint);
auto hWndParent = GetParent(hWndPnt);
DisableUserOpe();
CancelFlg = NO;
// ローカル側で選ばれているファイルをFileListBaseに登録
if (hWndDragStart == hWndListLocal) {
PathDir = AskLocalCurDir();
if (hWndPnt != hWndListRemote && hWndPnt != hWndListLocal && hWndParent != hWndListRemote && hWndParent != hWndListLocal)
MakeSelectedFileList(WIN_LOCAL, NO, NO, FileListBase, &CancelFlg);
FileListBaseNoExpand = FileListBase;
} else if (hWndDragStart == hWndListRemote) {
if (hWndPnt != hWndListRemote && hWndPnt != hWndListLocal && hWndParent != hWndListRemote && hWndParent != hWndListLocal) {
// 選択されているリモートファイルのリストアップ
// このタイミングでリモートからローカルの一時フォルダへダウンロードする
// (2007.8.31 yutaka)
doTransferRemoteFile();
PathDir = remoteFileDir;
FileListBase = remoteFileListBase;
FileListBaseNoExpand = remoteFileListBaseNoExpand;
}
}
auto const& pf =
#if defined(HAVE_TANDEM)
empty(FileListBaseNoExpand) ? FileListBase :
#endif
FileListBaseNoExpand;
// 特定の操作を行うと異常終了するバグ修正
if (!empty(pf)) {
Dragging = NO;
ReleaseCapture();
// ドロップ先が他プロセスかつカーソルが自プロセスのドロップ可能なウィンドウ上にある場合の対策
EnableWindow(GetMainHwnd(), FALSE);
}
EnableUserOpe();
if (empty(pf)) {
// ファイルが未選択の場合は何もしない。(yutaka)
*(HANDLE*)lParam = NULL;
return FALSE;
}
// ドロップ先が他プロセスかつカーソルが自プロセスのドロップ可能なウィンドウ上にある場合の対策
EnableWindow(GetMainHwnd(), FALSE);
/* ドロップファイルリストの作成 */
/* ファイル名の配列を作成する */
/* NTの場合はUNICODEになるようにする */
std::vector<fs::path> filenames;
for (auto const& f : FileListBaseNoExpand)
filenames.emplace_back(PathDir / f.Name);
*(HANDLE*)lParam = CreateDropFileMem(filenames);
return TRUE;
}
}
*(HANDLE*)lParam = NULL;
return 0;
case WM_DRAGOVER: {
// 同一ウィンドウ内でのD&Dはリモート側のみ
if (Win != WIN_REMOTE)
return 0;
if (MoveMode == MOVE_DISABLE)
return 0;
POINT Point;
GetCursorPos(&Point);
auto hWndPnt = WindowFromPoint(Point);
ScreenToClient(hWnd, &Point);
// 以前の選択を消す
static int prev_index = -1;
ListView_SetItemState(hWnd, prev_index, 0, LVIS_DROPHILITED);
RemoteDropFileIndex = -1;
if (hWndPnt == hWndListRemote)
if (LVHITTESTINFO hi{ Point }; ListView_HitTest(hWnd, &hi) != -1 && hi.flags == LVHT_ONITEMLABEL) { // The position is over a list-view item's text.
prev_index = hi.iItem;
if (GetItem(Win, hi.iItem).Node == NODE_DIR) {
ListView_SetItemState(hWnd, hi.iItem, LVIS_DROPHILITED, LVIS_DROPHILITED);
RemoteDropFileIndex = hi.iItem;
}
}
return 0;
}
case WM_RBUTTONDOWN:
if (AskUserOpeDisabled())
return 0;
/* ここでファイルを選ぶ */
CallWindowProcW(ListViewProc, hWnd, message, wParam, lParam);
SetFocus(hWnd);
if (hWnd == hWndListRemote)
ShowPopupMenu(WIN_REMOTE, 0);
else if (hWnd == hWndListLocal)
ShowPopupMenu(WIN_LOCAL, 0);
return 0;
case WM_LBUTTONDBLCLK:
if (AskUserOpeDisabled())
return 0;
DoubleClickProc(Win, NO, -1);
return 0;
case WM_MOUSEMOVE:
if (AskUserOpeDisabled())
return 0;
if (wParam == MK_LBUTTON) {
if (Dragging == NO && hWnd == hWndDragStart && AskConnecting() == YES && SendMessageW(hWnd, LVM_GETSELECTEDCOUNT, 0, 0) > 0 && (abs(GET_X_LPARAM(lParam) - DragPoint.x) > 5 || abs(GET_Y_LPARAM(lParam) - DragPoint.y) > 5)) {
SetCapture(hWnd);
Dragging = YES;
} else if (Dragging == YES) {
// OLE D&Dの開始を指示する
PostMessageW(hWnd, WM_DRAGDROP, MAKEWPARAM(wParam, lParam), 0);
} else
break;
} else
break;
return 0;
case WM_MOUSEWHEEL:
if (AskUserOpeDisabled())
return 0;
if (Dragging == NO) {
short const zDelta = (short)HIWORD(wParam);
auto hWndPnt = WindowFromPoint({ GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) });
if ((wParam & MAKEWPARAM(MK_SHIFT, 0)) && (hWndPnt == hWndListRemote || hWndPnt == hWndListLocal || hWndPnt == GetTaskWnd()))
PostMessageW(hWndPnt, WM_VSCROLL, zDelta > 0 ? MAKEWPARAM(SB_PAGEUP, 0) : MAKEWPARAM(SB_PAGEDOWN, 0), 0);
else if (hWndPnt == hWnd)
break;
else if (hWndPnt == hWndDst || hWndPnt == GetTaskWnd())
PostMessageW(hWndPnt, message, wParam, lParam);
}
return 0;
case WM_NOTIFY:
switch (auto hdr = reinterpret_cast<NMHDR*>(lParam); hdr->code) {
case HDN_ITEMCHANGEDW:
if (auto header = reinterpret_cast<NMHEADERW*>(lParam); header->pitem && (header->pitem->mask & HDI_WIDTH))
(hWnd == hWndListLocal ? LocalTabWidth : RemoteTabWidth)[header->iItem] = header->pitem->cxy;
break;
}
break;
}
return CallWindowProcW(ListViewProc, hWnd, message, wParam, lParam);
}
// ファイル一覧方法にしたがってリストビューを設定する
void SetListViewType() noexcept {
SetWindowLongPtrW(GetLocalHwnd(), GWL_STYLE, GetWindowLongPtrW(GetLocalHwnd(), GWL_STYLE) & ~LVS_TYPEMASK | ListType);
SetWindowLongPtrW(GetRemoteHwnd(), GWL_STYLE, GetWindowLongPtrW(GetRemoteHwnd(), GWL_STYLE) & ~LVS_TYPEMASK | ListType);
}
// ホスト側のファイル一覧ウインドウにファイル名をセット
void GetRemoteDirForWnd(int Mode, int *CancelCheckWork) {
if (AskConnecting() == YES) {
DisableUserOpe();
SetRemoteDirHist(AskRemoteCurDir());
if (Mode == CACHE_LASTREAD || DoDirList(L""sv, 0, CancelCheckWork) == FTP_COMPLETE) {
if (auto lines = GetListLine(0)) {
remoteFileList.clear();
for (auto const& line : *lines)
if (auto p = std::get_if<FILELIST>(&line); p && p->Node != NODE_NONE && AskFilterStr(p->Name, p->Node) == YES && (DotFile == YES || p->Name[0] != '.'))
remoteFileList.emplace_back(*p);
DispFileList2View(GetRemoteHwnd(), remoteFileList);
// 先頭のアイテムを選択
ListView_SetItemState(GetRemoteHwnd(), 0, LVIS_FOCUSED, LVIS_FOCUSED);
} else {
Notice(IDS_MSGJPN048);
SendMessageW(GetRemoteHwnd(), LVM_DELETEALLITEMS, 0, 0);
}
} else {
#if defined(HAVE_OPENVMS)
/* OpenVMSの場合空ディレクトリ移動の時に出るので、メッセージだけ出さない
* ようにする(VIEWはクリアして良い) */
if (AskHostType() != HTYPE_VMS)
#endif
Notice(IDS_MSGJPN049);
SendMessageW(GetRemoteHwnd(), LVM_DELETEALLITEMS, 0, 0);
}
EnableUserOpe();
}
}
// ローカル側のファイル一覧ウインドウにファイル名をセット
void RefreshIconImageList(std::vector<FILELIST>& files)
{
HBITMAP hBitmap;
if(DispFileIcon == YES)
{
SendMessageW(hWndListLocal, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)NULL);
ShowWindow(hWndListLocal, SW_SHOW);
SendMessageW(hWndListRemote, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)NULL);
ShowWindow(hWndListRemote, SW_SHOW);
ImageList_Destroy(ListImgFileIcon);
ListImgFileIcon = ImageList_Create(16, 16, ILC_MASK | ILC_COLOR32, 0, 1);
hBitmap = LoadBitmapW(GetFtpInst(), MAKEINTRESOURCEW(dirattr16_bmp));
ImageList_AddMasked(ListImgFileIcon, hBitmap, RGB(255, 0, 0));
DeleteObject(hBitmap);
int ImageId = 0;
for (auto& file : files) {
file.ImageId = -1;
fs::path fullpath{ file.Name };
if (file.Node != NODE_DRIVE)
fullpath = fs::current_path() / fullpath;
if (SHFILEINFOW fi; __pragma(warning(suppress:6001)) SHGetFileInfoW(fullpath.c_str(), 0, &fi, sizeof(SHFILEINFOW), SHGFI_SMALLICON | SHGFI_ICON)) {
if (ImageList_AddIcon(ListImgFileIcon, fi.hIcon) >= 0)
file.ImageId = ImageId++;
DestroyIcon(fi.hIcon);
}
}
SendMessageW(hWndListLocal, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)ListImgFileIcon);
ShowWindow(hWndListLocal, SW_SHOW);
SendMessageW(hWndListRemote, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)ListImgFileIcon);
ShowWindow(hWndListRemote, SW_SHOW);
}
else
{
SendMessageW(hWndListLocal, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)ListImg);
ShowWindow(hWndListLocal, SW_SHOW);
SendMessageW(hWndListRemote, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)ListImg);
ShowWindow(hWndListRemote, SW_SHOW);
}
}
void GetLocalDirForWnd() {
auto const cwd = DoLocalPWD();
SetLocalDirHist(cwd);
DispLocalFreeSpace(cwd);
// ローカル側自動更新
if(ChangeNotification != INVALID_HANDLE_VALUE)
FindCloseChangeNotification(ChangeNotification);
ChangeNotification = FindFirstChangeNotificationW(cwd.c_str(), FALSE, FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_DIR_NAME | FILE_NOTIFY_CHANGE_ATTRIBUTES | FILE_NOTIFY_CHANGE_SIZE | FILE_NOTIFY_CHANGE_LAST_WRITE);
/* ディレクトリ/ファイル */
localFileList.clear();
FindFile(cwd / L"*", [](WIN32_FIND_DATAW const& data) {
if (DotFile != YES && data.cFileName[0] == L'.')
return true;
if (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
localFileList.emplace_back(data.cFileName, NODE_DIR, NO, (int64_t)data.nFileSizeHigh << 32 | data.nFileSizeLow, 0, data.ftLastWriteTime, FINFO_ALL);
else if (AskFilterStr(data.cFileName, NODE_FILE) == YES)
localFileList.emplace_back(data.cFileName, NODE_FILE, NO, (int64_t)data.nFileSizeHigh << 32 | data.nFileSizeLow, 0, data.ftLastWriteTime, FINFO_ALL);
return true;
});
/* ドライブ */
if (DispDrives)
GetDrives([](const wchar_t drive[]) { localFileList.emplace_back(drive, NODE_DRIVE, NO, 0, 0, FILETIME{}, FINFO_ALL); });
// ファイルアイコン表示対応
RefreshIconImageList(localFileList);
DispFileList2View(GetLocalHwnd(), localFileList);
// 先頭のアイテムを選択
ListView_SetItemState(GetLocalHwnd(), 0, LVIS_FOCUSED, LVIS_FOCUSED);
return;
}
// ファイル一覧用リストの内容をファイル一覧ウインドウにセット
static void DispFileList2View(HWND hWnd, std::vector<FILELIST>& files) {
std::sort(begin(files), end(files), [hWnd](FILELIST& l, FILELIST& r) {
if (l.Node != r.Node)
return l.Node < r.Node;
auto const Sort = hWnd == GetRemoteHwnd() ? l.Node == NODE_DIR ? AskSortType().RemoteDirectory : AskSortType().RemoteFile : l.Node == NODE_DIR ? AskSortType().LocalDirectory : AskSortType().LocalFile;
auto const test = [ascent = (Sort & SORT_GET_ORD) == SORT_ASCENT](auto r) { return ascent ? r < 0 : r > 0; };
LONGLONG Cmp = 0;
fs::path lf{ l.Name }, rf{ r.Name };
if ((Sort & SORT_MASK_ORD) == SORT_EXT && test(Cmp = _wcsicmp(lf.extension().c_str(), rf.extension().c_str())))
return true;
#if defined(HAVE_TANDEM)
if (AskHostType() == HTYPE_TANDEM && (Sort & SORT_MASK_ORD) == SORT_EXT && test(Cmp = (LONGLONG)l.Attr - r.Attr))
return true;
#endif
if ((Sort & SORT_MASK_ORD) == SORT_SIZE && test(Cmp = l.Size - r.Size))
return true;
if ((Sort & SORT_MASK_ORD) == SORT_DATE && test(Cmp = CompareFileTime(&l.Time, &r.Time)))
return true;
if ((Sort & SORT_MASK_ORD) == SORT_NAME || Cmp == 0)
if (test(_wcsicmp(lf.c_str(), rf.c_str())))
return true;
return false;
});
SendMessageW(hWnd, WM_SETREDRAW, false, 0);
SendMessageW(hWnd, LVM_DELETEALLITEMS, 0, 0);
for (int index = 0; auto& file : files)
AddListView(hWnd, index++, file.Name, file.Node, file.Size, &file.Time, file.Attr, file.Owner, file.Link, file.InfoExist, file.ImageId);
SendMessageW(hWnd, WM_SETREDRAW, true, 0);
UpdateWindow(hWnd);
DispSelectedSpace();
}
// FILETIME(UTC)を日付文字列(JST)に変換
static auto FileTimeToString(FILETIME ft, int InfoExist) {
std::wstring str;
if ((ft.dwLowDateTime != 0 || ft.dwHighDateTime != 0) && (InfoExist & (FINFO_DATE | FINFO_TIME)) != 0) {
FileTimeToLocalFileTime(&ft, &ft);
if (SYSTEMTIME st; FileTimeToSystemTime(&ft, &st)) {
if (InfoExist & FINFO_DATE)
std::format_to(std::back_inserter(str), L"{:04d}/{:02d}/{:02d} "sv, st.wYear, st.wMonth, st.wDay);
else
str += L" "sv;
if (InfoExist & FINFO_TIME)
std::vformat_to(std::back_inserter(str), DispTimeSeconds == YES ? L"{:02d}:{:02d}:{:02d}"sv : L"{:02d}:{:02d}"sv, std::make_wformat_args(st.wHour, st.wMinute, st.wSecond));
else
str += DispTimeSeconds == YES ? L" "sv : L" "sv;
}
}
return str;
}
// パス名の中の拡張子の先頭を返す
static std::wstring GetFileExt(std::wstring const& path) {
if (path != L"."sv && path != L".."sv)
if (auto const pos = path.rfind(L'.'); pos != std::wstring::npos)
return path.substr(pos + 1);
return {};
}
// 属性の値を文字列に変換
static std::wstring AttrValue2String(int Attr) {
if (DispPermissionsNumber == YES)
return std::format(L"{:03x}"sv, Attr);
auto str = L"rwxrwxrwx"s;
constexpr int masks[] = { 0x400, 0x200, 0x100, 0x40, 0x20, 0x10, 0x4, 0x2, 0x1 };
for (size_t i = 0; i < std::size(masks); i++)
if ((Attr & masks[i]) == 0)
str[i] = L'-';
return str;
}
/*----- ファイル一覧ウインドウ(リストビュー)に追加 --------------------------
*
* Parameter
* HWND hWnd : ウインドウハンドル
* int Pos : 挿入位置
* char *Name : 名前
* int Type : タイプ (NIDE_xxxx)
* LONGLONG Size : サイズ
* FILETIME *Time : 日付
* int Attr : 属性
* char Owner : オーナ名
* int Link : リンクかどうか
* int InfoExist : 情報があるかどうか (FINFO_xxx)
*
* Return Value
* なし
*----------------------------------------------------------------------------*/
static void AddListView(HWND hWnd, int Pos, std::wstring const& Name, int Type, LONGLONG Size, FILETIME* Time, int Attr, std::wstring const& Owner, int Link, int InfoExist, int ImageId) {
static const std::locale default_locale{ ""s };
LVITEMW item;
std::wstring text;
/* アイコン/ファイル名 */
if (Type == NODE_FILE && AskTransferTypeAssoc(Name, TYPE_X) == TYPE_I)
Type = 3;
item = { .mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM, .iItem = Pos, .pszText = const_cast<LPWSTR>(Name.c_str()), .iImage = DispFileIcon == YES && hWnd == GetLocalHwnd() ? ImageId + 5 : Link == NO ? Type : 4, .lParam = Pos };
SendMessageW(hWnd, LVM_INSERTITEMW, 0, (LPARAM)&item);
/* 日付/時刻 */
text = FileTimeToString(*Time, InfoExist);
item = { .mask = LVIF_TEXT, .iItem = Pos, .iSubItem = 1, .pszText = const_cast<LPWSTR>(text.c_str()) };
SendMessageW(hWnd, LVM_SETITEMW, 0, (LPARAM)&item);
/* サイズ */
text = Type == NODE_DIR ? L"<DIR>"s
: Type == NODE_DRIVE ? L"<DRIVE>"s
: 0 <= Size ? std::format(default_locale, L"{:Ld}"sv, Size)
: L""s;
item = { .mask = LVIF_TEXT, .iItem = Pos, .iSubItem = 2, .pszText = const_cast<LPWSTR>(text.c_str()) };
SendMessageW(hWnd, LVM_SETITEMW, 0, (LPARAM)&item);
/* 拡張子 */
std::wstring extension;
#if defined(HAVE_TANDEM)
if (AskHostType() == HTYPE_TANDEM)
extension = std::to_wstring(Attr);
else
#endif
extension = GetFileExt(Name);
item = { .mask = LVIF_TEXT, .iItem = Pos, .iSubItem = 3, .pszText = const_cast<LPWSTR>(extension.c_str()) };
SendMessageW(hWnd, LVM_SETITEMW, 0, (LPARAM)&item);
if (hWnd == GetRemoteHwnd()) {
/* 属性 */
#if defined(HAVE_TANDEM)
if ((InfoExist & FINFO_ATTR) && (AskHostType() != HTYPE_TANDEM))
#else
if (InfoExist & FINFO_ATTR)
#endif
text = AttrValue2String(Attr);
else
text = L""s;
item = { .mask = LVIF_TEXT, .iItem = Pos, .iSubItem = 4, .pszText = const_cast<LPWSTR>(text.c_str()) };
SendMessageW(hWnd, LVM_SETITEMW, 0, (LPARAM)&item);
/* オーナ名 */
item = { .mask = LVIF_TEXT, .iItem = Pos, .iSubItem = 5, .pszText = const_cast<LPWSTR>(Owner.c_str()) };
SendMessageW(hWnd, LVM_SETITEMW, 0, (LPARAM)&item);
}
}
void RefreshLocal() {
std::vector<std::tuple<std::wstring, UINT>> states;
for (int pos = -1; (pos = (int)SendMessageW(hWndListLocal, LVM_GETNEXTITEM, pos, LVNI_SELECTED)) != -1;) {
LVITEMW li{ .mask = LVIF_PARAM | LVIF_STATE, .iItem = pos, .stateMask = LVIS_SELECTED };
SendMessageW(hWndListLocal, LVM_GETITEMW, 0, (LPARAM)&li);
states.emplace_back(localFileList[li.lParam].Name, li.state);
}
if (auto const pos = (int)SendMessageW(hWndListLocal, LVM_GETNEXTITEM, -1, LVNI_FOCUSED); pos != -1)
states.emplace_back(GetItem(WIN_LOCAL, pos).Name, LVIS_FOCUSED);
auto const topPos = (int)SendMessageW(hWndListLocal, LVM_GETTOPINDEX, 0, 0);
GetLocalDirForWnd();
for (auto [name, state] : states)
if (auto const it = std::ranges::find(localFileList, name, &FILELIST::Name); it != end(localFileList)) {
LVFINDINFOW lf{ .flags = LVFI_PARAM, .lParam = std::distance(begin(localFileList), it) };
auto const pos = (int)SendMessageW(hWndListLocal, LVM_FINDITEMW, -1, (LPARAM)&lf);
LVITEMW li{ .mask = LVIF_STATE, .iItem = pos, .state = state, .stateMask = state };
SendMessageW(hWndListLocal, LVM_SETITEMW, 0, (LPARAM)&li);
}
SendMessageW(hWndListLocal, LVM_ENSUREVISIBLE, (WPARAM)(size(localFileList) - 1), true);
SendMessageW(hWndListLocal, LVM_ENSUREVISIBLE, (WPARAM)topPos, true);
}
/*----- ファイル名一覧ウインドウをソートし直す --------------------------------
*
* Parameter
* int Win : ウィンドウ番号 (WIN_xxxx)
*
* Return Value
* なし
*----------------------------------------------------------------------------*/
void ReSortDispList(int Win, int *CancelCheckWork)
{
if(Win == WIN_REMOTE)
GetRemoteDirForWnd(CACHE_LASTREAD, CancelCheckWork);
else
GetLocalDirForWnd();
return;
}
// ワイルドカードにマッチするかどうかを返す
// VAX VMSの時は ; 以降は無視する
bool CheckFname(std::wstring const& file, std::wstring const& spec) {
auto const pos = AskHostType() == HTYPE_VMS ? file.find(L';') : std::wstring::npos;
return PathMatchSpecW((pos == std::wstring::npos ? file : file.substr(0, pos)).c_str(), spec.c_str());
}
// ファイル一覧ウインドウのファイルを選択する
void SelectFileInList(HWND hWnd, int Type, std::vector<FILELIST> const& Base) {
static bool IgnoreNew = false;
static bool IgnoreOld = false;
static bool IgnoreExist = false;
struct Select {
using result_t = bool;
INT_PTR OnInit(HWND hDlg) noexcept {
SendDlgItemMessageW(hDlg, SEL_FNAME, EM_LIMITTEXT, 40, 0);
SetText(hDlg, SEL_FNAME, FindStr);
SendDlgItemMessageW(hDlg, SEL_REGEXP, BM_SETCHECK, FindMode, 0);
SendDlgItemMessageW(hDlg, SEL_NOOLD, BM_SETCHECK, IgnoreOld ? BST_CHECKED : BST_UNCHECKED, 0);
SendDlgItemMessageW(hDlg, SEL_NONEW, BM_SETCHECK, IgnoreNew ? BST_CHECKED : BST_UNCHECKED, 0);
SendDlgItemMessageW(hDlg, SEL_NOEXIST, BM_SETCHECK, IgnoreExist ? BST_CHECKED : BST_UNCHECKED, 0);
return TRUE;
}
void OnCommand(HWND hDlg, WORD id) {
switch (id) {
case IDOK:
FindStr = GetText(hDlg, SEL_FNAME);
FindMode = (int)SendDlgItemMessageW(hDlg, SEL_REGEXP, BM_GETCHECK, 0, 0);
IgnoreOld = SendDlgItemMessageW(hDlg, SEL_NOOLD, BM_GETCHECK, 0, 0) == BST_CHECKED;
IgnoreNew = SendDlgItemMessageW(hDlg, SEL_NONEW, BM_GETCHECK, 0, 0) == BST_CHECKED;
IgnoreExist = SendDlgItemMessageW(hDlg, SEL_NOEXIST, BM_GETCHECK, 0, 0) == BST_CHECKED;
EndDialog(hDlg, true);
break;
case IDCANCEL:
EndDialog(hDlg, false);
break;
case IDHELP:
ShowHelp(IDH_HELP_TOPIC_0000061);
break;
}
}
};
int Win = WIN_LOCAL, WinDst = WIN_REMOTE;
if (hWnd == GetRemoteHwnd())
std::swap(Win, WinDst);
if (Type == SELECT_ALL) {
LVITEMW item{ 0, 0, 0, GetSelectedCount(Win) <= 1 ? LVIS_SELECTED : 0u, LVIS_SELECTED };
for (int const i : std::views::iota(0, GetItemCount(Win)))
if (GetItem(Win, i).Node != NODE_DRIVE)
SendMessageW(hWnd, LVM_SETITEMSTATE, i, (LPARAM)&item);
return;
}
if (Type == SELECT_REGEXP) {
if (!Dialog(GetFtpInst(), Win == WIN_LOCAL ? sel_local_dlg : sel_remote_dlg, hWnd, Select{}))
return;
try {
std::variant<std::wstring, boost::wregex> pattern;
if (FindMode == 0)
pattern = FindStr;
else
pattern = boost::wregex{ FindStr, boost::regex_constants::icase };
int CsrPos = -1;
auto const& thatFileList = WinDst == WIN_LOCAL ? localFileList : remoteFileList;
for (int const i : std::views::iota(0, GetItemCount(Win))) {
UINT state = 0;
if (auto const& thisItem = GetItem(Win, i); thisItem.Node != NODE_DRIVE) {
auto matched = std::visit([name = thisItem.Name](auto&& pattern) {
using t = std::decay_t<decltype(pattern)>;
if constexpr (std::is_same_v<t, std::wstring>)
return CheckFname(name, pattern);
else if constexpr (std::is_same_v<t, boost::wregex>)
return boost::regex_match(name, pattern);
else
static_assert(false_v<t>, "not supported variant type.");
}, pattern);
if (matched) {
auto const thatIt = std::ranges::find(thatFileList, thisItem.Name, &FILELIST::Name);
if (!(thatIt != end(thatFileList) && (IgnoreExist || IgnoreNew && CompareFileTime(&thisItem.Time, &thatIt->Time) > 0 || IgnoreOld && CompareFileTime(&thisItem.Time, &thatIt->Time) < 0)))
state = LVIS_SELECTED;
}
if (state != 0 && CsrPos == -1)
CsrPos = i;
}
LVITEMW item{ 0, 0, 0, state, LVIS_SELECTED };
SendMessageW(hWnd, LVM_SETITEMSTATE, i, (LPARAM)&item);
}
if (CsrPos != -1) {
LVITEMW item{ 0, 0, 0, LVIS_FOCUSED, LVIS_FOCUSED };
SendMessageW(hWnd, LVM_SETITEMSTATE, CsrPos, (LPARAM)&item);
SendMessageW(hWnd, LVM_ENSUREVISIBLE, CsrPos, (LPARAM)TRUE);
}
}
catch (boost::regex_error&) {}
return;
}
if (Type == SELECT_LIST) {
for (int const i : std::views::iota(0, GetItemCount(Win))) {
auto const& item = GetItem(Win, i);
LVITEMW li{ 0, 0, 0, SearchFileList(item.Name, Base, COMP_STRICT) != NULL ? LVIS_SELECTED : 0u, LVIS_SELECTED };
SendMessageW(hWnd, LVM_SETITEMSTATE, i, (LPARAM)&li);
}
return;
}
}
// ファイル一覧ウインドウのファイルを検索する
void FindFileInList(HWND hWnd, int Type) {
static std::variant<std::wstring, boost::wregex> pattern;
int const Win = hWnd == GetRemoteHwnd() ? WIN_REMOTE : WIN_LOCAL;
switch (Type) {
case FIND_FIRST:
if (!InputDialog(find_dlg, hWnd, Win == WIN_LOCAL ? IDS_MSGJPN050 : IDS_MSGJPN051, FindStr, 40 + 1, &FindMode))
return;
try {