OSDN Git Service

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