OSDN Git Service

6b1072a8c7d036db10194693a38117d4c5e4e553
[ffftp/ffftp.git] / filelist.c
1 /*=============================================================================\r
2 *\r
3 *                                                               ファイル一覧\r
4 *\r
5 ===============================================================================\r
6 / Copyright (C) 1997-2007 Sota. All rights reserved.\r
7 /\r
8 / Redistribution and use in source and binary forms, with or without \r
9 / modification, are permitted provided that the following conditions \r
10 / are met:\r
11 /\r
12 /  1. Redistributions of source code must retain the above copyright \r
13 /     notice, this list of conditions and the following disclaimer.\r
14 /  2. Redistributions in binary form must reproduce the above copyright \r
15 /     notice, this list of conditions and the following disclaimer in the \r
16 /     documentation and/or other materials provided with the distribution.\r
17 /\r
18 / THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR \r
19 / IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES \r
20 / OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. \r
21 / IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, \r
22 / INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, \r
23 / BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF \r
24 / USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON \r
25 / ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
26 / (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF \r
27 / THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
28 /============================================================================*/\r
29 \r
30 // UTF-8対応\r
31 //#define _WIN32_WINNT  0x400\r
32 \r
33 #define STRICT\r
34 // IPv6対応\r
35 #include <winsock2.h>\r
36 #include <windows.h>\r
37 #include <stdio.h>\r
38 #include <stdlib.h>\r
39 #include <string.h>\r
40 #include <ctype.h>\r
41 #include <time.h>\r
42 #include <mbstring.h>\r
43 #include <malloc.h>\r
44 #include <windowsx.h>\r
45 #include <commctrl.h>\r
46 #include <sys/types.h>\r
47 #include <sys/stat.h>\r
48 #include <direct.h>\r
49 \r
50 #include "common.h"\r
51 #include "resource.h"\r
52 \r
53 #include <htmlhelp.h>\r
54 #include "helpid.h"\r
55 \r
56 #include <shlobj.h>\r
57 #include "OleDragDrop.h"\r
58 #include "common.h"\r
59 \r
60 // UTF-8対応\r
61 #undef __MBSWRAPPER_H__\r
62 #include "mbswrapper.h"\r
63 \r
64 #define BUF_SIZE                256\r
65 #define CF_CNT 2\r
66 #define WM_DRAGDROP             (WM_APP + 100)\r
67 #define WM_GETDATA              (WM_APP + 101)\r
68 #define WM_DRAGOVER             (WM_APP + 102)\r
69 \r
70 \r
71 /*===== ファイルリストのリスト用ストラクチャ =====*/\r
72 \r
73 typedef struct {\r
74         FILELIST *Top;                  /* ファイルリストの先頭 */\r
75         int Files;                              /* ファイルの数 */\r
76 } FLISTANCHOR;\r
77 \r
78 /*===== プロトタイプ =====*/\r
79 \r
80 static LRESULT CALLBACK LocalWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);\r
81 static LRESULT CALLBACK RemoteWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);\r
82 static LRESULT FileListCommonWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);\r
83 static void AddDispFileList(FLISTANCHOR *Anchor, char *Name, FILETIME *Time, LONGLONG Size, int Attr, int Type, int Link, char *Owner, int InfoExist, int Win);\r
84 static void EraseDispFileList(FLISTANCHOR *Anchor);\r
85 static void DispFileList2View(HWND hWnd, FLISTANCHOR *Anchor);\r
86 static void AddListView(HWND hWnd, int Pos, char *Name, int Type, LONGLONG Size, FILETIME *Time, int Attr, char *Owner, int Link, int InfoExist);\r
87 // 64ビット対応\r
88 //static BOOL CALLBACK SelectDialogCallBack(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam);\r
89 static INT_PTR CALLBACK SelectDialogCallBack(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam);\r
90 static void DispListList(FILELIST *Pos, char *Title);\r
91 static void MakeRemoteTree1(char *Path, char *Cur, FILELIST **Base, int *CancelCheckWork);\r
92 static void MakeRemoteTree2(char *Path, char *Cur, FILELIST **Base, int *CancelCheckWork);\r
93 static void CopyTmpListToFileList(FILELIST **Base, FILELIST *List);\r
94 static int GetListOneLine(char *Buf, int Max, FILE *Fd);\r
95 static int MakeDirPath(char *Str, int ListType, char *Path, char *Dir);\r
96 static void MakeLocalTree(char *Path, FILELIST **Base);\r
97 static void AddFileList(FILELIST *Pkt, FILELIST **Base);\r
98 static int AnalizeFileInfo(char *Str);\r
99 static int CheckUnixType(char *Str, char *Tmp, int Add1, int Add2, int Day);\r
100 static int CheckHHMMformat(char *Str);\r
101 static int CheckYYMMDDformat(char *Str, char Sym, int Dig3);\r
102 static int CheckYYYYMMDDformat(char *Str, char Sym);\r
103 static int ResolvFileInfo(char *Str, int ListType, char *Fname, LONGLONG *Size, FILETIME *Time, int *Attr, char *Owner, int *Link, int *InfoExist);\r
104 static int FindField(char *Str, char *Buf, int Num, int ToLast);\r
105 // MLSD対応\r
106 static int FindField2(char *Str, char *Buf, char Separator, int Num, int ToLast);\r
107 static void GetMonth(char *Str, WORD *Month, WORD *Day);\r
108 static int GetYearMonthDay(char *Str, WORD *Year, WORD *Month, WORD *Day);\r
109 static int GetHourAndMinute(char *Str, WORD *Hour, WORD *Minute);\r
110 static int GetVMSdate(char *Str, WORD *Year, WORD *Month, WORD *Day);\r
111 static int CheckSpecialDirName(char *Fname);\r
112 static int AskFilterStr(char *Fname, int Type);\r
113 // 64ビット対応\r
114 //static BOOL CALLBACK FilterWndProc(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam);\r
115 static INT_PTR CALLBACK FilterWndProc(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam);\r
116 static int atoi_n(const char *Str, int Len);\r
117 \r
118 /*===== 外部参照 =====*/\r
119 \r
120 extern int SepaWidth;\r
121 extern int RemoteWidth;\r
122 extern int ListHeight;\r
123 extern char FilterStr[FILTER_EXT_LEN+1];\r
124 extern HWND hHelpWin;\r
125 \r
126 /* 設定値 */\r
127 extern int LocalWidth;\r
128 extern int LocalTabWidth[4];\r
129 extern int RemoteTabWidth[6];\r
130 extern char UserMailAdrs[USER_MAIL_LEN+1];\r
131 extern HFONT ListFont;\r
132 extern int ListType;\r
133 extern int FindMode;\r
134 extern int DotFile;\r
135 extern int DispIgnoreHide;\r
136 extern int DispDrives;\r
137 extern int MoveMode;\r
138 \r
139 /*===== ローカルなワーク =====*/\r
140 \r
141 static HWND hWndListLocal = NULL;\r
142 static HWND hWndListRemote = NULL;\r
143 \r
144 static WNDPROC LocalProcPtr;\r
145 static WNDPROC RemoteProcPtr;\r
146 \r
147 static HIMAGELIST ListImg = NULL;\r
148 \r
149 static char FindStr[40+1] = { "*" };            /* 検索文字列 */\r
150 static int IgnoreNew = NO;\r
151 static int IgnoreOld = NO;\r
152 static int IgnoreExist = NO;\r
153 \r
154 static int Dragging = NO;\r
155 \r
156 static int StratusMode;                 /* 0=ファイル, 1=ディレクトリ, 2=リンク */\r
157 \r
158 \r
159 // リモートファイルリスト (2007.9.3 yutaka)\r
160 static FILELIST *remoteFileListBase;\r
161 static FILELIST *remoteFileListBaseNoExpand;\r
162 static char remoteFileDir[FMAX_PATH + 1];\r
163 \r
164 \r
165 /*----- ファイルリストウインドウを作成する ------------------------------------\r
166 *\r
167 *       Parameter\r
168 *               HWND hWnd : 親ウインドウのウインドウハンドル\r
169 *               HINSTANCE hInst : インスタンスハンドル\r
170 *\r
171 *       Return Value\r
172 *               int ステータス\r
173 *                       FFFTP_SUCCESS/FFFTP_FAIL\r
174 *----------------------------------------------------------------------------*/\r
175 \r
176 int MakeListWin(HWND hWnd, HINSTANCE hInst)\r
177 {\r
178         int Sts;\r
179         LV_COLUMN LvCol;\r
180         long Tmp;\r
181 \r
182         /*===== ローカル側のリストビュー =====*/\r
183 \r
184         hWndListLocal = CreateWindowEx(/*WS_EX_STATICEDGE*/WS_EX_CLIENTEDGE,\r
185                         WC_LISTVIEWA, NULL,\r
186                         WS_CHILD | /*WS_BORDER | */LVS_REPORT | LVS_SHOWSELALWAYS,\r
187                         0, TOOLWIN_HEIGHT*2, LocalWidth, ListHeight,\r
188                         GetMainHwnd(), (HMENU)1500, hInst, NULL);\r
189 \r
190         if(hWndListLocal != NULL)\r
191         {\r
192                 // 64ビット対応\r
193 //              LocalProcPtr = (WNDPROC)SetWindowLong(hWndListLocal, GWL_WNDPROC, (LONG)LocalWndProc);\r
194                 LocalProcPtr = (WNDPROC)SetWindowLongPtr(hWndListLocal, GWLP_WNDPROC, (LONG_PTR)LocalWndProc);\r
195 \r
196             Tmp = SendMessage(hWndListLocal, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);\r
197             Tmp |= LVS_EX_FULLROWSELECT;\r
198             SendMessage(hWndListLocal, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, (LPARAM)Tmp);\r
199 \r
200                 if(ListFont != NULL)\r
201                         SendMessage(hWndListLocal, WM_SETFONT, (WPARAM)ListFont, MAKELPARAM(TRUE, 0));\r
202 \r
203                 ListImg = ImageList_LoadBitmap(hInst, MAKEINTRESOURCE(dirattr_bmp), 16, 9, RGB(255,0,0));\r
204                 SendMessage(hWndListLocal, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)ListImg);\r
205                 ShowWindow(hWndListLocal, SW_SHOW);\r
206 \r
207                 LvCol.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;\r
208                 LvCol.cx = LocalTabWidth[0];\r
209                 LvCol.pszText = MSGJPN038;\r
210                 LvCol.iSubItem = 0;\r
211                 SendMessage(hWndListLocal, LVM_INSERTCOLUMN, 0, (LPARAM)&LvCol);\r
212 \r
213                 LvCol.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;\r
214                 LvCol.cx = LocalTabWidth[1];\r
215                 LvCol.pszText = MSGJPN039;\r
216                 LvCol.iSubItem = 1;\r
217                 SendMessage(hWndListLocal, LVM_INSERTCOLUMN, 1, (LPARAM)&LvCol);\r
218 \r
219                 LvCol.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM | LVCF_FMT;\r
220                 LvCol.fmt = LVCFMT_RIGHT;\r
221                 LvCol.cx = LocalTabWidth[2];\r
222                 LvCol.pszText = MSGJPN040;\r
223                 LvCol.iSubItem = 2;\r
224                 SendMessage(hWndListLocal, LVM_INSERTCOLUMN, 2, (LPARAM)&LvCol);\r
225 \r
226                 LvCol.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;\r
227                 LvCol.cx = LocalTabWidth[3];\r
228                 LvCol.pszText = MSGJPN041;\r
229                 LvCol.iSubItem = 3;\r
230                 SendMessage(hWndListLocal, LVM_INSERTCOLUMN, 3, (LPARAM)&LvCol);\r
231         }\r
232 \r
233         /*===== ホスト側のリストビュー =====*/\r
234 \r
235         hWndListRemote = CreateWindowEx(/*WS_EX_STATICEDGE*/WS_EX_CLIENTEDGE,\r
236                         WC_LISTVIEWA, NULL,\r
237                         WS_CHILD | /*WS_BORDER | */LVS_REPORT | LVS_SHOWSELALWAYS,\r
238                         LocalWidth + SepaWidth, TOOLWIN_HEIGHT*2, RemoteWidth, ListHeight,\r
239                         GetMainHwnd(), (HMENU)1500, hInst, NULL);\r
240 \r
241         if(hWndListRemote != NULL)\r
242         {\r
243                 // 64ビット対応\r
244 //              RemoteProcPtr = (WNDPROC)SetWindowLong(hWndListRemote, GWL_WNDPROC, (LONG)RemoteWndProc);\r
245                 RemoteProcPtr = (WNDPROC)SetWindowLongPtr(hWndListRemote, GWLP_WNDPROC, (LONG_PTR)RemoteWndProc);\r
246 \r
247             Tmp = SendMessage(hWndListRemote, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);\r
248             Tmp |= LVS_EX_FULLROWSELECT;\r
249             SendMessage(hWndListRemote, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, (LPARAM)Tmp);\r
250 \r
251                 if(ListFont != NULL)\r
252                         SendMessage(hWndListRemote, WM_SETFONT, (WPARAM)ListFont, MAKELPARAM(TRUE, 0));\r
253 \r
254                 SendMessage(hWndListRemote, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)ListImg);\r
255                 ShowWindow(hWndListRemote, SW_SHOW);\r
256 \r
257                 LvCol.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;\r
258                 LvCol.cx = RemoteTabWidth[0];\r
259                 LvCol.pszText = MSGJPN042;\r
260                 LvCol.iSubItem = 0;\r
261                 SendMessage(hWndListRemote, LVM_INSERTCOLUMN, 0, (LPARAM)&LvCol);\r
262 \r
263                 LvCol.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;\r
264                 LvCol.cx = RemoteTabWidth[1];\r
265                 LvCol.pszText = MSGJPN043;\r
266                 LvCol.iSubItem = 1;\r
267                 SendMessage(hWndListRemote, LVM_INSERTCOLUMN, 1, (LPARAM)&LvCol);\r
268 \r
269                 LvCol.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM | LVCF_FMT;\r
270                 LvCol.fmt = LVCFMT_RIGHT;\r
271                 LvCol.cx = RemoteTabWidth[2];\r
272                 LvCol.pszText = MSGJPN044;\r
273                 LvCol.iSubItem = 2;\r
274                 SendMessage(hWndListRemote, LVM_INSERTCOLUMN, 2, (LPARAM)&LvCol);\r
275 \r
276                 LvCol.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;\r
277                 LvCol.cx = RemoteTabWidth[3];\r
278                 LvCol.pszText = MSGJPN045;\r
279                 LvCol.iSubItem = 3;\r
280                 SendMessage(hWndListRemote, LVM_INSERTCOLUMN, 3, (LPARAM)&LvCol);\r
281 \r
282                 LvCol.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;\r
283                 LvCol.cx = RemoteTabWidth[4];\r
284                 LvCol.pszText = MSGJPN046;\r
285                 LvCol.iSubItem = 4;\r
286                 SendMessage(hWndListRemote, LVM_INSERTCOLUMN, 4, (LPARAM)&LvCol);\r
287 \r
288                 LvCol.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;\r
289                 LvCol.cx = RemoteTabWidth[5];\r
290                 LvCol.pszText = MSGJPN047;\r
291                 LvCol.iSubItem = 5;\r
292                 SendMessage(hWndListRemote, LVM_INSERTCOLUMN, 5, (LPARAM)&LvCol);\r
293         }\r
294 \r
295         Sts = FFFTP_SUCCESS;\r
296         if((hWndListLocal == NULL) ||\r
297            (hWndListRemote == NULL))\r
298         {\r
299                 Sts = FFFTP_FAIL;\r
300         }\r
301         return(Sts);\r
302 }\r
303 \r
304 \r
305 /*----- ファイルリストウインドウを削除 ----------------------------------------\r
306 *\r
307 *       Parameter\r
308 *               なし\r
309 *\r
310 *       Return Value\r
311 *               なし\r
312 *----------------------------------------------------------------------------*/\r
313 \r
314 void DeleteListWin(void)\r
315 {\r
316 //      if(ListImg != NULL)\r
317 //              ImageList_Destroy(ListImg);\r
318         if(hWndListLocal != NULL)\r
319                 DestroyWindow(hWndListLocal);\r
320         if(hWndListRemote != NULL)\r
321                 DestroyWindow(hWndListRemote);\r
322         return;\r
323 }\r
324 \r
325 \r
326 /*----- ローカル側のファイルリストのウインドウハンドルを返す ------------------\r
327 *\r
328 *       Parameter\r
329 *               なし\r
330 *\r
331 *       Return Value\r
332 *               HWND ウインドウハンドル\r
333 *----------------------------------------------------------------------------*/\r
334 \r
335 HWND GetLocalHwnd(void)\r
336 {\r
337         return(hWndListLocal);\r
338 }\r
339 \r
340 \r
341 /*----- ホスト側のファイルリストのウインドウハンドルを返す --------------------\r
342 *\r
343 *       Parameter\r
344 *               なし\r
345 *\r
346 *       Return Value\r
347 *               HWND ウインドウハンドル\r
348 *----------------------------------------------------------------------------*/\r
349 \r
350 HWND GetRemoteHwnd(void)\r
351 {\r
352         return(hWndListRemote);\r
353 }\r
354 \r
355 \r
356 /*----- ローカル側のファイルリストウインドウのメッセージ処理 ------------------\r
357 *\r
358 *       Parameter\r
359 *               HWND hWnd : ウインドウハンドル\r
360 *               UINT message  : メッセージ番号\r
361 *               WPARAM wParam : メッセージの WPARAM 引数\r
362 *               LPARAM lParam : メッセージの LPARAM 引数\r
363 *\r
364 *       Return Value\r
365 *               メッセージに対応する戻り値\r
366 *----------------------------------------------------------------------------*/\r
367 \r
368 static LRESULT CALLBACK LocalWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)\r
369 {\r
370         return(FileListCommonWndProc(hWnd, message, wParam, lParam));\r
371 }\r
372 \r
373 \r
374 /*----- ホスト側のファイルリストウインドウのメッセージ処理 --------------------\r
375 *\r
376 *       Parameter\r
377 *               HWND hWnd : ウインドウハンドル\r
378 *               UINT message  : メッセージ番号\r
379 *               WPARAM wParam : メッセージの WPARAM 引数\r
380 *               LPARAM lParam : メッセージの LPARAM 引数\r
381 *\r
382 *       Return Value\r
383 *               メッセージに対応する戻り値\r
384 *----------------------------------------------------------------------------*/\r
385 \r
386 static LRESULT CALLBACK RemoteWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)\r
387 {\r
388         return(FileListCommonWndProc(hWnd, message, wParam, lParam));\r
389 }\r
390 \r
391 \r
392 // ダイアログプロシージャ\r
393 static BOOL CALLBACK doOleDlgProc(HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)\r
394 {\r
395 #define TIMER_ID     (100)      // 作成するタイマの識別ID\r
396 #define TIMER_ELAPSE (100)       // WM_TIMERの発生間隔\r
397         MSG message;\r
398 \r
399         switch( msg ){\r
400         case WM_INITDIALOG:  // ダイアログボックスが作成されたとき\r
401                 SetTimer( hDlg, TIMER_ID, 0, NULL);\r
402                 return TRUE;\r
403 \r
404         case WM_TIMER:\r
405                 ShowWindow(hDlg, SW_HIDE);  // ダイアログは隠す\r
406 \r
407                 if (wp != TIMER_ID)\r
408                         break;\r
409 \r
410                 if (PeekMessage(&message, NULL, 0, 0, PM_REMOVE)) {\r
411                                 TranslateMessage(&message);\r
412                                 DispatchMessage(&message);\r
413 \r
414                 } else {\r
415                         if (AskTransferNow() == NO) {\r
416                                 EndDialog( hDlg, 0 );\r
417                                 return TRUE;\r
418                         }\r
419                 }\r
420 \r
421                 SetTimer( hDlg, TIMER_ID, TIMER_ELAPSE, NULL );\r
422                 return TRUE;\r
423 \r
424         case WM_COMMAND:     // ダイアログボックス内の何かが選択されたとき\r
425                 switch( LOWORD( wp ) ){\r
426 //              case IDOK:       // 「OK」ボタンが選択された\r
427                 case IDCANCEL:   // 「キャンセル」ボタンが選択された\r
428                         // ダイアログボックスを消す\r
429                         EndDialog( hDlg, 0 );\r
430                         break;\r
431                 }\r
432                 return TRUE;\r
433         }\r
434 \r
435         return FALSE;  // DefWindowProc()ではなく、FALSEを返すこと!\r
436 #undef TIMER_ID     \r
437 #undef TIMER_ELAPSE \r
438 }\r
439 \r
440 \r
441 static void doTransferRemoteFile(void)\r
442 {\r
443         FILELIST *FileListBase, *FileListBaseNoExpand, *pf;\r
444         int CancelFlg = NO;\r
445         char LocDir[FMAX_PATH+1];\r
446         char TmpDir[FMAX_PATH+1];\r
447         char buf[32];\r
448         int i;\r
449         DWORD pid;\r
450 \r
451         // すでにリモートから転送済みなら何もしない。(2007.9.3 yutaka)\r
452         if (remoteFileListBase != NULL)\r
453                 return;\r
454 \r
455         FileListBase = NULL;\r
456         MakeSelectedFileList(WIN_REMOTE, YES, NO, &FileListBase, &CancelFlg);\r
457         FileListBaseNoExpand = NULL;\r
458         MakeSelectedFileList(WIN_REMOTE, NO, NO, &FileListBaseNoExpand, &CancelFlg);\r
459 \r
460         // set temporary folder\r
461         AskLocalCurDir(LocDir, FMAX_PATH);\r
462 \r
463         // アプリを多重起動してもコンフリクトしないように、テンポラリフォルダ名にプロセスID\r
464         // を付加する。(2007.9.13 yutaka)\r
465         GetTempPath(sizeof(TmpDir), TmpDir);\r
466         pid = GetCurrentProcessId();\r
467         _snprintf_s(buf, sizeof(buf), _TRUNCATE, "ffftp%d", pid);\r
468         strncat_s(TmpDir, sizeof(TmpDir), buf, _TRUNCATE);\r
469         _mkdir(TmpDir);\r
470 #if 0\r
471         if (TmpDir[strlen(TmpDir) - 1] == '\\') {\r
472                 TmpDir[strlen(TmpDir) - 1] = '\0';\r
473         }\r
474 #endif\r
475 \r
476         // 既存のファイルを削除する\r
477         for (pf = FileListBase ; pf ; pf = pf->Next) {\r
478                 char fn[FMAX_PATH+1];\r
479 \r
480                 strncpy_s(fn, sizeof(fn), TmpDir, _TRUNCATE);\r
481                 strncat_s(fn, sizeof(fn), "\\", _TRUNCATE);\r
482                 strncat_s(fn, sizeof(fn), pf->File, _TRUNCATE);\r
483 \r
484                 remove(fn);\r
485         }\r
486 \r
487         // ダウンロード先をテンポラリに設定\r
488         SetLocalDirHist(TmpDir);\r
489 \r
490         // FFFTPにダウンロード要求を出し、ダウンロードの完了を待つ。\r
491         PostMessage(GetMainHwnd(), WM_COMMAND, MAKEWPARAM(MENU_DOWNLOAD, 0), 0);\r
492 \r
493         for (i = 0 ; i < 10 ; i++) {\r
494                 MSG msg;\r
495 \r
496                 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {\r
497                         TranslateMessage(&msg);\r
498                         DispatchMessage(&msg);\r
499 \r
500                 } else {\r
501                         // 転送スレッドが動き出したら抜ける。\r
502                         if (AskTransferNow() == YES)\r
503                                 break;\r
504                 }\r
505 \r
506                 Sleep(10);\r
507         }\r
508 \r
509         // OLE D&D中にメインウィンドウをユーザに操作させると、おかしくなるので、\r
510         // 隠しモーダルダイアログを作る。\r
511         // (2007.9.11 yutaka)\r
512         DialogBox(GetFtpInst(), MAKEINTRESOURCE(IDD_OLEDRAG), GetMainHwnd(), (DLGPROC)doOleDlgProc);\r
513 \r
514         // ダウンロード先を元に戻す\r
515         SetLocalDirHist(LocDir);\r
516         SetCurrentDirAsDirHist();\r
517 \r
518         remoteFileListBase = FileListBase;  // あとでフリーすること\r
519         remoteFileListBaseNoExpand = FileListBaseNoExpand;  // あとでフリーすること\r
520         strncpy_s(remoteFileDir, sizeof(remoteFileDir), TmpDir, _TRUNCATE);\r
521 \r
522 #if 0\r
523         // add temporary list\r
524         if (remoteFileListBase != NULL) {\r
525                 FILELIST *pf = remoteFileListBase;\r
526                 char fn[FMAX_PATH + 1];\r
527                 while (pf) {\r
528                         strncpy_s(fn, sizeof(fn), remoteFileDir, _TRUNCATE);\r
529                         strncat_s(fn, sizeof(fn), "\\", _TRUNCATE);\r
530                         strncat_s(fn, sizeof(fn), pf->File, _TRUNCATE);\r
531                         AddTempFileList(fn);\r
532                         pf = pf->Next;\r
533                 }\r
534         }\r
535 #endif\r
536 }\r
537 \r
538 \r
539 int isDirectory(char *fn)\r
540 {\r
541         struct _stat buf;\r
542 \r
543         if (_stat(fn, &buf) == 0) {\r
544                 if (buf.st_mode & _S_IFDIR) { // is directory\r
545                         return 1;\r
546                 }\r
547         }\r
548         return 0;\r
549 }\r
550 \r
551 // テンポラリのファイルおよびフォルダを削除する。\r
552 void doDeleteRemoteFile(void)\r
553 {\r
554         if (remoteFileListBase != NULL) {\r
555 #if 0\r
556                 int dirs = 0;\r
557                 int i, count;\r
558                 FILELIST *pf = remoteFileListBase;\r
559                 char fn[FMAX_PATH + 1];\r
560                 while (pf) {\r
561                         strncpy_s(fn, sizeof(fn), remoteFileDir, _TRUNCATE);\r
562                         strncat_s(fn, sizeof(fn), "\\", _TRUNCATE);\r
563                         strncat_s(fn, sizeof(fn), pf->File, _TRUNCATE);\r
564                         if (isDirectory(fn)) {\r
565                                 dirs++;\r
566                         } else {\r
567                                 remove(fn);\r
568                         }\r
569                         pf = pf->Next;\r
570                 }\r
571 \r
572                 count = 0;\r
573                 for (i = 0 ; i < 1000 ; i++) {\r
574                         pf = remoteFileListBase;\r
575                         while (pf) {\r
576                                 strncpy_s(fn, sizeof(fn), remoteFileDir, _TRUNCATE);\r
577                                 strncat_s(fn, sizeof(fn), "\\", _TRUNCATE);\r
578                                 strncat_s(fn, sizeof(fn), pf->File, _TRUNCATE);\r
579                                 if (isDirectory(fn)) {\r
580                                         if (_rmdir(fn) == 0) { // ディレクトリを消せたらカウントアップ\r
581                                                 count++;\r
582                                                 if (count >= dirs)  // すべて消せたら終わり\r
583                                                         goto skip;\r
584                                         }\r
585                                 }\r
586                                 pf = pf->Next;\r
587                         }\r
588                 }\r
589 skip:\r
590                 _rmdir(remoteFileDir);  // 自分で作ったディレクトリも消す\r
591 #else\r
592                 SHFILEOPSTRUCT FileOp = { NULL, FO_DELETE, remoteFileDir, NULL, \r
593                         FOF_SILENT | FOF_NOCONFIRMATION | FOF_NOERRORUI, \r
594                         FALSE, NULL, NULL };    \r
595                 SHFileOperation(&FileOp);\r
596 #endif\r
597 \r
598                 DeleteFileList(&remoteFileListBase);\r
599                 remoteFileListBase = NULL;\r
600         }\r
601 \r
602         if (remoteFileListBaseNoExpand != NULL) {\r
603                 DeleteFileList(&remoteFileListBaseNoExpand);\r
604                 remoteFileListBaseNoExpand = NULL;\r
605         }\r
606 }\r
607 \r
608 \r
609 // yutaka\r
610 // cf. http://www.nakka.com/lib/\r
611 /* ドロップファイルの作成 */\r
612 static HDROP APIPRIVATE CreateDropFileMem(char **FileName,int cnt,BOOL fWide)\r
613 {\r
614         HDROP hDrop;\r
615         LPDROPFILES lpDropFile;\r
616         wchar_t wbuf[BUF_SIZE];\r
617         int flen = 0;\r
618         int i;\r
619         \r
620         if(fWide == TRUE){\r
621                 /* ワイドキャラ */\r
622                 for(i = 0;i < cnt;i++){\r
623                         // UTF-8対応\r
624 //                      MultiByteToWideChar(CP_ACP,0,FileName[i],-1,wbuf,BUF_SIZE);\r
625 //                      flen += (wcslen(wbuf) + 1) * sizeof(wchar_t);\r
626                         flen += sizeof(wchar_t) * MtoW(NULL, 0, FileName[i], -1);\r
627                 }\r
628                 flen++;\r
629         }else{\r
630                 /* マルチバイト */\r
631                 for(i = 0;i < cnt;i++){\r
632                         // UTF-8対応\r
633 //                      flen += lstrlen(FileName[i]) + 1;\r
634                         MtoW(wbuf, BUF_SIZE, FileName[i], -1);\r
635                         flen += sizeof(char) * WtoA(NULL, 0, wbuf, -1);\r
636                 }\r
637         }\r
638 \r
639         hDrop = (HDROP)GlobalAlloc(GHND,sizeof(DROPFILES) + flen + 1);\r
640         if (hDrop == NULL){\r
641                 return NULL;\r
642         }\r
643 \r
644         lpDropFile = (LPDROPFILES) GlobalLock(hDrop);\r
645         lpDropFile->pFiles = sizeof(DROPFILES);         /* ファイル名のリストまでのオフセット */\r
646         lpDropFile->pt.x = 0;\r
647         lpDropFile->pt.y = 0;\r
648         lpDropFile->fNC = FALSE;\r
649         lpDropFile->fWide = fWide;                                      /* ワイドキャラの場合は TRUE */\r
650 \r
651         /* 構造体の後ろにファイル名のリストをコピーする。(ファイル名\0ファイル名\0ファイル名\0\0) */\r
652         if(fWide == TRUE){\r
653                 /* ワイドキャラ */\r
654                 wchar_t *buf;\r
655 \r
656                 buf = (wchar_t *)(&lpDropFile[1]);\r
657                 for(i = 0;i < cnt;i++){\r
658                         // UTF-8対応\r
659 //                      MultiByteToWideChar(CP_ACP,0,FileName[i],-1,wbuf,BUF_SIZE);\r
660 //                      wcscpy(buf,wbuf);\r
661 //                      buf += wcslen(wbuf) + 1;\r
662                         buf += MtoW(buf, BUF_SIZE, FileName[i], -1);\r
663                 }\r
664         }else{\r
665                 /* マルチバイト */\r
666                 char *buf;\r
667 \r
668                 buf = (char *)(&lpDropFile[1]);\r
669                 for(i = 0;i < cnt;i++){\r
670                         // UTF-8対応\r
671 //                      lstrcpy(buf,FileName[i]);\r
672 //                      buf += lstrlen(FileName[i]) + 1;\r
673                         MtoW(wbuf, BUF_SIZE, FileName[i], -1);\r
674                         buf += WtoA(buf, BUF_SIZE, wbuf, -1);\r
675                 }\r
676         }\r
677 \r
678         GlobalUnlock(hDrop);\r
679         return(hDrop);\r
680 }\r
681 \r
682 \r
683 // OLE D&Dを開始する \r
684 // (2007.8.30 yutaka)\r
685 static void doDragDrop(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)\r
686 {\r
687         UINT cf[CF_CNT];\r
688         POINT pt;\r
689         int ret;\r
690 \r
691         // テンポラリをきれいにする (2007.9.3 yutaka)\r
692         doDeleteRemoteFile();\r
693 \r
694         /* ドラッグ&ドロップの開始 */\r
695         cf[0] = CF_HDROP;\r
696         cf[1] = CF_HDROP;       /* ファイル */\r
697         if((ret = OLE_IDropSource_Start(hWnd,WM_GETDATA, WM_DRAGOVER, cf,1,DROPEFFECT_COPY | DROPEFFECT_MOVE | DROPEFFECT_LINK)) == DROPEFFECT_MOVE){\r
698         }\r
699 \r
700         // ドロップ先のアプリに WM_LBUTTONUP を飛ばす。\r
701         GetCursorPos(&pt);\r
702         ScreenToClient(hWnd, &pt);\r
703         PostMessage(hWnd,WM_LBUTTONUP,0,MAKELPARAM(pt.x,pt.y));\r
704 }\r
705 \r
706 \r
707 \r
708 /*----- ファイル一覧ウインドウの共通メッセージ処理 ----------------------------\r
709 *\r
710 *       Parameter\r
711 *               HWND hWnd : ウインドウハンドル\r
712 *               UINT message  : メッセージ番号\r
713 *               WPARAM wParam : メッセージの WPARAM 引数\r
714 *               LPARAM lParam : メッセージの LPARAM 引数\r
715 *\r
716 *       Return Value\r
717 *               メッセージに対応する戻り値\r
718 *----------------------------------------------------------------------------*/\r
719 \r
720 static LRESULT FileListCommonWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)\r
721 {\r
722         POINT Point;\r
723         HWND hWndPnt;\r
724         HWND hWndParent;\r
725         static HCURSOR hCsrDrg;\r
726         static HCURSOR hCsrNoDrg;\r
727         static POINT DragPoint;\r
728         static HWND hWndDragStart;\r
729         static int RemoteDropFileIndex = -1;\r
730         int Win;\r
731         HWND hWndDst;\r
732         WNDPROC ProcPtr;\r
733         HWND hWndHistEdit;\r
734 \r
735         Win = WIN_LOCAL;\r
736         hWndDst = hWndListRemote;\r
737         ProcPtr = LocalProcPtr;\r
738         hWndHistEdit = GetLocalHistEditHwnd();\r
739         if(hWnd == hWndListRemote)\r
740         {\r
741                 Win = WIN_REMOTE;\r
742                 hWndDst = hWndListLocal;\r
743                 ProcPtr = RemoteProcPtr;\r
744                 hWndHistEdit = GetRemoteHistEditHwnd();\r
745         }\r
746 \r
747         switch (message)\r
748         {\r
749         case WM_SYSKEYDOWN:\r
750                         if (wParam == 'D') {    // Alt+D\r
751                                 SetFocus(hWndHistEdit);\r
752                                 break;\r
753                         }\r
754                         EraseListViewTips();\r
755                         return(CallWindowProc(ProcPtr, hWnd, message, wParam, lParam));\r
756 \r
757         case WM_KEYDOWN:\r
758                         if(wParam == 0x09)\r
759                         {\r
760                                 SetFocus(hWndDst);\r
761                                 break;\r
762                         }\r
763                         EraseListViewTips();\r
764                         return(CallWindowProc(ProcPtr, hWnd, message, wParam, lParam));\r
765 \r
766                 case WM_SETFOCUS :\r
767                         SetFocusHwnd(hWnd);\r
768                         MakeButtonsFocus();\r
769                         DispCurrentWindow(Win);\r
770                         DispSelectedSpace();\r
771                         return(CallWindowProc(ProcPtr, hWnd, message, wParam, lParam));\r
772 \r
773                 case WM_KILLFOCUS :\r
774                         EraseListViewTips();\r
775                         MakeButtonsFocus();\r
776                         DispCurrentWindow(-1);\r
777                         return(CallWindowProc(ProcPtr, hWnd, message, wParam, lParam));\r
778 \r
779                 case WM_DROPFILES :\r
780                         // ドラッグ中は処理しない。ドラッグ後にWM_LBUTTONDOWNが飛んでくるため、そこで処理する。\r
781                         if (Dragging == YES) \r
782                                 return (FALSE);\r
783 \r
784                         if(hWnd == hWndListRemote)\r
785                         {\r
786                                 if(AskConnecting() == YES)\r
787                                         UpLoadDragProc(wParam);\r
788                         }\r
789                         else if(hWnd == hWndListLocal)\r
790                         {\r
791                                 ChangeDirDropFileProc(wParam);\r
792                         }\r
793                         break;\r
794 \r
795                 case WM_LBUTTONDOWN :\r
796                         EraseListViewTips();\r
797                         SetFocus(hWnd);\r
798                         DragPoint.x = LOWORD(lParam);\r
799                         DragPoint.y = HIWORD(lParam);\r
800                         hWndDragStart = hWnd;\r
801                         return(CallWindowProc(ProcPtr, hWnd, message, wParam, lParam));\r
802                         break;\r
803 \r
804                 case WM_LBUTTONUP :\r
805                         if(Dragging == YES)\r
806                         {\r
807                                 Dragging = NO;\r
808                                 ReleaseCapture();\r
809                                 hCsrDrg = LoadCursor(NULL, IDC_ARROW);\r
810                                 SetCursor(hCsrDrg);\r
811 \r
812                                 Point.x = (long)(short)LOWORD(lParam);\r
813                                 Point.y = (long)(short)HIWORD(lParam);\r
814                                 ClientToScreen(hWnd, &Point);\r
815                                 hWndPnt = WindowFromPoint(Point);\r
816                                 if(hWndPnt == hWndDst)  // local <-> remote \r
817                                 {\r
818                                         if(hWndPnt == hWndListRemote) {\r
819                                                 PostMessage(GetMainHwnd(), WM_COMMAND, MAKEWPARAM(MENU_UPLOAD, 0), 0);\r
820                                         } else if(hWndPnt == hWndListLocal) {\r
821                                                 PostMessage(GetMainHwnd(), WM_COMMAND, MAKEWPARAM(MENU_DOWNLOAD, 0), 0);\r
822                                         }\r
823                                 } else { // 同一ウィンドウ内の場合 (yutaka)\r
824                                         if (hWndDragStart == hWndListRemote && hWndPnt == hWndListRemote) {\r
825                                                 // remote <-> remoteの場合は、サーバでのファイルの移動を行う。(2007.9.5 yutaka)\r
826                                                 if (RemoteDropFileIndex != -1) {\r
827                                                         ListView_SetItemState(hWnd, RemoteDropFileIndex, 0, LVIS_DROPHILITED);\r
828                                                         MoveRemoteFileProc(RemoteDropFileIndex);\r
829                                                 }\r
830 \r
831                                         }\r
832 \r
833                                 }\r
834                         }\r
835                         return(CallWindowProc(ProcPtr, hWnd, message, wParam, lParam));\r
836 \r
837                 case WM_DRAGDROP:  \r
838                         // OLE D&Dを開始する (yutaka)\r
839                         doDragDrop(hWnd, message, wParam, lParam);\r
840                         return (TRUE);\r
841                         break;\r
842  \r
843                 case WM_GETDATA:  // ファイルのパスをD&D先のアプリへ返す (yutaka)\r
844                         switch(wParam)\r
845                         {\r
846                         case CF_HDROP:          /* ファイル */\r
847                                 {\r
848                                         OSVERSIONINFO os_info;\r
849                                         BOOL NTFlag = FALSE;\r
850                                         char **FileNameList;\r
851                                         int filelen;\r
852                                         int i, j, filenum = 0;\r
853  \r
854                                         FILELIST *FileListBase, *FileListBaseNoExpand, *pf;\r
855                                         int CancelFlg = NO;\r
856                                         char LocDir[FMAX_PATH+1];\r
857                                         char *PathDir;\r
858  \r
859                                         // 変数が未初期化のバグ修正\r
860                                         FileListBaseNoExpand = NULL;\r
861                                         // ローカル側で選ばれているファイルをFileListBaseに登録\r
862                                         if (hWndDragStart == hWndListLocal) {\r
863                                                 AskLocalCurDir(LocDir, FMAX_PATH);\r
864                                                 PathDir = LocDir;\r
865  \r
866                                                 FileListBase = NULL;\r
867                                                 // ローカル側からアプリケーションにD&Dできないバグ修正\r
868 //                                              MakeSelectedFileList(WIN_LOCAL, YES, NO, &FileListBase, &CancelFlg);                    \r
869                                                 MakeSelectedFileList(WIN_LOCAL, NO, NO, &FileListBase, &CancelFlg);                     \r
870                                                 FileListBaseNoExpand = FileListBase;\r
871  \r
872                                         } else if (hWndDragStart == hWndListRemote) {\r
873                                                 GetCursorPos(&Point);\r
874                                                 hWndPnt = WindowFromPoint(Point);\r
875                                                 hWndParent = GetParent(hWndPnt);\r
876                                                 if (hWndPnt == hWndListRemote || hWndPnt == hWndListLocal ||\r
877                                                         hWndParent == hWndListRemote || hWndParent == hWndListLocal) {\r
878                                                         FileListBase = NULL;\r
879  \r
880                                                 } else {\r
881                                                         // 選択されているリモートファイルのリストアップ\r
882                                                         // このタイミングでリモートからローカルの一時フォルダへダウンロードする\r
883                                                         // (2007.8.31 yutaka)\r
884                                                         doTransferRemoteFile();\r
885                                                         PathDir = remoteFileDir;\r
886                                                         FileListBase = remoteFileListBase;\r
887                                                         FileListBaseNoExpand = remoteFileListBaseNoExpand;\r
888                                                 }\r
889  \r
890                                         } \r
891  \r
892                                         pf = FileListBaseNoExpand;\r
893                                         for (filenum = 0; pf ; filenum++) {\r
894                                                 pf = pf->Next;\r
895                                         }\r
896                                         // ファイルが未選択の場合は何もしない。(yutaka)\r
897                                         if (filenum <= 0) {\r
898                                                 *((HANDLE *)lParam) = NULL;\r
899                                                 return (FALSE);\r
900                                         }\r
901                                         \r
902                                         /* ファイル名の配列を作成する */\r
903                                         // TODO: GlobalAllocが返すのはメモリポインタではなくハンドルだが実際は同じ値\r
904                                         FileNameList = (char **)GlobalAlloc(GPTR,sizeof(char *) * filenum);\r
905                                         if(FileNameList == NULL){\r
906                                                 abort();\r
907                                         }\r
908                                         pf = FileListBaseNoExpand;\r
909                                         for (j = 0; pf ; j++) {\r
910                                                 filelen = strlen(PathDir) + 1 + strlen(pf->File) + 1;\r
911                                                 FileNameList[j] = (char *)GlobalAlloc(GPTR, filelen);\r
912                                                 strncpy_s(FileNameList[j], filelen, PathDir, _TRUNCATE);\r
913                                                 strncat_s(FileNameList[j], filelen, "\\", _TRUNCATE);\r
914                                                 strncat_s(FileNameList[j], filelen, pf->File, _TRUNCATE);\r
915                                                 pf = pf->Next;\r
916 #if 0\r
917                                                 if (FileListBase->Node == NODE_DIR) { \r
918                                                         // フォルダを掴んだ場合はそれ以降展開しない\r
919                                                         filenum = 1;\r
920                                                         break;\r
921                                                 }\r
922 #endif\r
923                                         }\r
924                                         \r
925                                         os_info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);\r
926                                         GetVersionEx(&os_info);\r
927                                         if(os_info.dwPlatformId == VER_PLATFORM_WIN32_NT){\r
928                                                 NTFlag = TRUE;\r
929                                         }\r
930  \r
931                                         /* ドロップファイルリストの作成 */\r
932                                         /* NTの場合はUNICODEになるようにする */\r
933                                         *((HANDLE *)lParam) = CreateDropFileMem(FileNameList, filenum, NTFlag);\r
934  \r
935                                         /* ファイル名の配列を解放する */\r
936                                         for (i = 0; i < filenum ; i++) {\r
937                                                 GlobalFree(FileNameList[i]);\r
938                                         }\r
939                                         GlobalFree(FileNameList);\r
940  \r
941                                         if (hWndDragStart == hWndListLocal) {\r
942                                                 DeleteFileList(&FileListBase);\r
943                                         } else {\r
944                                                 // あとでファイル削除してフリーする\r
945                                         }\r
946  \r
947                                         return (TRUE);\r
948                                 }\r
949                                 break;\r
950  \r
951                         default:\r
952                                 *((HANDLE *)lParam) = NULL;\r
953                                 break;\r
954                         }\r
955  \r
956                         break;\r
957 \r
958                 case WM_DRAGOVER:\r
959                         {\r
960                                 LVHITTESTINFO hi;\r
961                                 int Node, index;\r
962                                 static int prev_index = -1;\r
963 \r
964                                 // 同一ウィンドウ内でのD&Dはリモート側のみ\r
965                                 if (Win != WIN_REMOTE)\r
966                                         break;\r
967 \r
968                                 if(MoveMode == MOVE_DISABLE)\r
969                                         break;\r
970 \r
971                                 memset(&hi, 0, sizeof(hi));\r
972 \r
973                                 GetCursorPos(&Point);\r
974                                 hWndPnt = WindowFromPoint(Point);\r
975                                 ScreenToClient(hWnd, &Point);\r
976 \r
977                                 hi.pt = Point;\r
978 \r
979                                 // 以前の選択を消す\r
980                                 ListView_SetItemState(hWnd, prev_index, 0, LVIS_DROPHILITED);\r
981                                 RemoteDropFileIndex = -1;\r
982 \r
983                                 if ((hWndPnt == hWndListRemote) && (ListView_HitTest(hWnd, &hi) != -1)) {\r
984                                         if (hi.flags == LVHT_ONITEMLABEL) { // The position is over a list-view item's text.\r
985                                         \r
986                                                 index = hi.iItem;\r
987                                                 prev_index = index;\r
988                                                 Node = GetNodeType(Win, index);\r
989                                                 if (Node == NODE_DIR) {\r
990                                                         ListView_SetItemState(hWnd, index, LVIS_DROPHILITED, LVIS_DROPHILITED);\r
991                                                         RemoteDropFileIndex = index;\r
992                                                 }\r
993                                         }\r
994                                 } \r
995 \r
996                         }\r
997                         break;\r
998 \r
999                 case WM_RBUTTONDOWN :\r
1000                         /* ここでファイルを選ぶ */\r
1001                         CallWindowProc(ProcPtr, hWnd, message, wParam, lParam);\r
1002 \r
1003                         EraseListViewTips();\r
1004                         SetFocus(hWnd);\r
1005                         if(hWnd == hWndListRemote)\r
1006                                 RemoteRbuttonMenu(0);\r
1007                         else if(hWnd == hWndListLocal)\r
1008                                 LocalRbuttonMenu(0);\r
1009                         break;\r
1010 \r
1011                 case WM_LBUTTONDBLCLK :\r
1012                         DoubleClickProc(Win, NO, -1);\r
1013                         break;\r
1014 \r
1015                 case WM_MOUSEMOVE :\r
1016                         if(wParam == MK_LBUTTON)\r
1017                         {\r
1018                                 if((Dragging == NO) && \r
1019                                    (hWnd == hWndDragStart) &&\r
1020                                    (AskConnecting() == YES) &&\r
1021                                    (SendMessage(hWnd, LVM_GETSELECTEDCOUNT, 0, 0) > 0) &&\r
1022                                    ((abs((short)LOWORD(lParam) - DragPoint.x) > 5) ||\r
1023                                         (abs((short)HIWORD(lParam) - DragPoint.y) > 5)))\r
1024                                 {\r
1025                                         SetCapture(hWnd);\r
1026                                         Dragging = YES;\r
1027                                         hCsrDrg = LoadCursor(GetFtpInst(), MAKEINTRESOURCE(drag_csr));\r
1028                                         hCsrNoDrg = LoadCursor(GetFtpInst(), MAKEINTRESOURCE(nodrop_csr));\r
1029                                         SetCursor(hCsrDrg);\r
1030                                 }\r
1031                                 else if(Dragging == YES)\r
1032                                 {\r
1033                                         Point.x = (long)(short)LOWORD(lParam);\r
1034                                         Point.y = (long)(short)HIWORD(lParam);\r
1035                                         ClientToScreen(hWnd, &Point);\r
1036                                         hWndPnt = WindowFromPoint(Point);\r
1037                                         if((hWndPnt == hWndListRemote) || (hWndPnt == hWndListLocal))\r
1038                                                 SetCursor(hCsrDrg);\r
1039                                         else {\r
1040                                                 // マウスポインタの×表示をやめる (yutaka)\r
1041 #if 0\r
1042                                                 SetCursor(hCsrNoDrg);\r
1043 #endif\r
1044                                         }\r
1045 \r
1046                                         // OLE D&Dの開始を指示する\r
1047                                         PostMessage(hWnd, WM_DRAGDROP, MAKEWPARAM(wParam, lParam), 0);\r
1048 \r
1049                                 }\r
1050                                 else\r
1051                                         return(CallWindowProc(ProcPtr, hWnd, message, wParam, lParam));\r
1052                         }\r
1053                         else\r
1054                         {\r
1055                                 CheckTipsDisplay(hWnd, lParam);\r
1056                                 return(CallWindowProc(ProcPtr, hWnd, message, wParam, lParam));\r
1057                         }\r
1058                         break;\r
1059 \r
1060                 case WM_MOUSEWHEEL :\r
1061                         if(Dragging == NO)\r
1062                         {\r
1063                 short zDelta = (short)HIWORD(wParam);\r
1064 \r
1065                                 EraseListViewTips();\r
1066                                 Point.x = (short)LOWORD(lParam);\r
1067                                 Point.y = (short)HIWORD(lParam);\r
1068                                 hWndPnt = WindowFromPoint(Point);\r
1069 \r
1070                                 if((wParam & MAKEWPARAM(MK_SHIFT, 0)) && \r
1071                                    ((hWndPnt == hWndListRemote) ||\r
1072                                         (hWndPnt == hWndListLocal) || \r
1073                                         (hWndPnt == GetTaskWnd())))\r
1074                                 {\r
1075                                         PostMessage(hWndPnt, WM_VSCROLL, zDelta > 0 ? MAKEWPARAM(SB_PAGEUP, 0) : MAKEWPARAM(SB_PAGEDOWN, 0), 0);\r
1076 //                                      PostMessage(hWndPnt, WM_VSCROLL, MAKEWPARAM(SB_ENDSCROLL, 0), 0);\r
1077                                 }\r
1078                                 else if(hWndPnt == hWnd)\r
1079                                         return(CallWindowProc(ProcPtr, hWnd, message, wParam, lParam));\r
1080                                 else if((hWndPnt == hWndDst) || (hWndPnt == GetTaskWnd()))\r
1081                                         PostMessage(hWndPnt, message, wParam, lParam);\r
1082                         }\r
1083                         break;\r
1084 \r
1085                 default :\r
1086                         return(CallWindowProc(ProcPtr, hWnd, message, wParam, lParam));\r
1087         }\r
1088     return(0L);\r
1089 }\r
1090 \r
1091 \r
1092 /*----- ファイルリストのタブ幅を取得する --------------------------------------\r
1093 *\r
1094 *       Parameter\r
1095 *               なし\r
1096 *\r
1097 *       Return Value\r
1098 *               なし\r
1099 *----------------------------------------------------------------------------*/\r
1100 \r
1101 void GetListTabWidth(void)\r
1102 {\r
1103         LV_COLUMN LvCol;\r
1104         int i;\r
1105 \r
1106         for(i = 0; i <= 3; i++)\r
1107         {\r
1108                 LvCol.mask = LVCF_WIDTH;\r
1109                 if(SendMessage(hWndListLocal, LVM_GETCOLUMN, i, (LPARAM)&LvCol) == TRUE)\r
1110                         LocalTabWidth[i] = LvCol.cx;\r
1111         }\r
1112 \r
1113         for(i = 0; i <= 5; i++)\r
1114         {\r
1115                 LvCol.mask = LVCF_WIDTH;\r
1116                 if(SendMessage(hWndListRemote, LVM_GETCOLUMN, i, (LPARAM)&LvCol) == TRUE)\r
1117                         RemoteTabWidth[i] = LvCol.cx;\r
1118         }\r
1119         return;\r
1120 }\r
1121 \r
1122 \r
1123 /*----- ファイル一覧方法にしたがってリストビューを設定する --------------------\r
1124 *\r
1125 *       Parameter\r
1126 *               なし\r
1127 *\r
1128 *       Return Value\r
1129 *               なし\r
1130 *----------------------------------------------------------------------------*/\r
1131 \r
1132 void SetListViewType(void)\r
1133 {\r
1134         // 64ビット対応\r
1135 //      long lStyle;\r
1136         LONG_PTR lStyle;\r
1137 \r
1138         switch(ListType)\r
1139         {\r
1140                 case LVS_LIST :\r
1141                         // 64ビット対応\r
1142 //                      lStyle = GetWindowLong(GetLocalHwnd(), GWL_STYLE);\r
1143                         lStyle = GetWindowLongPtr(GetLocalHwnd(), GWL_STYLE);\r
1144                         lStyle &= ~(LVS_REPORT | LVS_LIST);\r
1145                         lStyle |= LVS_LIST;\r
1146                         // 64ビット対応\r
1147 //                      SetWindowLong(GetLocalHwnd(), GWL_STYLE, lStyle);\r
1148                         SetWindowLongPtr(GetLocalHwnd(), GWL_STYLE, lStyle);\r
1149 \r
1150                         // 64ビット対応\r
1151 //                      lStyle = GetWindowLong(GetRemoteHwnd(), GWL_STYLE);\r
1152                         lStyle = GetWindowLongPtr(GetRemoteHwnd(), GWL_STYLE);\r
1153                         lStyle &= ~(LVS_REPORT | LVS_LIST);\r
1154                         lStyle |= LVS_LIST;\r
1155                         // 64ビット対応\r
1156 //                      SetWindowLong(GetRemoteHwnd(), GWL_STYLE, lStyle);\r
1157                         SetWindowLongPtr(GetRemoteHwnd(), GWL_STYLE, lStyle);\r
1158                         break;\r
1159 \r
1160                 default :\r
1161                         // 64ビット対応\r
1162 //                      lStyle = GetWindowLong(GetLocalHwnd(), GWL_STYLE);\r
1163                         lStyle = GetWindowLongPtr(GetLocalHwnd(), GWL_STYLE);\r
1164                         lStyle &= ~(LVS_REPORT | LVS_LIST);\r
1165                         lStyle |= LVS_REPORT;\r
1166                         // 64ビット対応\r
1167 //                      SetWindowLong(GetLocalHwnd(), GWL_STYLE, lStyle);\r
1168                         SetWindowLongPtr(GetLocalHwnd(), GWL_STYLE, lStyle);\r
1169 \r
1170                         // 64ビット対応\r
1171 //                      lStyle = GetWindowLong(GetRemoteHwnd(), GWL_STYLE);\r
1172                         lStyle = GetWindowLongPtr(GetRemoteHwnd(), GWL_STYLE);\r
1173                         lStyle &= ~(LVS_REPORT | LVS_LIST);\r
1174                         lStyle |= LVS_REPORT;\r
1175                         // 64ビット対応\r
1176 //                      SetWindowLong(GetRemoteHwnd(), GWL_STYLE, lStyle);\r
1177                         SetWindowLongPtr(GetRemoteHwnd(), GWL_STYLE, lStyle);\r
1178                         break;\r
1179         }\r
1180         return;\r
1181 }\r
1182 \r
1183 \r
1184 /*----- ホスト側のファイル一覧ウインドウにファイル名をセット ------------------\r
1185 *\r
1186 *       Parameter\r
1187 *               int Mode : キャッシュモード (CACHE_xxx)\r
1188 *\r
1189 *       Return Value\r
1190 *               なし\r
1191 *----------------------------------------------------------------------------*/\r
1192 \r
1193 void GetRemoteDirForWnd(int Mode, int *CancelCheckWork)\r
1194 {\r
1195         FILE *fd;\r
1196         LONGLONG Size;\r
1197         char Str[FMAX_PATH+1];\r
1198         char Buf[FMAX_PATH+1];\r
1199         FILETIME Time;\r
1200         int Attr;\r
1201         int Type;\r
1202         int ListType;\r
1203         int Num;\r
1204         FLISTANCHOR Anchor;\r
1205         char Owner[OWNER_NAME_LEN+1];\r
1206         int Link;\r
1207         int InfoExist;\r
1208 \r
1209 //#pragma aaa\r
1210 //DoPrintf("===== GetRemoteDirForWnd");\r
1211 \r
1212         Anchor.Top = NULL;\r
1213         Anchor.Files = 0;\r
1214 \r
1215         if(AskConnecting() == YES)\r
1216         {\r
1217 //              SetCursor(LoadCursor(NULL, IDC_WAIT));\r
1218                 DisableUserOpe();\r
1219 \r
1220                 AskRemoteCurDir(Buf, FMAX_PATH);\r
1221                 SetRemoteDirHist(Buf);\r
1222 \r
1223                 Type = FTP_COMPLETE;\r
1224                 if(Mode != CACHE_LASTREAD)\r
1225                 {\r
1226 \r
1227                         if((Num = AskCached(Buf)) == -1)\r
1228                         {\r
1229                                 Num = AskFreeCache();\r
1230                                 Mode = CACHE_REFRESH;\r
1231                         }\r
1232 \r
1233                         if(Mode == CACHE_REFRESH)\r
1234                         {\r
1235                                 if((Type = DoDirListCmdSkt("", "", Num, CancelCheckWork)) == FTP_COMPLETE)\r
1236                                         SetCache(Num, Buf);\r
1237                                 else\r
1238                                         ClearCache(Num);\r
1239                         }\r
1240                 }\r
1241                 else\r
1242                         Num = AskCurrentFileListNum();\r
1243 \r
1244                 if(Type == FTP_COMPLETE)\r
1245                 {\r
1246                         SetCurrentFileListNum(Num);\r
1247                         MakeCacheFileName(Num, Buf);\r
1248                         if((fd = fopen(Buf, "rb"))!=NULL)\r
1249                         {\r
1250                                 ListType = LIST_UNKNOWN;\r
1251 \r
1252                                 while(GetListOneLine(Str, FMAX_PATH, fd) == FFFTP_SUCCESS)\r
1253                                 {\r
1254                                         if((ListType = AnalizeFileInfo(Str)) != LIST_UNKNOWN)\r
1255                                         {\r
1256                                                 if((Type = ResolvFileInfo(Str, ListType, Buf, &Size, &Time, &Attr, Owner, &Link, &InfoExist)) != NODE_NONE)\r
1257                                                 {\r
1258                                                         if(AskFilterStr(Buf, Type) == YES)\r
1259                                                         {\r
1260                                                                 if((DotFile == YES) || (Buf[0] != '.'))\r
1261                                                                 {\r
1262                                                                         AddDispFileList(&Anchor, Buf, &Time, Size, Attr, Type, Link, Owner, InfoExist, WIN_REMOTE);\r
1263                                                                 }\r
1264                                                         }\r
1265                                                 }\r
1266                                         }\r
1267                                 }\r
1268                                 fclose(fd);\r
1269 \r
1270                                 DispFileList2View(GetRemoteHwnd(), &Anchor);\r
1271                                 EraseDispFileList(&Anchor);\r
1272 \r
1273                                 // 先頭のアイテムを選択\r
1274                                 ListView_SetItemState(GetRemoteHwnd(), 0, LVIS_FOCUSED, LVIS_FOCUSED);\r
1275                         }\r
1276                         else\r
1277                         {\r
1278                                 SetTaskMsg(MSGJPN048);\r
1279                                 SendMessage(GetRemoteHwnd(), LVM_DELETEALLITEMS, 0, 0);\r
1280                         }\r
1281                 }\r
1282                 else\r
1283                 {\r
1284 #if defined(HAVE_OPENVMS)\r
1285                         /* OpenVMSの場合空ディレクトリ移動の時に出るので、メッセージだけ出さない\r
1286                          * ようにする(VIEWはクリアして良い) */\r
1287                         if (AskHostType() != HTYPE_VMS)\r
1288 #endif\r
1289                         SetTaskMsg(MSGJPN049);\r
1290                         SendMessage(GetRemoteHwnd(), LVM_DELETEALLITEMS, 0, 0);\r
1291                 }\r
1292 \r
1293 //              SetCursor(LoadCursor(NULL, IDC_ARROW));\r
1294                 EnableUserOpe();\r
1295 \r
1296         }\r
1297 \r
1298 //#pragma aaa\r
1299 //DoPrintf("===== GetRemoteDirForWnd Done");\r
1300 \r
1301         return;\r
1302 }\r
1303 \r
1304 \r
1305 /*----- ローカル側のファイル一覧ウインドウにファイル名をセット ----------------\r
1306 *\r
1307 *       Parameter\r
1308 *               なし\r
1309 *\r
1310 *       Return Value\r
1311 *               なし\r
1312 *----------------------------------------------------------------------------*/\r
1313 \r
1314 void GetLocalDirForWnd(void)\r
1315 {\r
1316         HANDLE fHnd;\r
1317         WIN32_FIND_DATA Find;\r
1318         char Scan[FMAX_PATH+1];\r
1319         char *Pos;\r
1320         char Buf[10];\r
1321         FILETIME Time;\r
1322         FLISTANCHOR Anchor;\r
1323         DWORD NoDrives;\r
1324         int Tmp;\r
1325 \r
1326         Anchor.Top = NULL;\r
1327         Anchor.Files = 0;\r
1328 \r
1329         DoLocalPWD(Scan);\r
1330         SetLocalDirHist(Scan);\r
1331         DispLocalFreeSpace(Scan);\r
1332 \r
1333         /* ディレクトリ/ファイル */\r
1334 \r
1335         SetYenTail(Scan);\r
1336         strcat(Scan, "*");\r
1337         if((fHnd = FindFirstFileAttr(Scan, &Find, DispIgnoreHide)) != INVALID_HANDLE_VALUE)\r
1338         {\r
1339                 do\r
1340                 {\r
1341                         if((strcmp(Find.cFileName, ".") != 0) &&\r
1342                            (strcmp(Find.cFileName, "..") != 0))\r
1343                         {\r
1344                                 if((DotFile == YES) || (Find.cFileName[0] != '.'))\r
1345                                 {\r
1346                                         if(Find.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)\r
1347                                                 AddDispFileList(&Anchor, Find.cFileName, &Find.ftLastWriteTime, MakeLongLong(Find.nFileSizeHigh, Find.nFileSizeLow), 0, NODE_DIR, NO, "", FINFO_ALL, WIN_LOCAL);\r
1348                                         else\r
1349                                         {\r
1350                                                 if(AskFilterStr(Find.cFileName, NODE_FILE) == YES)\r
1351                                                 {\r
1352                                                         AddDispFileList(&Anchor, Find.cFileName, &Find.ftLastWriteTime, MakeLongLong(Find.nFileSizeHigh, Find.nFileSizeLow), 0, NODE_FILE, NO, "", FINFO_ALL, WIN_LOCAL);\r
1353                                                 }\r
1354                                         }\r
1355                                 }\r
1356                         }\r
1357                 }\r
1358                 while(FindNextFileAttr(fHnd, &Find, DispIgnoreHide) == TRUE);\r
1359                 FindClose(fHnd);\r
1360         }\r
1361 \r
1362         /* ドライブ */\r
1363         if(DispDrives)\r
1364         {\r
1365                 GetLogicalDriveStrings(FMAX_PATH, Scan);\r
1366                 NoDrives = LoadHideDriveListRegistory();\r
1367 \r
1368                 Pos = Scan;\r
1369                 while(*Pos != NUL)\r
1370                 {\r
1371                         Tmp = toupper(*Pos) - 'A';\r
1372                         if((NoDrives & (0x00000001 << Tmp)) == 0)\r
1373                         {\r
1374                                 sprintf(Buf, "%s", Pos);\r
1375                                 memset(&Time, 0, sizeof(FILETIME));\r
1376                                 AddDispFileList(&Anchor, Buf, &Time, 0, 0, NODE_DRIVE, NO, "", FINFO_ALL, WIN_LOCAL);\r
1377                         }\r
1378                         Pos = strchr(Pos, NUL) + 1;\r
1379                 }\r
1380         }\r
1381 \r
1382         DispFileList2View(GetLocalHwnd(), &Anchor);\r
1383         EraseDispFileList(&Anchor);\r
1384 \r
1385         // 先頭のアイテムを選択\r
1386         ListView_SetItemState(GetLocalHwnd(), 0, LVIS_FOCUSED, LVIS_FOCUSED);\r
1387 \r
1388         return;\r
1389 }\r
1390 \r
1391 \r
1392 /*----- ファイル情報をファイル一覧用リストに登録する --------------------------\r
1393 *\r
1394 *       Parameter\r
1395 *               FLISTANCHOR *Anchor : ファイルリストの先頭\r
1396 *               char *Name : ファイル名\r
1397 *               FILETIME *Time : 日付\r
1398 *               LONGLONG Size : サイズ\r
1399 *               int Attr : 属性\r
1400 *               int Type : タイプ (NODE_xxxx)\r
1401 *               int Link : リンクかどうか (YES/NO)\r
1402 *               char *Owner : オーナ名\r
1403 *               int InfoExist : 情報があるかどうか (FINFO_xxx)\r
1404 *               int Win : ウィンドウ番号 (WIN_xxxx)\r
1405 *\r
1406 *       Return Value\r
1407 *               なし\r
1408 *----------------------------------------------------------------------------*/\r
1409 \r
1410 static void AddDispFileList(FLISTANCHOR *Anchor, char *Name, FILETIME *Time, LONGLONG Size, int Attr, int Type, int Link, char *Owner, int InfoExist, int Win)\r
1411 {\r
1412         int i;\r
1413         FILELIST *Pos;\r
1414         FILELIST *Prev;\r
1415         FILELIST *New;\r
1416         int FileSort;\r
1417         int DirSort;\r
1418         int Sort;\r
1419         LONGLONG Cmp;\r
1420 \r
1421         FileSort = AskSortType(ITEM_LFILE);\r
1422         DirSort = AskSortType(ITEM_LDIR);\r
1423         if(Win == WIN_REMOTE)\r
1424         {\r
1425                 FileSort = AskSortType(ITEM_RFILE);\r
1426                 DirSort = AskSortType(ITEM_RDIR);\r
1427         }\r
1428 \r
1429         Pos = Anchor->Top;\r
1430         for(i = 0; i < Anchor->Files; i++)\r
1431         {\r
1432                 if((Type == NODE_DIR) && (Pos->Node == NODE_FILE))\r
1433                         break;\r
1434                 if((Type == NODE_FILE) && (Pos->Node == NODE_DRIVE))\r
1435                         break;\r
1436 \r
1437                 if(Type == Pos->Node)\r
1438                 {\r
1439                         if(Type == NODE_DIR)\r
1440                                 Sort = DirSort;\r
1441                         else\r
1442                                 Sort = FileSort;\r
1443 \r
1444                         if((Sort & SORT_GET_ORD) == SORT_ASCENT)\r
1445                         {\r
1446                                 if((((Sort & SORT_MASK_ORD) == SORT_EXT) &&\r
1447                                         ((Cmp = _mbsicmp(GetFileExt(Name), GetFileExt(Pos->File))) < 0)) ||\r
1448                                    (((Sort & SORT_MASK_ORD) == SORT_SIZE) &&\r
1449                                         ((Cmp = Size - Pos->Size) < 0)) ||\r
1450                                    (((Sort & SORT_MASK_ORD) == SORT_DATE) &&\r
1451                                         ((Cmp = CompareFileTime(Time, &Pos->Time)) < 0)))\r
1452                                 {\r
1453                                         break;\r
1454                                 }\r
1455 \r
1456                                 if(((Sort & SORT_MASK_ORD) == SORT_NAME) || (Cmp == 0))\r
1457                                 {\r
1458                                         if(_mbsicmp(Name, Pos->File) < 0)\r
1459                                                 break;\r
1460                                 }\r
1461                         }\r
1462                         else\r
1463                         {\r
1464                                 if((((Sort & SORT_MASK_ORD) == SORT_EXT) &&\r
1465                                         ((Cmp = _mbsicmp(GetFileExt(Name), GetFileExt(Pos->File))) > 0)) ||\r
1466                                    (((Sort & SORT_MASK_ORD) == SORT_SIZE) &&\r
1467                                         ((Cmp = Size - Pos->Size) > 0)) ||\r
1468                                    (((Sort & SORT_MASK_ORD) == SORT_DATE) &&\r
1469                                         ((Cmp = CompareFileTime(Time, &Pos->Time)) > 0)))\r
1470                                 {\r
1471                                         break;\r
1472                                 }\r
1473 \r
1474                                 if(((Sort & SORT_MASK_ORD) == SORT_NAME) || (Cmp == 0))\r
1475                                 {\r
1476                                         if(_mbsicmp(Name, Pos->File) > 0)\r
1477                                                 break;\r
1478                                 }\r
1479                         }\r
1480                 }\r
1481                 Prev = Pos;\r
1482                 Pos = Pos->Next;\r
1483         }\r
1484 \r
1485         if((New = malloc(sizeof(FILELIST))) != NULL)\r
1486         {\r
1487                 strcpy(New->File, Name);\r
1488                 New->Node = Type;\r
1489                 New->Link = Link;\r
1490                 New->Size = Size;\r
1491                 New->Attr = Attr;\r
1492                 New->Time = *Time;\r
1493                 strcpy(New->Owner, Owner);\r
1494                 New->InfoExist = InfoExist;\r
1495 \r
1496                 if(Pos == Anchor->Top)\r
1497                 {\r
1498                         New->Next = Anchor->Top;\r
1499                         Anchor->Top = New;\r
1500                 }\r
1501                 else\r
1502                 {\r
1503                         New->Next = Prev->Next;\r
1504                         Prev->Next = New;\r
1505                 }\r
1506                 Anchor->Files += 1;\r
1507         }\r
1508         return;\r
1509 }\r
1510 \r
1511 \r
1512 /*----- ファイル一覧用リストをクリアする --------------------------------------\r
1513 *\r
1514 *       Parameter\r
1515 *               FLISTANCHOR *Anchor : ファイルリストの先頭\r
1516 *\r
1517 *       Return Value\r
1518 *               なし\r
1519 *----------------------------------------------------------------------------*/\r
1520 \r
1521 static void EraseDispFileList(FLISTANCHOR *Anchor)\r
1522 {\r
1523         FILELIST *Pos;\r
1524         FILELIST *Next;\r
1525         int i;\r
1526 \r
1527         Pos = Anchor->Top;\r
1528         for(i = 0; i < Anchor->Files; i++)\r
1529         {\r
1530                 Next = Pos->Next;\r
1531                 free(Pos);\r
1532                 Pos = Next;\r
1533         }\r
1534         Anchor->Files = 0;\r
1535         Anchor->Top = NULL;\r
1536         return;\r
1537 }\r
1538 \r
1539 \r
1540 /*----- ファイル一覧用リストの内容をファイル一覧ウインドウにセット ------------\r
1541 *\r
1542 *       Parameter\r
1543 *               HWND hWnd : ウインドウハンドル\r
1544 *               FLISTANCHOR *Anchor : ファイルリストの先頭\r
1545 *\r
1546 *       Return Value\r
1547 *               なし\r
1548 *----------------------------------------------------------------------------*/\r
1549 \r
1550 static void DispFileList2View(HWND hWnd, FLISTANCHOR *Anchor)\r
1551 {\r
1552         int i;\r
1553         FILELIST *Pos;\r
1554 \r
1555         SendMessage(hWnd, WM_SETREDRAW, (WPARAM)FALSE, 0);\r
1556         SendMessage(hWnd, LVM_DELETEALLITEMS, 0, 0);\r
1557 \r
1558         Pos = Anchor->Top;\r
1559         for(i = 0; i < Anchor->Files; i++)\r
1560         {\r
1561                 AddListView(hWnd, -1, Pos->File, Pos->Node, Pos->Size, &Pos->Time, Pos->Attr, Pos->Owner, Pos->Link, Pos->InfoExist);\r
1562                 Pos = Pos->Next;\r
1563         }\r
1564 \r
1565         SendMessage(hWnd, WM_SETREDRAW, (WPARAM)TRUE, 0);\r
1566         UpdateWindow(hWnd);\r
1567 \r
1568         DispSelectedSpace();\r
1569         return;\r
1570 }\r
1571 \r
1572 \r
1573 /*----- ファイル一覧ウインドウ(リストビュー)に追加 --------------------------\r
1574 *\r
1575 *       Parameter\r
1576 *               HWND hWnd : ウインドウハンドル\r
1577 *               int Pos : 挿入位置\r
1578 *               char *Name : 名前\r
1579 *               int Type : タイプ (NIDE_xxxx)\r
1580 *               LONGLONG Size : サイズ\r
1581 *               FILETIME *Time : 日付\r
1582 *               int Attr : 属性\r
1583 *               char Owner : オーナ名\r
1584 *               int Link : リンクかどうか\r
1585 *               int InfoExist : 情報があるかどうか (FINFO_xxx)\r
1586 *\r
1587 *       Return Value\r
1588 *               なし\r
1589 *----------------------------------------------------------------------------*/\r
1590 \r
1591 static void AddListView(HWND hWnd, int Pos, char *Name, int Type, LONGLONG Size, FILETIME *Time, int Attr, char *Owner, int Link, int InfoExist)\r
1592 {\r
1593         LV_ITEM LvItem;\r
1594         char Tmp[20];\r
1595 \r
1596         if(Pos == -1)\r
1597                 Pos = SendMessage(hWnd, LVM_GETITEMCOUNT, 0, 0);\r
1598 \r
1599         /* アイコン/ファイル名 */\r
1600         LvItem.mask = LVIF_TEXT | LVIF_IMAGE;\r
1601         LvItem.iItem = Pos;\r
1602         LvItem.iSubItem = 0;\r
1603         LvItem.pszText = Name;\r
1604         if((Type == NODE_FILE) && (AskTransferTypeAssoc(Name, TYPE_X) == TYPE_I))\r
1605                 Type = 3;\r
1606         if(Link == NO)\r
1607                 LvItem.iImage = Type;\r
1608         else\r
1609                 LvItem.iImage = 4;\r
1610         LvItem.iItem = SendMessage(hWnd, LVM_INSERTITEM, 0, (LPARAM)&LvItem);\r
1611 \r
1612         /* 日付/時刻 */\r
1613         FileTime2TimeString(Time, Tmp, DISPFORM_LEGACY, InfoExist);\r
1614         LvItem.mask = LVIF_TEXT;\r
1615         LvItem.iItem = Pos;\r
1616         LvItem.iSubItem = 1;\r
1617         LvItem.pszText = Tmp;\r
1618         LvItem.iItem = SendMessage(hWnd, LVM_SETITEM, 0, (LPARAM)&LvItem);\r
1619 \r
1620         /* サイズ */\r
1621         if(Type == NODE_DIR)\r
1622                 strcpy(Tmp, "<DIR>");\r
1623         else if(Type == NODE_DRIVE)\r
1624                 strcpy(Tmp, "<DRIVE>");\r
1625         else if(Size >= 0)\r
1626                 MakeNumString(Size, Tmp, TRUE);\r
1627         else\r
1628                 strcpy(Tmp, "");\r
1629         LvItem.mask = LVIF_TEXT;\r
1630         LvItem.iItem = Pos;\r
1631         LvItem.iSubItem = 2;\r
1632         LvItem.pszText = Tmp;\r
1633         LvItem.iItem = SendMessage(hWnd, LVM_SETITEM, 0, (LPARAM)&LvItem);\r
1634 \r
1635         /* 拡張子 */\r
1636         LvItem.mask = LVIF_TEXT;\r
1637         LvItem.iItem = Pos;\r
1638         LvItem.iSubItem = 3;\r
1639         LvItem.pszText = GetFileExt(Name);\r
1640         LvItem.iItem = SendMessage(hWnd, LVM_SETITEM, 0, (LPARAM)&LvItem);\r
1641 \r
1642         if(hWnd == GetRemoteHwnd())\r
1643         {\r
1644                 /* 属性 */\r
1645                 strcpy(Tmp, "");\r
1646                 if(InfoExist & FINFO_ATTR)\r
1647                         AttrValue2String(Attr, Tmp);\r
1648                 LvItem.mask = LVIF_TEXT;\r
1649                 LvItem.iItem = Pos;\r
1650                 LvItem.iSubItem = 4;\r
1651                 LvItem.pszText = Tmp;\r
1652                 LvItem.iItem = SendMessage(hWnd, LVM_SETITEM, 0, (LPARAM)&LvItem);\r
1653 \r
1654                 /* オーナ名 */\r
1655                 LvItem.mask = LVIF_TEXT;\r
1656                 LvItem.iItem = Pos;\r
1657                 LvItem.iSubItem = 5;\r
1658                 LvItem.pszText = Owner;\r
1659                 LvItem.iItem = SendMessage(hWnd, LVM_SETITEM, 0, (LPARAM)&LvItem);\r
1660         }\r
1661         return;\r
1662 }\r
1663 \r
1664 \r
1665 /*----- ファイル名一覧ウインドウをソートし直す --------------------------------\r
1666 *\r
1667 *       Parameter\r
1668 *               int Win : ウィンドウ番号 (WIN_xxxx)\r
1669 *\r
1670 *       Return Value\r
1671 *               なし\r
1672 *----------------------------------------------------------------------------*/\r
1673 \r
1674 void ReSortDispList(int Win, int *CancelCheckWork)\r
1675 {\r
1676         if(Win == WIN_REMOTE)\r
1677                 GetRemoteDirForWnd(CACHE_LASTREAD, CancelCheckWork);\r
1678         else\r
1679                 GetLocalDirForWnd();\r
1680         return;\r
1681 }\r
1682 \r
1683 \r
1684 /*----- ファイル一覧ウインドウのファイルを選択する ----------------------------\r
1685 *\r
1686 *       Parameter\r
1687 *               HWND hWnd : ウインドウハンドル\r
1688 *               int Type : 選択方法 (SELECT_xxx)\r
1689 *\r
1690 *       Return Value\r
1691 *               なし\r
1692 *----------------------------------------------------------------------------*/\r
1693 \r
1694 void SelectFileInList(HWND hWnd, int Type)\r
1695 {\r
1696         int Win;\r
1697         int WinDst;\r
1698         int i;\r
1699         int Num;\r
1700         char RegExp[FMAX_PATH+1];\r
1701         char Name[FMAX_PATH+1];\r
1702         LV_ITEM LvItem;\r
1703         int CsrPos;\r
1704         FILETIME Time1;\r
1705         FILETIME Time2;\r
1706         int Find;\r
1707 \r
1708         Win = WIN_LOCAL;\r
1709         WinDst = WIN_REMOTE;\r
1710         if(hWnd == GetRemoteHwnd())\r
1711         {\r
1712                 Win = WIN_REMOTE;\r
1713                 WinDst = WIN_LOCAL;\r
1714         }\r
1715 \r
1716         Num = GetItemCount(Win);\r
1717         switch(Type)\r
1718         {\r
1719                 case SELECT_ALL :\r
1720                         LvItem.state = 0;\r
1721                         if(GetSelectedCount(Win) <= 1)\r
1722                                 LvItem.state = LVIS_SELECTED;\r
1723                         for(i = 0; i < Num; i++)\r
1724                         {\r
1725                                 if(GetNodeType(Win, i) != NODE_DRIVE)\r
1726                                 {\r
1727                                         LvItem.mask = LVIF_STATE;\r
1728                                         LvItem.iItem = i;\r
1729                                         LvItem.stateMask = LVIS_SELECTED;\r
1730                                         LvItem.iSubItem = 0;\r
1731                                         SendMessage(hWnd, LVM_SETITEMSTATE, i, (LPARAM)&LvItem);\r
1732                                 }\r
1733                         }\r
1734                         break;\r
1735 \r
1736                 case SELECT_REGEXP :\r
1737                         if(((Win == WIN_LOCAL) &&\r
1738                                 (DialogBox(GetFtpInst(), MAKEINTRESOURCE(sel_local_dlg), hWnd, SelectDialogCallBack) == YES)) ||\r
1739                            ((Win == WIN_REMOTE) &&\r
1740                                 (DialogBox(GetFtpInst(), MAKEINTRESOURCE(sel_remote_dlg), hWnd, SelectDialogCallBack) == YES)))\r
1741                         {\r
1742                                 strcpy(RegExp, FindStr);\r
1743 //                              if(FindMode == 0)\r
1744 //                                      WildCard2RegExp(RegExp);\r
1745 \r
1746                                 _mbslwr(RegExp);\r
1747                                 if((FindMode == 0) || (JreCompileStr(RegExp) == TRUE))\r
1748                                 {\r
1749                                         CsrPos = -1;\r
1750                                         for(i = 0; i < Num; i++)\r
1751                                         {\r
1752                                                 GetNodeName(Win, i, Name, FMAX_PATH);\r
1753                                                 Find = FindNameNode(WinDst, Name);\r
1754 \r
1755                                                 _mbslwr(Name);\r
1756                                                 LvItem.state = 0;\r
1757                                                 if(GetNodeType(Win, i) != NODE_DRIVE)\r
1758                                                 {\r
1759                                                         if(((FindMode == 0) && (CheckFname(Name, RegExp) == FFFTP_SUCCESS)) ||\r
1760                                                            ((FindMode != 0) && (JreGetStrMatchInfo(Name, 0) != NULL)))\r
1761                                                         {\r
1762                                                                 LvItem.state = LVIS_SELECTED;\r
1763 \r
1764                                                                 if(Find >= 0)\r
1765                                                                 {\r
1766                                                                         if(IgnoreExist == YES)\r
1767                                                                                 LvItem.state = 0;\r
1768 \r
1769                                                                         if((LvItem.state != 0) && (IgnoreNew == YES))\r
1770                                                                         {\r
1771                                                                                 GetNodeTime(Win, i, &Time1);\r
1772                                                                                 GetNodeTime(WinDst, Find, &Time2);\r
1773                                                                                 if(CompareFileTime(&Time1, &Time2) > 0)\r
1774                                                                                         LvItem.state = 0;\r
1775                                                                         }\r
1776 \r
1777                                                                         if((LvItem.state != 0) && (IgnoreOld == YES))\r
1778                                                                         {\r
1779                                                                                 GetNodeTime(Win, i, &Time1);\r
1780                                                                                 GetNodeTime(WinDst, Find, &Time2);\r
1781                                                                                 if(CompareFileTime(&Time1, &Time2) < 0)\r
1782                                                                                         LvItem.state = 0;\r
1783                                                                         }\r
1784                                                                 }\r
1785                                                         }\r
1786                                                 }\r
1787 \r
1788                                                 if((LvItem.state != 0) && (CsrPos == -1))\r
1789                                                         CsrPos = i;\r
1790 \r
1791                                                 LvItem.mask = LVIF_STATE;\r
1792                                                 LvItem.iItem = i;\r
1793                                                 LvItem.stateMask = LVIS_SELECTED;\r
1794                                                 LvItem.iSubItem = 0;\r
1795                                                 SendMessage(hWnd, LVM_SETITEMSTATE, i, (LPARAM)&LvItem);\r
1796                                         }\r
1797                                         if(CsrPos != -1)\r
1798                                         {\r
1799                                                 LvItem.mask = LVIF_STATE;\r
1800                                                 LvItem.iItem = CsrPos;\r
1801                                                 LvItem.state = LVIS_FOCUSED;\r
1802                                                 LvItem.stateMask = LVIS_FOCUSED;\r
1803                                                 LvItem.iSubItem = 0;\r
1804                                                 SendMessage(hWnd, LVM_SETITEMSTATE, CsrPos, (LPARAM)&LvItem);\r
1805                                                 SendMessage(hWnd, LVM_ENSUREVISIBLE, CsrPos, (LPARAM)TRUE);\r
1806                                         }\r
1807                                 }\r
1808                         }\r
1809                         break;\r
1810         }\r
1811         return;\r
1812 }\r
1813 \r
1814 \r
1815 /*----- 選択ダイアログのコールバック ------------------------------------------\r
1816 *\r
1817 *       Parameter\r
1818 *               HWND hDlg : ウインドウハンドル\r
1819 *               UINT message : メッセージ番号\r
1820 *               WPARAM wParam : メッセージの WPARAM 引数\r
1821 *               LPARAM lParam : メッセージの LPARAM 引数\r
1822 *\r
1823 *       Return Value\r
1824 *               BOOL TRUE/FALSE\r
1825 *----------------------------------------------------------------------------*/\r
1826 \r
1827 // 64ビット対応\r
1828 //static BOOL CALLBACK SelectDialogCallBack(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam)\r
1829 static INT_PTR CALLBACK SelectDialogCallBack(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam)\r
1830 {\r
1831         switch (iMessage)\r
1832         {\r
1833                 case WM_INITDIALOG :\r
1834                         SendDlgItemMessage(hDlg, SEL_FNAME, EM_LIMITTEXT, 40, 0);\r
1835                         SendDlgItemMessage(hDlg, SEL_FNAME, WM_SETTEXT, 0, (LPARAM)FindStr);\r
1836                         SendDlgItemMessage(hDlg, SEL_REGEXP, BM_SETCHECK, FindMode, 0);\r
1837                         SendDlgItemMessage(hDlg, SEL_NOOLD, BM_SETCHECK, IgnoreOld, 0);\r
1838                         SendDlgItemMessage(hDlg, SEL_NONEW, BM_SETCHECK, IgnoreNew, 0);\r
1839                         SendDlgItemMessage(hDlg, SEL_NOEXIST, BM_SETCHECK, IgnoreExist, 0);\r
1840                         return(TRUE);\r
1841 \r
1842                 case WM_COMMAND :\r
1843                         switch(GET_WM_COMMAND_ID(wParam, lParam))\r
1844                         {\r
1845                                 case IDOK :\r
1846                                         SendDlgItemMessage(hDlg, SEL_FNAME, WM_GETTEXT, 40+1, (LPARAM)FindStr);\r
1847                                         FindMode = SendDlgItemMessage(hDlg, SEL_REGEXP, BM_GETCHECK, 0, 0);\r
1848                                         IgnoreOld = SendDlgItemMessage(hDlg, SEL_NOOLD, BM_GETCHECK, 0, 0);\r
1849                                         IgnoreNew = SendDlgItemMessage(hDlg, SEL_NONEW, BM_GETCHECK, 0, 0);\r
1850                                         IgnoreExist = SendDlgItemMessage(hDlg, SEL_NOEXIST, BM_GETCHECK, 0, 0);\r
1851                                         EndDialog(hDlg, YES);\r
1852                                         break;\r
1853 \r
1854                                 case IDCANCEL :\r
1855                                         EndDialog(hDlg, NO);\r
1856                                         break;\r
1857 \r
1858                                 case IDHELP :\r
1859                                         hHelpWin = HtmlHelp(NULL, AskHelpFilePath(), HH_HELP_CONTEXT, IDH_HELP_TOPIC_0000061);\r
1860                                         break;\r
1861                         }\r
1862             return(TRUE);\r
1863         }\r
1864         return(FALSE);\r
1865 }\r
1866 \r
1867 \r
1868 /*----- ファイル一覧ウインドウのファイルを検索する ----------------------------\r
1869 *\r
1870 *       Parameter\r
1871 *               HWND hWnd : ウインドウハンドル\r
1872 *               int Type : 検索方法 (FIND_xxx)\r
1873 *\r
1874 *       Return Value\r
1875 *               なし\r
1876 *----------------------------------------------------------------------------*/\r
1877 \r
1878 void FindFileInList(HWND hWnd, int Type)\r
1879 {\r
1880         int Win;\r
1881         int i;\r
1882         int Num;\r
1883         static char RegExp[FMAX_PATH+1] = { "" };\r
1884         char Name[FMAX_PATH+1];\r
1885         LV_ITEM LvItem;\r
1886         char *Title;\r
1887 \r
1888         Win = WIN_LOCAL;\r
1889         Title = MSGJPN050;\r
1890         if(hWnd == GetRemoteHwnd())\r
1891         {\r
1892                 Win = WIN_REMOTE;\r
1893                 Title = MSGJPN051;\r
1894         }\r
1895 \r
1896         Num = GetItemCount(Win);\r
1897         switch(Type)\r
1898         {\r
1899                 case FIND_FIRST :\r
1900                         if(InputDialogBox(find_dlg, hWnd, Title, FindStr, 40+1, &FindMode, IDH_HELP_TOPIC_0000001) == YES)\r
1901                         {\r
1902                                 strcpy(RegExp, FindStr);\r
1903 //                              if(FindMode == 0)\r
1904 //                                      WildCard2RegExp(RegExp);\r
1905 \r
1906                                 _mbslwr(RegExp);\r
1907                                 if((FindMode == 0) || (JreCompileStr(RegExp) == TRUE))\r
1908                                 {\r
1909                                         for(i = GetCurrentItem(Win)+1; i < Num; i++)\r
1910                                         {\r
1911                                                 GetNodeName(Win, i, Name, FMAX_PATH);\r
1912                                                 _mbslwr(Name);\r
1913 \r
1914                                                 LvItem.state = 0;\r
1915                                                 if(((FindMode == 0) && (CheckFname(Name, RegExp) == FFFTP_SUCCESS)) ||\r
1916                                                    ((FindMode != 0) && (JreGetStrMatchInfo(Name, 0) != NULL)))\r
1917                                                 {\r
1918                                                         LvItem.mask = LVIF_STATE;\r
1919                                                         LvItem.iItem = i;\r
1920                                                         LvItem.state = LVIS_FOCUSED;\r
1921                                                         LvItem.stateMask = LVIS_FOCUSED;\r
1922                                                         LvItem.iSubItem = 0;\r
1923                                                         SendMessage(hWnd, LVM_SETITEMSTATE, i, (LPARAM)&LvItem);\r
1924                                                         SendMessage(hWnd, LVM_ENSUREVISIBLE, i, (LPARAM)TRUE);\r
1925                                                         break;\r
1926                                                 }\r
1927                                         }\r
1928                                 }\r
1929                         }\r
1930                         break;\r
1931 \r
1932                 case FIND_NEXT :\r
1933                         for(i = GetCurrentItem(Win)+1; i < Num; i++)\r
1934                         {\r
1935                                 GetNodeName(Win, i, Name, FMAX_PATH);\r
1936                                 _mbslwr(Name);\r
1937 \r
1938                                 LvItem.state = 0;\r
1939                                 if(((FindMode == 0) && (CheckFname(Name, RegExp) == FFFTP_SUCCESS)) ||\r
1940                                    ((FindMode != 0) && (JreGetStrMatchInfo(Name, 0) != NULL)))\r
1941                                 {\r
1942                                         LvItem.mask = LVIF_STATE;\r
1943                                         LvItem.iItem = i;\r
1944                                         LvItem.state = LVIS_FOCUSED;\r
1945                                         LvItem.stateMask = LVIS_FOCUSED;\r
1946                                         LvItem.iSubItem = 0;\r
1947                                         SendMessage(hWnd, LVM_SETITEMSTATE, i, (LPARAM)&LvItem);\r
1948                                         SendMessage(hWnd, LVM_ENSUREVISIBLE, i, (LPARAM)TRUE);\r
1949                                         break;\r
1950                                 }\r
1951                         }\r
1952                         break;\r
1953         }\r
1954         return;\r
1955 }\r
1956 \r
1957 \r
1958 #if 0\r
1959 /*----- ワイルドカードを正規表現に変換する ------------------------------------\r
1960 *\r
1961 *       Parameter\r
1962 *               char *Str : 文字列\r
1963 *\r
1964 *       Return Value\r
1965 *               なし\r
1966 *----------------------------------------------------------------------------*/\r
1967 \r
1968 void WildCard2RegExp(char *Str)\r
1969 {\r
1970         char Tmp[FMAX_PATH+1];\r
1971         char *Org;\r
1972         char *Pos;\r
1973         UINT Ch;\r
1974 \r
1975         Org = Str;\r
1976         Pos = Tmp;\r
1977 \r
1978         *Pos++ = '^';\r
1979         *Pos++ = '(';\r
1980         while(*Str != NUL)\r
1981         {\r
1982                 if(Pos >= Tmp + FMAX_PATH - 3)\r
1983                         break;\r
1984 \r
1985                 Ch = _mbsnextc(Str);\r
1986                 Str = _mbsinc(Str);\r
1987 \r
1988                 if(Ch <= 0x7F)\r
1989                 {\r
1990                         if(strchr("[]()^$.+", Ch) != NULL)\r
1991                         {\r
1992                                 *Pos++ = '\\';\r
1993                                 *Pos++ = Ch;\r
1994                         }\r
1995                         else if(Ch == '*')\r
1996                         {\r
1997                                 *Pos++ = '.';\r
1998                                 *Pos++ = '*';\r
1999                         }\r
2000                         else if(Ch == '?')\r
2001                                 *Pos++ = '.';\r
2002                         else if(Ch == '|')\r
2003                         {\r
2004                                 *Pos++ = '|';\r
2005                         }\r
2006                         else\r
2007                                 *Pos++ = Ch;\r
2008                 }\r
2009                 else\r
2010                 {\r
2011                         _mbsnset(Pos, Ch, 1);\r
2012                         Pos = _mbsinc(Pos);\r
2013                 }\r
2014         }\r
2015         *Pos++ = ')';\r
2016         *Pos++ = '$';\r
2017         *Pos = NUL;\r
2018         strcpy(Org, Tmp);\r
2019 \r
2020         return;\r
2021 }\r
2022 #endif\r
2023 \r
2024 \r
2025 /*----- カーソル位置のアイテム番号を返す --------------------------------------\r
2026 *\r
2027 *       Parameter\r
2028 *               int Win : ウィンドウ番号 (WIN_xxxx)\r
2029 *\r
2030 *       Return Value\r
2031 *               int アイテム番号\r
2032 *----------------------------------------------------------------------------*/\r
2033 \r
2034 int GetCurrentItem(int Win)\r
2035 {\r
2036         HWND hWnd;\r
2037         int Ret;\r
2038 \r
2039         hWnd = GetLocalHwnd();\r
2040         if(Win == WIN_REMOTE)\r
2041                 hWnd = GetRemoteHwnd();\r
2042 \r
2043         if((Ret = SendMessage(hWnd, LVM_GETNEXTITEM, -1, MAKELPARAM(LVNI_ALL | LVNI_FOCUSED, 0))) == -1)\r
2044                 Ret = 0;\r
2045 \r
2046         return(Ret);\r
2047 }\r
2048 \r
2049 \r
2050 /*----- アイテム数を返す ------------------------------------------------------\r
2051 *\r
2052 *       Parameter\r
2053 *               int Win : ウィンドウ番号 (WIN_xxxx)\r
2054 *\r
2055 *       Return Value\r
2056 *               int アイテム数\r
2057 *----------------------------------------------------------------------------*/\r
2058 \r
2059 int GetItemCount(int Win)\r
2060 {\r
2061         HWND hWnd;\r
2062 \r
2063         hWnd = GetLocalHwnd();\r
2064         if(Win == WIN_REMOTE)\r
2065                 hWnd = GetRemoteHwnd();\r
2066 \r
2067         return(SendMessage(hWnd, LVM_GETITEMCOUNT, 0, 0));\r
2068 }\r
2069 \r
2070 \r
2071 /*----- 選択されているアイテム数を返す ----------------------------------------\r
2072 *\r
2073 *       Parameter\r
2074 *               int Win : ウィンドウ番号 (WIN_xxxx)\r
2075 *\r
2076 *       Return Value\r
2077 *               int 選択されているアイテム数\r
2078 *----------------------------------------------------------------------------*/\r
2079 \r
2080 int GetSelectedCount(int Win)\r
2081 {\r
2082         HWND hWnd;\r
2083 \r
2084         hWnd = GetLocalHwnd();\r
2085         if(Win == WIN_REMOTE)\r
2086                 hWnd = GetRemoteHwnd();\r
2087 \r
2088         return(SendMessage(hWnd, LVM_GETSELECTEDCOUNT, 0, 0));\r
2089 }\r
2090 \r
2091 \r
2092 /*----- 選択されている最初のアイテム番号を返す --------------------------------\r
2093 *\r
2094 *       Parameter\r
2095 *               int Win : ウィンドウ番号 (WIN_xxxx)\r
2096 *               int All : 選ばれていないものを含める\r
2097 *\r
2098 *       Return Value\r
2099 *               int アイテム番号\r
2100 *                       -1 = 選択されていない\r
2101 *----------------------------------------------------------------------------*/\r
2102 \r
2103 int GetFirstSelected(int Win, int All)\r
2104 {\r
2105         HWND hWnd;\r
2106         int Ope;\r
2107 \r
2108         hWnd = GetLocalHwnd();\r
2109         if(Win == WIN_REMOTE)\r
2110                 hWnd = GetRemoteHwnd();\r
2111 \r
2112         Ope = LVNI_SELECTED;\r
2113         if(All == YES)\r
2114                 Ope = LVNI_ALL;\r
2115 \r
2116         return(SendMessage(hWnd, LVM_GETNEXTITEM, (WPARAM)-1, (LPARAM)MAKELPARAM(Ope, 0)));\r
2117 }\r
2118 \r
2119 \r
2120 /*----- 選択されている次のアイテム番号を返す ----------------------------------\r
2121 *\r
2122 *       Parameter\r
2123 *               int Win : ウィンドウ番号 (WIN_xxxx)\r
2124 *               int Pos : 今のアイテム番号\r
2125 *               int All : 選ばれていないものも含める\r
2126 *\r
2127 *       Return Value\r
2128 *               int アイテム番号\r
2129 *                       -1 = 選択されていない\r
2130 *----------------------------------------------------------------------------*/\r
2131 \r
2132 int GetNextSelected(int Win, int Pos, int All)\r
2133 {\r
2134         HWND hWnd;\r
2135         int Ope;\r
2136 \r
2137         hWnd = GetLocalHwnd();\r
2138         if(Win == WIN_REMOTE)\r
2139                 hWnd = GetRemoteHwnd();\r
2140 \r
2141         Ope = LVNI_SELECTED;\r
2142         if(All == YES)\r
2143                 Ope = LVNI_ALL;\r
2144 \r
2145         return(SendMessage(hWnd, LVM_GETNEXTITEM, (WPARAM)Pos, (LPARAM)MAKELPARAM(Ope, 0)));\r
2146 }\r
2147 \r
2148 \r
2149 /*----- 指定された名前のアイテムを探す ----------------------------------------\r
2150 *\r
2151 *       Parameter\r
2152 *               int Win : ウインドウ番号 (WIN_xxx)\r
2153 *               char *Name : 名前\r
2154 *\r
2155 *       Return Value\r
2156 *               int アイテム番号\r
2157 *                       -1=見つからなかった\r
2158 *----------------------------------------------------------------------------*/\r
2159 \r
2160 int FindNameNode(int Win, char *Name)\r
2161 {\r
2162         LV_FINDINFO FindInfo;\r
2163         HWND hWnd;\r
2164 \r
2165         hWnd = GetLocalHwnd();\r
2166         if(Win == WIN_REMOTE)\r
2167                 hWnd = GetRemoteHwnd();\r
2168 \r
2169         FindInfo.flags = LVFI_STRING;\r
2170         FindInfo.psz = Name;\r
2171         return(SendMessage(hWnd, LVM_FINDITEM, -1, (LPARAM)&FindInfo));\r
2172 }\r
2173 \r
2174 \r
2175 /*----- 指定位置のアイテムの名前を返す ----------------------------------------\r
2176 *\r
2177 *       Parameter\r
2178 *               int Win : ウインドウ番号 (WIN_xxx)\r
2179 *               int Pos : 位置\r
2180 *               char *Buf : 名前を返すバッファ\r
2181 *               int Max : バッファのサイズ\r
2182 *\r
2183 *       Return Value\r
2184 *               なし\r
2185 *----------------------------------------------------------------------------*/\r
2186 \r
2187 void GetNodeName(int Win, int Pos, char *Buf, int Max)\r
2188 {\r
2189         HWND hWnd;\r
2190         LV_ITEM LvItem;\r
2191 \r
2192         hWnd = GetLocalHwnd();\r
2193         if(Win == WIN_REMOTE)\r
2194                 hWnd = GetRemoteHwnd();\r
2195 \r
2196         LvItem.mask = LVIF_TEXT;\r
2197         LvItem.iItem = Pos;\r
2198         LvItem.iSubItem = 0;\r
2199         LvItem.pszText = Buf;\r
2200         LvItem.cchTextMax = Max;\r
2201         SendMessage(hWnd, LVM_GETITEM, 0, (LPARAM)&LvItem);\r
2202         return;\r
2203 }\r
2204 \r
2205 \r
2206 /*----- 指定位置のアイテムの日付を返す ----------------------------------------\r
2207 *\r
2208 *       Parameter\r
2209 *               int Win : ウインドウ番号 (WIN_xxx)\r
2210 *               int Pos : 位置\r
2211 *               FILETIME *Buf : 日付を返すバッファ\r
2212 *\r
2213 *       Return Value\r
2214 *               int ステータス\r
2215 *                       YES/NO=日付情報がなかった\r
2216 *----------------------------------------------------------------------------*/\r
2217 \r
2218 int GetNodeTime(int Win, int Pos, FILETIME *Buf)\r
2219 {\r
2220         HWND hWnd;\r
2221         LV_ITEM LvItem;\r
2222         char Tmp[20];\r
2223         int Ret;\r
2224 \r
2225         hWnd = GetLocalHwnd();\r
2226         if(Win == WIN_REMOTE)\r
2227                 hWnd = GetRemoteHwnd();\r
2228 \r
2229         LvItem.mask = LVIF_TEXT;\r
2230         LvItem.iItem = Pos;\r
2231         LvItem.iSubItem = 1;\r
2232         LvItem.pszText = Tmp;\r
2233         LvItem.cchTextMax = 20;\r
2234         SendMessage(hWnd, LVM_GETITEM, 0, (LPARAM)&LvItem);\r
2235         Ret = TimeString2FileTime(Tmp, Buf);\r
2236         return(Ret);\r
2237 }\r
2238 \r
2239 \r
2240 /*----- 指定位置のアイテムのサイズを返す --------------------------------------\r
2241 *\r
2242 *       Parameter\r
2243 *               int Win : ウインドウ番号 (WIN_xxx)\r
2244 *               int Pos : 位置\r
2245 *               int *Buf : サイズを返すワーク\r
2246 *\r
2247 *       Return Value\r
2248 *               int ステータス\r
2249 *                       YES/NO=サイズ情報がなかった\r
2250 *----------------------------------------------------------------------------*/\r
2251 \r
2252 int GetNodeSize(int Win, int Pos, LONGLONG *Buf)\r
2253 {\r
2254         HWND hWnd;\r
2255         LV_ITEM LvItem;\r
2256         char Tmp[40];\r
2257         int Ret;\r
2258 \r
2259         hWnd = GetLocalHwnd();\r
2260         if(Win == WIN_REMOTE)\r
2261                 hWnd = GetRemoteHwnd();\r
2262 \r
2263         LvItem.mask = LVIF_TEXT;\r
2264         LvItem.iItem = Pos;\r
2265         LvItem.iSubItem = 2;\r
2266         LvItem.pszText = Tmp;\r
2267         LvItem.cchTextMax = 20;\r
2268         SendMessage(hWnd, LVM_GETITEM, 0, (LPARAM)&LvItem);\r
2269         *Buf = -1;\r
2270         Ret = NO;\r
2271         if(strlen(Tmp) > 0)\r
2272         {\r
2273                 RemoveComma(Tmp);\r
2274                 *Buf = _atoi64(Tmp);\r
2275                 Ret = YES;\r
2276         }\r
2277         return(Ret);\r
2278 }\r
2279 \r
2280 \r
2281 /*----- 指定位置のアイテムの属性を返す ----------------------------------------\r
2282 *\r
2283 *       Parameter\r
2284 *               int Win : ウインドウ番号 (WIN_xxx)\r
2285 *               int Pos : 位置\r
2286 *               int *Buf : 属性を返すワーク\r
2287 *\r
2288 *       Return Value\r
2289 *               int ステータス\r
2290 *                       YES/NO=サイズ情報がなかった\r
2291 *----------------------------------------------------------------------------*/\r
2292 \r
2293 int GetNodeAttr(int Win, int Pos, int *Buf)\r
2294 {\r
2295         LV_ITEM LvItem;\r
2296         char Tmp[20];\r
2297         int Ret;\r
2298 \r
2299         *Buf = 0;\r
2300         Ret = NO;\r
2301         if(Win == WIN_REMOTE)\r
2302         {\r
2303                 LvItem.mask = LVIF_TEXT;\r
2304                 LvItem.iItem = Pos;\r
2305                 LvItem.iSubItem = 4;\r
2306                 LvItem.pszText = Tmp;\r
2307                 LvItem.cchTextMax = 20;\r
2308                 SendMessage(GetRemoteHwnd(), LVM_GETITEM, 0, (LPARAM)&LvItem);\r
2309                 if(strlen(Tmp) > 0)\r
2310                 {\r
2311                         *Buf = AttrString2Value(Tmp);\r
2312                         Ret = YES;\r
2313                 }\r
2314         }\r
2315         return(Ret);\r
2316 }\r
2317 \r
2318 \r
2319 /*----- 指定位置のアイテムのタイプを返す --------------------------------------\r
2320 *\r
2321 *       Parameter\r
2322 *               int Win : ウインドウ番号 (WIN_xxx)\r
2323 *               int Pos : 位置\r
2324 *\r
2325 *       Return Value\r
2326 *               int タイプ (NODE_xxx)\r
2327 *----------------------------------------------------------------------------*/\r
2328 \r
2329 int GetNodeType(int Win, int Pos)\r
2330 {\r
2331         char Tmp[20];\r
2332         LV_ITEM LvItem;\r
2333         int Ret;\r
2334         HWND hWnd;\r
2335 \r
2336         hWnd = GetLocalHwnd();\r
2337         if(Win == WIN_REMOTE)\r
2338                 hWnd = GetRemoteHwnd();\r
2339 \r
2340         LvItem.mask = LVIF_TEXT;\r
2341         LvItem.iItem = Pos;\r
2342         LvItem.iSubItem = 2;\r
2343         LvItem.pszText = Tmp;\r
2344         LvItem.cchTextMax = 20;\r
2345         SendMessage(hWnd, LVM_GETITEM, 0, (LPARAM)&LvItem);\r
2346 \r
2347         if(strcmp(Tmp, "<DIR>") == 0)\r
2348                 Ret = NODE_DIR;\r
2349         else if(strcmp(Tmp, "<DRIVE>") == 0)\r
2350                 Ret = NODE_DRIVE;\r
2351         else\r
2352                 Ret = NODE_FILE;\r
2353 \r
2354         return(Ret);\r
2355 }\r
2356 \r
2357 \r
2358 /*----- 指定位置のアイテムのオーナ名を返す ------------------------------------\r
2359 *\r
2360 *       Parameter\r
2361 *               int Win : ウインドウ番号 (WIN_xxx)\r
2362 *               int Pos : 位置\r
2363 *               char *Buf : オーナ名を返すバッファ\r
2364 *               int Max : バッファのサイズ\r
2365 *\r
2366 *       Return Value\r
2367 *               なし\r
2368 *----------------------------------------------------------------------------*/\r
2369 \r
2370 void GetNodeOwner(int Win, int Pos, char *Buf, int Max)\r
2371 {\r
2372         LV_ITEM LvItem;\r
2373 \r
2374         strcpy(Buf, "");\r
2375         if(Win == WIN_REMOTE)\r
2376         {\r
2377                 LvItem.mask = LVIF_TEXT;\r
2378                 LvItem.iItem = Pos;\r
2379                 LvItem.iSubItem = 5;\r
2380                 LvItem.pszText = Buf;\r
2381                 LvItem.cchTextMax = Max;\r
2382                 SendMessage(GetRemoteHwnd(), LVM_GETITEM, 0, (LPARAM)&LvItem);\r
2383         }\r
2384         return;\r
2385 }\r
2386 \r
2387 \r
2388 /*----- ホスト側のファイル一覧ウインドウをクリア ------------------------------\r
2389 *\r
2390 *       Parameter\r
2391 *               なし\r
2392 *\r
2393 *       Return Value\r
2394 *               なし\r
2395 *----------------------------------------------------------------------------*/\r
2396 \r
2397 void EraseRemoteDirForWnd(void)\r
2398 {\r
2399         SendMessage(GetRemoteHwnd(), LVM_DELETEALLITEMS, 0, 0);\r
2400         SendMessage(GetRemoteHistHwnd(), CB_RESETCONTENT, 0, 0);\r
2401         return;\r
2402 }\r
2403 \r
2404 \r
2405 /*----- 選択されているファイルの総サイズを返す --------------------------------\r
2406 *\r
2407 *       Parameter\r
2408 *               int Win : ウインドウ番号 (WIN_xxx)\r
2409 *\r
2410 *       Return Value\r
2411 *               double サイズ\r
2412 *----------------------------------------------------------------------------*/\r
2413 \r
2414 double GetSelectedTotalSize(int Win)\r
2415 {\r
2416         double Ret;\r
2417         LONGLONG Size;\r
2418         int Pos;\r
2419 \r
2420         Ret = 0;\r
2421         if(GetSelectedCount(Win) > 0)\r
2422         {\r
2423                 Pos = GetFirstSelected(Win, NO);\r
2424                 while(Pos != -1)\r
2425                 {\r
2426                         GetNodeSize(Win, Pos, &Size);\r
2427                         if(Size >= 0)\r
2428                                 Ret += Size;\r
2429                         Pos = GetNextSelected(Win, Pos, NO);\r
2430                 }\r
2431         }\r
2432         return(Ret);\r
2433 }\r
2434 \r
2435 \r
2436 \r
2437 /*===================================================================\r
2438 \r
2439 ===================================================================*/\r
2440 \r
2441 \r
2442 \r
2443 /*----- ファイル一覧で選ばれているファイルをリストに登録する ------------------\r
2444 *\r
2445 *       Parameter\r
2446 *               int Win : ウインドウ番号 (WIN_xxx)\r
2447 *               int Expand : サブディレクトリを展開する (YES/NO)\r
2448 *               int All : 選ばれていないものもすべて登録する (YES/NO)\r
2449 *               FILELIST **Base : ファイルリストの先頭\r
2450 *\r
2451 *       Return Value\r
2452 *               なし\r
2453 *----------------------------------------------------------------------------*/\r
2454 \r
2455 void MakeSelectedFileList(int Win, int Expand, int All, FILELIST **Base, int *CancelCheckWork)\r
2456 {\r
2457         int Pos;\r
2458         char Name[FMAX_PATH+1];\r
2459         char Cur[FMAX_PATH+1];\r
2460         FILELIST Pkt;\r
2461         int Node;\r
2462         DWORD Attr;\r
2463         int Ignore;\r
2464 \r
2465         if((All == YES) || (GetSelectedCount(Win) > 0))\r
2466         {\r
2467                 /*===== カレントディレクトリのファイル =====*/\r
2468 \r
2469                 Pos = GetFirstSelected(Win, All);\r
2470                 while(Pos != -1)\r
2471                 {\r
2472                         Node = GetNodeType(Win, Pos);\r
2473                         if((Node == NODE_FILE) ||\r
2474                            ((Expand == NO) && (Node == NODE_DIR)))\r
2475                         {\r
2476                                 Pkt.InfoExist = 0;\r
2477                                 GetNodeName(Win, Pos, Pkt.File, FMAX_PATH);\r
2478                                 if(GetNodeSize(Win, Pos, &Pkt.Size) == YES)\r
2479                                         Pkt.InfoExist |= FINFO_SIZE;\r
2480                                 if(GetNodeAttr(Win, Pos, &Pkt.Attr) == YES)\r
2481                                         Pkt.InfoExist |= FINFO_ATTR;\r
2482                                 if(GetNodeTime(Win, Pos, &Pkt.Time) == YES)\r
2483                                         Pkt.InfoExist |= (FINFO_TIME | FINFO_DATE);\r
2484                                 Pkt.Node = Node;\r
2485 \r
2486                                 Ignore = NO;\r
2487                                 if((DispIgnoreHide == YES) && (Win == WIN_LOCAL))\r
2488                                 {\r
2489                                         AskLocalCurDir(Cur, FMAX_PATH);\r
2490                                         SetYenTail(Cur);\r
2491                                         strcat(Cur, Pkt.File);\r
2492                                         Attr = GetFileAttributes(Cur);\r
2493                                         if((Attr != 0xFFFFFFFF) && (Attr & FILE_ATTRIBUTE_HIDDEN))\r
2494                                                 Ignore = YES;\r
2495                                 }\r
2496 \r
2497                                 if(Ignore == NO)\r
2498                                         AddFileList(&Pkt, Base);\r
2499                         }\r
2500                         Pos = GetNextSelected(Win, Pos, All);\r
2501                 }\r
2502 \r
2503                 if(Expand == YES)\r
2504                 {\r
2505                         /*===== ディレクトリツリー =====*/\r
2506 \r
2507                         Pos = GetFirstSelected(Win, All);\r
2508                         while(Pos != -1)\r
2509                         {\r
2510                                 if(GetNodeType(Win, Pos) == NODE_DIR)\r
2511                                 {\r
2512                                         GetNodeName(Win, Pos, Name, FMAX_PATH);\r
2513                                         strcpy(Pkt.File, Name);\r
2514                                         ReplaceAll(Pkt.File, '\\', '/');\r
2515 //8/26\r
2516 \r
2517                                         Ignore = NO;\r
2518                                         if((DispIgnoreHide == YES) && (Win == WIN_LOCAL))\r
2519                                         {\r
2520                                                 AskLocalCurDir(Cur, FMAX_PATH);\r
2521                                                 SetYenTail(Cur);\r
2522                                                 strcat(Cur, Pkt.File);\r
2523                                                 ReplaceAll(Cur, '/', '\\');\r
2524                                                 Attr = GetFileAttributes(Cur);\r
2525                                                 if((Attr != 0xFFFFFFFF) && (Attr & FILE_ATTRIBUTE_HIDDEN))\r
2526                                                         Ignore = YES;\r
2527                                         }\r
2528 \r
2529                                         if(Ignore == NO)\r
2530                                         {\r
2531                                                 Pkt.Node = NODE_DIR;\r
2532                                                 Pkt.Attr = 0;\r
2533                                                 Pkt.Size = 0;\r
2534                                                 memset(&Pkt.Time, 0, sizeof(FILETIME));\r
2535                                                 AddFileList(&Pkt, Base);\r
2536 \r
2537                                                 if(Win == WIN_LOCAL)\r
2538                                                         MakeLocalTree(Name, Base);\r
2539                                                 else\r
2540                                                 {\r
2541                                                         AskRemoteCurDir(Cur, FMAX_PATH);\r
2542 \r
2543                                                         if((AskListCmdMode() == NO) &&\r
2544                                                            (AskUseNLST_R() == YES))\r
2545                                                                 MakeRemoteTree1(Name, Cur, Base, CancelCheckWork);\r
2546                                                         else\r
2547                                                                 MakeRemoteTree2(Name, Cur, Base, CancelCheckWork);\r
2548 \r
2549 //DispListList(*Base, "LIST");\r
2550 \r
2551                                                 }\r
2552                                         }\r
2553                                 }\r
2554                                 Pos = GetNextSelected(Win, Pos, All);\r
2555                         }\r
2556                 }\r
2557         }\r
2558         return;\r
2559 }\r
2560 \r
2561 \r
2562 /* デバッグ用 */\r
2563 /* ファイルリストの内容を表示 */\r
2564 static void DispListList(FILELIST *Pos, char *Title)\r
2565 {\r
2566         DoPrintf("############ %s ############", Title);\r
2567         while(Pos != NULL)\r
2568         {\r
2569                 DoPrintf("%d %s", Pos->Node, Pos->File);\r
2570                 Pos = Pos->Next;\r
2571         }\r
2572         DoPrintf("############ END ############");\r
2573         return;\r
2574 }\r
2575 \r
2576 \r
2577 /*----- Drag&Dropされたファイルをリストに登録する -----------------------------\r
2578 *\r
2579 *       Parameter\r
2580 *               WPARAM wParam : ドロップされたファイルの情報\r
2581 *               char *Cur : カレントディレクトリを返すバッファ\r
2582 *               FILELIST **Base : ファイルリストの先頭\r
2583 *\r
2584 *       Return Value\r
2585 *               なし\r
2586 *----------------------------------------------------------------------------*/\r
2587 \r
2588 void MakeDroppedFileList(WPARAM wParam, char *Cur, FILELIST **Base)\r
2589 {\r
2590         int Max;\r
2591         int i;\r
2592         char Name[FMAX_PATH+1];\r
2593         char Tmp[FMAX_PATH+1];\r
2594         FILELIST Pkt;\r
2595         HANDLE fHnd;\r
2596         WIN32_FIND_DATA Find;\r
2597 \r
2598         Max = DragQueryFile((HDROP)wParam, 0xFFFFFFFF, NULL, 0);\r
2599 \r
2600         DragQueryFile((HDROP)wParam, 0, Cur, FMAX_PATH);\r
2601         GetUpperDir(Cur);\r
2602 \r
2603         for(i = 0; i < Max; i++)\r
2604         {\r
2605                 DragQueryFile((HDROP)wParam, i, Name, FMAX_PATH);\r
2606 \r
2607                 if((GetFileAttributes(Name) & FILE_ATTRIBUTE_DIRECTORY) == 0)\r
2608                 {\r
2609                         Pkt.Node = NODE_FILE;\r
2610                         strcpy(Pkt.File, GetFileName(Name));\r
2611 \r
2612                         memset(&Pkt.Time, 0, sizeof(FILETIME));\r
2613                         if((fHnd = FindFirstFile(Name, &Find)) != INVALID_HANDLE_VALUE)\r
2614                         {\r
2615                                 FindClose(fHnd);\r
2616                                 Pkt.Time = Find.ftLastWriteTime;\r
2617                         }\r
2618                         AddFileList(&Pkt, Base);\r
2619                 }\r
2620         }\r
2621 \r
2622         GetCurrentDirectory(FMAX_PATH, Tmp);\r
2623         SetCurrentDirectory(Cur);\r
2624         for(i = 0; i < Max; i++)\r
2625         {\r
2626                 DragQueryFile((HDROP)wParam, i, Name, FMAX_PATH);\r
2627 \r
2628                 if(GetFileAttributes(Name) & FILE_ATTRIBUTE_DIRECTORY)\r
2629                 {\r
2630                         Pkt.Node = NODE_DIR;\r
2631                         strcpy(Pkt.File, GetFileName(Name));\r
2632                         AddFileList(&Pkt, Base);\r
2633 \r
2634                         MakeLocalTree(Pkt.File, Base);\r
2635                 }\r
2636         }\r
2637         SetCurrentDirectory(Tmp);\r
2638 \r
2639         DragFinish((HDROP)wParam);\r
2640 \r
2641         return;\r
2642 }\r
2643 \r
2644 \r
2645 /*----- Drag&Dropされたファイルがあるフォルダを取得する -----------------------\r
2646 *\r
2647 *       Parameter\r
2648 *               WPARAM wParam : ドロップされたファイルの情報\r
2649 *               char *Cur : カレントディレクトリを返すバッファ\r
2650 *\r
2651 *       Return Value\r
2652 *               なし\r
2653 *----------------------------------------------------------------------------*/\r
2654 \r
2655 void MakeDroppedDir(WPARAM wParam, char *Cur)\r
2656 {\r
2657         int Max;\r
2658 \r
2659         Max = DragQueryFile((HDROP)wParam, 0xFFFFFFFF, NULL, 0);\r
2660         DragQueryFile((HDROP)wParam, 0, Cur, FMAX_PATH);\r
2661         GetUpperDir(Cur);\r
2662         DragFinish((HDROP)wParam);\r
2663 \r
2664         return;\r
2665 }\r
2666 \r
2667 \r
2668 /*----- ホスト側のサブディレクトリ以下のファイルをリストに登録する(1)-------\r
2669 *\r
2670 *       Parameter\r
2671 *               char *Path : パス名\r
2672 *               char *Cur : カレントディレクトリ\r
2673 *               FILELIST **Base : ファイルリストの先頭\r
2674 *\r
2675 *       Return Value\r
2676 *               なし\r
2677 *\r
2678 *       Note\r
2679 *               NLST -alLR を使う\r
2680 *----------------------------------------------------------------------------*/\r
2681 \r
2682 static void MakeRemoteTree1(char *Path, char *Cur, FILELIST **Base, int *CancelCheckWork)\r
2683 {\r
2684         int Sts;\r
2685 \r
2686         if(DoCWD(Path, NO, NO, NO) == FTP_COMPLETE)\r
2687         {\r
2688                 /* サブフォルダも含めたリストを取得 */\r
2689                 Sts = DoDirListCmdSkt("R", "", 999, CancelCheckWork);   /* NLST -alLR*/\r
2690                 DoCWD(Cur, NO, NO, NO);\r
2691 \r
2692                 if(Sts == FTP_COMPLETE)\r
2693                         AddRemoteTreeToFileList(999, Path, RDIR_NLST, Base);\r
2694         }\r
2695         return;\r
2696 }\r
2697 \r
2698 \r
2699 /*----- ホスト側のサブディレクトリ以下のファイルをリストに登録する(2)-------\r
2700 *\r
2701 *       Parameter\r
2702 *               char *Path : パス名\r
2703 *               char *Cur : カレントディレクトリ\r
2704 *               FILELIST **Base : ファイルリストの先頭\r
2705 *\r
2706 *       Return Value\r
2707 *               なし\r
2708 *\r
2709 *       Note\r
2710 *               各フォルダに移動してリストを取得\r
2711 *----------------------------------------------------------------------------*/\r
2712 \r
2713 static void MakeRemoteTree2(char *Path, char *Cur, FILELIST **Base, int *CancelCheckWork)\r
2714 {\r
2715         int Sts;\r
2716         FILELIST *CurList;\r
2717         FILELIST *Pos;\r
2718         FILELIST Pkt;\r
2719 \r
2720         /* VAX VMS は CWD xxx/yyy という指定ができないので */\r
2721         /* CWD xxx, Cwd yyy と複数に分ける                                       */\r
2722         if(AskHostType() != HTYPE_VMS)\r
2723                 Sts = DoCWD(Path, NO, NO, NO);\r
2724         else\r
2725         {\r
2726 #if defined(HAVE_OPENVMS)\r
2727                 /* OpenVMSの場合、ディレクトリ移動時は"HOGE.DIR;1"を"HOGE"にする */\r
2728                 ReformVMSDirName(Path, TRUE);\r
2729 #endif\r
2730                 Sts = DoCWDStepByStep(Path, Cur);\r
2731         }\r
2732 \r
2733         if(Sts == FTP_COMPLETE)\r
2734         {\r
2735                 Sts = DoDirListCmdSkt("", "", 999, CancelCheckWork);            /* NLST -alL*/\r
2736                 DoCWD(Cur, NO, NO, NO);\r
2737 \r
2738                 if(Sts == FTP_COMPLETE)\r
2739                 {\r
2740                         CurList = NULL;\r
2741                         AddRemoteTreeToFileList(999, Path, RDIR_CWD, &CurList);\r
2742                         CopyTmpListToFileList(Base, CurList);\r
2743 \r
2744                         Pos = CurList;\r
2745                         while(Pos != NULL)\r
2746                         {\r
2747                                 if(Pos->Node == NODE_DIR)\r
2748                                 {\r
2749                                         /* まずディレクトリ名をセット */\r
2750                                         strcpy(Pkt.File, Pos->File);\r
2751                                         Pkt.Node = NODE_DIR;\r
2752                                         Pkt.Size = 0;\r
2753                                         Pkt.Attr = 0;\r
2754                                         memset(&Pkt.Time, 0, sizeof(FILETIME));\r
2755                                         AddFileList(&Pkt, Base);\r
2756 \r
2757                                         /* そのディレクトリの中を検索 */\r
2758                                         MakeRemoteTree2(Pos->File, Cur, Base, CancelCheckWork);\r
2759                                 }\r
2760                                 Pos = Pos->Next;\r
2761                         }\r
2762                         DeleteFileList(&CurList);\r
2763                 }\r
2764         }\r
2765         return;\r
2766 }\r
2767 \r
2768 \r
2769 /*----- ファイルリストの内容を別のファイルリストにコピー ----------------------\r
2770 *\r
2771 *       Parameter\r
2772 *               FILELIST **Base : コピー先\r
2773 *               FILELIST *List : コピー元\r
2774 *\r
2775 *       Return Value\r
2776 *               なし\r
2777 *\r
2778 *       Note\r
2779 *               コピーするのはファイルの情報だけ\r
2780 *               ディレクトリの情報はコピーしない\r
2781 *----------------------------------------------------------------------------*/\r
2782 \r
2783 static void CopyTmpListToFileList(FILELIST **Base, FILELIST *List)\r
2784 {\r
2785         while(List != NULL)\r
2786         {\r
2787                 if(List->Node == NODE_FILE)\r
2788                         AddFileList(List, Base);\r
2789 \r
2790                 List = List->Next;\r
2791         }\r
2792         return;\r
2793 }\r
2794 \r
2795 \r
2796 /*----- ホスト側のファイル情報をファイルリストに登録 --------------------------\r
2797 *\r
2798 *       Parameter\r
2799 *               int Num : テンポラリファイルのファイル名番号 (_ffftp.???)\r
2800 *               char *Path : パス名\r
2801 *               int IncDir : 再帰検索の方法 (RDIR_xxx)\r
2802 *               FILELIST **Base : ファイルリストの先頭\r
2803 *\r
2804 *       Return Value\r
2805 *               なし\r
2806 *----------------------------------------------------------------------------*/\r
2807 \r
2808 void AddRemoteTreeToFileList(int Num, char *Path, int IncDir, FILELIST **Base)\r
2809 {\r
2810         char Str[FMAX_PATH+1];\r
2811         char Dir[FMAX_PATH+1];\r
2812         char Name[FMAX_PATH+1];\r
2813         LONGLONG Size;\r
2814         FILETIME Time;\r
2815         int Attr;\r
2816         FILELIST Pkt;\r
2817         FILE *fd;\r
2818         int Node;\r
2819         int ListType;\r
2820         char Owner[OWNER_NAME_LEN+1];\r
2821         int Link;\r
2822         int InfoExist;\r
2823 \r
2824         MakeCacheFileName(Num, Str);\r
2825         if((fd = fopen(Str, "rb")) != NULL)\r
2826         {\r
2827                 strcpy(Dir, Path);\r
2828 \r
2829                 ListType = LIST_UNKNOWN;\r
2830 \r
2831                 while(GetListOneLine(Str, FMAX_PATH, fd) == FFFTP_SUCCESS)\r
2832                 {\r
2833                         if((ListType = AnalizeFileInfo(Str)) == LIST_UNKNOWN)\r
2834                         {\r
2835                                 if(MakeDirPath(Str, ListType, Path, Dir) == FFFTP_SUCCESS)\r
2836                                 {\r
2837                                         if(IncDir == RDIR_NLST)\r
2838                                         {\r
2839                                                 strcpy(Pkt.File, Dir);\r
2840                                                 Pkt.Node = NODE_DIR;\r
2841                                                 Pkt.Size = 0;\r
2842                                                 Pkt.Attr = 0;\r
2843                                                 memset(&Pkt.Time, 0, sizeof(FILETIME));\r
2844                                                 AddFileList(&Pkt, Base);\r
2845                                         }\r
2846                                 }\r
2847                         }\r
2848                         else\r
2849                         {\r
2850                                 Node = ResolvFileInfo(Str, ListType, Name, &Size, &Time, &Attr, Owner, &Link, &InfoExist);\r
2851 \r
2852                                 if(AskFilterStr(Name, Node) == YES)\r
2853                                 {\r
2854                                         if((Node == NODE_FILE) ||\r
2855                                            ((IncDir == RDIR_CWD) && (Node == NODE_DIR)))\r
2856                                         {\r
2857                                                 strcpy(Pkt.File, Dir);\r
2858                                                 if(strlen(Pkt.File) > 0)\r
2859                                                         SetSlashTail(Pkt.File);\r
2860                                                 strcat(Pkt.File, Name);\r
2861                                                 Pkt.Node = Node;\r
2862                                                 Pkt.Link = Link;\r
2863                                                 Pkt.Size = Size;\r
2864                                                 Pkt.Attr = Attr;\r
2865                                                 Pkt.Time = Time;\r
2866                                                 Pkt.InfoExist = InfoExist;\r
2867                                                 AddFileList(&Pkt, Base);\r
2868                                         }\r
2869                                 }\r
2870                         }\r
2871                 }\r
2872                 fclose(fd);\r
2873         }\r
2874         return;\r
2875 }\r
2876 \r
2877 \r
2878 /*----- ファイル一覧情報の1行を取得 ------------------------------------------\r
2879 *\r
2880 *       Parameter\r
2881 *               char *Buf : 1行の情報をセットするバッファ\r
2882 *               int Max : 最大文字数\r
2883 *               FILE *Fd : ストリーム\r
2884 *\r
2885 *       Return Value\r
2886 *               int ステータス (FFFTP_SUCCESS/FFFTP_FAIL)\r
2887 *\r
2888 *       Note\r
2889 *               VAX VMS以外の時は fgets(Buf, Max, Fd) と同じ\r
2890 *               Vax VMSの時は、複数行のファイル情報を1行にまとめる\r
2891 *----------------------------------------------------------------------------*/\r
2892 \r
2893 static int GetListOneLine(char *Buf, int Max, FILE *Fd)\r
2894 {\r
2895         char Tmp[FMAX_PATH+1];\r
2896         int Sts;\r
2897 \r
2898         Sts = FFFTP_FAIL;\r
2899         while((Sts == FFFTP_FAIL) && (fgets(Buf, Max, Fd) != NULL))\r
2900         {\r
2901                 Sts = FFFTP_SUCCESS;\r
2902                 RemoveReturnCode(Buf);\r
2903                 ReplaceAll(Buf, '\x08', ' ');\r
2904 \r
2905                 /* VAX VMSではファイル情報が複数行にわかれている     */\r
2906                 /* それを1行にまとめる                                                               */\r
2907                 if(AskHostType() == HTYPE_VMS)\r
2908                 {\r
2909                         if(strchr(Buf, ';') == NULL)    /* ファイル名以外の行 */\r
2910                                 Sts = FFFTP_FAIL;\r
2911                         else\r
2912                         {\r
2913                                 Max -= strlen(Buf);\r
2914                                 while(strchr(Buf, ')') == NULL)\r
2915                                 {\r
2916                                         if(fgets(Tmp, FMAX_PATH, Fd) != NULL)\r
2917                                         {\r
2918                                                 RemoveReturnCode(Tmp);\r
2919                                                 ReplaceAll(Buf, '\x08', ' ');\r
2920                                                 if((int)strlen(Tmp) > Max)\r
2921                                                         Tmp[Max] = NUL;\r
2922                                                 Max -= strlen(Tmp);\r
2923                                                 strcat(Buf, Tmp);\r
2924                                         }\r
2925                                         else\r
2926                                                 break;\r
2927                                 }\r
2928                         }\r
2929                 }\r
2930         }\r
2931 \r
2932 //      DoPrintf("List : %s", Buf);\r
2933 \r
2934         return(Sts);\r
2935 }\r
2936 \r
2937 \r
2938 /*----- サブディレクトリ情報の解析 --------------------------------------------\r
2939 *\r
2940 *       Parameter\r
2941 *               char *Str : ファイル情報(1行)\r