OSDN Git Service

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