OSDN Git Service

7cf67a29cbe8b62074ed9b992bd9acb351b87447
[ffftp/ffftp.git] / getput.c
1 /*=============================================================================\r
2 *\r
3 *                                                       \83_\83E\83\93\83\8d\81[\83h\81^\83A\83b\83v\83\8d\81[\83h\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 /* \82±\82Ì\83\\81[\83X\82Í\88ê\95\94\81AWS_FTP Version 93.12.05 \82Ì\83\\81[\83X\82ð\8eQ\8dl\82É\82µ\82Ü\82µ\82½\81B */\r
31 /* \83X\83\8c\83b\83h\82Ì\8dì\90¬\81^\8fI\97¹\82É\8aÖ\82µ\82Ä\81A\94ó\8cû\93a\8dì\90¬\82Ì\83p\83b\83`\82ð\91g\82Ý\8d\9e\82Ý\82Ü\82µ\82½\81B */\r
32 \r
33 /*\r
34         \88ê\95\94\81A\8d\82\91¬\89»\82Ì\82½\82ß\82Ì\83R\81[\83h\92Ç\89Á by H.Shirouzu at 2002/10/02\r
35 */\r
36 \r
37 #define STRICT\r
38 #include <stdio.h>\r
39 #include <stdlib.h>\r
40 #include <stdarg.h>\r
41 #include <string.h>\r
42 #include <mbstring.h>\r
43 #include <time.h>\r
44 #include <winsock.h>\r
45 #include <windowsx.h>\r
46 #include <commctrl.h>\r
47 #include <process.h>\r
48 \r
49 #include "common.h"\r
50 #include "resource.h"\r
51 \r
52 #define SET_BUFFER_SIZE\r
53 \r
54 /* Add by H.Shirouzu at 2002/10/02 */\r
55 #undef BUFSIZE\r
56 #define BUFSIZE                 (32 * 1024)\r
57 #define SOCKBUF_SIZE    (256 * 1024)\r
58 /* End */\r
59 \r
60 #ifdef DISABLE_NETWORK_BUFFERS\r
61 #undef BUFSIZE\r
62 #define BUFSIZE                 (64 * 1024)     // RWIN\92l\88È\89º\82Å\8f[\95ª\82È\91å\82«\82³\82ª\96]\82Ü\82µ\82¢\82Æ\8ev\82í\82ê\82é\81B\r
63 #undef SET_BUFFER_SIZE\r
64 #endif\r
65 \r
66 #define TIMER_DISPLAY           1               /* \95\\8e¦\8dX\90V\97p\83^\83C\83}\82ÌID */\r
67 #define DISPLAY_TIMING          500             /* \95\\8e¦\8dX\90V\8e\9e\8aÔ 0.5\95b */\r
68 \r
69 #define ERR_MSG_LEN                     1024\r
70 \r
71 \r
72 /* \8dí\8f\9c\8am\94F\83_\83C\83A\83\8d\83O\82Ì\8fî\95ñ */\r
73 typedef struct {\r
74         int Cur;\r
75         TRANSPACKET *Pkt;\r
76 } MIRRORDELETEINFO;\r
77 \r
78 \r
79 /*===== \83v\83\8d\83g\83^\83C\83v =====*/\r
80 \r
81 static void DispTransPacket(TRANSPACKET *Pkt);\r
82 static void EraseTransFileList(void);\r
83 static ULONG WINAPI TransferThread(void *Dummy);\r
84 static int MakeNonFullPath(TRANSPACKET *Pkt, char *CurDir, char *Tmp);\r
85 static int DownLoadNonPassive(TRANSPACKET *Pkt, int *CancelCheckWork);\r
86 static int DownLoadPassive(TRANSPACKET *Pkt, int *CancelCheckWork);\r
87 static int DownLoadFile(TRANSPACKET *Pkt, SOCKET dSkt, int CreateMode, int *CancelCheckWork);\r
88 static void DispDownloadFinishMsg(TRANSPACKET *Pkt, int iRetCode);\r
89 static int DispUpDownErrDialog(int ResID, HWND hWnd, char *Fname);\r
90 static BOOL CALLBACK UpDownErrorDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);\r
91 static int SetDownloadResume(TRANSPACKET *Pkt, int ProcMode, LONGLONG Size, int *Mode, int *CancelCheckWork);\r
92 static BOOL CALLBACK NoResumeWndProc(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam);\r
93 static int DoUpLoad(SOCKET cSkt, TRANSPACKET *Pkt);\r
94 static int UpLoadNonPassive(TRANSPACKET *Pkt);\r
95 static int UpLoadPassive(TRANSPACKET *Pkt);\r
96 static int UpLoadFile(TRANSPACKET *Pkt, SOCKET dSkt);\r
97 static int TermCodeConvAndSend(TERMCODECONVINFO *tInfo, SOCKET Skt, char *Data, int Size, int Ascii);\r
98 static void DispUploadFinishMsg(TRANSPACKET *Pkt, int iRetCode);\r
99 static int SetUploadResume(TRANSPACKET *Pkt, int ProcMode, LONGLONG Size, int *Mode);\r
100 static LRESULT CALLBACK TransDlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam);\r
101 static void DispTransferStatus(HWND hWnd, int End, TRANSPACKET *Pkt);\r
102 static void DispTransFileInfo(TRANSPACKET *Pkt, char *Title, int SkipButton, int Info);\r
103 static int GetAdrsAndPort(char *Str, char *Adrs, int *Port, int Max);\r
104 static int IsSpecialDevice(char *Fname);\r
105 static int MirrorDelNotify(int Cur, int Notify, TRANSPACKET *Pkt);\r
106 static BOOL CALLBACK MirrorDeleteDialogCallBack(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam);\r
107 static void SetErrorMsg(char *fmt, ...);\r
108 \r
109 /*===== \83\8d\81[\83J\83\8b\82È\83\8f\81[\83N =====*/\r
110 \r
111 static HANDLE hTransferThread;\r
112 static int fTransferThreadExit = FALSE;\r
113 \r
114 static HANDLE hRunMutex;                                /* \93]\91\97\83X\83\8c\83b\83h\8eÀ\8ds\83~\83\85\81[\83e\83b\83N\83X */\r
115 static HANDLE hListAccMutex;                    /* \93]\91\97\83t\83@\83C\83\8b\83A\83N\83Z\83X\97p\83~\83\85\81[\83e\83b\83N\83X */\r
116 \r
117 static int TransFiles = 0;                              /* \93]\91\97\91Ò\82¿\83t\83@\83C\83\8b\90\94 */\r
118 static TRANSPACKET *TransPacketBase = NULL;     /* \93]\91\97\83t\83@\83C\83\8b\83\8a\83X\83g */\r
119 \r
120 static int Canceled;            /* \92\86\8e~\83t\83\89\83O YES/NO */\r
121 static int ClearAll;            /* \91S\82Ä\92\86\8e~\83t\83\89\83O YES/NO */\r
122 \r
123 static int ForceAbort;          /* \93]\91\97\92\86\8e~\83t\83\89\83O */\r
124                                                         /* \82±\82Ì\83t\83\89\83O\82Í\83X\83\8c\83b\83h\82ð\8fI\97¹\82³\82¹\82é\82Æ\82«\82É\8eg\82¤ */\r
125 \r
126 static LONGLONG AllTransSizeNow;        /* \8d¡\89ñ\82Ì\93]\91\97\82Å\93]\91\97\82µ\82½\83T\83C\83Y */\r
127 static time_t TimeStart;        /* \93]\91\97\8aJ\8en\8e\9e\8aÔ */\r
128 \r
129 static int KeepDlg = NO;        /* \93]\91\97\92\86\83_\83C\83A\83\8d\83O\82ð\8fÁ\82³\82È\82¢\82©\82Ç\82¤\82© (YES/NO) */\r
130 static int MoveToForeground = NO;               /* \83E\83C\83\93\83h\83E\82ð\91O\96Ê\82É\88Ú\93®\82·\82é\82©\82Ç\82¤\82© (YES/NO) */\r
131 \r
132 static char CurDir[FMAX_PATH+1] = { "" };\r
133 static char ErrMsg[ERR_MSG_LEN+7];\r
134 \r
135 /*===== \8aO\95\94\8eQ\8fÆ =====*/\r
136 \r
137 /* \90Ý\92è\92l */\r
138 extern int SaveTimeStamp;\r
139 extern int RmEOF;\r
140 // extern int TimeOut;\r
141 extern int FwallType;\r
142 extern int MirUpDelNotify;\r
143 extern int MirDownDelNotify;\r
144 extern int FolderAttr;\r
145 extern int FolderAttrNum;\r
146 \r
147 \r
148 /*----- \83t\83@\83C\83\8b\93]\91\97\83X\83\8c\83b\83h\82ð\8bN\93®\82·\82é ----------------------------------------\r
149 *\r
150 *       Parameter\r
151 *               \82È\82µ\r
152 *\r
153 *       Return Value\r
154 *               \82È\82µ\r
155 *----------------------------------------------------------------------------*/\r
156 \r
157 int MakeTransferThread(void)\r
158 {\r
159         DWORD dwID;\r
160 \r
161         hListAccMutex = CreateMutex( NULL, FALSE, NULL );\r
162         hRunMutex = CreateMutex( NULL, TRUE, NULL );\r
163 \r
164         ClearAll = NO;\r
165         ForceAbort = NO;\r
166 \r
167         fTransferThreadExit = FALSE;\r
168         hTransferThread = (HANDLE)_beginthreadex(NULL, 0, TransferThread, 0, 0, &dwID);\r
169         if (hTransferThread == NULL)\r
170                 return(FAIL); /* XXX */\r
171 \r
172         return(SUCCESS);\r
173 }\r
174 \r
175 \r
176 /*----- \83t\83@\83C\83\8b\93]\91\97\83X\83\8c\83b\83h\82ð\8fI\97¹\82·\82é ----------------------------------------\r
177 *\r
178 *       Parameter\r
179 *               \82È\82µ\r
180 *\r
181 *       Return Value\r
182 *               \82È\82µ\r
183 *----------------------------------------------------------------------------*/\r
184 \r
185 void CloseTransferThread(void)\r
186 {\r
187         Canceled = YES;\r
188         ClearAll = YES;\r
189         ForceAbort = YES;\r
190 \r
191         fTransferThreadExit = TRUE;\r
192         while(WaitForSingleObject(hTransferThread, 10) == WAIT_TIMEOUT)\r
193         {\r
194                 BackgrndMessageProc();\r
195                 Canceled = YES;\r
196         }\r
197         CloseHandle(hTransferThread);\r
198 \r
199         ReleaseMutex( hRunMutex );\r
200 \r
201         CloseHandle( hListAccMutex );\r
202         CloseHandle( hRunMutex );\r
203         return;\r
204 }\r
205 \r
206 \r
207 /*----- \93]\91\97\82·\82é\83t\83@\83C\83\8b\8fî\95ñ\82ð\83\8a\83X\83g\82É\92Ç\89Á\82·\82é --------------------------------\r
208 *\r
209 *       Parameter\r
210 *               TRANSPACKET *Pkt : \93]\91\97\83t\83@\83C\83\8b\8fî\95ñ\r
211 *               TRANSPACKET **Base : \83\8a\83X\83g\82Ì\90æ\93ª\r
212 *\r
213 *       Return Value\r
214 *               int \83X\83e\81[\83^\83X\r
215 *                       SUCCESS/FAIL\r
216 *----------------------------------------------------------------------------*/\r
217 \r
218 int AddTmpTransFileList(TRANSPACKET *Pkt, TRANSPACKET **Base)\r
219 {\r
220         TRANSPACKET *Pos;\r
221         TRANSPACKET *Prev;\r
222         int Sts;\r
223 \r
224         Sts = FAIL;\r
225         if((Pos = malloc(sizeof(TRANSPACKET))) != NULL)\r
226         {\r
227                 memcpy(Pos, Pkt, sizeof(TRANSPACKET));\r
228                 Pos->Next = NULL;\r
229 \r
230                 if(*Base == NULL)\r
231                         *Base = Pos;\r
232                 else\r
233                 {\r
234                         Prev = *Base;\r
235                         while(Prev->Next != NULL)\r
236                                 Prev = Prev->Next;\r
237                         Prev->Next = Pos;\r
238                 }\r
239                 Sts = SUCCESS;\r
240         }\r
241         return(Sts);\r
242 }\r
243 \r
244 \r
245 /*----- \93]\91\97\82·\82é\83t\83@\83C\83\8b\8fî\95ñ\83\8a\83X\83g\82ð\83N\83\8a\83A\82·\82é --------------------------------\r
246 *\r
247 *       Parameter\r
248 *               TRANSPACKET **Base : \83\8a\83X\83g\82Ì\90æ\93ª\r
249 *\r
250 *       Return Value\r
251 *               \82È\82µ\r
252 *----------------------------------------------------------------------------*/\r
253 \r
254 void EraseTmpTransFileList(TRANSPACKET **Base)\r
255 {\r
256         TRANSPACKET *Pos;\r
257         TRANSPACKET *Next;\r
258 \r
259         Pos = *Base;\r
260         while(Pos != NULL)\r
261         {\r
262                 Next = Pos->Next;\r
263                 free(Pos);\r
264                 Pos = Next;\r
265         }\r
266         *Base = NULL;\r
267         return;\r
268 }\r
269 \r
270 \r
271 /*----- \93]\91\97\82·\82é\83t\83@\83C\83\8b\8fî\95ñ\83\8a\83X\83g\82©\82ç\82P\82Â\82Ì\8fî\95ñ\82ð\8eæ\82è\8f\9c\82­ --------------------\r
272 *\r
273 *       Parameter\r
274 *               TRANSPACKET *Pkt : \93]\91\97\83t\83@\83C\83\8b\8fî\95ñ\r
275 *               TRANSPACKET **Base : \83\8a\83X\83g\82Ì\90æ\93ª\r
276 *\r
277 *       Return Value\r
278 *               int \83X\83e\81[\83^\83X\r
279 *                       SUCCESS/FAIL\r
280 *----------------------------------------------------------------------------*/\r
281 \r
282 int RemoveTmpTransFileListItem(TRANSPACKET **Base, int Num)\r
283 {\r
284         TRANSPACKET *Pos;\r
285         TRANSPACKET *Prev;\r
286         int Sts;\r
287 \r
288         Sts = FAIL;\r
289         Pos = *Base;\r
290         if(Num == 0)\r
291         {\r
292                 *Base = Pos->Next;\r
293                 free(Pos);\r
294                 Sts = SUCCESS;\r
295         }\r
296         else\r
297         {\r
298                 while(Pos != NULL)\r
299                 {\r
300                         Prev = Pos;\r
301                         Pos = Pos->Next;\r
302                         if(--Num == 0)\r
303                         {\r
304                                 Prev->Next = Pos->Next;\r
305                                 free(Pos);\r
306                                 Sts = SUCCESS;\r
307                                 break;\r
308                         }\r
309                 }\r
310         }\r
311         return(Sts);\r
312 }\r
313 \r
314 \r
315 /*----- \93]\91\97\82·\82é\83t\83@\83C\83\8b\8fî\95ñ\82ð\93]\91\97\83t\83@\83C\83\8b\83\8a\83X\83g\82É\93o\98^\82·\82é --------------------\r
316 *\r
317 *       Parameter\r
318 *               TRANSPACKET *Pkt : \93]\91\97\83t\83@\83C\83\8b\8fî\95ñ\r
319 *\r
320 *       Return Value\r
321 *               \82È\82µ\r
322 *----------------------------------------------------------------------------*/\r
323 \r
324 void AddTransFileList(TRANSPACKET *Pkt)\r
325 {\r
326         DispTransPacket(Pkt);\r
327 \r
328         WaitForSingleObject(hListAccMutex, INFINITE);\r
329 \r
330         if(AddTmpTransFileList(Pkt, &TransPacketBase) == SUCCESS)\r
331         {\r
332                 if((strncmp(Pkt->Cmd, "RETR", 4) == 0) ||\r
333                    (strncmp(Pkt->Cmd, "STOR", 4) == 0))\r
334                 {\r
335                         TransFiles++;\r
336                         PostMessage(GetMainHwnd(), WM_CHANGE_COND, 0, 0);\r
337                 }\r
338         }\r
339         ReleaseMutex(hListAccMutex);\r
340 \r
341         return;\r
342 }\r
343 \r
344 \r
345 /*----- \93]\91\97\83t\83@\83C\83\8b\8fî\95ñ\82ð\93]\91\97\83t\83@\83C\83\8b\83\8a\83X\83g\82É\92Ç\89Á\82·\82é ------------------------\r
346 *\r
347 *       Parameter\r
348 *               TRANSPACKET *Pkt : \93]\91\97\83t\83@\83C\83\8b\8fî\95ñ\r
349 *               TRANSPACKET **Base : \83\8a\83X\83g\82Ì\90æ\93ª\r
350 *\r
351 *       Return Value\r
352 *               \82È\82µ\r
353 *\r
354 *       Note\r
355 *               Pkt\8e©\91Ì\82ð\83\8a\83X\83g\82É\98A\8c\8b\82·\82é\r
356 *----------------------------------------------------------------------------*/\r
357 \r
358 void AppendTransFileList(TRANSPACKET *Pkt)\r
359 {\r
360         TRANSPACKET *Pos;\r
361 \r
362         WaitForSingleObject(hListAccMutex, INFINITE);\r
363 \r
364         if(TransPacketBase == NULL)\r
365                 TransPacketBase = Pkt;\r
366         else\r
367         {\r
368                 Pos = TransPacketBase;\r
369                 while(Pos->Next != NULL)\r
370                         Pos = Pos->Next;\r
371                 Pos->Next = Pkt;\r
372         }\r
373 \r
374         while(Pkt != NULL)\r
375         {\r
376                 DispTransPacket(Pkt);\r
377 \r
378                 if((strncmp(Pkt->Cmd, "RETR", 4) == 0) ||\r
379                    (strncmp(Pkt->Cmd, "STOR", 4) == 0))\r
380                 {\r
381                         TransFiles++;\r
382                         PostMessage(GetMainHwnd(), WM_CHANGE_COND, 0, 0);\r
383                 }\r
384                 Pkt = Pkt->Next;\r
385         }\r
386 \r
387         ReleaseMutex(hListAccMutex);\r
388         return;\r
389 }\r
390 \r
391 \r
392 /*----- \93]\91\97\83t\83@\83C\83\8b\8fî\95ñ\82ð\95\\8e¦\82·\82é --------------------------------------------\r
393 *\r
394 *       Parameter\r
395 *               TRANSPACKET *Pkt : \93]\91\97\83t\83@\83C\83\8b\8fî\95ñ\r
396 *\r
397 *       Return Value\r
398 *               \82È\82µ\r
399 *----------------------------------------------------------------------------*/\r
400 \r
401 static void DispTransPacket(TRANSPACKET *Pkt)\r
402 {\r
403         if((strncmp(Pkt->Cmd, "RETR", 4) == 0) || (strncmp(Pkt->Cmd, "STOR", 4) == 0))\r
404                 DoPrintf("TransList Cmd=%s : %s : %s", Pkt->Cmd, Pkt->RemoteFile, Pkt->LocalFile);\r
405         else if(strncmp(Pkt->Cmd, "R-", 2) == 0)\r
406                 DoPrintf("TransList Cmd=%s : %s", Pkt->Cmd, Pkt->RemoteFile);\r
407         else if(strncmp(Pkt->Cmd, "L-", 2) == 0)\r
408                 DoPrintf("TransList Cmd=%s : %s", Pkt->Cmd, Pkt->LocalFile);\r
409         else if(strncmp(Pkt->Cmd, "MKD", 3) == 0)\r
410         {\r
411                 if(strlen(Pkt->LocalFile) > 0)\r
412                         DoPrintf("TransList Cmd=%s : %s", Pkt->Cmd, Pkt->LocalFile);\r
413                 else\r
414                         DoPrintf("TransList Cmd=%s : %s", Pkt->Cmd, Pkt->RemoteFile);\r
415         }\r
416         else\r
417                 DoPrintf("TransList Cmd=%s", Pkt->Cmd);\r
418         return;\r
419 }\r
420 \r
421 \r
422 /*----- \93]\91\97\83t\83@\83C\83\8b\83\8a\83X\83g\82ð\83N\83\8a\83A\82·\82é ----------------------------------------\r
423 *\r
424 *       Parameter\r
425 *               \82È\82µ\r
426 *\r
427 *       Return Value\r
428 *               \82È\82µ\r
429 *----------------------------------------------------------------------------*/\r
430 \r
431 static void EraseTransFileList(void)\r
432 {\r
433         TRANSPACKET *New;\r
434         TRANSPACKET *Next;\r
435         TRANSPACKET *NotDel;\r
436         TRANSPACKET Pkt;\r
437 \r
438         NotDel = NULL;\r
439 \r
440         WaitForSingleObject(hListAccMutex, INFINITE);\r
441         New = TransPacketBase;\r
442         while(New != NULL)\r
443         {\r
444                 /* \8dÅ\8cã\82Ì"BACKCUR"\82Í\95K\97v\82È\82Ì\82Å\8fÁ\82³\82È\82¢ */\r
445                 if(strcmp(New->Cmd, "BACKCUR") == 0)\r
446                 {\r
447                         if(NotDel != NULL)\r
448                                 free(NotDel);\r
449                         NotDel = New;\r
450                         New = New->Next;\r
451                         NotDel->Next = NULL;\r
452                 }\r
453                 else\r
454                 {\r
455                         Next = New->Next;\r
456                         free(New);\r
457                         New = Next;\r
458                 }\r
459         }\r
460         TransPacketBase = NotDel;\r
461         TransFiles = 0;\r
462         PostMessage(GetMainHwnd(), WM_CHANGE_COND, 0, 0);\r
463         ReleaseMutex(hListAccMutex);\r
464 \r
465         strcpy(Pkt.Cmd, "GOQUIT");\r
466         AddTransFileList(&Pkt);\r
467         return;\r
468 }\r
469 \r
470 \r
471 /*----- \93]\91\97\92\86\83_\83C\83A\83\8d\83O\82ð\8fÁ\82³\82È\82¢\82æ\82¤\82É\82·\82é\82©\82Ç\82¤\82©\82ð\90Ý\92è --------------------\r
472 *\r
473 *       Parameter\r
474 *               int Sw : \93]\91\97\92\86\83_\83C\83A\83\8d\83O\82ð\8fÁ\82³\82È\82¢\82©\82Ç\82¤\82© (YES/NO)\r
475 *\r
476 *       Return Value\r
477 *               \82È\82µ\r
478 *----------------------------------------------------------------------------*/\r
479 \r
480 void KeepTransferDialog(int Sw)\r
481 {\r
482         KeepDlg = Sw;\r
483         return;\r
484 }\r
485 \r
486 \r
487 /*----- \8c»\8dÝ\93]\91\97\92\86\82©\82Ç\82¤\82©\82ð\95Ô\82· ----------------------------------------------\r
488 *\r
489 *       Parameter\r
490 *               \82È\82µ\r
491 *\r
492 *       Return Value\r
493 *               int \83X\83e\81[\83^\83X (YES/NO=\93]\91\97\92\86\82Å\82Í\82È\82¢)\r
494 *----------------------------------------------------------------------------*/\r
495 \r
496 int AskTransferNow(void)\r
497 {\r
498         return(TransPacketBase != NULL ? YES : NO);\r
499 }\r
500 \r
501 \r
502 /*----- \93]\91\97\82·\82é\83t\83@\83C\83\8b\82Ì\90\94\82ð\95Ô\82· --------------------------------------------\r
503 *\r
504 *       Parameter\r
505 *               \82È\82µ\r
506 *\r
507 *       Return Value\r
508 *               int \93]\91\97\82·\82é\83t\83@\83C\83\8b\82Ì\90\94\r
509 *----------------------------------------------------------------------------*/\r
510 \r
511 int AskTransferFileNum(void)\r
512 {\r
513         return(TransFiles);\r
514 }\r
515 \r
516 \r
517 /*----- \93]\91\97\92\86\83E\83C\83\93\83h\83E\82ð\91O\96Ê\82É\8fo\82· ------------------------------------------\r
518 *\r
519 *       Parameter\r
520 *               \82È\82µ\r
521 *\r
522 *       Return Value\r
523 *               \82È\82µ\r
524 *----------------------------------------------------------------------------*/\r
525 \r
526 void GoForwardTransWindow(void)\r
527 {\r
528         MoveToForeground = YES;\r
529         return;\r
530 }\r
531 \r
532 \r
533 /*----- \93]\91\97\83\\83P\83b\83g\82Ì\83J\83\8c\83\93\83g\83f\83B\83\8c\83N\83g\83\8a\8fî\95ñ\82ð\8f\89\8aú\89» ------------------------\r
534 *\r
535 *       Parameter\r
536 *               \82È\82µ\r
537 *\r
538 *       Return Value\r
539 *               \82È\82µ\r
540 *----------------------------------------------------------------------------*/\r
541 \r
542 void InitTransCurDir(void)\r
543 {\r
544         strcpy(CurDir, "");\r
545         return;\r
546 }\r
547 \r
548 \r
549 /*----- \83t\83@\83C\83\8b\93]\91\97\83X\83\8c\83b\83h\82Ì\83\81\83C\83\93\83\8b\81[\83v ------------------------------------\r
550 *\r
551 *       Parameter\r
552 *               void *Dummy : \8eg\82í\82È\82¢\r
553 *\r
554 *       Return Value\r
555 *               \82È\82µ\r
556 *----------------------------------------------------------------------------*/\r
557 \r
558 static ULONG WINAPI TransferThread(void *Dummy)\r
559 {\r
560         TRANSPACKET *Pos;\r
561         HWND hWndTrans;\r
562         char Tmp[FMAX_PATH+1];\r
563         int CwdSts;\r
564         int GoExit;\r
565         int Down;\r
566         int Up;\r
567         int DelNotify;\r
568 \r
569         hWndTrans = NULL;\r
570         Down = NO;\r
571         Up = NO;\r
572         GoExit = NO;\r
573         DelNotify = NO;\r
574 \r
575         while((TransPacketBase != NULL) ||\r
576                   (WaitForSingleObject(hRunMutex, 200) == WAIT_TIMEOUT))\r
577         {\r
578                 if(fTransferThreadExit == TRUE)\r
579                         break;\r
580 \r
581                 WaitForSingleObject(hListAccMutex, INFINITE);\r
582                 memset(ErrMsg, NUL, ERR_MSG_LEN+7);\r
583 \r
584                 Canceled = NO;\r
585 \r
586                 if(TransPacketBase != NULL)\r
587                 {\r
588                         ReleaseMutex(hListAccMutex);\r
589                         if(hWndTrans == NULL)\r
590                         {\r
591                                 if((strncmp(TransPacketBase->Cmd, "RETR", 4) == 0) ||\r
592                                    (strncmp(TransPacketBase->Cmd, "STOR", 4) == 0) ||\r
593                                    (strncmp(TransPacketBase->Cmd, "MKD", 3) == 0) ||\r
594                                    (strncmp(TransPacketBase->Cmd, "L-", 2) == 0) ||\r
595                                    (strncmp(TransPacketBase->Cmd, "R-", 2) == 0))\r
596                                 {\r
597                                         hWndTrans = CreateDialog(GetFtpInst(), MAKEINTRESOURCE(transfer_dlg), HWND_DESKTOP, (DLGPROC)TransDlgProc);\r
598                                         if(MoveToForeground == YES)\r
599                                                 SetForegroundWindow(hWndTrans);\r
600                                         ShowWindow(hWndTrans, SW_SHOWNOACTIVATE);\r
601                                 }\r
602                         }\r
603                         TransPacketBase->hWndTrans = hWndTrans;\r
604 \r
605                         if(hWndTrans != NULL)\r
606                         {\r
607                                 if(MoveToForeground == YES)\r
608                                 {\r
609                                         SetForegroundWindow(hWndTrans);\r
610                                         MoveToForeground = NO;\r
611                                 }\r
612                         }\r
613 \r
614                         if(hWndTrans != NULL)\r
615                                 SendMessage(hWndTrans, WM_SET_PACKET, 0, (LPARAM)TransPacketBase);\r
616 \r
617                         /* \83_\83E\83\93\83\8d\81[\83h */\r
618                         if(strncmp(TransPacketBase->Cmd, "RETR", 4) == 0)\r
619                         {\r
620                                 /* \95s\90³\82È\83p\83X\82ð\8c\9f\8fo */\r
621                                 if(CheckPathViolation(TransPacketBase) == NO)\r
622                                 {\r
623                                         /* \83t\83\8b\83p\83X\82ð\8eg\82í\82È\82¢\82½\82ß\82Ì\8f\88\97\9d */\r
624                                         if(MakeNonFullPath(TransPacketBase, CurDir, Tmp) == SUCCESS)\r
625                                         {\r
626                                                 if(strncmp(TransPacketBase->Cmd, "RETR-S", 6) == 0)\r
627                                                 {\r
628                                                         /* \83T\83C\83Y\82Æ\93ú\95t\82ð\8eæ\93¾ */\r
629                                                         DoSIZE(TransPacketBase->RemoteFile, &TransPacketBase->Size);\r
630                                                         DoMDTM(TransPacketBase->RemoteFile, &TransPacketBase->Time);\r
631                                                         strcpy(TransPacketBase->Cmd, "RETR ");\r
632                                                 }\r
633 \r
634                                                 Down = YES;\r
635 //                                              if(DoDownLoad(AskTrnCtrlSkt(), TransPacketBase, NO) == 429)\r
636 //                                              {\r
637 //                                                      if(ReConnectTrnSkt() == SUCCESS)\r
638                                                                 DoDownLoad(AskTrnCtrlSkt(), TransPacketBase, NO, &Canceled);\r
639 //                                              }\r
640                                         }\r
641                                 }\r
642                         }\r
643                         /* \83A\83b\83v\83\8d\81[\83h */\r
644                         else if(strncmp(TransPacketBase->Cmd, "STOR", 4) == 0)\r
645                         {\r
646                                 /* \83t\83\8b\83p\83X\82ð\8eg\82í\82È\82¢\82½\82ß\82Ì\8f\88\97\9d */\r
647                                 if(MakeNonFullPath(TransPacketBase, CurDir, Tmp) == SUCCESS)\r
648                                 {\r
649                                         Up = YES;\r
650 //                                      if(DoUpLoad(AskTrnCtrlSkt(), TransPacketBase) == 429)\r
651 //                                      {\r
652 //                                              if(ReConnectTrnSkt() == SUCCESS)\r
653                                                         DoUpLoad(AskTrnCtrlSkt(), TransPacketBase);\r
654 //                                      }\r
655                                 }\r
656                         }\r
657                         /* \83t\83H\83\8b\83_\8dì\90¬\81i\83\8d\81[\83J\83\8b\82Ü\82½\82Í\83z\83X\83g\81j */\r
658                         else if(strncmp(TransPacketBase->Cmd, "MKD", 3) == 0)\r
659                         {\r
660                                 DispTransFileInfo(TransPacketBase, MSGJPN078, FALSE, YES);\r
661 \r
662                                 if(strlen(TransPacketBase->RemoteFile) > 0)\r
663                                 {\r
664                                         /* \83t\83\8b\83p\83X\82ð\8eg\82í\82È\82¢\82½\82ß\82Ì\8f\88\97\9d */\r
665                                         CwdSts = FTP_COMPLETE;\r
666 \r
667                                         strcpy(Tmp, TransPacketBase->RemoteFile);\r
668                                         if(ProcForNonFullpath(Tmp, CurDir, hWndTrans, 1) == FAIL)\r
669                                         {\r
670                                                 ClearAll = YES;\r
671                                                 CwdSts = FTP_ERROR;\r
672                                         }\r
673 \r
674                                         if(CwdSts == FTP_COMPLETE)\r
675                                         {\r
676                                                 Up = YES;\r
677                                                 CommandProcTrn(NULL, "MKD %s", Tmp);\r
678                                                 /* \82·\82Å\82É\83t\83H\83\8b\83_\82ª\82 \82é\8fê\8d\87\82à\82 \82é\82Ì\82Å\81A */\r
679                                                 /* \82±\82±\82Å\82Í\83G\83\89\81[\83`\83F\83b\83N\82Í\82µ\82È\82¢ */\r
680 \r
681                                         if(FolderAttr)\r
682                                                 CommandProcTrn(NULL, "%s %03d %s", AskHostChmodCmd(), FolderAttrNum, Tmp);\r
683                                         }\r
684                                 }\r
685                                 else if(strlen(TransPacketBase->LocalFile) > 0)\r
686                                 {\r
687                                         Down = YES;\r
688                                         DoLocalMKD(TransPacketBase->LocalFile);\r
689                                 }\r
690                         }\r
691                         /* \83f\83B\83\8c\83N\83g\83\8a\8dì\90¬\81i\8fí\82É\83z\83X\83g\91¤\81j */\r
692                         else if(strncmp(TransPacketBase->Cmd, "R-MKD", 5) == 0)\r
693                         {\r
694                                 DispTransFileInfo(TransPacketBase, MSGJPN079, FALSE, YES);\r
695 \r
696                                 /* \83t\83\8b\83p\83X\82ð\8eg\82í\82È\82¢\82½\82ß\82Ì\8f\88\97\9d */\r
697                                 if(MakeNonFullPath(TransPacketBase, CurDir, Tmp) == SUCCESS)\r
698                                 {\r
699                                         Up = YES;\r
700                                         CommandProcTrn(NULL, "%s%s", TransPacketBase->Cmd+2, TransPacketBase->RemoteFile);\r
701 \r
702                                         if(FolderAttr)\r
703                                                 CommandProcTrn(NULL, "%s %03d %s", AskHostChmodCmd(), FolderAttrNum, TransPacketBase->RemoteFile);\r
704                                 }\r
705                         }\r
706                         /* \83f\83B\83\8c\83N\83g\83\8a\8dí\8f\9c\81i\8fí\82É\83z\83X\83g\91¤\81j */\r
707                         else if(strncmp(TransPacketBase->Cmd, "R-RMD", 5) == 0)\r
708                         {\r
709                                 DispTransFileInfo(TransPacketBase, MSGJPN080, FALSE, YES);\r
710 \r
711                                 DelNotify = MirrorDelNotify(WIN_REMOTE, DelNotify, TransPacketBase);\r
712                                 if((DelNotify == YES) || (DelNotify == YES_ALL))\r
713                                 {\r
714                                         /* \83t\83\8b\83p\83X\82ð\8eg\82í\82È\82¢\82½\82ß\82Ì\8f\88\97\9d */\r
715                                         if(MakeNonFullPath(TransPacketBase, CurDir, Tmp) == SUCCESS)\r
716                                         {\r
717                                                 Up = YES;\r
718                                                 CommandProcTrn(NULL, "%s%s", TransPacketBase->Cmd+2, TransPacketBase->RemoteFile);\r
719                                         }\r
720                                 }\r
721                         }\r
722                         /* \83t\83@\83C\83\8b\8dí\8f\9c\81i\8fí\82É\83z\83X\83g\91¤\81j */\r
723                         else if(strncmp(TransPacketBase->Cmd, "R-DELE", 6) == 0)\r
724                         {\r
725                                 DispTransFileInfo(TransPacketBase, MSGJPN081, FALSE, YES);\r
726 \r
727                                 DelNotify = MirrorDelNotify(WIN_REMOTE, DelNotify, TransPacketBase);\r
728                                 if((DelNotify == YES) || (DelNotify == YES_ALL))\r
729                                 {\r
730                                         /* \83t\83\8b\83p\83X\82ð\8eg\82í\82È\82¢\82½\82ß\82Ì\8f\88\97\9d */\r
731                                         if(MakeNonFullPath(TransPacketBase, CurDir, Tmp) == SUCCESS)\r
732                                         {\r
733                                                 Up = YES;\r
734                                                 CommandProcTrn(NULL, "%s%s", TransPacketBase->Cmd+2, TransPacketBase->RemoteFile);\r
735                                         }\r
736                                 }\r
737                         }\r
738                         /* \83f\83B\83\8c\83N\83g\83\8a\8dì\90¬\81i\8fí\82É\83\8d\81[\83J\83\8b\91¤\81j */\r
739                         else if(strncmp(TransPacketBase->Cmd, "L-MKD", 5) == 0)\r
740                         {\r
741                                 DispTransFileInfo(TransPacketBase, MSGJPN082, FALSE, YES);\r
742 \r
743                                 Down = YES;\r
744                                 DoLocalMKD(TransPacketBase->LocalFile);\r
745                         }\r
746                         /* \83f\83B\83\8c\83N\83g\83\8a\8dí\8f\9c\81i\8fí\82É\83\8d\81[\83J\83\8b\91¤\81j */\r
747                         else if(strncmp(TransPacketBase->Cmd, "L-RMD", 5) == 0)\r
748                         {\r
749                                 DispTransFileInfo(TransPacketBase, MSGJPN083, FALSE, YES);\r
750 \r
751                                 DelNotify = MirrorDelNotify(WIN_LOCAL, DelNotify, TransPacketBase);\r
752                                 if((DelNotify == YES) || (DelNotify == YES_ALL))\r
753                                 {\r
754                                         Down = YES;\r
755                                         DoLocalRMD(TransPacketBase->LocalFile);\r
756                                 }\r
757                         }\r
758                         /* \83t\83@\83C\83\8b\8dí\8f\9c\81i\8fí\82É\83\8d\81[\83J\83\8b\91¤\81j */\r
759                         else if(strncmp(TransPacketBase->Cmd, "L-DELE", 6) == 0)\r
760                         {\r
761                                 DispTransFileInfo(TransPacketBase, MSGJPN084, FALSE, YES);\r
762 \r
763                                 DelNotify = MirrorDelNotify(WIN_LOCAL, DelNotify, TransPacketBase);\r
764                                 if((DelNotify == YES) || (DelNotify == YES_ALL))\r
765                                 {\r
766                                         Down = YES;\r
767                                         DoLocalDELE(TransPacketBase->LocalFile);\r
768                                 }\r
769                         }\r
770                         /* \83J\83\8c\83\93\83g\83f\83B\83\8c\83N\83g\83\8a\82ð\90Ý\92è */\r
771                         else if(strcmp(TransPacketBase->Cmd, "SETCUR") == 0)\r
772                         {\r
773                                 if(AskShareProh() == YES)\r
774                                 {\r
775                                         if(strcmp(CurDir, TransPacketBase->RemoteFile) != 0)\r
776                                         {\r
777                                                 if(CommandProcTrn(NULL, "CWD %s", TransPacketBase->RemoteFile)/100 != FTP_COMPLETE)\r
778                                                 {\r
779                                                         DispCWDerror(hWndTrans);\r
780                                                         ClearAll = YES;\r
781                                                 }\r
782                                         }\r
783                                 }\r
784                                 strcpy(CurDir, TransPacketBase->RemoteFile);\r
785                         }\r
786                         /* \83J\83\8c\83\93\83g\83f\83B\83\8c\83N\83g\83\8a\82ð\96ß\82· */\r
787                         else if(strcmp(TransPacketBase->Cmd, "BACKCUR") == 0)\r
788                         {\r
789                                 if(AskShareProh() == NO)\r
790                                 {\r
791                                         if(strcmp(CurDir, TransPacketBase->RemoteFile) != 0)\r
792                                                 CommandProcTrn(NULL, "CWD %s", TransPacketBase->RemoteFile);\r
793                                         strcpy(CurDir, TransPacketBase->RemoteFile);\r
794                                 }\r
795                         }\r
796                         /* \8e©\93®\8fI\97¹\82Ì\82½\82ß\82Ì\92Ê\92m */\r
797                         else if(strcmp(TransPacketBase->Cmd, "GOQUIT") == 0)\r
798                         {\r
799                                 GoExit = YES;\r
800                         }\r
801 \r
802                         /*===== \82P\82Â\82Ì\8f\88\97\9d\8fI\82í\82è =====*/\r
803 \r
804                         if(ForceAbort == NO)\r
805                         {\r
806                                 WaitForSingleObject(hListAccMutex, INFINITE);\r
807                                 if(ClearAll == YES)\r
808                                         EraseTransFileList();\r
809                                 else\r
810                                 {\r
811                                         if((strncmp(TransPacketBase->Cmd, "RETR", 4) == 0) ||\r
812                                            (strncmp(TransPacketBase->Cmd, "STOR", 4) == 0))\r
813                                         {\r
814                                                 TransFiles--;\r
815                                                 PostMessage(GetMainHwnd(), WM_CHANGE_COND, 0, 0);\r
816                                         }\r
817                                         Pos = TransPacketBase;\r
818                                         TransPacketBase = TransPacketBase->Next;\r
819                                         free(Pos);\r
820                                 }\r
821                                 ClearAll = NO;\r
822                                 ReleaseMutex(hListAccMutex);\r
823 \r
824                                 if(BackgrndMessageProc() == YES)\r
825                                 {\r
826                                         WaitForSingleObject(hListAccMutex, INFINITE);\r
827                                         EraseTransFileList();\r
828                                         ReleaseMutex(hListAccMutex);\r
829                                 }\r
830                         }\r
831                 }\r
832                 else\r
833                 {\r
834                         DelNotify = NO;\r
835 \r
836                         ReleaseMutex(hListAccMutex);\r
837                         if(KeepDlg == NO)\r
838                         {\r
839                                 if(hWndTrans != NULL)\r
840                                 {\r
841                                         DestroyWindow(hWndTrans);\r
842                                         hWndTrans = NULL;\r
843 \r
844                                         if(GoExit == YES)\r
845                                         {\r
846                                                 SoundPlay(SND_TRANS);\r
847 \r
848                                                 if(AskAutoExit() == NO)\r
849                                                 {\r
850                                                         if(Down == YES)\r
851                                                                 PostMessage(GetMainHwnd(), WM_REFRESH_LOCAL_FLG, 0, 0);\r
852                                                         if(Up == YES)\r
853                                                                 PostMessage(GetMainHwnd(), WM_REFRESH_REMOTE_FLG, 0, 0);\r
854                                                 }\r
855                                                 Down = NO;\r
856                                                 Up = NO;\r
857                                         }\r
858                                 }\r
859                         }\r
860                         BackgrndMessageProc();\r
861 \r
862                         if(GoExit == YES)\r
863                         {\r
864                                 PostMessage(GetMainHwnd(), WM_COMMAND, MAKEWPARAM(MENU_AUTO_EXIT, 0), 0);\r
865                                 GoExit = NO;\r
866                         }\r
867                 }\r
868         }\r
869         return 0;\r
870 }\r
871 \r
872 \r
873 /*----- \83t\83\8b\83p\83X\82ð\8eg\82í\82È\82¢\83t\83@\83C\83\8b\83A\83N\83Z\83X\82Ì\8f\80\94õ ------------------------------\r
874 *\r
875 *       Parameter\r
876 *               TRANSPACKET *Pkt : \93]\91\97\83p\83P\83b\83g\r
877 *               char *Cur : \83J\83\8c\83\93\83g\83f\83B\83\8c\83N\83g\83\8a\r
878 *               char *Tmp : \8dì\8bÆ\97p\83G\83\8a\83A\r
879 *\r
880 *       Return Value\r
881 *               int \83X\83e\81[\83^\83X(SUCCESS/FAIL)\r
882 *\r
883 *       Note\r
884 *               \83t\83\8b\83p\83X\82ð\8eg\82í\82È\82¢\8e\9e\82Í\81A\r
885 *                       \82±\82Ì\83\82\83W\83\85\81[\83\8b\93à\82Å CWD \82ð\8ds\82È\82¢\81A\r
886 *                       Pkt->RemoteFile \82É\83t\83@\83C\83\8b\96¼\82Ì\82Ý\8ec\82·\81B\81i\83p\83X\96¼\82Í\8fÁ\82·\81j\r
887 *----------------------------------------------------------------------------*/\r
888 \r
889 static int MakeNonFullPath(TRANSPACKET *Pkt, char *Cur, char *Tmp)\r
890 {\r
891         int Sts;\r
892 \r
893         Sts = ProcForNonFullpath(Pkt->RemoteFile, Cur, Pkt->hWndTrans, 1);\r
894         if(Sts == FAIL)\r
895                 ClearAll = YES;\r
896 \r
897         return(Sts);\r
898 }\r
899 \r
900 \r
901 \r
902 \r
903 /*----- \83_\83E\83\93\83\8d\81[\83h\82ð\8ds\82È\82¤ --------------------------------------------------\r
904 *\r
905 *       Parameter\r
906 *               SOCKET cSkt : \83R\83\93\83g\83\8d\81[\83\8b\83\\83P\83b\83g\r
907 *               TRANSPACKET *Pkt : \93]\91\97\83t\83@\83C\83\8b\8fî\95ñ\r
908 *               int DirList : \83f\83B\83\8c\83N\83g\83\8a\83\8a\83X\83g\82Ì\83_\83E\83\93\83\8d\81[\83h(YES/NO)\r
909 *\r
910 *       Return Value\r
911 *               int \89\9e\93\9a\83R\81[\83h\r
912 *\r
913 *       Note\r
914 *               \82±\82Ì\83\82\83W\83\85\81[\83\8b\82Í\81A\83t\83@\83C\83\8b\88ê\97\97\82Ì\8eæ\93¾\82È\82Ç\82ð\8ds\82È\82¤\8dÛ\82É\83\81\83C\83\93\82Ì\83X\83\8c\83b\83h\r
915 *               \82©\82ç\82à\8cÄ\82Î\82ê\82é\81B\83\81\83C\83\93\82Ì\83X\83\8c\83b\83h\82©\82ç\8cÄ\82Î\82ê\82é\8e\9e\82Í Pkt->hWndTrans == NULL\81B\r
916 *----------------------------------------------------------------------------*/\r
917 \r
918 int DoDownLoad(SOCKET cSkt, TRANSPACKET *Pkt, int DirList, int *CancelCheckWork)\r
919 {\r
920         int iRetCode;\r
921         char Reply[ERR_MSG_LEN+7];\r
922 \r
923         Pkt->ctrl_skt = cSkt;\r
924         if(IsSpecialDevice(GetFileName(Pkt->LocalFile)) == YES)\r
925         {\r
926                 iRetCode = 500;\r
927                 SetTaskMsg(MSGJPN085, GetFileName(Pkt->LocalFile));\r
928                 DispDownloadFinishMsg(Pkt, iRetCode);\r
929         }\r
930         else if(Pkt->Mode != EXIST_IGNORE)\r
931         {\r
932                 if(Pkt->Type == TYPE_I)\r
933                         Pkt->KanjiCode = KANJI_NOCNV;\r
934 \r
935                 iRetCode = command(Pkt->ctrl_skt, Reply, CancelCheckWork, "TYPE %c", Pkt->Type);\r
936                 if(iRetCode/100 < FTP_RETRY)\r
937                 {\r
938                         if(Pkt->hWndTrans != NULL)\r
939                         {\r
940                                 AllTransSizeNow = 0;\r
941 \r
942                                 if(DirList == NO)\r
943                                         DispTransFileInfo(Pkt, MSGJPN086, TRUE, YES);\r
944                                 else\r
945                                         DispTransFileInfo(Pkt, MSGJPN087, FALSE, NO);\r
946                         }\r
947 \r
948                         if(BackgrndMessageProc() == NO)\r
949                         {\r
950                                 if(AskPasvMode() != YES)\r
951                                         iRetCode = DownLoadNonPassive(Pkt, CancelCheckWork);\r
952                                 else\r
953                                         iRetCode = DownLoadPassive(Pkt, CancelCheckWork);\r
954                         }\r
955                         else\r
956                                 iRetCode = 500;\r
957                 }\r
958                 else\r
959                         SetErrorMsg(Reply);\r
960         }\r
961         else\r
962         {\r
963                 DispTransFileInfo(Pkt, MSGJPN088, TRUE, YES);\r
964                 SetTaskMsg(MSGJPN089, Pkt->RemoteFile);\r
965                 iRetCode = 200;\r
966         }\r
967         return(iRetCode);\r
968 }\r
969 \r
970 \r
971 /*----- \92Ê\8fí\83\82\81[\83h\82Å\83t\83@\83C\83\8b\82ð\83_\83E\83\93\83\8d\81[\83h ------------------------------------\r
972 *\r
973 *       Parameter\r
974 *               TRANSPACKET *Pkt : \93]\91\97\83t\83@\83C\83\8b\8fî\95ñ\r
975 *\r
976 *       Return Value\r
977 *               int \89\9e\93\9a\83R\81[\83h\r
978 *----------------------------------------------------------------------------*/\r
979 \r
980 static int DownLoadNonPassive(TRANSPACKET *Pkt, int *CancelCheckWork)\r
981 {\r
982         int iRetCode;\r
983         int iLength;\r
984         SOCKET data_socket = INVALID_SOCKET;   // data channel socket\r
985         SOCKET listen_socket = INVALID_SOCKET; // data listen socket\r
986         char Buf[1024];\r
987         int CreateMode;\r
988         struct sockaddr_in saSockAddr1;\r
989         char Reply[ERR_MSG_LEN+7];\r
990 \r
991         if((listen_socket = GetFTPListenSocket(Pkt->ctrl_skt, CancelCheckWork)) != INVALID_SOCKET)\r
992         {\r
993                 if(SetDownloadResume(Pkt, Pkt->Mode, Pkt->ExistSize, &CreateMode, CancelCheckWork) == YES)\r
994                 {\r
995                         sprintf(Buf, "%s%s", Pkt->Cmd, Pkt->RemoteFile);\r
996                         iRetCode = command(Pkt->ctrl_skt, Reply, CancelCheckWork, "%s", Buf);\r
997                         if(iRetCode/100 == FTP_PRELIM)\r
998                         {\r
999                                 if(SocksGet2ndBindReply(listen_socket, &data_socket) == FAIL)\r
1000                                 {\r
1001                                         iLength = sizeof(saSockAddr1);\r
1002                                         data_socket = do_accept(listen_socket, (struct sockaddr *)&saSockAddr1, (int *)&iLength);\r
1003 \r
1004                                         if(shutdown(listen_socket, 1) != 0)\r
1005                                                 ReportWSError("shutdown listen", WSAGetLastError());\r
1006                                         listen_socket = DoClose(listen_socket);\r
1007 \r
1008                                         if(data_socket == INVALID_SOCKET)\r
1009                                         {\r
1010                                                 SetErrorMsg(MSGJPN280);\r
1011                                                 ReportWSError("accept", WSAGetLastError());\r
1012                                                 iRetCode = 500;\r
1013                                         }\r
1014                                         else\r
1015                                                 DoPrintf("Skt=%u : accept from %s port %u", data_socket, inet_ntoa(saSockAddr1.sin_addr), ntohs(saSockAddr1.sin_port));\r
1016                                 }\r
1017 \r
1018                                 if(data_socket != INVALID_SOCKET)\r
1019                                 {\r
1020                                         iRetCode = DownLoadFile(Pkt, data_socket, CreateMode, CancelCheckWork);\r
1021 //                                      data_socket = DoClose(data_socket);\r
1022                                 }\r
1023                         }\r
1024                         else\r
1025                         {\r
1026                                 SetErrorMsg(Reply);\r
1027                                 SetTaskMsg(MSGJPN090);\r
1028                                 listen_socket = DoClose(listen_socket);\r
1029                                 iRetCode = 500;\r
1030                         }\r
1031                 }\r
1032                 else\r
1033                         iRetCode = 500;\r
1034         }\r
1035         else\r
1036         {\r
1037                 iRetCode = 500;\r
1038                 SetErrorMsg(MSGJPN279);\r
1039         }\r
1040         DispDownloadFinishMsg(Pkt, iRetCode);\r
1041 \r
1042         return(iRetCode);\r
1043 }\r
1044 \r
1045 \r
1046 /*----- Passive\83\82\81[\83h\82Å\83t\83@\83C\83\8b\82ð\83_\83E\83\93\83\8d\81[\83h ---------------------------------\r
1047 *\r
1048 *       Parameter\r
1049 *               TRANSPACKET *Pkt : \93]\91\97\83t\83@\83C\83\8b\8fî\95ñ\r
1050 *\r
1051 *       Return Value\r
1052 *               int \89\9e\93\9a\83R\81[\83h\r
1053 *----------------------------------------------------------------------------*/\r
1054 \r
1055 static int DownLoadPassive(TRANSPACKET *Pkt, int *CancelCheckWork)\r
1056 {\r
1057         int iRetCode;\r
1058         SOCKET data_socket = INVALID_SOCKET;   // data channel socket\r
1059         char Buf[1024];\r
1060         int CreateMode;\r
1061         char Adrs[20];\r
1062         int Port;\r
1063         int Flg;\r
1064         char Reply[ERR_MSG_LEN+7];\r
1065 \r
1066         iRetCode = command(Pkt->ctrl_skt, Buf, CancelCheckWork, "PASV");\r
1067         if(iRetCode/100 == FTP_COMPLETE)\r
1068         {\r
1069                 if(GetAdrsAndPort(Buf, Adrs, &Port, 19) == SUCCESS)\r
1070                 {\r
1071                         if((data_socket = connectsock(Adrs, Port, MSGJPN091, CancelCheckWork)) != INVALID_SOCKET)\r
1072                         {\r
1073                                 if(setsockopt(data_socket, IPPROTO_TCP, TCP_NODELAY, (LPSTR)&Flg, sizeof(Flg)) == SOCKET_ERROR)\r
1074                                         ReportWSError("setsockopt", WSAGetLastError());\r
1075 \r
1076                                 if(SetDownloadResume(Pkt, Pkt->Mode, Pkt->ExistSize, &CreateMode, CancelCheckWork) == YES)\r
1077                                 {\r
1078                                         sprintf(Buf, "%s%s", Pkt->Cmd, Pkt->RemoteFile);\r
1079                                         iRetCode = command(Pkt->ctrl_skt, Reply, CancelCheckWork, "%s", Buf);\r
1080                                         if(iRetCode/100 == FTP_PRELIM)\r
1081                                         {\r
1082                                                 iRetCode = DownLoadFile(Pkt, data_socket, CreateMode, CancelCheckWork);\r
1083 //                                              data_socket = DoClose(data_socket);\r
1084                                         }\r
1085                                         else\r
1086                                         {\r
1087                                                 SetErrorMsg(Reply);\r
1088                                                 SetTaskMsg(MSGJPN092);\r
1089                                                 data_socket = DoClose(data_socket);\r
1090                                                 iRetCode = 500;\r
1091                                         }\r
1092                                 }\r
1093                                 else\r
1094                                         iRetCode = 500;\r
1095                         }\r
1096                         else\r
1097                                 iRetCode = 500;\r
1098                 }\r
1099                 else\r
1100                 {\r
1101                         SetErrorMsg(MSGJPN093);\r
1102                         SetTaskMsg(MSGJPN093);\r
1103                         iRetCode = 500;\r
1104                 }\r
1105         }\r
1106         else\r
1107                 SetErrorMsg(Buf);\r
1108 \r
1109         DispDownloadFinishMsg(Pkt, iRetCode);\r
1110 \r
1111         return(iRetCode);\r
1112 }\r
1113 \r
1114 \r
1115 /*----- \83_\83E\83\93\83\8d\81[\83h\82Ì\8eÀ\8ds ----------------------------------------------------\r
1116 *\r
1117 *       Parameter\r
1118 *               TRANSPACKET *Pkt : \93]\91\97\83t\83@\83C\83\8b\8fî\95ñ\r
1119 *               SOCKET dSkt : \83f\81[\83^\83\\83P\83b\83g\r
1120 *               int CreateMode : \83t\83@\83C\83\8b\8dì\90¬\83\82\81[\83h (CREATE_ALWAYS/OPEN_ALWAYS)\r
1121 *\r
1122 *       Return Value\r
1123 *               int \89\9e\93\9a\83R\81[\83h\r
1124 *\r
1125 *       Note\r
1126 *               \93]\91\97\82Ì\8co\89ß\95\\8e¦\82Í\r
1127 *                       \83_\83C\83A\83\8d\83O\82ð\8fo\82·(Pkt->hWndTrans!=NULL)\8fê\8d\87\81A\83C\83\93\83^\81[\83o\83\8b\83^\83C\83}\82Å\8co\89ß\82ð\95\\8e¦\82·\82é\r
1128 *                       \83_\83C\83A\83\8d\83O\82ð\8fo\82³\82È\82¢\8fê\8d\87\81A\82±\82Ì\83\8b\81[\83`\83\93\82©\82çDispDownloadSize()\82ð\8cÄ\82Ô\r
1129 *----------------------------------------------------------------------------*/\r
1130 \r
1131 static int DownLoadFile(TRANSPACKET *Pkt, SOCKET dSkt, int CreateMode, int *CancelCheckWork)\r
1132 {\r
1133         int iNumBytes;\r
1134         char Buf[BUFSIZE];\r
1135         char Buf2[BUFSIZE+3];\r
1136         HANDLE iFileHandle;\r
1137         SECURITY_ATTRIBUTES Sec;\r
1138         DWORD Writed;\r
1139         CODECONVINFO cInfo;\r
1140         int Continue;\r
1141 //      fd_set ReadFds;\r
1142 //      struct timeval Tout;\r
1143 //      struct timeval *ToutPtr;\r
1144         int iRetCode;\r
1145         int TimeOutErr;\r
1146         char TmpBuf[ONELINE_BUF_SIZE];\r
1147         DWORD dwFileAttributes;\r
1148 \r
1149 #ifdef SET_BUFFER_SIZE\r
1150 /* Add by H.Shirouzu at 2002/10/02 */\r
1151         int buf_size = SOCKBUF_SIZE;\r
1152         for ( ; buf_size > 0; buf_size /= 2)\r
1153                 if (setsockopt(dSkt, SOL_SOCKET, SO_RCVBUF, (char *)&buf_size, sizeof(buf_size)) == 0)\r
1154                         break;\r
1155 /* End */\r
1156 #endif\r
1157 \r
1158 #ifdef DISABLE_NETWORK_BUFFERS\r
1159         // \94O\82Ì\82½\82ß\8eó\90M\83o\83b\83t\83@\82ð\96³\8cø\82É\82·\82é\81B\r
1160         int buf_size = 0;\r
1161         setsockopt(dSkt, SOL_SOCKET, SO_RCVBUF, (char *)&buf_size, sizeof(buf_size));\r
1162 #endif\r
1163 \r
1164         Pkt->Abort = ABORT_NONE;\r
1165 \r
1166         Sec.nLength = sizeof(SECURITY_ATTRIBUTES);\r
1167         Sec.lpSecurityDescriptor = NULL;\r
1168         Sec.bInheritHandle = FALSE;\r
1169 \r
1170         dwFileAttributes = GetFileAttributes(Pkt->LocalFile);\r
1171         if (dwFileAttributes != INVALID_FILE_ATTRIBUTES && (dwFileAttributes & FILE_ATTRIBUTE_READONLY)) {\r
1172                 // \93Ç\82Ý\8eæ\82è\90ê\97p\r
1173                 if (MessageBox(GetMainHwnd(), MSGJPN296, MSGJPN086, MB_YESNO) == IDYES) {\r
1174                         // \91®\90«\82ð\89ð\8f\9c\r
1175                         SetFileAttributes(Pkt->LocalFile, dwFileAttributes ^ FILE_ATTRIBUTE_READONLY);\r
1176                 }\r
1177         }\r
1178 \r
1179         if((iFileHandle = CreateFile(Pkt->LocalFile, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, &Sec, CreateMode, FILE_ATTRIBUTE_NORMAL, NULL)) != INVALID_HANDLE_VALUE)\r
1180         {\r
1181                 // UTF-8\91Î\89\9e\r
1182                 int ProcessedBOM = NO;\r
1183                 if(CreateMode == OPEN_ALWAYS)\r
1184                         SetFilePointer(iFileHandle, 0, 0, FILE_END);\r
1185 \r
1186                 if(Pkt->hWndTrans != NULL)\r
1187                 {\r
1188                         TimeStart = time(NULL);\r
1189                         SetTimer(Pkt->hWndTrans, TIMER_DISPLAY, DISPLAY_TIMING, NULL);\r
1190                 }\r
1191 \r
1192                 InitCodeConvInfo(&cInfo);\r
1193                 cInfo.KanaCnv = Pkt->KanaCnv;\r
1194 \r
1195                 /*===== \83t\83@\83C\83\8b\82ð\8eó\90M\82·\82é\83\8b\81[\83v =====*/\r
1196                 while((Pkt->Abort == ABORT_NONE) && (ForceAbort == NO))\r
1197                 {\r
1198 //                      FD_ZERO(&ReadFds);\r
1199 //                      FD_SET(dSkt, &ReadFds);\r
1200 //                      ToutPtr = NULL;\r
1201 //                      if(TimeOut != 0)\r
1202 //                      {\r
1203 //                              Tout.tv_sec = TimeOut;\r
1204 //                              Tout.tv_usec = 0;\r
1205 //                              ToutPtr = &Tout;\r
1206 //                      }\r
1207 //                      iNumBytes = select(0, &ReadFds, NULL, NULL, ToutPtr);\r
1208 //                      if(iNumBytes == SOCKET_ERROR)\r
1209 //                      {\r
1210 //                              ReportWSError("select", WSAGetLastError());\r
1211 //                              if(Pkt->Abort == ABORT_NONE)\r
1212 //                                      Pkt->Abort = ABORT_ERROR;\r
1213 //                              break;\r
1214 //                      }\r
1215 //                      else if(iNumBytes == 0)\r
1216 //                      {\r
1217 //                              SetErrorMsg(MSGJPN094);\r
1218 //                              SetTaskMsg(MSGJPN094);\r
1219 //                              Pkt->Abort = ABORT_ERROR;\r
1220 //                              break;\r
1221 //                      }\r
1222 \r
1223                         if((iNumBytes = do_recv(dSkt, Buf, BUFSIZE, 0, &TimeOutErr, CancelCheckWork)) <= 0)\r
1224                         {\r
1225                                 if(TimeOutErr == YES)\r
1226                                 {\r
1227                                         SetErrorMsg(MSGJPN094);\r
1228                                         SetTaskMsg(MSGJPN094);\r
1229                                         if(Pkt->hWndTrans != NULL)\r
1230                                                 ClearAll = YES;\r
1231                                         if(Pkt->Abort == ABORT_NONE)\r
1232                                                 Pkt->Abort = ABORT_ERROR;\r
1233                                 }\r
1234                                 else if(iNumBytes == SOCKET_ERROR)\r
1235                                 {\r
1236                                         if(Pkt->Abort == ABORT_NONE)\r
1237                                                 Pkt->Abort = ABORT_ERROR;\r
1238                                 }\r
1239                                 break;\r
1240                         }\r
1241 \r
1242                         /* \8a¿\8e\9a\83R\81[\83h\95Ï\8a· */\r
1243                         if(Pkt->KanjiCode != KANJI_NOCNV)\r
1244                         {\r
1245                                 cInfo.Str = Buf;\r
1246                                 cInfo.StrLen = iNumBytes;\r
1247                                 cInfo.Buf = Buf2;\r
1248                                 cInfo.BufSize = BUFSIZE+3;\r
1249                                 do\r
1250                                 {\r
1251                                         // \82±\82±\82Å\91S\82ÄUTF-8\82Ö\95Ï\8a·\82·\82é\r
1252                                         // TODO: SJIS\88È\8aO\82à\92¼\90ÚUTF-8\82Ö\95Ï\8a·\r
1253 //                                      if(Pkt->KanjiCode == KANJI_JIS)\r
1254 //                                              Continue = ConvJIStoSJIS(&cInfo);\r
1255 //                                      else\r
1256 //                                              Continue = ConvEUCtoSJIS(&cInfo);\r
1257                                         char Buf3[(BUFSIZE + 3) * 4];\r
1258                                         CODECONVINFO cInfo2;\r
1259                                         switch(Pkt->KanjiCode)\r
1260                                         {\r
1261                                         case KANJI_SJIS:\r
1262                                                 switch(Pkt->KanjiCodeDesired)\r
1263                                                 {\r
1264                                                 case KANJI_SJIS:\r
1265                                                         memcpy(Buf3, cInfo.Str, cInfo.StrLen);\r
1266                                                         cInfo2.OutLen = cInfo.StrLen;\r
1267                                                         Continue = NO;\r
1268                                                         break;\r
1269                                                 case KANJI_JIS:\r
1270                                                         break;\r
1271                                                 case KANJI_EUC:\r
1272                                                         break;\r
1273                                                 case KANJI_UTF8N:\r
1274                                                         if(ProcessedBOM == NO)\r
1275                                                         {\r
1276                                                                 memcpy(Buf3, "\xEF\xBB\xBF", 3);\r
1277                                                                 cInfo2.OutLen = 3;\r
1278                                                                 Continue = YES;\r
1279                                                                 ProcessedBOM = YES;\r
1280                                                                 break;\r
1281                                                         }\r
1282                                                         Continue = ConvSJIStoUTF8N(&cInfo);\r
1283                                                         memcpy(Buf3, Buf2, cInfo.OutLen);\r
1284                                                         cInfo2.OutLen = cInfo.OutLen;\r
1285                                                         break;\r
1286                                                 }\r
1287                                                 break;\r
1288                                         case KANJI_JIS:\r
1289                                                 switch(Pkt->KanjiCodeDesired)\r
1290                                                 {\r
1291                                                 case KANJI_SJIS:\r
1292                                                         Continue = ConvJIStoSJIS(&cInfo);\r
1293                                                         memcpy(Buf3, Buf2, cInfo.OutLen);\r
1294                                                         cInfo2.OutLen = cInfo.OutLen;\r
1295                                                         break;\r
1296                                                 case KANJI_JIS:\r
1297                                                         memcpy(Buf3, cInfo.Str, cInfo.StrLen);\r
1298                                                         cInfo2.OutLen = cInfo.StrLen;\r
1299                                                         Continue = NO;\r
1300                                                         break;\r
1301                                                 case KANJI_EUC:\r
1302                                                         break;\r
1303                                                 case KANJI_UTF8N:\r
1304                                                         if(ProcessedBOM == NO)\r
1305                                                         {\r
1306                                                                 memcpy(Buf3, "\xEF\xBB\xBF", 3);\r
1307                                                                 cInfo2.OutLen = 3;\r
1308                                                                 Continue = YES;\r
1309                                                                 ProcessedBOM = YES;\r
1310                                                                 break;\r
1311                                                         }\r
1312                                                         Continue = ConvJIStoSJIS(&cInfo);\r
1313                                                         InitCodeConvInfo(&cInfo2);\r
1314                                                         cInfo2.KanaCnv = NO;\r
1315                                                         cInfo2.Str = cInfo.Buf;\r
1316                                                         cInfo2.StrLen = cInfo.OutLen;\r
1317                                                         cInfo2.Buf = Buf3;\r
1318                                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
1319                                                         ConvSJIStoUTF8N(&cInfo2);\r
1320                                                         break;\r
1321                                                 }\r
1322                                                 break;\r
1323                                         case KANJI_EUC:\r
1324                                                 switch(Pkt->KanjiCodeDesired)\r
1325                                                 {\r
1326                                                 case KANJI_SJIS:\r
1327                                                         Continue = ConvEUCtoSJIS(&cInfo);\r
1328                                                         memcpy(Buf3, Buf2, cInfo.OutLen);\r
1329                                                         cInfo2.OutLen = cInfo.OutLen;\r
1330                                                         break;\r
1331                                                 case KANJI_JIS:\r
1332                                                         break;\r
1333                                                 case KANJI_EUC:\r
1334                                                         memcpy(Buf3, cInfo.Str, cInfo.StrLen);\r
1335                                                         cInfo2.OutLen = cInfo.StrLen;\r
1336                                                         Continue = NO;\r
1337                                                         break;\r
1338                                                 case KANJI_UTF8N:\r
1339                                                         if(ProcessedBOM == NO)\r
1340                                                         {\r
1341                                                                 memcpy(Buf3, "\xEF\xBB\xBF", 3);\r
1342                                                                 cInfo2.OutLen = 3;\r
1343                                                                 Continue = YES;\r
1344                                                                 ProcessedBOM = YES;\r
1345                                                                 break;\r
1346                                                         }\r
1347                                                         Continue = ConvEUCtoSJIS(&cInfo);\r
1348                                                         InitCodeConvInfo(&cInfo2);\r
1349                                                         cInfo2.KanaCnv = NO;\r
1350                                                         cInfo2.Str = cInfo.Buf;\r
1351                                                         cInfo2.StrLen = cInfo.OutLen;\r
1352                                                         cInfo2.Buf = Buf3;\r
1353                                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
1354                                                         ConvSJIStoUTF8N(&cInfo2);\r
1355                                                         break;\r
1356                                                 }\r
1357                                                 break;\r
1358                                         case KANJI_UTF8N:\r
1359                                                 if(ProcessedBOM == NO)\r
1360                                                 {\r
1361                                                         if(memcmp(Buf, "\xEF\xBB\xBF", 3) == 0)\r
1362                                                         {\r
1363                                                                 cInfo.Str += 3;\r
1364                                                                 cInfo.StrLen -= 3;\r
1365                                                         }\r
1366                                                         cInfo2.OutLen = 0;\r
1367                                                         switch(Pkt->KanjiCodeDesired)\r
1368                                                         {\r
1369                                                         case KANJI_UTF8N:\r
1370                                                                 memcpy(Buf3, "\xEF\xBB\xBF", 3);\r
1371                                                                 cInfo2.OutLen = 3;\r
1372                                                                 break;\r
1373                                                         }\r
1374                                                         Continue = YES;\r
1375                                                         ProcessedBOM = YES;\r
1376                                                         break;\r
1377                                                 }\r
1378                                                 switch(Pkt->KanjiCodeDesired)\r
1379                                                 {\r
1380                                                 case KANJI_SJIS:\r
1381                                                         Continue = ConvUTF8NtoSJIS(&cInfo);\r
1382                                                         memcpy(Buf3, Buf2, cInfo.OutLen);\r
1383                                                         cInfo2.OutLen = cInfo.OutLen;\r
1384                                                         break;\r
1385                                                 case KANJI_JIS:\r
1386                                                         break;\r
1387                                                 case KANJI_EUC:\r
1388                                                         break;\r
1389                                                 case KANJI_UTF8N:\r
1390                                                         memcpy(Buf3, cInfo.Str, cInfo.StrLen);\r
1391                                                         cInfo2.OutLen = cInfo.StrLen;\r
1392                                                         Continue = NO;\r
1393                                                         break;\r
1394                                                 }\r
1395                                                 break;\r
1396                                         }\r
1397 //                                      if(WriteFile(iFileHandle, Buf2, cInfo.OutLen, &Writed, NULL) == FALSE)\r
1398                                         if(WriteFile(iFileHandle, Buf3, cInfo2.OutLen, &Writed, NULL) == FALSE)\r
1399                                                 Pkt->Abort = ABORT_DISKFULL;\r
1400                                 }\r
1401                                 while((Continue == YES) && (Pkt->Abort == ABORT_NONE));\r
1402                         }\r
1403                         else\r
1404                         {\r
1405                                 if(WriteFile(iFileHandle, Buf, iNumBytes, &Writed, NULL) == FALSE)\r
1406                                         Pkt->Abort = ABORT_DISKFULL;\r
1407                         }\r
1408 \r
1409                         Pkt->ExistSize += iNumBytes;\r
1410                         if(Pkt->hWndTrans != NULL)\r
1411                                 AllTransSizeNow += iNumBytes;\r
1412                         else\r
1413                         {\r
1414                                 /* \93]\91\97\83_\83C\83A\83\8d\83O\82ð\8fo\82³\82È\82¢\8e\9e\82Ì\8co\89ß\95\\8e¦ */\r
1415                                 DispDownloadSize(Pkt->ExistSize);\r
1416                         }\r
1417 \r
1418                         if(BackgrndMessageProc() == YES)\r
1419                                 ForceAbort = YES;\r
1420                 }\r
1421 \r
1422                 /* \8f\91\82«\8ec\82µ\82½\83f\81[\83^\82ð\8f\91\82«\8d\9e\82Þ */\r
1423                 if(Pkt->KanjiCode != KANJI_NOCNV)\r
1424                 {\r
1425                         cInfo.Buf = Buf2;\r
1426                         cInfo.BufSize = BUFSIZE+3;\r
1427                         FlushRestData(&cInfo);\r
1428                         if(WriteFile(iFileHandle, Buf2, cInfo.OutLen, &Writed, NULL) == FALSE)\r
1429                                 Pkt->Abort = ABORT_DISKFULL;\r
1430                 }\r
1431 \r
1432                 /* \83O\83\89\83t\95\\8e¦\82ð\8dX\90V */\r
1433                 if(Pkt->hWndTrans != NULL)\r
1434                 {\r
1435                         KillTimer(Pkt->hWndTrans, TIMER_DISPLAY);\r
1436                         DispTransferStatus(Pkt->hWndTrans, YES, Pkt);\r
1437                         TimeStart = time(NULL) - TimeStart + 1;\r
1438                 }\r
1439                 else\r
1440                 {\r
1441                         /* \93]\91\97\83_\83C\83A\83\8d\83O\82ð\8fo\82³\82È\82¢\8e\9e\82Ì\8co\89ß\95\\8e¦\82ð\8fÁ\82· */\r
1442                         DispDownloadSize(-1);\r
1443                 }\r
1444 \r
1445                 /* \83t\83@\83C\83\8b\82Ì\83^\83C\83\80\83X\83^\83\93\83v\82ð\8d\87\82í\82¹\82é */\r
1446                 if((SaveTimeStamp == YES) &&\r
1447                    ((Pkt->Time.dwLowDateTime != 0) || (Pkt->Time.dwHighDateTime != 0)))\r
1448                 {\r
1449                         SetFileTime(iFileHandle, &Pkt->Time, &Pkt->Time, &Pkt->Time);\r
1450                 }\r
1451 \r
1452                 CloseHandle(iFileHandle);\r
1453 \r
1454                 if(iNumBytes == SOCKET_ERROR)\r
1455                         ReportWSError("recv",WSAGetLastError());\r
1456         }\r
1457         else\r
1458         {\r
1459                 SetErrorMsg(MSGJPN095, Pkt->LocalFile);\r
1460                 SetTaskMsg(MSGJPN095, Pkt->LocalFile);\r
1461                 Pkt->Abort = ABORT_ERROR;\r
1462         }\r
1463 \r
1464 \r
1465         if(shutdown(dSkt, 1) != 0)\r
1466                 ReportWSError("shutdown", WSAGetLastError());\r
1467 \r
1468         DoClose(dSkt);\r
1469 \r
1470         if(ForceAbort == NO)\r
1471         {\r
1472                 /* Abort\82ð\83z\83X\83g\82É\93`\82¦\82é */\r
1473                 if(Pkt->Abort != ABORT_NONE && iFileHandle != INVALID_HANDLE_VALUE)\r
1474                 {\r
1475                         SendData(Pkt->ctrl_skt, "\xFF\xF4\xFF", 3, MSG_OOB, CancelCheckWork);   /* MSG_OOB\82É\92\8d\88Ó */\r
1476                         SendData(Pkt->ctrl_skt, "\xF2", 1, 0, CancelCheckWork);\r
1477                         command(Pkt->ctrl_skt, NULL, CancelCheckWork, "ABOR");\r
1478                 }\r
1479         }\r
1480 \r
1481         iRetCode = ReadReplyMessage(Pkt->ctrl_skt, Buf, 1024, CancelCheckWork, TmpBuf);\r
1482 \r
1483 //#pragma aaa\r
1484 //DoPrintf("##DOWN REPLY : %s", Buf);\r
1485 \r
1486         if(Pkt->Abort == ABORT_DISKFULL)\r
1487         {\r
1488                 SetErrorMsg(MSGJPN096);\r
1489                 SetTaskMsg(MSGJPN096);\r
1490         }\r
1491         if(iRetCode >= FTP_RETRY)\r
1492                 SetErrorMsg(Buf);\r
1493         if(Pkt->Abort != ABORT_NONE)\r
1494                 iRetCode = 500;\r
1495 \r
1496         return(iRetCode);\r
1497 }\r
1498 \r
1499 \r
1500 /*----- \83_\83E\83\93\83\8d\81[\83h\8fI\97¹\81^\92\86\8e~\8e\9e\82Ì\83\81\83b\83Z\81[\83W\82ð\95\\8e¦ ----------------------------\r
1501 *\r
1502 *       Parameter\r
1503 *               TRANSPACKET *Pkt : \93]\91\97\83t\83@\83C\83\8b\8fî\95ñ\r
1504 *               int iRetCode : \89\9e\93\9a\83R\81[\83h\r
1505 *\r
1506 *       Return Value\r
1507 *               \82È\82µ\r
1508 *----------------------------------------------------------------------------*/\r
1509 \r
1510 static void DispDownloadFinishMsg(TRANSPACKET *Pkt, int iRetCode)\r
1511 {\r
1512         char Fname[FMAX_PATH+1];\r
1513 \r
1514         if(ForceAbort == NO)\r
1515         {\r
1516                 if((iRetCode/100) >= FTP_CONTINUE)\r
1517                 {\r
1518                         strcpy(Fname, Pkt->RemoteFile);\r
1519 \r
1520 #if defined(HAVE_OPENVMS)\r
1521                         /* OpenVMS\82Ì\8fê\8d\87\81A\8bó\83f\83B\83\8c\83N\83g\83\8a\82Ö\88Ú\93®\82·\82é\82Æ550 File not found\82É\82È\82Á\82Ä\r
1522                          * \83G\83\89\81[\83_\83C\83A\83\8d\83O\82â\83G\83\89\81[\83\81\83b\83Z\81[\83W\82ª\8fo\82é\82Ì\82Å\89½\82à\82µ\82È\82¢ */\r
1523                         if (AskHostType() == HTYPE_VMS)\r
1524                                 return;\r
1525 #endif\r
1526 \r
1527                         if((strncmp(Pkt->Cmd, "NLST", 4) == 0) || (strncmp(Pkt->Cmd, "LIST", 4) == 0))\r
1528                         {\r
1529                                 SetTaskMsg(MSGJPN097);\r
1530                                 strcpy(Fname, MSGJPN098);\r
1531                         }\r
1532                         else if((Pkt->hWndTrans != NULL) && (TimeStart != 0))\r
1533                                 SetTaskMsg(MSGJPN099, TimeStart, Pkt->ExistSize/TimeStart);\r
1534                         else\r
1535                                 SetTaskMsg(MSGJPN100);\r
1536 \r
1537                         if(Pkt->Abort != ABORT_USER)\r
1538                         {\r
1539                                 if(DispUpDownErrDialog(downerr_dlg, Pkt->hWndTrans, Fname) == NO)\r
1540                                         ClearAll = YES;\r
1541                         }\r
1542                 }\r
1543                 else\r
1544                 {\r
1545                         if((strncmp(Pkt->Cmd, "NLST", 4) == 0) || (strncmp(Pkt->Cmd, "LIST", 4) == 0))\r
1546                                 SetTaskMsg(MSGJPN101, Pkt->ExistSize);\r
1547                         else if((Pkt->hWndTrans != NULL) && (TimeStart != 0))\r
1548                                 SetTaskMsg(MSGJPN102, TimeStart, Pkt->ExistSize/TimeStart);\r
1549                         else\r
1550                                 SetTaskMsg(MSGJPN103, Pkt->ExistSize);\r
1551                 }\r
1552         }\r
1553         return;\r
1554 }\r
1555 \r
1556 \r
1557 /*----- \83_\83E\83\93\83\8d\81[\83h\81^\83A\83b\83v\83\8d\81[\83h\83G\83\89\81[\82Ì\83_\83C\83A\83\8d\83O\82ð\95\\8e¦ --------------------\r
1558 *\r
1559 *       Parameter\r
1560 *               int RedID : \83_\83C\83A\83\8d\83O\83{\83b\83N\83X\82Ì\83\8a\83\\81[\83XID\r
1561 *               HWND hWnd : \8f\91\82«\8d\9e\82Ý\92\86\83_\83C\83A\83\8d\83O\82Ì\83E\83C\83\93\83h\83E\r
1562 *               char *Fname : \83t\83@\83C\83\8b\96¼\r
1563 *\r
1564 *       Return Value\r
1565 *               int \83X\83e\81[\83^\83X (YES=\92\86\8e~/NO=\91S\82Ä\92\86\8e~)\r
1566 *----------------------------------------------------------------------------*/\r
1567 \r
1568 static int DispUpDownErrDialog(int ResID, HWND hWnd, char *Fname)\r
1569 {\r
1570         if(hWnd == NULL)\r
1571                 hWnd = GetMainHwnd();\r
1572 \r
1573         SoundPlay(SND_ERROR);\r
1574         return(DialogBoxParam(GetFtpInst(), MAKEINTRESOURCE(ResID), hWnd, UpDownErrorDialogProc, (LPARAM)Fname));\r
1575 }\r
1576 \r
1577 \r
1578 /*----- \83_\83E\83\93\83\8d\81[\83h\83G\83\89\81[\81^\83A\83b\83v\83\8d\81[\83h\83G\83\89\81[\83_\83C\83A\83\8d\83O\82Ì\83R\81[\83\8b\83o\83b\83N --------\r
1579 *\r
1580 *       Parameter\r
1581 *               HWND hDlg : \83E\83C\83\93\83h\83E\83n\83\93\83h\83\8b\r
1582 *               UINT message : \83\81\83b\83Z\81[\83W\94Ô\8d\86\r
1583 *               WPARAM wParam : \83\81\83b\83Z\81[\83W\82Ì WPARAM \88ø\90\94\r
1584 *               LPARAM lParam : \83\81\83b\83Z\81[\83W\82Ì LPARAM \88ø\90\94\r
1585 *\r
1586 *       Return Value\r
1587 *               BOOL TRUE/FALSE\r
1588 *----------------------------------------------------------------------------*/\r
1589 \r
1590 static BOOL CALLBACK UpDownErrorDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)\r
1591 {\r
1592         switch (message)\r
1593         {\r
1594                 case WM_INITDIALOG :\r
1595                         SendDlgItemMessage(hDlg, UPDOWN_ERR_FNAME, WM_SETTEXT, 0, (LPARAM)lParam);\r
1596                         SendDlgItemMessage(hDlg, UPDOWN_ERR_MSG, WM_SETTEXT, 0, (LPARAM)ErrMsg);\r
1597                         return(TRUE);\r
1598 \r
1599                 case WM_COMMAND :\r
1600                         switch(GET_WM_COMMAND_ID(wParam, lParam))\r
1601                         {\r
1602                                 case IDOK :\r
1603                                         EndDialog(hDlg, YES);\r
1604                                         break;\r
1605 \r
1606                                 case IDCANCEL :\r
1607                                         EndDialog(hDlg, NO);\r
1608                                         break;\r
1609                         }\r
1610                         return(TRUE);\r
1611         }\r
1612     return(FALSE);\r
1613 }\r
1614 \r
1615 \r
1616 /*----- \83_\83E\83\93\83\8d\81[\83h\82Ì\83\8a\83W\83\85\81[\83\80\82Ì\8f\80\94õ\82ð\8ds\82¤ ----------------------------------\r
1617 *\r
1618 *       Parameter\r
1619 *               TRANSPACKET *Pkt : \93]\91\97\83t\83@\83C\83\8b\8fî\95ñ\r
1620 *               iont ProcMode : \8f\88\97\9d\83\82\81[\83h(EXIST_xxx)\r
1621 *               LONGLONG Size : \83\8d\81[\83h\8dÏ\82Ý\82Ì\83t\83@\83C\83\8b\82Ì\83T\83C\83Y\r
1622 *               int *Mode : \83t\83@\83C\83\8b\8dì\90¬\83\82\81[\83h (CREATE_xxxx)\r
1623 *\r
1624 *       Return Value\r
1625 *               int \93]\91\97\82ð\8ds\82¤\82©\82Ç\82¤\82©(YES/NO=\82±\82Ì\83t\83@\83C\83\8b\82ð\92\86\8e~/NO_ALL=\91S\82Ä\92\86\8e~)\r
1626 *\r
1627 *       Note\r
1628 *               Pkt->ExistSize\82Ì\83Z\83b\83g\82ð\8ds\82È\82¤\r
1629 *----------------------------------------------------------------------------*/\r
1630 \r
1631 static int SetDownloadResume(TRANSPACKET *Pkt, int ProcMode, LONGLONG Size, int *Mode, int *CancelCheckWork)\r
1632 {\r
1633         int iRetCode;\r
1634         int Com;\r
1635         char Reply[ERR_MSG_LEN+7];\r
1636         char Tmp[40];\r
1637 \r
1638         Com = YES;\r
1639 \r
1640         Pkt->ExistSize = 0;\r
1641         *Mode = CREATE_ALWAYS;\r
1642 \r
1643         if(ProcMode == EXIST_RESUME)\r
1644         {\r
1645                 iRetCode = command(Pkt->ctrl_skt, Reply, CancelCheckWork, "REST %s", MakeNumString(Size, Tmp, FALSE));\r
1646                 if(iRetCode/100 < FTP_RETRY)\r
1647                 {\r
1648                         /* \83\8a\83W\83\85\81[\83\80 */\r
1649                         if(Pkt->hWndTrans != NULL)\r
1650                                 Pkt->ExistSize = Size;\r
1651                         *Mode = OPEN_ALWAYS;\r
1652                 }\r
1653                 else\r
1654                 {\r
1655                         Com = DialogBox(GetFtpInst(), MAKEINTRESOURCE(noresume_dlg), Pkt->hWndTrans, NoResumeWndProc);\r
1656                         if(Com != YES)\r
1657                         {\r
1658                                 if(Com == NO_ALL)               /* \91S\82Ä\92\86\8e~ */\r
1659                                         ClearAll = YES;\r
1660                                 Pkt->Abort = ABORT_USER;\r
1661                         }\r
1662                 }\r
1663         }\r
1664         return(Com);\r
1665 }\r
1666 \r
1667 \r
1668 /*----- resume\83G\83\89\81[\83_\83C\83A\83\8d\83O\82Ì\83R\81[\83\8b\83o\83b\83N ----------------------------------\r
1669 *\r
1670 *       Parameter\r
1671 *               HWND hDlg : \83E\83C\83\93\83h\83E\83n\83\93\83h\83\8b\r
1672 *               UINT message : \83\81\83b\83Z\81[\83W\94Ô\8d\86\r
1673 *               WPARAM wParam : \83\81\83b\83Z\81[\83W\82Ì WPARAM \88ø\90\94\r
1674 *               LPARAM lParam : \83\81\83b\83Z\81[\83W\82Ì LPARAM \88ø\90\94\r
1675 *\r
1676 *       Return Value\r
1677 *               BOOL TRUE/FALSE\r
1678 *----------------------------------------------------------------------------*/\r
1679 \r
1680 static BOOL CALLBACK NoResumeWndProc(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam)\r
1681 {\r
1682         switch (iMessage)\r
1683         {\r
1684                 case WM_INITDIALOG :\r
1685                         return(TRUE);\r
1686 \r
1687                 case WM_COMMAND :\r
1688                         switch(GET_WM_COMMAND_ID(wParam, lParam))\r
1689                         {\r
1690                                 case IDOK :\r
1691                                         EndDialog(hDlg, YES);\r
1692                                         break;\r
1693 \r
1694                                 case IDCANCEL :\r
1695                                         EndDialog(hDlg, NO);\r
1696                                         break;\r
1697 \r
1698                                 case RESUME_CANCEL_ALL :\r
1699                                         EndDialog(hDlg, NO_ALL);\r
1700                                         break;\r
1701                         }\r
1702             return(TRUE);\r
1703         }\r
1704         return(FALSE);\r
1705 }\r
1706 \r
1707 \r
1708 \r
1709 /*----- \83A\83b\83v\83\8d\81[\83h\82ð\8ds\82È\82¤ --------------------------------------------------\r
1710 *\r
1711 *       Parameter\r
1712 *               SOCKET cSkt : \83R\83\93\83g\83\8d\81[\83\8b\83\\83P\83b\83g\r
1713 *               TRANSPACKET *Pkt : \93]\91\97\83t\83@\83C\83\8b\8fî\95ñ\r
1714 *\r
1715 *       Return Value\r
1716 *               int \89\9e\93\9a\83R\81[\83h\r
1717 *----------------------------------------------------------------------------*/\r
1718 \r
1719 static int DoUpLoad(SOCKET cSkt, TRANSPACKET *Pkt)\r
1720 {\r
1721         int iRetCode;\r
1722         char Reply[ERR_MSG_LEN+7];\r
1723 \r
1724         Pkt->ctrl_skt = cSkt;\r
1725 \r
1726         if(Pkt->Mode != EXIST_IGNORE)\r
1727         {\r
1728                 if(CheckFileReadable(Pkt->LocalFile) == SUCCESS)\r
1729                 {\r
1730                         if(Pkt->Type == TYPE_I)\r
1731                                 Pkt->KanjiCode = KANJI_NOCNV;\r
1732 \r
1733                         iRetCode = command(Pkt->ctrl_skt, Reply, &Canceled, "TYPE %c", Pkt->Type);\r
1734                         if(iRetCode/100 < FTP_RETRY)\r
1735                         {\r
1736                                 if(Pkt->Mode == EXIST_UNIQUE)\r
1737                                         strcpy(Pkt->Cmd, "STOU ");\r
1738 \r
1739                                 if(Pkt->hWndTrans != NULL)\r
1740                                         DispTransFileInfo(Pkt, MSGJPN104, TRUE, YES);\r
1741 \r
1742                                 if(BackgrndMessageProc() == NO)\r
1743                                 {\r
1744                                         if(AskPasvMode() != YES)\r
1745                                                 iRetCode = UpLoadNonPassive(Pkt);\r
1746                                         else\r
1747                                                 iRetCode = UpLoadPassive(Pkt);\r
1748                                 }\r
1749                                 else\r
1750                                         iRetCode = 500;\r
1751                         }\r
1752                         else\r
1753                                 SetErrorMsg(Reply);\r
1754 \r
1755                         /* \91®\90«\95Ï\8dX */\r
1756                         if((Pkt->Attr != -1) && ((iRetCode/100) == FTP_COMPLETE))\r
1757                                 command(Pkt->ctrl_skt, Reply, &Canceled, "%s %03X %s", AskHostChmodCmd(), Pkt->Attr, Pkt->RemoteFile);\r
1758                 }\r
1759                 else\r
1760                 {\r
1761                         SetErrorMsg(MSGJPN105, Pkt->LocalFile);\r
1762                         SetTaskMsg(MSGJPN105, Pkt->LocalFile);\r
1763                         iRetCode = 500;\r
1764                         Pkt->Abort = ABORT_ERROR;\r
1765                         DispUploadFinishMsg(Pkt, iRetCode);\r
1766                 }\r
1767         }\r
1768         else\r
1769         {\r
1770                 DispTransFileInfo(Pkt, MSGJPN106, TRUE, YES);\r
1771                 SetTaskMsg(MSGJPN107, Pkt->LocalFile);\r
1772                 iRetCode = 200;\r
1773         }\r
1774         return(iRetCode);\r
1775 }\r
1776 \r
1777 \r
1778 /*----- \92Ê\8fí\83\82\81[\83h\82Å\83t\83@\83C\83\8b\82ð\83A\83b\83v\83\8d\81[\83h ------------------------------------\r
1779 *\r
1780 *       Parameter\r
1781 *               TRANSPACKET *Pkt : \93]\91\97\83t\83@\83C\83\8b\8fî\95ñ\r
1782 *\r
1783 *       Return Value\r
1784 *               int \89\9e\93\9a\83R\81[\83h\r
1785 *----------------------------------------------------------------------------*/\r
1786 \r
1787 static int UpLoadNonPassive(TRANSPACKET *Pkt)\r
1788 {\r
1789         int iRetCode;\r
1790         int iLength;\r
1791         SOCKET data_socket = INVALID_SOCKET;   // data channel socket\r
1792         SOCKET listen_socket = INVALID_SOCKET; // data listen socket\r
1793         char Buf[1024];\r
1794         struct sockaddr_in saSockAddr1;\r
1795         int Resume;\r
1796         char Reply[ERR_MSG_LEN+7];\r
1797 \r
1798         if((listen_socket = GetFTPListenSocket(Pkt->ctrl_skt, &Canceled)) != INVALID_SOCKET)\r
1799         {\r
1800                 SetUploadResume(Pkt, Pkt->Mode, Pkt->ExistSize, &Resume);\r
1801                 if(Resume == NO)\r
1802                         sprintf(Buf, "%s%s", Pkt->Cmd, Pkt->RemoteFile);\r
1803                 else\r
1804                         sprintf(Buf, "%s%s", "APPE ", Pkt->RemoteFile);\r
1805 \r
1806                 iRetCode = command(Pkt->ctrl_skt, Reply, &Canceled, "%s", Buf);\r
1807                 if((iRetCode/100) == FTP_PRELIM)\r
1808                 {\r
1809                         if(SocksGet2ndBindReply(listen_socket, &data_socket) == FAIL)\r
1810                         {\r
1811                                 iLength=sizeof(saSockAddr1);\r
1812                                 data_socket = do_accept(listen_socket,(struct sockaddr *)&saSockAddr1, (int *)&iLength);\r
1813 \r
1814                                 if(shutdown(listen_socket, 1) != 0)\r
1815                                         ReportWSError("shutdown listen", WSAGetLastError());\r
1816                                 listen_socket = DoClose(listen_socket);\r
1817 \r
1818                                 if(data_socket == INVALID_SOCKET)\r
1819                                 {\r
1820                                         SetErrorMsg(MSGJPN280);\r
1821                                         ReportWSError("accept", WSAGetLastError());\r
1822                                         iRetCode = 500;\r
1823                                 }\r
1824                                 else\r
1825                                         DoPrintf("Skt=%u : accept from %s port %u", data_socket, inet_ntoa(saSockAddr1.sin_addr), ntohs(saSockAddr1.sin_port));\r
1826                         }\r
1827 \r
1828                         if(data_socket != INVALID_SOCKET)\r
1829                         {\r
1830                                 iRetCode = UpLoadFile(Pkt, data_socket);\r
1831                                 data_socket = DoClose(data_socket);\r
1832                         }\r
1833                 }\r
1834                 else\r
1835                 {\r
1836                         SetErrorMsg(Reply);\r
1837                         SetTaskMsg(MSGJPN108);\r
1838                         listen_socket = DoClose(listen_socket);\r
1839                         iRetCode = 500;\r
1840                 }\r
1841         }\r
1842         else\r
1843         {\r
1844                 SetErrorMsg(MSGJPN279);\r
1845                 iRetCode = 500;\r
1846         }\r
1847         DispUploadFinishMsg(Pkt, iRetCode);\r
1848 \r
1849         return(iRetCode);\r
1850 }\r
1851 \r
1852 \r
1853 /*----- Passive\83\82\81[\83h\82Å\83t\83@\83C\83\8b\82ð\83A\83b\83v\83\8d\81[\83h ---------------------------------\r
1854 *\r
1855 *       Parameter\r
1856 *               TRANSPACKET *Pkt : \93]\91\97\83t\83@\83C\83\8b\8fî\95ñ\r
1857 *\r
1858 *       Return Value\r
1859 *               int \89\9e\93\9a\83R\81[\83h\r
1860 *----------------------------------------------------------------------------*/\r
1861 \r
1862 static int UpLoadPassive(TRANSPACKET *Pkt)\r
1863 {\r
1864         int iRetCode;\r
1865         SOCKET data_socket = INVALID_SOCKET;   // data channel socket\r
1866         char Buf[1024];\r
1867         char Adrs[20];\r
1868         int Port;\r
1869         int Flg;\r
1870         int Resume;\r
1871         char Reply[ERR_MSG_LEN+7];\r
1872 \r
1873         iRetCode = command(Pkt->ctrl_skt, Buf, &Canceled, "PASV");\r
1874         if(iRetCode/100 == FTP_COMPLETE)\r
1875         {\r
1876                 if(GetAdrsAndPort(Buf, Adrs, &Port, 19) == SUCCESS)\r
1877                 {\r
1878                         if((data_socket = connectsock(Adrs, Port, MSGJPN109, &Canceled)) != INVALID_SOCKET)\r
1879                         {\r
1880                                 if(setsockopt(data_socket, IPPROTO_TCP, TCP_NODELAY, (LPSTR)&Flg, sizeof(Flg)) == SOCKET_ERROR)\r
1881                                         ReportWSError("setsockopt", WSAGetLastError());\r
1882 \r
1883                                 SetUploadResume(Pkt, Pkt->Mode, Pkt->ExistSize, &Resume);\r
1884                                 if(Resume == NO)\r
1885                                         sprintf(Buf, "%s%s", Pkt->Cmd, Pkt->RemoteFile);\r
1886                                 else\r
1887                                         sprintf(Buf, "%s%s", "APPE ", Pkt->RemoteFile);\r
1888 \r
1889                                 iRetCode = command(Pkt->ctrl_skt, Reply, &Canceled, "%s", Buf);\r
1890                                 if(iRetCode/100 == FTP_PRELIM)\r
1891                                 {\r
1892                                         iRetCode = UpLoadFile(Pkt, data_socket);\r
1893 \r
1894                                         data_socket = DoClose(data_socket);\r
1895                                 }\r
1896                                 else\r
1897                                 {\r
1898                                         SetErrorMsg(Reply);\r
1899                                         SetTaskMsg(MSGJPN110);\r
1900                                         data_socket = DoClose(data_socket);\r
1901                                         iRetCode = 500;\r
1902                                 }\r
1903                         }\r
1904                         else\r
1905                         {\r
1906                                 SetErrorMsg(MSGJPN281);\r
1907                                 iRetCode = 500;\r
1908                         }\r
1909                 }\r
1910                 else\r
1911                 {\r
1912                         SetErrorMsg(Buf);\r
1913                         SetTaskMsg(MSGJPN111);\r
1914                         iRetCode = 500;\r
1915                 }\r
1916         }\r
1917         else\r
1918                 SetErrorMsg(Buf);\r
1919 \r
1920         DispUploadFinishMsg(Pkt, iRetCode);\r
1921 \r
1922         return(iRetCode);\r
1923 }\r
1924 \r
1925 \r
1926 /*----- \83A\83b\83v\83\8d\81[\83h\82Ì\8eÀ\8ds ----------------------------------------------------\r
1927 *\r
1928 *       Parameter\r
1929 *               TRANSPACKET *Pkt : \93]\91\97\83t\83@\83C\83\8b\8fî\95ñ\r
1930 *               SOCKET dSkt : \83f\81[\83^\83\\83P\83b\83g\r
1931 *\r
1932 *       Return Value\r
1933 *               int \89\9e\93\9a\83R\81[\83h\r
1934 *\r
1935 *       Note\r
1936 *               \93]\91\97\82Ì\8co\89ß\95\\8e¦\82Í\81A\83C\83\93\83^\81[\83o\83\8b\83^\83C\83}\82Å\8co\89ß\82ð\95\\8e¦\82·\82é\r
1937 *               \93]\91\97\83_\83C\83A\83\8d\83O\82ð\8fo\82³\82È\82¢\82Å\83A\83b\83v\83\8d\81[\83h\82·\82é\82±\82Æ\82Í\82È\82¢\r
1938 *----------------------------------------------------------------------------*/\r
1939 \r
1940 static int UpLoadFile(TRANSPACKET *Pkt, SOCKET dSkt)\r
1941 {\r
1942         DWORD iNumBytes;\r
1943         HANDLE iFileHandle;\r
1944         SECURITY_ATTRIBUTES Sec;\r
1945         char Buf[BUFSIZE];\r
1946         char Buf2[BUFSIZE+3];\r
1947         CODECONVINFO cInfo;\r
1948         TERMCODECONVINFO tInfo;\r
1949         int Continue;\r
1950         char *EofPos;\r
1951         int iRetCode;\r
1952 #if 0\r
1953         int TimeOutErr;\r
1954 #endif\r
1955         char TmpBuf[ONELINE_BUF_SIZE];\r
1956         DWORD Low;\r
1957         DWORD High;\r
1958 \r
1959 #ifdef SET_BUFFER_SIZE\r
1960 /* Add by H.Shirouzu at 2002/10/02 */\r
1961         int buf_size = SOCKBUF_SIZE;\r
1962         for ( ; buf_size > 0; buf_size /= 2)\r
1963                 if (setsockopt(dSkt, SOL_SOCKET, SO_SNDBUF, (char *)&buf_size, sizeof(buf_size)) == 0)\r
1964                         break;\r
1965 /* End */\r
1966 #endif\r
1967 \r
1968 #ifdef DISABLE_NETWORK_BUFFERS\r
1969         // \94O\82Ì\82½\82ß\91\97\90M\83o\83b\83t\83@\82ð\96³\8cø\82É\82·\82é\81B\r
1970         int buf_size = 0;\r
1971         setsockopt(dSkt, SOL_SOCKET, SO_SNDBUF, (char *)&buf_size, sizeof(buf_size));\r
1972 #endif\r
1973 \r
1974         Pkt->Abort = ABORT_NONE;\r
1975 \r
1976         Sec.nLength = sizeof(SECURITY_ATTRIBUTES);\r
1977         Sec.lpSecurityDescriptor = NULL;\r
1978         Sec.bInheritHandle = FALSE;\r
1979 \r
1980         if((iFileHandle = CreateFile(Pkt->LocalFile, GENERIC_READ,\r
1981                 FILE_SHARE_READ|FILE_SHARE_WRITE, &Sec, OPEN_EXISTING, 0, NULL)) != INVALID_HANDLE_VALUE)\r
1982         {\r
1983                 // UTF-8\91Î\89\9e\r
1984                 int ProcessedBOM = NO;\r
1985                 if(Pkt->hWndTrans != NULL)\r
1986                 {\r
1987                         Low = GetFileSize(iFileHandle, &High);\r
1988                         Pkt->Size = MakeLongLong(High, Low);\r
1989 \r
1990                         High = (DWORD)HIGH32(Pkt->ExistSize);\r
1991                         Low = (DWORD)LOW32(Pkt->ExistSize);\r
1992                         SetFilePointer(iFileHandle, Low, &High, FILE_BEGIN);\r
1993 \r
1994                         AllTransSizeNow = 0;\r
1995                         TimeStart = time(NULL);\r
1996                         SetTimer(Pkt->hWndTrans, TIMER_DISPLAY, DISPLAY_TIMING, NULL);\r
1997                 }\r
1998 \r
1999                 InitCodeConvInfo(&cInfo);\r
2000                 cInfo.KanaCnv = Pkt->KanaCnv;\r
2001                 InitTermCodeConvInfo(&tInfo);\r
2002 \r
2003                 /*===== \83t\83@\83C\83\8b\82ð\91\97\90M\82·\82é\83\8b\81[\83v =====*/\r
2004                 while((Pkt->Abort == ABORT_NONE) &&\r
2005                           (ForceAbort == NO) &&\r
2006                           (ReadFile(iFileHandle, Buf, BUFSIZE, &iNumBytes, NULL) == TRUE))\r
2007                 {\r
2008                         if(iNumBytes == 0)\r
2009                                 break;\r
2010 \r
2011                         /* EOF\8f\9c\8b\8e */\r
2012                         EofPos = NULL;\r
2013                         if((RmEOF == YES) && (Pkt->Type == TYPE_A))\r
2014                         {\r
2015                                 if((EofPos = memchr(Buf, 0x1A, iNumBytes)) != NULL)\r
2016                                         iNumBytes = EofPos - Buf;\r
2017                         }\r
2018 \r
2019                         /* \8a¿\8e\9a\83R\81[\83h\95Ï\8a· */\r
2020                         if(Pkt->KanjiCode != KANJI_NOCNV)\r
2021                         {\r
2022                                 cInfo.Str = Buf;\r
2023                                 cInfo.StrLen = iNumBytes;\r
2024                                 cInfo.Buf = Buf2;\r
2025                                 cInfo.BufSize = BUFSIZE+3;\r
2026                                 do\r
2027                                 {\r
2028                                         // \82±\82±\82Å\91S\82ÄUTF-8\82Ö\95Ï\8a·\82·\82é\r
2029                                         // TODO: SJIS\88È\8aO\82à\92¼\90ÚUTF-8\82Ö\95Ï\8a·\r
2030 //                                      if(Pkt->KanjiCode == KANJI_JIS)\r
2031 //                                              Continue = ConvSJIStoJIS(&cInfo);\r
2032 //                                      else\r
2033 //                                              Continue = ConvSJIStoEUC(&cInfo);\r
2034                                         char Buf3[(BUFSIZE + 3) * 4];\r
2035                                         CODECONVINFO cInfo2;\r
2036                                         switch(Pkt->KanjiCodeDesired)\r
2037                                         {\r
2038                                         case KANJI_SJIS:\r
2039                                                 switch(Pkt->KanjiCode)\r
2040                                                 {\r
2041                                                 case KANJI_SJIS:\r
2042                                                         memcpy(Buf3, cInfo.Str, cInfo.StrLen);\r
2043                                                         cInfo2.OutLen = cInfo.StrLen;\r
2044                                                         Continue = NO;\r
2045                                                         break;\r
2046                                                 case KANJI_JIS:\r
2047                                                         break;\r
2048                                                 case KANJI_EUC:\r
2049                                                         break;\r
2050                                                 case KANJI_UTF8N:\r
2051                                                         if(ProcessedBOM == NO)\r
2052                                                         {\r
2053                                                                 memcpy(Buf3, "\xEF\xBB\xBF", 3);\r
2054                                                                 cInfo2.OutLen = 3;\r
2055                                                                 Continue = YES;\r
2056                                                                 ProcessedBOM = YES;\r
2057                                                                 break;\r
2058                                                         }\r
2059                                                         Continue = ConvSJIStoUTF8N(&cInfo);\r
2060                                                         memcpy(Buf3, cInfo.Str, cInfo.OutLen);\r
2061                                                         cInfo2.OutLen = cInfo.OutLen;\r
2062                                                         break;\r
2063                                                 }\r
2064                                                 break;\r
2065                                         case KANJI_JIS:\r
2066                                                 switch(Pkt->KanjiCode)\r
2067                                                 {\r
2068                                                 case KANJI_SJIS:\r
2069                                                         Continue = ConvJIStoSJIS(&cInfo);\r
2070                                                         memcpy(Buf3, Buf2, cInfo.OutLen);\r
2071                                                         cInfo2.OutLen = cInfo.OutLen;\r
2072                                                         break;\r
2073                                                 case KANJI_JIS:\r
2074                                                         memcpy(Buf3, cInfo.Str, cInfo.StrLen);\r
2075                                                         cInfo2.OutLen = cInfo.StrLen;\r
2076                                                         Continue = NO;\r
2077                                                         break;\r
2078                                                 case KANJI_EUC:\r
2079                                                         break;\r
2080                                                 case KANJI_UTF8N:\r
2081                                                         if(ProcessedBOM == NO)\r
2082                                                         {\r
2083                                                                 memcpy(Buf3, "\xEF\xBB\xBF", 3);\r
2084                                                                 cInfo2.OutLen = 3;\r
2085                                                                 Continue = YES;\r
2086                                                                 ProcessedBOM = YES;\r
2087                                                                 break;\r
2088                                                         }\r
2089                                                         Continue = ConvJIStoSJIS(&cInfo);\r
2090                                                         InitCodeConvInfo(&cInfo2);\r
2091                                                         cInfo2.KanaCnv = NO;\r
2092                                                         cInfo2.Str = cInfo.Buf;\r
2093                                                         cInfo2.StrLen = cInfo.OutLen;\r
2094                                                         cInfo2.Buf = Buf3;\r
2095                                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
2096                                                         ConvSJIStoUTF8N(&cInfo2);\r
2097                                                         break;\r
2098                                                 }\r
2099                                                 break;\r
2100                                         case KANJI_EUC:\r
2101                                                 switch(Pkt->KanjiCode)\r
2102                                                 {\r
2103                                                 case KANJI_SJIS:\r
2104                                                         Continue = ConvEUCtoSJIS(&cInfo);\r
2105                                                         memcpy(Buf3, Buf2, cInfo.OutLen);\r
2106                                                         cInfo2.OutLen = cInfo.OutLen;\r
2107                                                         break;\r
2108                                                 case KANJI_JIS:\r
2109                                                         break;\r
2110                                                 case KANJI_EUC:\r
2111                                                         memcpy(Buf3, cInfo.Str, cInfo.StrLen);\r
2112                                                         cInfo2.OutLen = cInfo.StrLen;\r
2113                                                         Continue = NO;\r
2114                                                         break;\r
2115                                                 case KANJI_UTF8N:\r
2116                                                         if(ProcessedBOM == NO)\r
2117                                                         {\r
2118                                                                 memcpy(Buf3, "\xEF\xBB\xBF", 3);\r
2119                                                                 cInfo2.OutLen = 3;\r
2120                                                                 Continue = YES;\r
2121                                                                 ProcessedBOM = YES;\r
2122                                                                 break;\r
2123                                                         }\r
2124                                                         Continue = ConvEUCtoSJIS(&cInfo);\r
2125                                                         InitCodeConvInfo(&cInfo2);\r
2126                                                         cInfo2.KanaCnv = NO;\r
2127                                                         cInfo2.Str = cInfo.Buf;\r
2128                                                         cInfo2.StrLen = cInfo.OutLen;\r
2129                                                         cInfo2.Buf = Buf3;\r
2130                                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
2131                                                         ConvSJIStoUTF8N(&cInfo2);\r
2132                                                         break;\r
2133                                                 }\r
2134                                                 break;\r
2135                                         case KANJI_UTF8N:\r
2136                                                 if(ProcessedBOM == NO)\r
2137                                                 {\r
2138                                                         if(memcmp(Buf, "\xEF\xBB\xBF", 3) == 0)\r
2139                                                         {\r
2140                                                                 cInfo.Str += 3;\r
2141                                                                 cInfo.StrLen -= 3;\r
2142                                                         }\r
2143                                                         cInfo2.OutLen = 0;\r
2144                                                         switch(Pkt->KanjiCode)\r
2145                                                         {\r
2146                                                         case KANJI_UTF8N:\r
2147                                                                 memcpy(Buf3, "\xEF\xBB\xBF", 3);\r
2148                                                                 cInfo2.OutLen = 3;\r
2149                                                                 break;\r
2150                                                         }\r
2151                                                         Continue = YES;\r
2152                                                         ProcessedBOM = YES;\r
2153                                                         break;\r
2154                                                 }\r
2155                                                 switch(Pkt->KanjiCode)\r
2156                                                 {\r
2157                                                 case KANJI_SJIS:\r
2158                                                         Continue = ConvUTF8NtoSJIS(&cInfo);\r
2159                                                         memcpy(Buf3, Buf2, cInfo.OutLen);\r
2160                                                         cInfo2.OutLen = cInfo.OutLen;\r
2161                                                         break;\r
2162                                                 case KANJI_JIS:\r
2163                                                         break;\r
2164                                                 case KANJI_EUC:\r
2165                                                         break;\r
2166                                                 case KANJI_UTF8N:\r
2167                                                         memcpy(Buf3, cInfo.Str, cInfo.StrLen);\r
2168                                                         cInfo2.OutLen = cInfo.StrLen;\r
2169                                                         Continue = NO;\r
2170                                                         break;\r
2171                                                 }\r
2172                                                 break;\r
2173                                         }\r
2174 \r
2175 //                                      if(TermCodeConvAndSend(&tInfo, dSkt, Buf2, cInfo.OutLen, Pkt->Type) == FAIL)\r
2176                                         if(TermCodeConvAndSend(&tInfo, dSkt, Buf3, cInfo2.OutLen, Pkt->Type) == FAIL)\r
2177                                         {\r
2178                                                 Pkt->Abort = ABORT_ERROR;\r
2179                                                         break;\r
2180                                         }\r
2181                                 }\r
2182                                 while(Continue == YES);\r
2183                         }\r
2184                         else\r
2185                         {\r
2186                                 if(TermCodeConvAndSend(&tInfo, dSkt, Buf, iNumBytes, Pkt->Type) == FAIL)\r
2187                                         Pkt->Abort = ABORT_ERROR;\r
2188                         }\r
2189 \r
2190                         Pkt->ExistSize += iNumBytes;\r
2191                         if(Pkt->hWndTrans != NULL)\r
2192                                 AllTransSizeNow += iNumBytes;\r
2193 \r
2194                         if(BackgrndMessageProc() == YES)\r
2195                                 ForceAbort = YES;\r
2196 \r
2197                         if(EofPos != NULL)\r
2198                                 break;\r
2199                 }\r
2200 \r
2201                 if((ForceAbort == NO) && (Pkt->Abort == ABORT_NONE))\r
2202                 {\r
2203                         /* \91\97\82è\8ec\82µ\82½\83f\81[\83^\82ð\91\97\90M */\r
2204                         if(Pkt->KanjiCode != KANJI_NOCNV)\r
2205                         {\r
2206                                 cInfo.Buf = Buf2;\r
2207                                 cInfo.BufSize = BUFSIZE+3;\r
2208                                 FlushRestData(&cInfo);\r
2209 \r
2210                                 if(TermCodeConvAndSend(&tInfo, dSkt, Buf2, cInfo.OutLen, Pkt->Type) == FAIL)\r
2211                                         Pkt->Abort = ABORT_ERROR;\r
2212                         }\r
2213 \r
2214                         tInfo.Buf = Buf2;\r
2215                         tInfo.BufSize = BUFSIZE+3;\r
2216                         FlushRestTermCodeConvData(&tInfo);\r
2217                         if(SendData(dSkt, Buf2, tInfo.OutLen, 0, &Canceled) == FAIL)\r
2218                                 Pkt->Abort = ABORT_ERROR;\r
2219                 }\r
2220 \r
2221                 /* \83O\83\89\83t\95\\8e¦\82ð\8dX\90V */\r
2222                 if(Pkt->hWndTrans != NULL)\r
2223                 {\r
2224                         KillTimer(Pkt->hWndTrans, TIMER_DISPLAY);\r
2225                         DispTransferStatus(Pkt->hWndTrans, YES, Pkt);\r
2226                         TimeStart = time(NULL) - TimeStart + 1;\r
2227                 }\r
2228                 CloseHandle(iFileHandle);\r
2229         }\r
2230         else\r
2231         {\r
2232                 SetErrorMsg(MSGJPN112, Pkt->LocalFile);\r
2233                 SetTaskMsg(MSGJPN112, Pkt->LocalFile);\r
2234                 Pkt->Abort = ABORT_ERROR;\r
2235         }\r
2236 \r
2237         if(shutdown(dSkt, 1) != 0)\r
2238                 ReportWSError("shutdown", WSAGetLastError());\r
2239 \r
2240 #if 0\r
2241         /* clean up */\r
2242         while(do_recv(dSkt, Buf, BUFSIZE, 0, &TimeOutErr, &Canceled) > 0)\r
2243                 ;\r
2244 #endif\r
2245 \r
2246         iRetCode = ReadReplyMessage(Pkt->ctrl_skt, Buf, 1024, &Canceled, TmpBuf);\r
2247 \r
2248 //#pragma aaa\r
2249 //DoPrintf("##UP REPLY : %s", Buf);\r
2250 \r
2251         if(iRetCode >= FTP_RETRY)\r
2252                 SetErrorMsg(Buf);\r
2253 \r
2254         if(Pkt->Abort != ABORT_NONE)\r
2255                 iRetCode = 500;\r
2256 \r
2257         return(iRetCode);\r
2258 }\r
2259 \r
2260 \r
2261 /*----- \83o\83b\83t\83@\82Ì\93à\97e\82ð\89ü\8ds\83R\81[\83h\95Ï\8a·\82µ\82Ä\91\97\90M --------------------------------\r
2262 *\r
2263 *       Parameter\r
2264 *               TERMCODECONVINFO *tInfo : \89ü\8ds\83R\81[\83h\95Ï\8a·\83p\83P\83b\83g\r
2265 *               SOCKET Skt : \83\\83P\83b\83g\r
2266 *               char *Data : \83f\81[\83^\r
2267 *               int Size : \83f\81[\83^\82Ì\83T\83C\83Y\r
2268 *               int Ascii : \83\82\81[\83h\81@\81@(TYPE_xx)\r
2269 *\r
2270 *       Return Value\r
2271 *               int \89\9e\93\9a\83R\81[\83h\r
2272 *----------------------------------------------------------------------------*/\r
2273 \r
2274 static int TermCodeConvAndSend(TERMCODECONVINFO *tInfo, SOCKET Skt, char *Data, int Size, int Ascii)\r
2275 {\r
2276         char Buf3[BUFSIZE*2];\r
2277         int Continue;\r
2278         int Ret;\r
2279 \r
2280         Ret = SUCCESS;\r
2281 \r
2282 // CR-LF\88È\8aO\82Ì\89ü\8ds\83R\81[\83h\82ð\95Ï\8a·\82µ\82È\82¢\83\82\81[\83h\82Í\82±\82±\82Ö\92Ç\89Á\r
2283         if(Ascii == TYPE_A)\r
2284         {\r
2285                 tInfo->Str = Data;\r
2286                 tInfo->StrLen = Size;\r
2287                 tInfo->Buf = Buf3;\r
2288                 tInfo->BufSize = BUFSIZE*2;\r
2289                 do\r
2290                 {\r
2291                         Continue = ConvTermCodeToCRLF(tInfo);\r
2292                         if((Ret = SendData(Skt, Buf3, tInfo->OutLen, 0, &Canceled)) == FAIL)\r
2293                                 break;\r
2294                 }\r
2295                 while(Continue == YES);\r
2296         }\r
2297         else\r
2298                 Ret = SendData(Skt, Data, Size, 0, &Canceled);\r
2299 \r
2300         return(Ret);\r
2301 }\r
2302 \r
2303 \r
2304 /*----- \83A\83b\83v\83\8d\81[\83h\8fI\97¹\81^\92\86\8e~\8e\9e\82Ì\83\81\83b\83Z\81[\83W\82ð\95\\8e¦ ----------------------------\r
2305 *\r
2306 *       Parameter\r
2307 *               TRANSPACKET *Pkt : \93]\91\97\83t\83@\83C\83\8b\8fî\95ñ\r
2308 *               int iRetCode : \89\9e\93\9a\83R\81[\83h\r
2309 *\r
2310 *       Return Value\r
2311 *               \82È\82µ\r
2312 *----------------------------------------------------------------------------*/\r
2313 \r
2314 static void DispUploadFinishMsg(TRANSPACKET *Pkt, int iRetCode)\r
2315 {\r
2316         if(ForceAbort == NO)\r
2317         {\r
2318                 if((iRetCode/100) >= FTP_CONTINUE)\r
2319                 {\r
2320                         if((Pkt->hWndTrans != NULL) && (TimeStart != 0))\r
2321                                 SetTaskMsg(MSGJPN113, TimeStart, Pkt->ExistSize/TimeStart);\r
2322                         else\r
2323                                 SetTaskMsg(MSGJPN114);\r
2324 \r
2325                         if(Pkt->Abort != ABORT_USER)\r
2326                         {\r
2327                                 if(DispUpDownErrDialog(uperr_dlg, Pkt->hWndTrans, Pkt->LocalFile) == NO)\r
2328                                         ClearAll = YES;\r
2329                         }\r
2330                 }\r
2331                 else\r
2332                 {\r
2333                         if((Pkt->hWndTrans != NULL) && (TimeStart != 0))\r
2334                                 SetTaskMsg(MSGJPN115, TimeStart, Pkt->ExistSize/TimeStart);\r
2335                         else\r
2336                                 SetTaskMsg(MSGJPN116);\r
2337                 }\r
2338         }\r
2339         return;\r
2340 }\r
2341 \r
2342 \r
2343 /*----- \83A\83b\83v\83\8d\81[\83h\82Ì\83\8a\83W\83\85\81[\83\80\82Ì\8f\80\94õ\82ð\8ds\82¤ ----------------------------------\r
2344 *\r
2345 *       Parameter\r
2346 *               TRANSPACKET *Pkt : \93]\91\97\83t\83@\83C\83\8b\8fî\95ñ\r
2347 *               iont ProcMode : \8f\88\97\9d\83\82\81[\83h(EXIST_xxx)\r
2348 *               LONGLONG Size : \83z\83X\83g\82É\82 \82é\83t\83@\83C\83\8b\82Ì\83T\83C\83Y\r
2349 *               int *Mode : \83\8a\83W\83\85\81[\83\80\82ð\8ds\82¤\82©\82Ç\82¤\82© (YES/NO)\r
2350 *\r
2351 *       Return Value\r
2352 *               int \83X\83e\81[\83^\83X = YES\r
2353 *\r
2354 *       Note\r
2355 *               Pkt->ExistSize\82Ì\83Z\83b\83g\82ð\8ds\82È\82¤\r
2356 *----------------------------------------------------------------------------*/\r
2357 \r
2358 static int SetUploadResume(TRANSPACKET *Pkt, int ProcMode, LONGLONG Size, int *Mode)\r
2359 {\r
2360         Pkt->ExistSize = 0;\r
2361         *Mode = NO;\r
2362         if(ProcMode == EXIST_RESUME)\r
2363         {\r
2364                 if(Pkt->hWndTrans != NULL)\r
2365                 {\r
2366                         Pkt->ExistSize = Size;\r
2367                         *Mode = YES;\r
2368                 }\r
2369         }\r
2370         return(YES);\r
2371 }\r
2372 \r
2373 \r
2374 /*----- \93]\91\97\92\86\83_\83C\83A\83\8d\83O\83{\83b\83N\83X\82Ì\83R\81[\83\8b\83o\83b\83N --------------------------------\r
2375 *\r
2376 *       Parameter\r
2377 *               HWND hDlg : \83E\83C\83\93\83h\83E\83n\83\93\83h\83\8b\r
2378 *               UINT message : \83\81\83b\83Z\81[\83W\94Ô\8d\86\r
2379 *               WPARAM wParam : \83\81\83b\83Z\81[\83W\82Ì WPARAM \88ø\90\94\r
2380 *               LPARAM lParam : \83\81\83b\83Z\81[\83W\82Ì LPARAM \88ø\90\94\r
2381 *\r
2382 *       Return Value\r
2383 *               BOOL TRUE/FALSE\r
2384 *----------------------------------------------------------------------------*/\r
2385 \r
2386 static LRESULT CALLBACK TransDlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam)\r
2387 {\r
2388         RECT RectDlg;\r
2389         RECT RectPar;\r
2390         HMENU hMenu;\r
2391         static TRANSPACKET *Pkt;\r
2392 \r
2393         switch(Msg)\r
2394         {\r
2395                 case WM_INITDIALOG :\r
2396                         GetWindowRect(hDlg, &RectDlg);\r
2397                         RectDlg.right -= RectDlg.left;\r
2398                         RectDlg.bottom -= RectDlg.top;\r
2399                         GetWindowRect(GetMainHwnd(), &RectPar);\r
2400                         MoveWindow(hDlg,\r
2401                                 ((RectPar.right + RectPar.left) / 2) - (RectDlg.right / 2),\r
2402                                 ((RectPar.bottom + RectPar.top) / 2) - (RectDlg.bottom / 2),\r
2403                                 RectDlg.right,\r
2404                                 RectDlg.bottom,\r
2405                                 FALSE);\r
2406 \r
2407                         hMenu = GetSystemMenu(hDlg, FALSE);\r
2408                         EnableMenuItem(hMenu, SC_CLOSE, MF_GRAYED);\r
2409                         break;\r
2410 \r
2411                 case WM_COMMAND :\r
2412                         switch(LOWORD(wParam))\r
2413                         {\r
2414                                 case TRANS_STOP_NEXT :\r
2415                                         ClearAll = YES;\r
2416                                         break;\r
2417 \r
2418                                 case TRANS_STOP_ALL :\r
2419                                         ClearAll = YES;\r
2420                                         /* \82±\82±\82É break \82Í\82È\82¢ */\r
2421 \r
2422                                 case IDCANCEL :\r
2423                                         Pkt->Abort = ABORT_USER;\r
2424                                         Canceled = YES;\r
2425                                         break;\r
2426                         }\r
2427                         break;\r
2428 \r
2429                 case WM_TIMER :\r
2430                         if(wParam == TIMER_DISPLAY)\r
2431                         {\r
2432                                 if(MoveToForeground == YES)\r
2433                                         SetForegroundWindow(hDlg);\r
2434                                 MoveToForeground = NO;\r
2435                                 KillTimer(hDlg, TIMER_DISPLAY);\r
2436                                 DispTransferStatus(hDlg, NO, Pkt);\r
2437                                 SetTimer(hDlg, TIMER_DISPLAY, DISPLAY_TIMING, NULL);\r
2438                         }\r
2439                         break;\r
2440 \r
2441                 case WM_SET_PACKET :\r
2442                         Pkt = (TRANSPACKET *)lParam;\r
2443                         break;\r
2444         }\r
2445         return(FALSE);\r
2446 }\r
2447 \r
2448 \r
2449 /*----- \93]\91\97\83X\83e\81[\83^\83X\82ð\95\\8e¦ --------------------------------------------------\r
2450 *\r
2451 *       Parameter\r
2452 *               HWND hWnd : \83E\83C\83\93\83h\83E\83n\83\93\83h\83\8b\r
2453 *               int End : \93]\91\97\82ª\8a®\97¹\82µ\82½\82©\82Ç\82¤\82© (YES/NO)\r
2454 *\r
2455 *       Return Value\r
2456 *               \82È\82µ\r
2457 *----------------------------------------------------------------------------*/\r
2458 \r
2459 static void DispTransferStatus(HWND hWnd, int End, TRANSPACKET *Pkt)\r
2460 {\r
2461         time_t TotalLap;\r
2462         int Per;\r
2463         LONGLONG Bps;\r
2464         LONGLONG Transed;\r
2465         char Num1[40];\r
2466         char Num2[40];\r
2467         char Tmp[80];\r
2468         char Str[80];\r
2469         char *Pos;\r
2470 \r
2471         if(hWnd != NULL)\r
2472         {\r
2473                 SendMessage(hWnd, WM_GETTEXT, 79, (LPARAM)Str);\r
2474                 if((Pos = strchr(Str, ')')) != NULL)\r
2475                         Pos ++;\r
2476                 else\r
2477                         Pos = Str;\r
2478                 sprintf(Tmp, "(%d)%s", AskTransferFileNum(), Pos);\r
2479                 SendMessage(hWnd, WM_SETTEXT, 0, (LPARAM)Tmp);\r
2480 \r
2481                 if(Pkt->Abort == ABORT_NONE)\r
2482                 {\r
2483                         if(End == NO)\r
2484                         {\r
2485                                 TotalLap = time(NULL) - TimeStart + 1;\r
2486 \r
2487                                 Bps = 0;\r
2488                                 if(TotalLap != 0)\r
2489                                         Bps = AllTransSizeNow / TotalLap;\r
2490                                 Transed = Pkt->Size - Pkt->ExistSize;\r
2491 \r
2492                                 if(Pkt->Size <= 0)\r
2493                                         sprintf(Tmp, "%d ", Pkt->ExistSize);\r
2494                                 else if(Pkt->Size < 1024)\r
2495                                         sprintf(Tmp, "%s / %s ", MakeNumString(Pkt->ExistSize, Num1, TRUE), MakeNumString(Pkt->Size, Num2, TRUE));\r
2496                                 else\r
2497                                         sprintf(Tmp, "%sk / %sk ", MakeNumString(Pkt->ExistSize/1024, Num1, TRUE), MakeNumString(Pkt->Size/1024, Num2, TRUE));\r
2498                                 strcpy(Str, Tmp);\r
2499 \r
2500                                 if(Bps == 0)\r
2501                                         sprintf(Tmp, "( 0 B/S )");\r
2502                                 else if(Bps < 1000)\r
2503                                         sprintf(Tmp, "( %s B/S )", MakeNumString(Bps, Num1, TRUE));\r
2504                                 else\r
2505                                         sprintf(Tmp, "( %s.%02d KB/S )", MakeNumString(Bps/1000, Num1, TRUE), (int)((Bps%1000)/10));\r
2506                                 strcat(Str, Tmp);\r
2507 \r
2508                                 if((Bps > 0) && (Pkt->Size > 0) && (Transed >= 0))\r
2509                                 {\r
2510                                         sprintf(Tmp, "  %d:%02d", (int)((Transed/Bps)/60), (int)((Transed/Bps)%60));\r
2511                                         strcat(Str, Tmp);\r
2512                                 }\r
2513                                 else\r
2514                                         strcat(Str, "  ??:??");\r
2515                         }\r
2516                         else\r
2517                                 strcpy(Str, MSGJPN117);\r
2518                 }\r
2519                 else\r
2520                         strcpy(Str, MSGJPN118);\r
2521 \r
2522                 SendDlgItemMessage(hWnd, TRANS_STATUS, WM_SETTEXT, 0, (LPARAM)Str);\r
2523 \r
2524                 if(Pkt->Size <= 0)\r
2525                         Per = 0;\r
2526                 else if(Pkt->Size < 1024*1024)\r
2527                         Per = (int)(Pkt->ExistSize * 100 / Pkt->Size);\r
2528                 else\r
2529                         Per = (int)((Pkt->ExistSize/1024) * 100 / (Pkt->Size/1024));\r
2530                 SendDlgItemMessage(hWnd, TRANS_TIME_BAR, PBM_SETPOS, Per, 0);\r
2531         }\r
2532         return;\r
2533 }\r
2534 \r
2535 \r
2536 /*----- \93]\91\97\82·\82é