OSDN Git Service

3f949c94e3d45ea25fa3f74caea8374e43f39268
[ffftp/ffftp.git] / main.c
1 /*=============================================================================\r
2 *\r
3 *                                                                       FFFTP\r
4 *\r
5 ===============================================================================\r
6 / Copyright (C) 1997-2007 Sota. All rights reserved.\r
7 /\r
8 / Redistribution and use in source and binary forms, with or without \r
9 / modification, are permitted provided that the following conditions \r
10 / are met:\r
11 /\r
12 /  1. Redistributions of source code must retain the above copyright \r
13 /     notice, this list of conditions and the following disclaimer.\r
14 /  2. Redistributions in binary form must reproduce the above copyright \r
15 /     notice, this list of conditions and the following disclaimer in the \r
16 /     documentation and/or other materials provided with the distribution.\r
17 /\r
18 / THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR \r
19 / IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES \r
20 / OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. \r
21 / IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, \r
22 / INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, \r
23 / BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF \r
24 / USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON \r
25 / ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
26 / (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF \r
27 / THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
28 /============================================================================*/\r
29 \r
30 #define  STRICT\r
31 #include <windows.h>\r
32 #include <stdio.h>\r
33 #include <stdlib.h>\r
34 #include <string.h>\r
35 #include <mbstring.h>\r
36 #include <malloc.h>\r
37 #include <windowsx.h>\r
38 #include <commctrl.h>\r
39 #include <stdarg.h>\r
40 #include <winsock.h>\r
41 \r
42 #include "common.h"\r
43 #include "resource.h"\r
44 #include "aes.h"\r
45 \r
46 #include <htmlhelp.h>\r
47 #include "helpid.h"\r
48 \r
49 // UTF-8対応\r
50 #undef __MBSWRAPPER_H__\r
51 #include "mbswrapper.h"\r
52 \r
53 \r
54 #define RESIZE_OFF              0               /* ウインドウの区切り位置変更していない */\r
55 #define RESIZE_ON               1               /* ウインドウの区切り位置変更中 */\r
56 #define RESIZE_PREPARE  2               /* ウインドウの区切り位置変更の準備 */\r
57 \r
58 #define RESIZE_HPOS             0               /* ローカル-ホスト間の区切り位置変更 */\r
59 #define RESIZE_VPOS             1               /* リスト-タスク間の区切り位置の変更 */\r
60 \r
61 \r
62 /*===== プロトタイプ =====*/\r
63 \r
64 static int InitApp(LPSTR lpszCmdLine, int cmdShow);\r
65 static int MakeAllWindows(int cmdShow);\r
66 static void DeleteAllObject(void);\r
67 static LRESULT CALLBACK FtpWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);\r
68 static void StartupProc(char *Cmd);\r
69 static int AnalyzeComLine(char *Str, int *AutoConnect, int *CmdOption, char *unc, int Max);\r
70 static int CheckIniFileName(char *Str, char *Ini);\r
71 static int CheckMasterPassword(char *Str, char *Ini);\r
72 static int GetTokenAfterOption(char *Str, char *Result, const char* Opt1, const char* Opt2 );\r
73 static char *GetToken(char *Str, char *Buf);\r
74 static void ExitProc(HWND hWnd);\r
75 static void ChangeDir(int Win, char *Path);\r
76 static void ResizeWindowProc(void);\r
77 static void CalcWinSize(void);\r
78 // static void AskWindowPos(HWND hWnd);\r
79 static void CheckResizeFrame(WPARAM Keys, int x, int y);\r
80 static void DispDirInfo(void);\r
81 static void DeleteAlltempFile(void);\r
82 static BOOL CALLBACK AboutDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);\r
83 static int EnterMasterPasswordAndSet( int Res, HWND hWnd );\r
84 \r
85 /*===== ローカルなワーク =====*/\r
86 \r
87 static const char FtpClassStr[] = "FFFTPWin";\r
88 \r
89 static HINSTANCE hInstFtp;\r
90 static HWND hWndFtp = NULL;\r
91 static HWND hWndCurFocus = NULL;\r
92 \r
93 static HACCEL Accel;\r
94 static HBRUSH RootColorBrush = NULL;\r
95 \r
96 static int Resizing = RESIZE_OFF;\r
97 static int ResizePos;\r
98 static HCURSOR hCursor;\r
99 \r
100 int ClientWidth;\r
101 static int ClientHeight;\r
102 int SepaWidth;\r
103 int RemoteWidth;\r
104 int ListHeight;\r
105 \r
106 static TEMPFILELIST *TempFiles = NULL;\r
107 \r
108 static int SaveExit = YES;\r
109 static int AutoExit = NO;\r
110 \r
111 static char HelpPath[FMAX_PATH+1];\r
112 static char IniPath[FMAX_PATH+1];\r
113 static int ForceIni = NO;\r
114 \r
115 TRANSPACKET MainTransPkt;               /* ファイル転送用パケット */\r
116                                                                 /* これを使って転送を行うと、ツールバーの転送 */\r
117                                                                 /* 中止ボタンで中止できる */\r
118 \r
119 char TitleHostName[HOST_ADRS_LEN+1];\r
120 char FilterStr[FILTER_EXT_LEN+1] = { "*" };\r
121 \r
122 int CancelFlg;\r
123 \r
124 static int SuppressRefresh = 0;\r
125 \r
126 static DWORD dwCookie;\r
127 \r
128 \r
129 /*===== グローバルなワーク =====*/\r
130 \r
131 HWND hHelpWin = NULL;\r
132 \r
133 /* 設定値 */\r
134 int WinPosX = CW_USEDEFAULT;\r
135 int WinPosY = 0;\r
136 int WinWidth = 630;\r
137 int WinHeight = 393;\r
138 int LocalWidth = 309;\r
139 int TaskHeight = 50;\r
140 int LocalTabWidth[4] = { 120, 90, 60, 37 };\r
141 int RemoteTabWidth[6] = { 120, 90, 60, 37, 60, 60 };\r
142 char UserMailAdrs[USER_MAIL_LEN+1] = { "who@example.com" };\r
143 char ViewerName[VIEWERS][FMAX_PATH+1] = { { "notepad" }, { "" }, { "" } };\r
144 HFONT ListFont = NULL;\r
145 LOGFONT ListLogFont;\r
146 int LocalFileSort = SORT_NAME;\r
147 int LocalDirSort = SORT_NAME;\r
148 int RemoteFileSort = SORT_NAME;\r
149 int RemoteDirSort = SORT_NAME;\r
150 int TransMode = TYPE_X;\r
151 int ConnectOnStart = YES;\r
152 int DebugConsole = NO;\r
153 int SaveWinPos = NO;\r
154 char AsciiExt[ASCII_EXT_LEN+1] = { "*.txt\0*.html\0*.htm\0*.cgi\0*.pl\0" };\r
155 int RecvMode = TRANS_DLG;\r
156 int SendMode = TRANS_DLG;\r
157 int MoveMode = MOVE_DLG;\r
158 int ListType = LVS_REPORT;\r
159 // LISTのキャッシュを無効にする(リモートのディレクトリの表示が更新されないバグ対策)\r
160 //int CacheEntry = 10;\r
161 int CacheEntry = -10;\r
162 int CacheSave = NO;\r
163 char DefaultLocalPath[FMAX_PATH+1] = { "" };\r
164 int SaveTimeStamp = YES;\r
165 int FindMode = 0;\r
166 int DotFile = YES;\r
167 int DclickOpen = YES;\r
168 int ConnectAndSet = YES;\r
169 SOUNDFILE Sound[SOUND_TYPES] = { { NO, "" }, { NO, "" }, { NO, "" } };\r
170 int FnameCnv = FNAME_NOCNV;\r
171 int TimeOut = 90;\r
172 int RmEOF = NO;\r
173 int RegType = REGTYPE_REG;\r
174 char FwallHost[HOST_ADRS_LEN+1] = { "" };\r
175 char FwallUser[USER_NAME_LEN+1] = { "" };\r
176 char FwallPass[PASSWORD_LEN+1] = { "" };\r
177 int FwallPort = PORT_NOR;\r
178 int FwallType = 1;\r
179 int FwallDefault = NO;\r
180 int FwallSecurity = SECURITY_AUTO;\r
181 int FwallResolv = NO;\r
182 int FwallLower = NO;\r
183 int FwallDelimiter = '@';\r
184 int PasvDefault = NO;\r
185 char MirrorNoTrn[MIRROR_LEN+1] = { "*.bak\0" };\r
186 char MirrorNoDel[MIRROR_LEN+1] = { "" };\r
187 int MirrorFnameCnv = NO;\r
188 int SplitVertical = YES;\r
189 int RasClose = NO;\r
190 int RasCloseNotify = YES;\r
191 int FileHist = 5;\r
192 char DefAttrList[DEFATTRLIST_LEN+1] = { "" };\r
193 SIZE HostDlgSize = { -1, -1 };\r
194 SIZE BmarkDlgSize = { -1, -1 };\r
195 SIZE MirrorDlgSize = { -1, -1 };\r
196 int Sizing = SW_RESTORE;\r
197 int SortSave = NO;\r
198 char TmpPath[FMAX_PATH+1];\r
199 int QuickAnonymous = YES;\r
200 int PassToHist = YES;\r
201 int VaxSemicolon = NO;\r
202 int SendQuit = NO;\r
203 int NoRasControl = NO;\r
204 int SuppressSave = NO;\r
205 int DispIgnoreHide = NO;\r
206 int DispDrives = NO;\r
207 int MirUpDelNotify = YES; \r
208 int MirDownDelNotify = YES; \r
209 int FolderAttr = NO;\r
210 int FolderAttrNum = 777;\r
211 // 同時接続対応\r
212 int MaxThreadCount = 1;\r
213 \r
214 \r
215 \r
216 \r
217 /*----- メインルーチン --------------------------------------------------------\r
218 *\r
219 *       Parameter\r
220 *               HINSTANCE hInstance : このアプリケーションのこのインスタンスのハンドル\r
221 *               HINSTANCE hPrevInstance : このアプリケーションの直前のインスタンスのハンドル\r
222 *               LPSTR lpszCmdLine : アプリケーションが起動したときのコマンドラインをさすロングポインタ\r
223 *               int cmdShow : 最初に表示するウインドウの形式。\r
224 *\r
225 *       Return Value\r
226 *               int 最後のメッセージのwParam\r
227 *----------------------------------------------------------------------------*/\r
228 \r
229 int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int cmdShow)\r
230 {\r
231     MSG Msg;\r
232         int Ret;\r
233         BOOL Sts;\r
234 \r
235         // プロセス保護\r
236 #ifdef ENABLE_PROCESS_PROTECTION\r
237         DWORD ProtectLevel;\r
238         char* pCommand;\r
239         char Option[FMAX_PATH+1];\r
240         ProtectLevel = PROCESS_PROTECTION_NONE;\r
241         pCommand = lpszCmdLine;\r
242         while(pCommand = GetToken(pCommand, Option))\r
243         {\r
244                 if(strcmp(Option, "--protect") == 0)\r
245                 {\r
246                         ProtectLevel = PROCESS_PROTECTION_DEFAULT;\r
247                         break;\r
248                 }\r
249                 else if(strcmp(Option, "--protect-high") == 0)\r
250                 {\r
251                         ProtectLevel = PROCESS_PROTECTION_HIGH;\r
252                         break;\r
253                 }\r
254                 else if(strcmp(Option, "--protect-medium") == 0)\r
255                 {\r
256                         ProtectLevel = PROCESS_PROTECTION_MEDIUM;\r
257                         break;\r
258                 }\r
259                 else if(strcmp(Option, "--protect-low") == 0)\r
260                 {\r
261                         ProtectLevel = PROCESS_PROTECTION_LOW;\r
262                         break;\r
263                 }\r
264         }\r
265         if(ProtectLevel != PROCESS_PROTECTION_NONE)\r
266         {\r
267                 SetProcessProtectionLevel(ProtectLevel);\r
268                 if(!InitializeLoadLibraryHook())\r
269                 {\r
270                         MessageBox(NULL, MSGJPN321, "FFFTP", MB_OK | MB_ICONERROR);\r
271                         return 0;\r
272                 }\r
273 #ifndef _DEBUG\r
274                 if(IsDebuggerPresent())\r
275                 {\r
276                         MessageBox(NULL, MSGJPN322, "FFFTP", MB_OK | MB_ICONERROR);\r
277                         return 0;\r
278                 }\r
279 #endif\r
280                 if(!UnloadUntrustedModule())\r
281                 {\r
282                         MessageBox(NULL, MSGJPN323, "FFFTP", MB_OK | MB_ICONERROR);\r
283                         return 0;\r
284                 }\r
285 #ifndef _DEBUG\r
286                 if(RestartProtectedProcess(" --restart"))\r
287                         return 0;\r
288 #endif\r
289                 if(!EnableLoadLibraryHook(TRUE))\r
290                 {\r
291                         MessageBox(NULL, MSGJPN324, "FFFTP", MB_OK | MB_ICONERROR);\r
292                         return 0;\r
293                 }\r
294         }\r
295         else\r
296                 InitializeLoadLibraryHook();\r
297 #endif\r
298 \r
299 #ifdef DISABLE_MULTI_CPUS\r
300         SetProcessAffinityMask(GetCurrentProcess(), 1);\r
301 #endif\r
302 \r
303         // yutaka\r
304         if(OleInitialize(NULL) != S_OK){\r
305                 MessageBox(NULL, MSGJPN298, "FFFTP", MB_OK | MB_ICONERROR);\r
306                 return 0;\r
307         }\r
308 \r
309         InitCommonControls();\r
310 \r
311         // FTPS対応\r
312 #ifdef USE_OPENSSL\r
313         LoadOpenSSL();\r
314 #endif\r
315 \r
316         Ret = FALSE;\r
317         hWndFtp = NULL;\r
318         hInstFtp = hInstance;\r
319         if(InitApp(lpszCmdLine, cmdShow) == FFFTP_SUCCESS)\r
320         {\r
321                 for(;;)\r
322                 {\r
323                         Sts = GetMessage(&Msg, NULL, 0, 0);\r
324                         if((Sts == 0) || (Sts == -1))\r
325                                 break;\r
326 \r
327                         if(!HtmlHelp(NULL, NULL, HH_PRETRANSLATEMESSAGE, (DWORD)&Msg))\r
328                         { \r
329                                 /* ディレクトリ名の表示コンボボックスでBSやRETが効くように */\r
330                                 /* コンボボックス内ではアクセラレータを無効にする */\r
331                                 if((Msg.hwnd == GetLocalHistEditHwnd()) ||\r
332                                    (Msg.hwnd == GetRemoteHistEditHwnd()) ||\r
333                                    ((hHelpWin != NULL) && (GetAncestor(Msg.hwnd, GA_ROOT) == hHelpWin)) ||\r
334                                    GetHideUI() == YES ||\r
335                                    (TranslateAccelerator(hWndFtp, Accel, &Msg) == 0))\r
336                                 {\r
337                                         TranslateMessage(&Msg);\r
338                                         DispatchMessage(&Msg);\r
339                                 }\r
340                         }\r
341                 }\r
342                 Ret = Msg.wParam;\r
343         }\r
344     UnregisterClass(FtpClassStr, hInstFtp);\r
345         // FTPS対応\r
346 #ifdef USE_OPENSSL\r
347         FreeOpenSSL();\r
348 #endif\r
349         OleUninitialize();\r
350         return(Ret);\r
351 }\r
352 \r
353 \r
354 /*----- アプリケーションの初期設定 --------------------------------------------\r
355 *\r
356 *       Parameter\r
357 *               HINSTANCE hInstance : このアプリケーションのこのインスタンスのハンドル\r
358 *               HINSTANCE hPrevInstance : このアプリケーションの直前のインスタンスのハンドル\r
359 *               LPSTR lpszCmdLine : アプリケーションが起動したときのコマンドラインをさすロングポインタ\r
360 *               int cmdShow : 最初に表示するウインドウの形式。\r
361 *\r
362 *       Return Value\r
363 *               int ステータス\r
364 *                       FFFTP_SUCCESS/FFFTP_FAIL\r
365 *----------------------------------------------------------------------------*/\r
366 \r
367 static int InitApp(LPSTR lpszCmdLine, int cmdShow)\r
368 {\r
369         int sts;\r
370         int Err;\r
371         WSADATA WSAData;\r
372         char PwdBuf[FMAX_PATH+1];\r
373         int useDefautPassword = 0; /* 警告文表示用 */\r
374         int masterpass;\r
375 \r
376         sts = FFFTP_FAIL;\r
377 \r
378         aes_init();\r
379         srand(GetTickCount());\r
380         \r
381         HtmlHelp(NULL, NULL, HH_INITIALIZE, (DWORD)&dwCookie);\r
382 \r
383         SaveUpdateBellInfo();\r
384 \r
385         if((Err = WSAStartup((WORD)0x0202, &WSAData)) != 0)\r
386                 MessageBox(NULL, ReturnWSError(Err), "FFFTP - Startup", MB_OK);\r
387         else\r
388         {\r
389                 Accel = LoadAccelerators(hInstFtp, MAKEINTRESOURCE(ffftp_accel));\r
390 \r
391                 GetTempPath(FMAX_PATH, TmpPath);\r
392 \r
393                 GetModuleFileName(NULL, HelpPath, FMAX_PATH);\r
394                 strcpy(GetFileName(HelpPath), "ffftp.chm");\r
395 \r
396                 if(CheckIniFileName(lpszCmdLine, IniPath) == 0)\r
397                 {\r
398                         GetModuleFileName(NULL, IniPath, FMAX_PATH);\r
399                         strcpy(GetFileName(IniPath), "ffftp.ini");\r
400                 }\r
401                 else\r
402                 {\r
403                         ForceIni = YES;\r
404                         RegType = REGTYPE_INI;\r
405                 }\r
406 \r
407 //              AllocConsole();\r
408 \r
409                 /* 2010.02.01 genta マスターパスワードを入力させる\r
410                   -z オプションがあるときは最初だけスキップ\r
411                   -z オプションがないときは,デフォルトパスワードをまず試す\r
412                   LoadRegistory()する\r
413                   パスワードが不一致なら再入力するか尋ねる.\r
414                   (破損していた場合はさせない)\r
415                 */\r
416                 if( CheckMasterPassword(lpszCmdLine, PwdBuf))\r
417                 {\r
418                         SetMasterPassword( PwdBuf );\r
419                         useDefautPassword = 0;\r
420                 }\r
421                 else {\r
422                         /* パスワード指定無し */\r
423                         SetMasterPassword( NULL );\r
424                         /* この場では表示できないのでフラグだけ立てておく*/\r
425                         useDefautPassword = 2;\r
426                 }\r
427 \r
428                 /* パスワードチェックのみ実施 */\r
429                 masterpass = 1;\r
430                 while( ValidateMasterPassword() == YES &&\r
431                                 GetMasterPasswordStatus() == PASSWORD_UNMATCH ){\r
432                         \r
433                         if( useDefautPassword != 2 ){\r
434                                 /* 再トライするか確認 */\r
435                                 if( MessageBox(NULL, MSGJPN304, "FFFTP", MB_YESNO | MB_ICONEXCLAMATION) == IDNO ){\r
436                                         useDefautPassword = 0; /* 不一致なので,もはやデフォルトかどうかは分からない */\r
437                                         break;\r
438                                 }\r
439                         }\r
440                         \r
441                         /* 再入力させる*/\r
442                         masterpass = EnterMasterPasswordAndSet(masterpasswd_dlg, NULL);\r
443                         if( masterpass == 2 ){\r
444                                 useDefautPassword = 1;\r
445                         }\r
446                         else if( masterpass == 0 ){\r
447                                 SaveExit = NO;\r
448                                 break;\r
449                         }\r
450                         else {\r
451                                 useDefautPassword = 0;\r
452                         }\r
453                 }\r
454                 \r
455                 if(masterpass != 0)\r
456                 {\r
457                         LoadRegistory();\r
458 \r
459                         // 暗号化通信対応\r
460                         SetSSLTimeoutCallback(TimeOut * 1000, SSLTimeoutCallback);\r
461 \r
462                         LoadJre();\r
463                         if(NoRasControl == NO)\r
464                                 LoadRasLib();\r
465                         LoadKernelLib();\r
466 \r
467                         //タイマの精度を改善\r
468                         timeBeginPeriod(1);\r
469 \r
470                         CountPrevFfftpWindows();\r
471 \r
472                         if(MakeAllWindows(cmdShow) == FFFTP_SUCCESS)\r
473                         {\r
474                                 hWndCurFocus = GetLocalHwnd();\r
475 \r
476                                 if(strlen(DefaultLocalPath) > 0)\r
477                                         SetCurrentDirectory(DefaultLocalPath);\r
478 \r
479                                 SetSortTypeImm(LocalFileSort, LocalDirSort, RemoteFileSort, RemoteDirSort);\r
480                                 SetTransferTypeImm(TransMode);\r
481                                 DispTransferType();\r
482                                 SetHostKanaCnvImm(YES);\r
483                                 SetHostKanjiCodeImm(KANJI_NOCNV);\r
484                                 // 本当はローカルのデフォルトをUTF-8にしたいが旧バージョンとの互換性のためShift_JISに設定\r
485 //                              SetLocalKanjiCodeImm(KANJI_UTF8N);\r
486                                 SetLocalKanjiCodeImm(KANJI_SJIS);\r
487                                 DispListType();\r
488                                 DispDotFileMode();\r
489                                 DispSyncMoveMode();\r
490 \r
491                                 MakeCacheBuf(CacheEntry);\r
492                                 if(CacheSave == YES)\r
493                                         LoadCache();\r
494 \r
495                                 if(MakeTransferThread() == FFFTP_SUCCESS)\r
496                                 {\r
497                                         DoPrintf("DEBUG MESSAGE ON ! ##");\r
498 \r
499                                         DispWindowTitle();\r
500                                         // SourceForge.JPによるフォーク\r
501 //                                      SetTaskMsg("FFFTP Ver." VER_STR " Copyright(C) 1997-2010 Sota & cooperators.");\r
502                                         SetTaskMsg("FFFTP Ver." VER_STR " Copyright(C) 1997-2010 Sota & cooperators.\r\nCopyright (C) 2011 Hiromichi Matsushima, Suguru Kawamoto.");\r
503 \r
504                                         if(ForceIni)\r
505                                                 SetTaskMsg("%s%s", MSGJPN283, IniPath);\r
506 \r
507                                         if(IsFolderExist(TmpPath) == NO)\r
508                                         {\r
509                                                 SetTaskMsg(MSGJPN152, TmpPath);\r
510                                                 GetTempPath(FMAX_PATH, TmpPath);\r
511                                                 SetTaskMsg(MSGJPN153, TmpPath);\r
512                                         }\r
513 \r
514                                         DoPrintf("Tmp =%s", TmpPath);\r
515                                         DoPrintf("Help=%s", HelpPath);\r
516 \r
517                                         DragAcceptFiles(GetRemoteHwnd(), TRUE);\r
518                                         DragAcceptFiles(GetLocalHwnd(), TRUE);\r
519 \r
520                                         SetAllHistoryToMenu();\r
521                                         GetLocalDirForWnd();\r
522                                         MakeButtonsFocus();\r
523                                         DispTransferFiles();\r
524 \r
525                                         StartupProc(lpszCmdLine);\r
526                                         sts = FFFTP_SUCCESS;\r
527 \r
528                                         /* セキュリティ警告文の表示 */\r
529                                         if( useDefautPassword ){\r
530                                                 SetTaskMsg(MSGJPN300);\r
531                                         }\r
532                                         \r
533                                         /* パスワード不一致警告文の表示 */\r
534                                         switch( GetMasterPasswordStatus() ){\r
535                                         case PASSWORD_UNMATCH:\r
536                                                 SetTaskMsg(MSGJPN301);\r
537                                                 break;\r
538                                         case BAD_PASSWORD_HASH:\r
539                                                 SetTaskMsg(MSGJPN302);\r
540                                                 break;\r
541                                         default:\r
542                                                 break;\r
543                                         }\r
544                                 }\r
545                         }\r
546                 }\r
547         }\r
548 \r
549         // 暗号化通信対応\r
550 #ifdef USE_OPENSSL\r
551         if(IsOpenSSLLoaded())\r
552                 SetTaskMsg(MSGJPN318);\r
553         else\r
554                 SetTaskMsg(MSGJPN319);\r
555 #endif\r
556 \r
557         if(sts == FFFTP_FAIL)\r
558                 DeleteAllObject();\r
559 \r
560         return(sts);\r
561 }\r
562 \r
563 \r
564 /*----- ウインドウを作成する --------------------------------------------------\r
565 *\r
566 *       Parameter\r
567 *               int cmdShow : 最初に表示するウインドウの形式。\r
568 *\r
569 *       Return Value\r
570 *               int ステータス\r
571 *                       FFFTP_SUCCESS/FFFTP_FAIL\r
572 *----------------------------------------------------------------------------*/\r
573 \r
574 static int MakeAllWindows(int cmdShow)\r
575 {\r
576         RECT Rect1;\r
577         RECT Rect2;\r
578         WNDCLASSEX wClass;\r
579         int Sts;\r
580         int StsTask;\r
581         int StsSbar;\r
582         int StsTbar;\r
583         int StsList;\r
584         int StsLvtips;\r
585         int StsSocket;\r
586 \r
587         /*===== メインウインドウ =====*/\r
588 \r
589         RootColorBrush = CreateSolidBrush(GetSysColor(COLOR_3DFACE));\r
590 \r
591         wClass.cbSize = sizeof(WNDCLASSEX);\r
592         wClass.style         = 0;\r
593         wClass.lpfnWndProc   = FtpWndProc;\r
594         wClass.cbClsExtra    = 0;\r
595         wClass.cbWndExtra    = 0;\r
596         wClass.hInstance     = hInstFtp;\r
597         wClass.hIcon         = LoadIcon(hInstFtp, MAKEINTRESOURCE(ffftp));\r
598         wClass.hCursor       = NULL;\r
599         wClass.hbrBackground = RootColorBrush;\r
600         wClass.lpszMenuName  = (LPSTR)MAKEINTRESOURCE(main_menu);\r
601         wClass.lpszClassName = FtpClassStr;\r
602         wClass.hIconSm       = NULL;\r
603         RegisterClassEx(&wClass);\r
604 \r
605         if(SaveWinPos == NO)\r
606         {\r
607                 WinPosX = CW_USEDEFAULT;\r
608                 WinPosY = 0;\r
609         }\r
610         // UTF-8対応\r
611         // ユーザー定義のクラスはデフォルトのWNDPROCがShift_JIS専用のため\r
612 //      hWndFtp = CreateWindow(FtpClassStr, "FFFTP",\r
613 //                              WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,\r
614 //                              WinPosX, WinPosY, WinWidth, WinHeight,\r
615 //                              HWND_DESKTOP, 0, hInstFtp, NULL);\r
616         hWndFtp = CreateWindowA(FtpClassStr, "FFFTP",\r
617                                 WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,\r
618                                 WinPosX, WinPosY, WinWidth, WinHeight,\r
619                                 HWND_DESKTOP, 0, hInstFtp, NULL);\r
620 \r
621         if(hWndFtp != NULL)\r
622         {\r
623                 SystemParametersInfo(SPI_GETWORKAREA, 0, &Rect1, 0);\r
624                 GetWindowRect(hWndFtp, &Rect2);\r
625                 if(Rect2.bottom > Rect1.bottom)\r
626                 {\r
627                         Rect2.top = max1(0, Rect2.top - (Rect2.bottom - Rect1.bottom));\r
628                         MoveWindow(hWndFtp, Rect2.left, Rect2.top, WinWidth, WinHeight, FALSE);\r
629                 }\r
630 \r
631                 /*===== ステイタスバー =====*/\r
632 \r
633                 StsSbar = MakeStatusBarWindow(hWndFtp, hInstFtp);\r
634 \r
635                 CalcWinSize();\r
636 \r
637                 /*===== ツールバー =====*/\r
638 \r
639                 StsTbar = MakeToolBarWindow(hWndFtp, hInstFtp);\r
640 \r
641                 /*===== ファイルリストウインドウ =====*/\r
642 \r
643                 StsList = MakeListWin(hWndFtp, hInstFtp);\r
644 \r
645                 /*==== タスクウインドウ ====*/\r
646 \r
647                 StsTask = MakeTaskWindow(hWndFtp, hInstFtp);\r
648 \r
649                 if((cmdShow != SW_MINIMIZE) && (cmdShow != SW_SHOWMINIMIZED) && (cmdShow != SW_SHOWMINNOACTIVE) &&\r
650                    (Sizing == SW_MAXIMIZE))\r
651                         cmdShow = SW_MAXIMIZE;\r
652 \r
653                 ShowWindow(hWndFtp, cmdShow);\r
654 \r
655                 /*==== ソケットウインドウ ====*/\r
656 \r
657                 StsSocket = MakeSocketWin(hWndFtp, hInstFtp);\r
658 \r
659                 StsLvtips = InitListViewTips(hWndFtp, hInstFtp);\r
660         }\r
661 \r
662         Sts = FFFTP_SUCCESS;\r
663         if((hWndFtp == NULL) ||\r
664            (StsTbar == FFFTP_FAIL) ||\r
665            (StsList == FFFTP_FAIL) ||\r
666            (StsSbar == FFFTP_FAIL) ||\r
667            (StsTask == FFFTP_FAIL) ||\r
668            (StsLvtips == FFFTP_FAIL) ||\r
669            (StsSocket == FFFTP_FAIL))\r
670         {\r
671                 Sts = FFFTP_FAIL;\r
672         }\r
673 \r
674         if(Sts == FFFTP_SUCCESS)\r
675                 SetListViewType();\r
676 \r
677         return(Sts);\r
678 }\r
679 \r
680 \r
681 /*----- ウインドウのタイトルを表示する ----------------------------------------\r
682 *\r
683 *       Parameter\r
684 *               なし\r
685 *\r
686 *       Return Value\r
687 *               なし\r
688 *----------------------------------------------------------------------------*/\r
689 \r
690 void DispWindowTitle(void)\r
691 {\r
692         char Tmp[HOST_ADRS_LEN+FILTER_EXT_LEN+20];\r
693 \r
694         if(AskConnecting() == YES)\r
695                 sprintf(Tmp, "%s (%s) - FFFTP", TitleHostName, FilterStr);\r
696         else\r
697                 sprintf(Tmp, "FFFTP (%s)", FilterStr);\r
698 \r
699         SetWindowText(GetMainHwnd(), Tmp);\r
700         return;\r
701 }\r
702 \r
703 \r
704 /*----- 全てのオブジェクトを削除 ----------------------------------------------\r
705 *\r
706 *       Parameter\r
707 *               なし\r
708 *\r
709 *       Return Value\r
710 *               なし\r
711 *----------------------------------------------------------------------------*/\r
712 \r
713 static void DeleteAllObject(void)\r
714 {\r
715         DeleteCacheBuf();\r
716 \r
717 //move to WM_DESTROY\r
718         WSACleanup();\r
719 \r
720 //test システム任せ\r
721 //      if(ListFont != NULL)\r
722 //              DeleteObject(ListFont);\r
723 //      if(RootColorBrush != NULL)\r
724 //              DeleteObject(RootColorBrush);\r
725 \r
726 //test システム任せ\r
727 //      DeleteListViewTips();\r
728 //      DeleteListWin();\r
729 //      DeleteStatusBarWindow();\r
730 //      DeleteTaskWindow();\r
731 //      DeleteToolBarWindow();\r
732 //      DeleteSocketWin();\r
733 \r
734 //move to WM_DESTROY\r
735         if(hWndFtp != NULL)\r
736                 DestroyWindow(hWndFtp);\r
737 \r
738         ReleaseJre();\r
739         ReleaseRasLib();\r
740         ReleaseKernelLib();\r
741 \r
742         return;\r
743 }\r
744 \r
745 \r
746 /*----- メインウインドウのウインドウハンドルを返す ----------------------------\r
747 *\r
748 *       Parameter\r
749 *               なし\r
750 *\r
751 *       Return Value\r
752 *               HWND ウインドウハンドル\r
753 *----------------------------------------------------------------------------*/\r
754 \r
755 HWND GetMainHwnd(void)\r
756 {\r
757         return(hWndFtp);\r
758 }\r
759 \r
760 \r
761 /*----- 現在フォーカスがあるウインドウのウインドウハンドルを返す --------------\r
762 *\r
763 *       Parameter\r
764 *               なし\r
765 *\r
766 *       Return Value\r
767 *               HWND ウインドウハンドル\r
768 *----------------------------------------------------------------------------*/\r
769 \r
770 HWND GetFocusHwnd(void)\r
771 {\r
772         return(hWndCurFocus);\r
773 }\r
774 \r
775 \r
776 /*----- 現在フォーカスがあるウインドウのをセットする --------------------------\r
777 *\r
778 *       Parameter\r
779 *               HWND hWnd : ウインドウハンドル\r
780 *\r
781 *       Return Value\r
782 *               なし\r
783 *----------------------------------------------------------------------------*/\r
784 \r
785 void SetFocusHwnd(HWND hWnd)\r
786 {\r
787         hWndCurFocus = hWnd;\r
788         return;\r
789 }\r
790 \r
791 \r
792 /*----- プログラムのインスタンスを返す ----------------------------------------\r
793 *\r
794 *       Parameter\r
795 *               なし\r
796 *\r
797 *       Return Value\r
798 *               HINSTANCE インスタンス\r
799 *----------------------------------------------------------------------------*/\r
800 \r
801 HINSTANCE GetFtpInst(void)\r
802 {\r
803         return(hInstFtp);\r
804 }\r
805 \r
806 \r
807 /*----- メインウインドウのメッセージ処理 --------------------------------------\r
808 *\r
809 *       Parameter\r
810 *               HWND hWnd : ウインドウハンドル\r
811 *               UINT message  : メッセージ番号\r
812 *               WPARAM wParam : メッセージの WPARAM 引数\r
813 *               LPARAM lParam : メッセージの LPARAM 引数\r
814 *\r
815 *       Return Value\r
816 *               メッセージに対応する戻り値\r
817 *----------------------------------------------------------------------------*/\r
818 \r
819 static LRESULT CALLBACK FtpWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)\r
820 {\r
821         PAINTSTRUCT ps;\r
822         LPTOOLTIPTEXT lpttt;\r
823         RECT Rect;\r
824 \r
825         int TmpTransType;\r
826 \r
827         switch (message)\r
828         {\r
829                 case WM_COMMAND :\r
830                         switch(LOWORD(wParam))\r
831                         {\r
832                                 case MENU_CONNECT :\r
833                                         ConnectProc(DLG_TYPE_CON, -1);\r
834                                         break;\r
835 \r
836                                 case MENU_CONNECT_NUM :\r
837                                         ConnectProc(DLG_TYPE_CON, (int)lParam);\r
838                                         if(AskConnecting() == YES)\r
839                                         {\r
840                                                 if(HIWORD(wParam) & OPT_MIRROR)\r
841                                                 {\r
842                                                         if(HIWORD(wParam) & OPT_FORCE)\r
843                                                                 MirrorUploadProc(NO);\r
844                                                         else\r
845                                                                 MirrorUploadProc(YES);\r
846                                                 }\r
847                                                 else if(HIWORD(wParam) & OPT_MIRRORDOWN)\r
848                                                 {\r
849                                                         if(HIWORD(wParam) & OPT_FORCE)\r
850                                                                 MirrorDownloadProc(NO);\r
851                                                         else\r
852                                                                 MirrorDownloadProc(YES);\r
853                                                 }\r
854                                         }\r
855                                         break;\r
856 \r
857                                 case MENU_SET_CONNECT :\r
858                                         ConnectProc(DLG_TYPE_SET, -1);\r
859                                         break;\r
860 \r
861                                 case MENU_QUICK :\r
862                                         QuickConnectProc();\r
863                                         break;\r
864 \r
865                                 case MENU_DISCONNECT :\r
866                                         if(AskTryingConnect() == YES)\r
867                                                 CancelFlg = YES;\r
868                                         else if(AskConnecting() == YES)\r
869                                         {\r
870                                                 SaveBookMark();\r
871                                                 SaveCurrentSetToHost();\r
872                                                 DisconnectProc();\r
873                                         }\r
874                                         break;\r
875 \r
876                                 case MENU_HIST_1 :\r
877                                 case MENU_HIST_2 :\r
878                                 case MENU_HIST_3 :\r
879                                 case MENU_HIST_4 :\r
880                                 case MENU_HIST_5 :\r
881                                 case MENU_HIST_6 :\r
882                                 case MENU_HIST_7 :\r
883                                 case MENU_HIST_8 :\r
884                                 case MENU_HIST_9 :\r
885                                 case MENU_HIST_10 :\r
886                                 case MENU_HIST_11 :\r
887                                 case MENU_HIST_12 :\r
888                                 case MENU_HIST_13 :\r
889                                 case MENU_HIST_14 :\r
890                                 case MENU_HIST_15 :\r
891                                 case MENU_HIST_16 :\r
892                                 case MENU_HIST_17 :\r
893                                 case MENU_HIST_18 :\r
894                                 case MENU_HIST_19 :\r
895                                 case MENU_HIST_20 :\r
896                                         HistoryConnectProc(LOWORD(wParam));\r
897                                         break;\r
898 \r
899                                 case MENU_UPDIR :\r
900                                         if(hWndCurFocus == GetLocalHwnd())\r
901                                                 PostMessage(hWnd, WM_COMMAND, MAKEWPARAM(MENU_LOCAL_UPDIR, 0), 0);\r
902                                         else\r
903                                                 PostMessage(hWnd, WM_COMMAND, MAKEWPARAM(MENU_REMOTE_UPDIR, 0), 0);\r
904                                         break;\r
905 \r
906                                 case MENU_DCLICK :\r
907                                         if(hWndCurFocus == GetLocalHwnd())\r
908                                                 DoubleClickProc(WIN_LOCAL, YES, -1);\r
909                                         else\r
910                                         {\r
911                                                 SuppressRefresh = 1;\r
912                                                 DoubleClickProc(WIN_REMOTE, YES, -1);\r
913                                                 SuppressRefresh = 0;\r
914                                         }\r
915                                         break;\r
916 \r
917                                 case MENU_OPEN1 :\r
918                                         if(hWndCurFocus == GetLocalHwnd())\r
919                                                 DoubleClickProc(WIN_LOCAL, YES, 0);\r
920                                         else\r
921                                         {\r
922                                                 SuppressRefresh = 1;\r
923                                                 DoubleClickProc(WIN_REMOTE, YES, 0);\r
924                                                 SuppressRefresh = 0;\r
925                                         }\r
926                                         break;\r
927 \r
928                                 case MENU_OPEN2 :\r
929                                         if(hWndCurFocus == GetLocalHwnd())\r
930                                                 DoubleClickProc(WIN_LOCAL, YES, 1);\r
931                                         else\r
932                                         {\r
933                                                 SuppressRefresh = 1;\r
934                                                 DoubleClickProc(WIN_REMOTE, YES, 1);\r
935                                                 SuppressRefresh = 0;\r
936                                         }\r
937                                         break;\r
938 \r
939                                 case MENU_OPEN3 :\r
940                                         if(hWndCurFocus == GetLocalHwnd())\r
941                                                 DoubleClickProc(WIN_LOCAL, YES, 2);\r
942                                         else\r
943                                         {\r
944                                                 SuppressRefresh = 1;\r
945                                                 DoubleClickProc(WIN_REMOTE, YES, 2);\r
946                                                 SuppressRefresh = 0;\r
947                                         }\r
948                                         break;\r
949 \r
950                                 case MENU_REMOTE_UPDIR :\r
951                                         SuppressRefresh = 1;\r
952                                         SetCurrentDirAsDirHist();\r
953                                         ChangeDir(WIN_REMOTE, "..");\r
954                                         SuppressRefresh = 0;\r
955                                         break;\r
956 \r
957                                 case MENU_LOCAL_UPDIR :\r
958                                         SetCurrentDirAsDirHist();\r
959                                         ChangeDir(WIN_LOCAL, "..");\r
960                                         break;\r
961 \r
962                                 case MENU_REMOTE_CHDIR :\r
963                                         SuppressRefresh = 1;\r
964                                         SetCurrentDirAsDirHist();\r
965                                         ChangeDirDirectProc(WIN_REMOTE);\r
966                                         SuppressRefresh = 0;\r
967                                         break;\r
968 \r
969                                 case MENU_LOCAL_CHDIR :\r
970                                         SetCurrentDirAsDirHist();\r
971                                         ChangeDirDirectProc(WIN_LOCAL);\r
972                                         break;\r
973 \r
974                                 case MENU_DOWNLOAD :\r
975                                         SetCurrentDirAsDirHist();\r
976                                         DownLoadProc(NO, NO, NO);\r
977                                         break;\r
978 \r
979                                 case MENU_DOWNLOAD_AS :\r
980                                         SetCurrentDirAsDirHist();\r
981                                         DownLoadProc(YES, NO, NO);\r
982                                         break;\r
983 \r
984                                 case MENU_DOWNLOAD_AS_FILE :\r
985                                         SetCurrentDirAsDirHist();\r
986                                         DownLoadProc(NO, YES, NO);\r
987                                         break;\r
988 \r
989                                 case MENU_DOWNLOAD_ALL :\r
990                                         SetCurrentDirAsDirHist();\r
991                                         DownLoadProc(NO, NO, YES);\r
992                                         break;\r
993 \r
994                                 case MENU_DOWNLOAD_NAME :\r
995                                         SetCurrentDirAsDirHist();\r
996                                         InputDownLoadProc();\r
997                                         break;\r
998 \r
999                                 case MENU_UPLOAD :\r
1000                                         SetCurrentDirAsDirHist();\r
1001                                         UpLoadListProc(NO, NO);\r
1002                                         break;\r
1003 \r
1004                                 case MENU_UPLOAD_AS :\r
1005                                         SetCurrentDirAsDirHist();\r
1006                                         UpLoadListProc(YES, NO);\r
1007                                         break;\r
1008 \r
1009                                 case MENU_UPLOAD_ALL :\r
1010                                         SetCurrentDirAsDirHist();\r
1011                                         UpLoadListProc(NO, YES);\r
1012                                         break;\r
1013 \r
1014                                 case MENU_MIRROR_UPLOAD :\r
1015                                         SetCurrentDirAsDirHist();\r
1016                                         MirrorUploadProc(YES);\r
1017                                         break;\r
1018 \r
1019                                 case MENU_MIRROR_DOWNLOAD :\r
1020                                         SetCurrentDirAsDirHist();\r
1021                                         MirrorDownloadProc(YES);\r
1022                                         break;\r
1023 \r
1024                                 case MENU_FILESIZE :\r
1025                                         SetCurrentDirAsDirHist();\r
1026                                         CalcFileSizeProc();\r
1027                                         break;\r
1028 \r
1029                                 case MENU_DELETE :\r
1030                                         SuppressRefresh = 1;\r
1031                                         SetCurrentDirAsDirHist();\r
1032                                         DeleteProc();\r
1033                                         SuppressRefresh = 0;\r
1034                                         break;\r
1035 \r
1036                                 case MENU_RENAME :\r
1037                                         SuppressRefresh = 1;\r
1038                                         SetCurrentDirAsDirHist();\r
1039                                         RenameProc();\r
1040                                         SuppressRefresh = 0;\r
1041                                         break;\r
1042 \r
1043                                 case MENU_MKDIR :\r
1044                                         SuppressRefresh = 1;\r
1045                                         SetCurrentDirAsDirHist();\r
1046                                         MkdirProc();\r
1047                                         SuppressRefresh = 0;\r
1048                                         break;\r
1049 \r
1050                                 case MENU_CHMOD :\r
1051                                         SuppressRefresh = 1;\r
1052                                         ChmodProc();\r
1053                                         SuppressRefresh = 0;\r
1054                                         break;\r
1055 \r
1056                                 case MENU_SOMECMD :\r
1057                                         SuppressRefresh = 1;\r
1058                                         SomeCmdProc();\r
1059                                         SuppressRefresh = 0;\r
1060                                         break;\r
1061 \r
1062                                 case MENU_OPTION :\r
1063                                         SetOption(0);\r
1064                                         if(ListFont != NULL)\r
1065                                         {\r
1066                                                 SendMessage(GetLocalHwnd(), WM_SETFONT, (WPARAM)ListFont, MAKELPARAM(TRUE, 0));\r
1067                                                 SendMessage(GetRemoteHwnd(), WM_SETFONT, (WPARAM)ListFont, MAKELPARAM(TRUE, 0));\r
1068                                                 SendMessage(GetTaskWnd(), WM_SETFONT, (WPARAM)ListFont, MAKELPARAM(TRUE, 0));\r
1069                                         }\r
1070                                         GetLocalDirForWnd();\r
1071                                         DispTransferType();\r
1072                                         CheckHistoryNum(0);\r
1073                                         SetAllHistoryToMenu();\r
1074                                         // 暗号化通信対応\r
1075                                         SetSSLTimeoutCallback(TimeOut * 1000, SSLTimeoutCallback);\r
1076                                         break;\r
1077 \r
1078                                 case MENU_FILTER :\r
1079                                         SetFilter(&CancelFlg);\r
1080                                         break;\r
1081 \r
1082                                 case MENU_SORT :\r
1083                                         if(SortSetting() == YES)\r
1084                                         {\r
1085                                                 LocalFileSort = AskSortType(ITEM_LFILE);\r
1086                                                 LocalDirSort = AskSortType(ITEM_LDIR);\r
1087                                                 RemoteFileSort = AskSortType(ITEM_RFILE);\r
1088                                                 RemoteDirSort = AskSortType(ITEM_RDIR);\r
1089                                                 ReSortDispList(WIN_LOCAL, &CancelFlg);\r
1090                                                 ReSortDispList(WIN_REMOTE, &CancelFlg);\r
1091                                         }\r
1092                                         break;\r
1093 \r
1094                                 case MENU_EXIT :\r
1095                                         PostMessage(hWnd, WM_CLOSE, 0, 0L);\r
1096                                         break;\r
1097 \r
1098                                 case MENU_AUTO_EXIT :\r
1099                                         if(AutoExit == YES)\r
1100                                                 PostMessage(hWnd, WM_CLOSE, 0, 0L);\r
1101                                         break;\r
1102 \r
1103                                 case MENU_ABOUT :\r
1104                                         DialogBox(hInstFtp, MAKEINTRESOURCE(about_dlg), hWnd, AboutDialogProc);\r
1105                                         break;\r
1106 \r
1107                                 case MENU_TEXT :\r
1108                                 case MENU_BINARY :\r
1109                                 case MENU_AUTO :\r
1110                                         SetTransferType(LOWORD(wParam));\r
1111                                         DispTransferType();\r
1112                                         break;\r
1113 \r
1114                                 case MENU_XFRMODE :\r
1115                                         switch(AskTransferType())\r
1116                                         {\r
1117                                                 case TYPE_A :\r
1118                                                         TmpTransType = MENU_BINARY;\r
1119                                                         break;\r
1120 \r
1121                                                 case TYPE_I :\r
1122                                                         TmpTransType = MENU_AUTO;\r
1123                                                         break;\r
1124 \r
1125                                                 default :\r
1126                                                         TmpTransType = MENU_TEXT;\r
1127                                                         break;\r
1128                                         }\r
1129                                         SetTransferType(TmpTransType);\r
1130                                         DispTransferType();\r
1131                                         break;\r
1132 \r
1133                                 // UTF-8対応\r
1134                                 case MENU_KNJ_SJIS :\r
1135                                 case MENU_KNJ_EUC :\r
1136                                 case MENU_KNJ_JIS :\r
1137                                 case MENU_KNJ_UTF8N :\r
1138                                 case MENU_KNJ_NONE :\r
1139                                         SetHostKanjiCode(LOWORD(wParam));\r
1140                                         break;\r
1141 \r
1142                                 case MENU_L_KNJ_SJIS :\r
1143                                 case MENU_L_KNJ_EUC :\r
1144                                 case MENU_L_KNJ_JIS :\r
1145                                 case MENU_L_KNJ_UTF8N :\r
1146                                         SetLocalKanjiCode(LOWORD(wParam));\r
1147                                         break;\r
1148 \r
1149                                 case MENU_KANACNV :\r
1150                                         SetHostKanaCnv();\r
1151                                         break;\r
1152 \r
1153                                 case MENU_REFRESH :\r
1154                                         SuppressRefresh = 1;\r
1155                                         GetLocalDirForWnd();\r
1156                                         if(CheckClosedAndReconnect() == FFFTP_SUCCESS)\r
1157                                                 GetRemoteDirForWnd(CACHE_REFRESH, &CancelFlg);\r
1158                                         SuppressRefresh = 0;\r
1159                                         break;\r
1160 \r
1161                                 case MENU_LIST :\r
1162                                         ListType = LVS_LIST;\r
1163                                         DispListType();\r
1164                                         SetListViewType();\r
1165                                         break;\r
1166 \r
1167                                 case MENU_REPORT :\r
1168                                         ListType = LVS_REPORT;\r
1169                                         DispListType();\r
1170                                         SetListViewType();\r
1171                                         break;\r
1172 \r
1173                                 case REFRESH_LOCAL :\r
1174                                         GetLocalDirForWnd();\r
1175                                         break;\r
1176 \r
1177                                 case REFRESH_REMOTE :\r
1178                                         SuppressRefresh = 1;\r
1179                                         if(CheckClosedAndReconnect() == FFFTP_SUCCESS)\r
1180                                                 GetRemoteDirForWnd(CACHE_REFRESH, &CancelFlg);\r
1181                                         SuppressRefresh = 0;\r
1182                                         break;\r
1183 \r
1184                                 case COMBO_LOCAL :\r
1185                                 case COMBO_REMOTE :\r
1186                                         SuppressRefresh = 1;\r
1187                                         if(HIWORD(wParam) == CBN_SELCHANGE)\r
1188                                         {\r
1189                                                 SetCurrentDirAsDirHist();\r
1190                                                 ChangeDirComboProc((HWND)lParam);\r
1191                                         }\r
1192                                         else if(HIWORD(wParam) != CBN_CLOSEUP)\r
1193                                         {\r
1194                                                 MakeButtonsFocus();\r
1195                                                 SuppressRefresh = 0;\r
1196                                                 return(0);\r
1197                                         }\r
1198                                         SuppressRefresh = 0;\r
1199                                         break;\r
1200 \r
1201                                 case MENU_HELP :\r
1202                                         hHelpWin = HtmlHelp(NULL, AskHelpFilePath(), HH_HELP_CONTEXT, IDH_HELP_TOPIC_0000001);\r
1203                                         break;\r
1204 \r
1205                                 case MENU_HELP_TROUBLE :\r
1206                                         ShellExecute(NULL, "open", MYWEB_URL, NULL, ".", SW_SHOW);\r
1207                                         break;\r
1208 \r
1209                                 case MENU_BMARK_ADD :\r
1210                                         AddCurDirToBookMark(WIN_REMOTE);\r
1211                                         break;\r
1212 \r
1213                                 case MENU_BMARK_ADD_LOCAL :\r
1214                                         AddCurDirToBookMark(WIN_LOCAL);\r
1215                                         break;\r
1216 \r
1217                                 case MENU_BMARK_ADD_BOTH :\r
1218                                         AddCurDirToBookMark(WIN_BOTH);\r
1219                                         break;\r
1220 \r
1221                                 case MENU_BMARK_EDIT :\r
1222                                         EditBookMark();\r
1223                                         break;\r
1224 \r
1225                                 case MENU_SELECT_ALL :\r
1226                                         SelectFileInList(hWndCurFocus, SELECT_ALL);\r
1227                                         break;\r
1228 \r
1229                                 case MENU_SELECT :\r
1230                                         SelectFileInList(hWndCurFocus, SELECT_REGEXP);\r
1231                                         break;\r
1232 \r
1233                                 case MENU_FIND :\r
1234                                         FindFileInList(hWndCurFocus, FIND_FIRST);\r
1235                                         break;\r
1236 \r
1237                                 case MENU_FINDNEXT :\r
1238                                         FindFileInList(hWndCurFocus, FIND_NEXT);\r
1239                                         break;\r
1240 \r
1241                                 case MENU_DOTFILE :\r
1242                                         DotFile ^= 1;\r
1243                                         DispDotFileMode();\r
1244                                         GetLocalDirForWnd();\r
1245                                         GetRemoteDirForWnd(CACHE_LASTREAD, &CancelFlg);\r
1246                                         break;\r
1247 \r
1248                                 case MENU_SYNC :\r
1249                                         ToggleSyncMoveMode();\r
1250                                         break;\r
1251 \r
1252                                 case MENU_IMPORT_WS :\r
1253                                         ImportFromWSFTP();\r
1254                                         break;\r
1255 \r
1256                                 case MENU_REGSAVE :\r
1257                                         GetListTabWidth();\r
1258                                         SaveRegistory();\r
1259                                         SaveSettingsToFile();\r
1260                                         break;\r
1261 \r
1262                                 case MENU_REGLOAD :\r
1263                                         if(LoadSettingsFromFile() == YES)\r
1264                                         {\r
1265                                                 MessageBox(hWnd, MSGJPN292, "FFFTP", MB_OK);\r
1266                                                 SaveExit = NO;\r
1267                                                 PostMessage(hWnd, WM_CLOSE, 0, 0L);\r
1268                                         }\r
1269                                         break;\r
1270 \r
1271                                 case MENU_REGINIT :\r
1272                                         if(DialogBox(hInstFtp, MAKEINTRESOURCE(reginit_dlg), hWnd, ExeEscDialogProc) == YES)\r
1273                                         {\r
1274                                                 ClearRegistory();\r
1275                                                 SaveExit = NO;\r
1276                                                 PostMessage(hWnd, WM_CLOSE, 0, 0L);\r
1277                                         }\r
1278                                         break;\r
1279                                 case MENU_CHANGEPASSWD: /* 2010.01.31 genta */\r
1280                                         if( GetMasterPasswordStatus() != PASSWORD_OK )\r
1281                                         {\r
1282                                                 /* 強制的に設定するか確認 */\r
1283                                                 if( DialogBox(hInstFtp, MAKEINTRESOURCE(forcepasschange_dlg), hWnd, ExeEscDialogProc) != YES){\r
1284                                                         break;\r
1285                                                 }\r
1286                                         }\r
1287                                         if( EnterMasterPasswordAndSet( newmasterpasswd_dlg, hWnd ) != 0 ){\r
1288                                                 SetTaskMsg( MSGJPN303 );\r
1289                                         }\r
1290                                         break;\r
1291 \r
1292                                 case MENU_DIRINFO :\r
1293                                         DispDirInfo();\r
1294                                         break;\r
1295 \r
1296                                 case MENU_TASKINFO :\r
1297                                         DispTaskMsg();\r
1298                                         break;\r
1299 \r
1300                                 case MENU_ABORT :\r
1301                                         CancelFlg = YES;\r
1302                                         if(AskTryingConnect() == NO)\r
1303                                                 MainTransPkt.Abort = ABORT_USER;\r
1304                                         break;\r
1305 \r
1306                                 case MENU_OTPCALC :\r
1307                                         OtpCalcTool();\r
1308                                         break;\r
1309 \r
1310                                 case MENU_URL_COPY :\r
1311                                         CopyURLtoClipBoard();\r
1312                                         break;\r
1313 \r
1314                                 case MENU_APPKEY :\r
1315                                         EraseListViewTips();\r
1316                                         if(hWndCurFocus == GetRemoteHwnd())\r
1317                                                 RemoteRbuttonMenu(1);\r
1318                                         else if(hWndCurFocus == GetLocalHwnd())\r
1319                                                 LocalRbuttonMenu(1);\r
1320                                         break;\r
1321 \r
1322                                 default :\r
1323                                         if((LOWORD(wParam) >= MENU_BMARK_TOP) &&\r
1324                                            (LOWORD(wParam) < MENU_BMARK_TOP+100))\r
1325                                         {\r
1326                                                 ChangeDirBmarkProc(LOWORD(wParam));\r
1327                                         }\r
1328                                         break;\r
1329                         }\r
1330 // 常にホストかローカルへフォーカスを移動\r
1331 //                      SetFocus(hWndCurFocus);\r
1332                         MakeButtonsFocus();\r
1333                         break;\r
1334 \r
1335                 case WM_NOTIFY :\r
1336                         switch(((LPNMHDR)lParam)->code)\r
1337                         {\r
1338                                 /* ツールチップコントロールメッセージの処理 */\r
1339                                 case TTN_NEEDTEXT:\r
1340                                         lpttt = (LPTOOLTIPTEXT)lParam;\r
1341                                         lpttt->hinst = hInstFtp;\r
1342                                         switch(lpttt->hdr.idFrom)\r
1343                                         {\r
1344                                                 case MENU_CONNECT :\r
1345                                                         lpttt->lpszText = MSGJPN154;\r
1346                                                         break;\r
1347 \r
1348                                                 case MENU_QUICK :\r
1349                                                         lpttt->lpszText = MSGJPN155;\r
1350                                                         break;\r
1351 \r
1352                                                 case MENU_DISCONNECT :\r
1353                                                         lpttt->lpszText = MSGJPN156;\r
1354                                                         break;\r
1355 \r
1356                                                 case MENU_DOWNLOAD :\r
1357                                                         lpttt->lpszText = MSGJPN157;\r
1358                                                         break;\r
1359 \r
1360                                                 case MENU_UPLOAD :\r
1361                                                         lpttt->lpszText = MSGJPN158;\r
1362                                                         break;\r
1363 \r
1364                                                 case MENU_MIRROR_UPLOAD :\r
1365                                                         lpttt->lpszText = MSGJPN159;\r
1366                                                         break;\r
1367 \r
1368                                                 case MENU_DELETE :\r
1369                                                         lpttt->lpszText = MSGJPN160;\r
1370                                                         break;\r
1371 \r
1372                                                 case MENU_RENAME :\r
1373                                                         lpttt->lpszText = MSGJPN161;\r
1374                                                         break;\r
1375 \r
1376                                                 case MENU_MKDIR :\r
1377                                                         lpttt->lpszText = MSGJPN162;\r
1378                                                         break;\r
1379 \r
1380                                                 case MENU_LOCAL_UPDIR :\r
1381                                                 case MENU_REMOTE_UPDIR :\r
1382                                                         lpttt->lpszText = MSGJPN163;\r
1383                                                         break;\r
1384 \r
1385                                                 case MENU_LOCAL_CHDIR :\r
1386                                                 case MENU_REMOTE_CHDIR :\r
1387                                                         lpttt->lpszText = MSGJPN164;\r
1388                                                         break;\r
1389 \r
1390                                                 case MENU_TEXT :\r
1391                                                         lpttt->lpszText = MSGJPN165;\r
1392                                                         break;\r
1393 \r
1394                                                 case MENU_BINARY :\r
1395                                                         lpttt->lpszText = MSGJPN166;\r
1396                                                         break;\r
1397 \r
1398                                                 case MENU_AUTO :\r
1399                                                         lpttt->lpszText = MSGJPN167;\r
1400                                                         break;\r
1401 \r
1402                                                 case MENU_REFRESH :\r
1403                                                         lpttt->lpszText = MSGJPN168;\r
1404                                                         break;\r
1405 \r
1406                                                 case MENU_LIST :\r
1407                                                         lpttt->lpszText = MSGJPN169;\r
1408                                                         break;\r
1409 \r
1410                                                 case MENU_REPORT :\r
1411                                                         lpttt->lpszText = MSGJPN170;\r
1412                                                         break;\r
1413 \r
1414                                                 case MENU_KNJ_SJIS :\r
1415                                                         lpttt->lpszText = MSGJPN307;\r
1416                                                         break;\r
1417 \r
1418                                                 case MENU_KNJ_EUC :\r
1419                                                         lpttt->lpszText = MSGJPN171;\r
1420                                                         break;\r
1421 \r
1422                                                 case MENU_KNJ_JIS :\r
1423                                                         lpttt->lpszText = MSGJPN172;\r
1424                                                         break;\r
1425 \r
1426                                                 case MENU_KNJ_UTF8N :\r
1427                                                         lpttt->lpszText = MSGJPN308;\r
1428                                                         break;\r
1429 \r
1430                                                 case MENU_KNJ_NONE :\r
1431                                                         lpttt->lpszText = MSGJPN173;\r
1432                                                         break;\r
1433 \r
1434                                                 case MENU_L_KNJ_SJIS :\r
1435                                                         lpttt->lpszText = MSGJPN309;\r
1436                                                         break;\r
1437 \r
1438                                                 case MENU_L_KNJ_EUC :\r
1439                                                         lpttt->lpszText = MSGJPN310;\r
1440                                                         break;\r
1441 \r
1442                                                 case MENU_L_KNJ_JIS :\r
1443                                                         lpttt->lpszText = MSGJPN311;\r
1444                                                         break;\r
1445 \r
1446                                                 case MENU_L_KNJ_UTF8N :\r
1447                                                         lpttt->lpszText = MSGJPN312;\r
1448                                                         break;\r
1449 \r
1450                                                 case MENU_KANACNV :\r
1451                                                         lpttt->lpszText = MSGJPN174;\r
1452                                                         break;\r
1453 \r
1454                                                 case MENU_SYNC :\r
1455                                                         lpttt->lpszText = MSGJPN175;\r
1456                                                         break;\r
1457 \r
1458                                                 case MENU_ABORT :\r
1459                                                         lpttt->lpszText = MSGJPN176;\r
1460                                                         break;\r
1461                                         }\r
1462                                         // UTF-8からShift_JISへ変換\r
1463                                         {\r
1464                                                 static wchar_t StringBufferUTF16[1024];\r
1465                                                 static char StringBufferSJIS[1024];\r
1466                                                 if(lpttt->lpszText)\r
1467                                                 {\r
1468                                                         MtoW(StringBufferUTF16, sizeof(StringBufferUTF16)/ sizeof(wchar_t), lpttt->lpszText, -1);\r
1469                                                         WtoA(StringBufferSJIS, sizeof(StringBufferSJIS)/ sizeof(char), StringBufferUTF16, -1);\r
1470                                                         lpttt->lpszText = StringBufferSJIS;\r
1471                                                 }\r
1472                                         }\r
1473                                         break;\r
1474 \r
1475                                 case LVN_COLUMNCLICK :\r
1476                                         if(((NMHDR *)lParam)->hwndFrom == GetLocalHwnd())\r
1477                                         {\r
1478                                                 SetSortTypeByColumn(WIN_LOCAL, ((NM_LISTVIEW *)lParam)->iSubItem);\r
1479                                                 ReSortDispList(WIN_LOCAL, &CancelFlg);\r
1480                                         }\r
1481                                         else if(((NMHDR *)lParam)->hwndFrom == GetRemoteHwnd())\r
1482                                         {\r
1483                                                 if(((NM_LISTVIEW *)lParam)->iSubItem != 4)\r
1484                                                 {\r
1485                                                         SetSortTypeByColumn(WIN_REMOTE, ((NM_LISTVIEW *)lParam)->iSubItem);\r
1486                                                         ReSortDispList(WIN_REMOTE, &CancelFlg);\r
1487                                                 }\r
1488                                         }\r
1489                                         SetFocus(hWndCurFocus);\r
1490                                         break;\r
1491 \r
1492                                 case LVN_ITEMCHANGED :\r
1493                                         DispSelectedSpace();\r
1494                                         MakeButtonsFocus();\r
1495                                         break;\r
1496                         }\r
1497                         break;\r
1498 \r
1499                 case WM_SIZE :\r
1500                         Sizing = SW_RESTORE;\r
1501                         if(wParam == SIZE_RESTORED)\r
1502                         {\r
1503                                 ResizeWindowProc();\r
1504                                 GetWindowRect(hWnd, &Rect);\r
1505                                 WinPosX = Rect.left;\r
1506                                 WinPosY = Rect.top;\r
1507                         }\r
1508                         else if(wParam == SIZE_MAXIMIZED)\r
1509                         {\r
1510                                 Sizing = SW_MAXIMIZE;\r
1511                                 ResizeWindowProc();\r
1512                         }\r
1513                         else\r
1514                                 return(DefWindowProc(hWnd, message, wParam, lParam));\r
1515                         break;\r
1516 \r
1517                 case WM_MOVING :\r
1518                         WinPosX = ((RECT *)lParam)->left;\r
1519                         WinPosY = ((RECT *)lParam)->top;\r
1520                         return(DefWindowProc(hWnd, message, wParam, lParam));\r
1521 \r
1522                 case WM_SETFOCUS :\r
1523                         SetFocus(hWndCurFocus);\r
1524                         break;\r
1525 \r
1526                 case WM_LBUTTONDOWN :\r
1527                 case WM_LBUTTONUP :\r
1528                 case WM_MOUSEMOVE :\r
1529                         CheckResizeFrame(wParam, LOWORD(lParam), HIWORD(lParam));\r
1530                         break;\r
1531 \r
1532                 case WM_CHANGE_COND :\r
1533                         DispTransferFiles();\r
1534                         break;\r
1535 \r
1536                 case WM_REFRESH_LOCAL_FLG :\r
1537                         PostMessage(hWnd,  WM_COMMAND, MAKEWPARAM(REFRESH_LOCAL, 0), 0);\r
1538                         break;\r
1539 \r
1540                 case WM_REFRESH_REMOTE_FLG :\r
1541                         if(SuppressRefresh == 0)\r
1542                                 PostMessage(hWnd,  WM_COMMAND, MAKEWPARAM(REFRESH_REMOTE, 0), 0);\r
1543                         break;\r
1544 \r
1545                 case WM_PAINT :\r
1546                     BeginPaint(hWnd, (LPPAINTSTRUCT) &ps);\r
1547                     EndPaint(hWnd, (LPPAINTSTRUCT) &ps);\r
1548                         break;\r
1549 \r
1550                 case WM_DESTROY :\r
1551 //                      WSACleanup();\r
1552 //                      DestroyWindow(hWndFtp);\r
1553                         PostQuitMessage(0);\r
1554                         break;\r
1555 \r
1556                 case WM_QUERYENDSESSION :\r
1557                         ExitProc(hWnd);\r
1558                         return(TRUE);\r
1559 \r
1560                 case WM_CLOSE :\r
1561                         if((AskTransferNow() == NO) ||\r
1562                            (DialogBox(hInstFtp, MAKEINTRESOURCE(exit_dlg), hWnd, ExeEscDialogProc) == YES))\r
1563                         {\r
1564                                 ExitProc(hWnd);\r
1565                                 return(DefWindowProc(hWnd, message, wParam, lParam));\r
1566                         }\r
1567                         break;\r
1568 \r
1569                 default :\r
1570                         return(DefWindowProc(hWnd, message, wParam, lParam));\r
1571         }\r
1572     return(0L);\r
1573 }\r
1574 \r
1575 \r
1576 /*----- プログラム開始時の処理 ------------------------------------------------\r
1577 *\r
1578 *       Parameter\r
1579 *               char *Cmd : コマンドライン文字列\r
1580 *\r
1581 *       Return Value\r
1582 *               なし\r
1583 *----------------------------------------------------------------------------*/\r
1584 \r
1585 static void StartupProc(char *Cmd)\r
1586 {\r
1587         int Sts;\r
1588         int AutoConnect;\r
1589         int CmdOption;\r
1590         int Kanji;\r
1591         int Kana;\r
1592         int FnameKanji;\r
1593         int TrMode;\r
1594         char unc[FMAX_PATH+1];\r
1595 \r
1596         Sts = AnalyzeComLine(Cmd, &AutoConnect, &CmdOption, unc, FMAX_PATH);\r
1597 \r
1598         TrMode = TYPE_DEFAULT;\r
1599         Kanji = KANJI_NOCNV;\r
1600         FnameKanji = KANJI_NOCNV;\r
1601         Kana = YES;\r
1602         if(CmdOption & OPT_ASCII)\r
1603                 TrMode = TYPE_A;\r
1604         if(CmdOption & OPT_BINARY)\r
1605                 TrMode = TYPE_I;\r
1606         if(CmdOption & OPT_EUC)\r
1607                 Kanji = KANJI_EUC;\r
1608         if(CmdOption & OPT_JIS)\r
1609                 Kanji = KANJI_JIS;\r
1610         if(CmdOption & OPT_EUC_NAME)\r
1611                 FnameKanji = KANJI_EUC;\r
1612         if(CmdOption & OPT_JIS_NAME)\r
1613                 FnameKanji = KANJI_JIS;\r
1614         if(CmdOption & OPT_KANA)\r
1615                 Kana = NO;\r
1616 \r
1617         if(CmdOption & OPT_QUIT)\r
1618                 AutoExit = YES;\r
1619 \r
1620         if(CmdOption & OPT_SAVEOFF)\r
1621                 SuppressSave = YES;\r
1622         if(CmdOption & OPT_SAVEON)\r
1623                 SuppressSave = NO;\r
1624 \r
1625         if(Sts == 0)\r
1626         {\r
1627                 if(ConnectOnStart == YES)\r
1628                         PostMessage(hWndFtp, WM_COMMAND, MAKEWPARAM(MENU_CONNECT, 0), 0);\r
1629         }\r
1630         else if(Sts == 1)\r
1631         {\r
1632                 DirectConnectProc(unc, Kanji, Kana, FnameKanji, TrMode);\r
1633         }\r
1634         else if(Sts == 2)\r
1635         {\r
1636                 PostMessage(hWndFtp, WM_COMMAND, MAKEWPARAM(MENU_CONNECT_NUM, CmdOption), (LPARAM)AutoConnect);\r
1637         }\r
1638         return;\r
1639 }\r
1640 \r
1641 \r
1642 /*----- コマンドラインを解析 --------------------------------------------------\r
1643 *\r
1644 *       Parameter\r
1645 *               char *Str : コマンドライン文字列\r
1646 *               int *AutoConnect : 接続ホスト番号を返すワーク\r
1647 *               int *CmdOption : オプションを返すワーク\r
1648 *               char *unc : uncを返すワーク\r
1649 *               int Max : uncの最大長\r
1650 *\r
1651 *       Return Value\r
1652 *               int ステータス\r
1653 *                       0=指定なし、1=URL指定、2=設定名指定、-1=エラー\r
1654 *\r
1655 *       Note\r
1656 *               -m      --mirror\r
1657 *               -d      --mirrordown\r
1658 *               -f      --force\r
1659 *               -q      --quit\r
1660 *               -s      --set\r
1661 *               -h      --help\r
1662 *               -e      --euc\r
1663 *               -j      --jis\r
1664 *               -a      --ascii\r
1665 *               -b      --binary\r
1666 *               -x      --auto\r
1667 *               -k      --kana\r
1668 *               -u      --eucname\r
1669 *               -i      --jisname\r
1670 *               -n  --ini               (CheckIniFileNameで検索)\r
1671 *                       --saveoff\r
1672 *                       --saveon\r
1673 *               -z      --mpasswd       (CheckMasterPasswordで検索)  2010.01.30 genta 追加\r
1674 *----------------------------------------------------------------------------*/\r
1675 \r
1676 static int AnalyzeComLine(char *Str, int *AutoConnect, int *CmdOption, char *unc, int Max)\r
1677 {\r
1678         int Ret;\r
1679         char Tmp[FMAX_PATH+1];\r
1680 \r
1681         *AutoConnect = -1;\r
1682         *CmdOption = 0;\r
1683 \r
1684         Ret = 0;\r
1685         memset(unc, NUL, Max+1);\r
1686 \r
1687         while((Ret != -1) && ((Str = GetToken(Str, Tmp)) != NULL))\r
1688         {\r
1689                 if(Tmp[0] == '-')\r
1690                 {\r
1691                         _strlwr(Tmp);\r
1692                         if((strcmp(&Tmp[1], "m") == 0) || (strcmp(&Tmp[1], "-mirror") == 0))\r
1693                                 *CmdOption |= OPT_MIRROR;\r
1694                         else if((strcmp(&Tmp[1], "d") == 0) || (strcmp(&Tmp[1], "-mirrordown") == 0))\r
1695                                 *CmdOption |= OPT_MIRRORDOWN;\r
1696                         else if((strcmp(&Tmp[1], "e") == 0) || (strcmp(&Tmp[1], "-euc") == 0))\r
1697                                 *CmdOption |= OPT_EUC;\r
1698                         else if((strcmp(&Tmp[1], "j") == 0) || (strcmp(&Tmp[1], "-jis") == 0))\r
1699                                 *CmdOption |= OPT_JIS;\r
1700                         else if((strcmp(&Tmp[1], "a") == 0) || (strcmp(&Tmp[1], "-ascii") == 0))\r
1701                                 *CmdOption |= OPT_ASCII;\r
1702                         else if((strcmp(&Tmp[1], "b") == 0) || (strcmp(&Tmp[1], "-binary") == 0))\r
1703                                 *CmdOption |= OPT_BINARY;\r
1704                         else if((strcmp(&Tmp[1], "x") == 0) || (strcmp(&Tmp[1], "-auto") == 0))\r
1705                                 *CmdOption |= OPT_AUTO;\r
1706                         else if((strcmp(&Tmp[1], "f") == 0) || (strcmp(&Tmp[1], "-force") == 0))\r
1707                                 *CmdOption |= OPT_FORCE;\r
1708                         else if((strcmp(&Tmp[1], "q") == 0) || (strcmp(&Tmp[1], "-quit") == 0))\r
1709                                 *CmdOption |= OPT_QUIT;\r
1710                         else if((strcmp(&Tmp[1], "k") == 0) || (strcmp(&Tmp[1], "-kana") == 0))\r
1711                                 *CmdOption |= OPT_KANA;\r
1712                         else if((strcmp(&Tmp[1], "u") == 0) || (strcmp(&Tmp[1], "-eucname") == 0))\r
1713                                 *CmdOption |= OPT_EUC_NAME;\r
1714                         else if((strcmp(&Tmp[1], "i") == 0) || (strcmp(&Tmp[1], "-jisname") == 0))\r
1715                                 *CmdOption |= OPT_JIS_NAME;\r
1716                         else if((strcmp(&Tmp[1], "n") == 0) || (strcmp(&Tmp[1], "-ini") == 0))\r
1717                         {\r
1718                                 if((Str = GetToken(Str, Tmp)) == NULL)\r
1719                                 {\r
1720                                         SetTaskMsg(MSGJPN282);\r
1721                                         Ret = -1;\r
1722                                 }\r
1723                         }\r
1724                         else if(strcmp(&Tmp[1], "-saveoff") == 0)\r
1725                                 *CmdOption |= OPT_SAVEOFF;\r
1726                         else if(strcmp(&Tmp[1], "-saveon") == 0)\r
1727                                 *CmdOption |= OPT_SAVEON;\r
1728                         else if((strcmp(&Tmp[1], "z") == 0) || (strcmp(&Tmp[1], "-mpasswd") == 0))\r
1729                         {       /* 2010.01.30 genta : Add master password option */\r
1730                                 if((Str = GetToken(Str, Tmp)) == NULL)\r
1731                                 {\r
1732                                         SetTaskMsg(MSGJPN299);\r
1733                                         Ret = -1;\r
1734                                 }\r
1735                         }\r
1736                         else if((strcmp(&Tmp[1], "s") == 0) || (strcmp(&Tmp[1], "-set") == 0))\r
1737                         {\r
1738                                 if(Ret == 0)\r
1739                                 {\r
1740                                         if((Str = GetToken(Str, Tmp)) != NULL)\r
1741                                         {\r
1742                                                 if((*AutoConnect = SearchHostName(Tmp)) != -1)\r
1743                                                         Ret = 2;\r
1744                                                 else\r
1745                                                 {\r
1746                                                         SetTaskMsg(MSGJPN177, Tmp);\r
1747                                                         Ret = -1;\r
1748                                                 }\r
1749                                         }\r
1750                                         else\r
1751                                         {\r
1752                                                 SetTaskMsg(MSGJPN178);\r
1753                                                 Ret = -1;\r
1754                                         }\r
1755                                 }\r
1756                                 else\r
1757                                 {\r
1758                                         SetTaskMsg(MSGJPN179);\r
1759                                         Ret = -1;\r
1760                                 }\r
1761                         }\r
1762                         else if((strcmp(&Tmp[1], "h") == 0) || (strcmp(&Tmp[1], "-help") == 0))\r
1763                         {\r
1764                                 hHelpWin = HtmlHelp(NULL, AskHelpFilePath(), HH_HELP_CONTEXT, IDH_HELP_TOPIC_0000024);\r
1765                         }\r
1766                         // プロセス保護\r
1767 #ifdef ENABLE_PROCESS_PROTECTION\r
1768                         else if(strcmp(Tmp, "--restart") == 0)\r
1769                         {\r
1770                         }\r
1771                         else if(strcmp(Tmp, "--protect") == 0)\r
1772                         {\r
1773                         }\r
1774                         else if(strcmp(Tmp, "--protect-high") == 0)\r
1775                         {\r
1776                         }\r
1777                         else if(strcmp(Tmp, "--protect-medium") == 0)\r
1778                         {\r
1779                         }\r
1780                         else if(strcmp(Tmp, "--protect-low") == 0)\r
1781                         {\r
1782                         }\r
1783 #endif\r
1784                         else\r
1785                         {\r
1786                                 SetTaskMsg(MSGJPN180, Tmp);\r
1787                                 Ret = -1;\r
1788                         }\r
1789                 }\r
1790                 else\r
1791                 {\r
1792                         if(Ret == 0)\r
1793                         {\r
1794                                 strncpy(unc, Tmp, Max);\r
1795                                 Ret = 1;\r
1796                         }\r
1797                         else\r
1798                         {\r
1799                                 SetTaskMsg(MSGJPN181);\r
1800                                 Ret = -1;\r
1801                         }\r
1802                 }\r
1803         }\r
1804         return(Ret);\r
1805 }\r
1806 \r
1807 \r
1808 /*----- INIファイルのパス名の指定をチェック ------------------------------------\r
1809 *\r
1810 *       Parameter\r
1811 *               char *Str : コマンドライン文字列\r
1812 *               char *Ini : iniファイル名を返すワーク\r
1813 *\r
1814 *       Return Value\r
1815 *               int ステータス\r
1816 *                       0=指定なし、1=あり\r
1817 *\r
1818 *       Note\r
1819 *               -n  --ini\r
1820 *----------------------------------------------------------------------------*/\r
1821 \r
1822 static int CheckIniFileName(char *Str, char *Ini)\r
1823 {\r
1824         return GetTokenAfterOption( Str, Ini, "n", "-ini" );\r
1825 }\r
1826 \r
1827 /* マスターパスワードの指定をチェック */\r
1828 static int CheckMasterPassword(char *Str, char *Ini)\r
1829 {\r
1830         return GetTokenAfterOption( Str, Ini, "z", "-mpasswd" );\r
1831 }\r
1832 \r
1833 /*----- オプションの後ろのトークンを取り出す ------------------------------------\r
1834 *\r
1835 *       Parameter\r
1836 *               char *Str : コマンドライン文字列\r
1837 *               char *Result : 取り出した文字列を格納するワーク\r
1838 *               const char* Opt1, *Opt2: オプション文字列(2つ)\r
1839 *\r
1840 *       Return Value\r
1841 *               int ステータス\r
1842 *                       0=指定なし、1=あり\r
1843 *\r
1844 *       Note\r
1845 *               2010.01.30 genta マスターパスワード取り出しのため共通化\r
1846 *----------------------------------------------------------------------------*/\r
1847 static int GetTokenAfterOption(char *Str, char *Result, const char* Opt1, const char* Opt2 )\r
1848 {\r
1849         int Ret = 0;\r
1850         char Tmp[FMAX_PATH+1];\r
1851 \r
1852         Result[0] = NUL;\r
1853         while((Str = GetToken(Str, Tmp)) != NULL)\r
1854         {\r
1855                 if(Tmp[0] == '-')\r
1856                 {\r
1857                         _strlwr(Tmp);\r
1858                         if((strcmp(&Tmp[1], Opt1) == 0) || (strcmp(&Tmp[1], Opt2) == 0))\r
1859                         {\r
1860                                 if((Str = GetToken(Str, Result)) != NULL)\r
1861                                         Ret = 1;\r
1862                                 break;\r
1863                         }\r
1864                 }\r
1865         }\r
1866         return(Ret);\r
1867 }\r
1868 \r
1869 /*----- トークンを返す --------------------------------------------------------\r
1870 *\r
1871 *       Parameter\r
1872 *               char *Str : 文字列\r
1873 *               char *Buf : 文字列を返すバッファ\r
1874 *\r
1875 *       Return Value\r
1876 *               char *返したトークンの末尾\r
1877 *                       NULL=終わり\r
1878 *----------------------------------------------------------------------------*/\r
1879 \r
1880 static char *GetToken(char *Str, char *Buf)\r
1881 {\r
1882         int InQuote;\r
1883 \r
1884         while(*Str != NUL)\r
1885         {\r
1886                 if((*Str != ' ') && (*Str != '\t'))\r
1887                         break;\r
1888                 Str++;\r
1889         }\r
1890 \r
1891         if(*Str != NUL)\r
1892         {\r
1893                 InQuote = 0;\r
1894                 while(*Str != NUL)\r
1895                 {\r
1896                         if(*Str == 0x22)\r
1897                                 InQuote = !InQuote;\r
1898                         else\r
1899                         {\r
1900                                 if(((*Str == ' ') || (*Str == '\t')) &&\r
1901                                    (InQuote == 0))\r
1902                                 {\r
1903                                         break;\r
1904                                 }\r
1905                                 *Buf++ = *Str;\r
1906                         }\r
1907                         Str++;\r
1908                 }\r
1909         }\r
1910         else\r
1911                 Str = NULL;\r
1912 \r
1913         *Buf = NUL;\r
1914 \r
1915         return(Str);\r
1916 }\r
1917 \r
1918 \r
1919 /*----- プログラム終了時の処理 ------------------------------------------------\r
1920 *\r
1921 *       Parameter\r
1922 *               HWND hWnd : ウインドウハンドル\r
1923 *\r
1924 *       Return Value\r
1925 *               なし\r
1926 *----------------------------------------------------------------------------*/\r
1927 \r
1928 static void ExitProc(HWND hWnd)\r
1929 {\r
1930         CancelFlg = YES;\r
1931 \r
1932         CloseTransferThread();\r
1933 \r
1934         if(SaveExit == YES)\r
1935         {\r
1936                 SaveBookMark();\r
1937                 SaveCurrentSetToHost();\r
1938         }\r
1939         DeleteAlltempFile();\r
1940 \r
1941 //      WSACancelBlockingCall();\r
1942         DisconnectProc();\r
1943 //      CloseTransferThread();\r
1944 \r
1945         if(SaveExit == YES)\r
1946         {\r
1947                 GetListTabWidth();\r
1948                 SaveRegistory();\r
1949 \r
1950                 if((CacheEntry > 0) && (CacheSave == YES))\r
1951                         SaveCache();\r
1952                 else\r
1953                         DeleteCache();\r
1954         }\r
1955         else\r
1956                 DeleteCache();\r
1957 \r
1958         if(RasClose == YES)\r
1959         {\r
1960                 DisconnectRas(RasCloseNotify);\r
1961         }\r
1962         DeleteAllObject();\r
1963         HtmlHelp(NULL, NULL, HH_UNINITIALIZE, dwCookie); \r
1964         return;\r
1965 }\r
1966 \r
1967 \r
1968 /*----- ファイル名をダブルクリックしたときの処理 ------------------------------\r
1969 *\r
1970 *       Parameter\r
1971 *               int Win : ウインドウ番号 (WIN_xxx)\r
1972 *               int Mode : 常に「開く」動作をするかどうか (YES/NO)\r
1973 *               int App : アプリケーション番号(-1=関連づけ優先)\r
1974 *\r
1975 *       Return Value\r
1976 *               なし\r
1977 *----------------------------------------------------------------------------*/\r
1978 \r
1979 void DoubleClickProc(int Win, int Mode, int App)\r
1980 {\r
1981         int Pos;\r
1982         int Type;\r
1983         char Local[FMAX_PATH+1];\r
1984         char Remote[FMAX_PATH+1];\r
1985         char Tmp[FMAX_PATH+1];\r
1986         int Sts;\r
1987         int UseDiffViewer;\r
1988 \r
1989         if(AskUserOpeDisabled() == NO)\r
1990         {\r
1991                 SetCurrentDirAsDirHist();\r
1992                 if(GetSelectedCount(Win) == 1)\r
1993                 {\r
1994                         if((Pos = GetFirstSelected(Win, NO)) != -1)\r
1995                         {\r
1996                                 GetNodeName(Win, Pos, Tmp, FMAX_PATH);\r
1997                                 Type = GetNodeType(Win, Pos);\r
1998 \r
1999                                 if(Win == WIN_LOCAL)\r
2000                                 {\r
2001                                         if((App != -1) || (Type == NODE_FILE))\r
2002                                         {\r
2003                                                 if((DclickOpen == YES) || (Mode == YES))\r
2004                                                 {\r
2005                                                         AskLocalCurDir(Local, FMAX_PATH);\r
2006                                                         ReplaceAll(Local, '/', '\\');\r
2007                                                         SetYenTail(Local);\r
2008                                                         strcat(Local, Tmp);\r
2009                                                         ExecViewer(Local, App);\r
2010                                                 }\r
2011                                                 else\r
2012                                                         PostMessage(hWndFtp, WM_COMMAND, MAKEWPARAM(MENU_UPLOAD, 0), 0);\r
2013                                         }\r
2014                                         else\r
2015                                                 ChangeDir(WIN_LOCAL, Tmp);\r
2016                                 }\r
2017                                 else if(CheckClosedAndReconnect() == FFFTP_SUCCESS)\r
2018                                 {\r
2019                                         if((App != -1) || (Type == NODE_FILE))\r
2020                                         {\r
2021                                                 if((DclickOpen == YES) || (Mode == YES))\r
2022                                                 {\r
2023                                                         // ビューワ2、3のパスが "d " で始まっていたら差分ビューア使用\r
2024                                                         if ((App == 1 || App == 2) && strncmp(ViewerName[App], "d ", 2) == 0)\r
2025                                                                 UseDiffViewer = YES;\r
2026                                                         else\r
2027                                                                 UseDiffViewer = NO;\r
2028 \r
2029                                                         strcpy(Remote, TmpPath);\r
2030                                                         SetYenTail(Remote);\r
2031                                                         if (UseDiffViewer == YES) {\r
2032                                                                 strcat(Remote, "remote.");\r
2033                                                         }\r
2034                                                         strcat(Remote, Tmp);\r
2035 \r
2036                                                         if(AskTransferNow() == YES)\r
2037                                                                 SktShareProh();\r
2038 \r
2039         //                                              MainTransPkt.ctrl_skt = AskCmdCtrlSkt();\r
2040                                                         strcpy(MainTransPkt.Cmd, "RETR ");\r
2041                                                         if(AskHostType() == HTYPE_ACOS)\r
2042                                                         {\r
2043                                                                 strcpy(MainTransPkt.RemoteFile, "'");\r
2044                                                                 strcat(MainTransPkt.RemoteFile, AskHostLsName());\r
2045                                                                 strcat(MainTransPkt.RemoteFile, "(");\r
2046                                                                 strcat(MainTransPkt.RemoteFile, Tmp);\r
2047                                                                 strcat(MainTransPkt.RemoteFile, ")");\r
2048                                                                 strcat(MainTransPkt.RemoteFile, "'");\r
2049                                                         }\r
2050                                                         else if(AskHostType() == HTYPE_ACOS_4)\r
2051                                                         {\r
2052                                                                 strcpy(MainTransPkt.RemoteFile, Tmp);\r
2053                                                         }\r
2054                                                         else\r
2055                                                         {\r
2056                                                                 strcpy(MainTransPkt.RemoteFile, Tmp);\r
2057                                                         }\r
2058                                                         strcpy(MainTransPkt.LocalFile, Remote);\r
2059                                                         MainTransPkt.Type = AskTransferTypeAssoc(MainTransPkt.RemoteFile, AskTransferType());\r
2060                                                         MainTransPkt.Size = 1;\r
2061                                                         MainTransPkt.KanjiCode = AskHostKanjiCode();\r
2062                                                         MainTransPkt.KanjiCodeDesired = AskLocalKanjiCode();\r
2063                                                         MainTransPkt.KanaCnv = AskHostKanaCnv();\r
2064                                                         MainTransPkt.Mode = EXIST_OVW;\r
2065                                                         MainTransPkt.ExistSize = 0;\r
2066                                                         MainTransPkt.hWndTrans = NULL;\r
2067                                                         MainTransPkt.Next = NULL;\r
2068 \r
2069                                                         DisableUserOpe();\r
2070 \r
2071                                                         /* 不正なパスを検出 */\r
2072                                                         if(CheckPathViolation(&MainTransPkt) == NO)\r
2073                                                         {\r
2074 //                                                              if((Sts = DoDownLoad(AskCmdCtrlSkt(), &MainTransPkt, NO)) == 429)\r
2075 //                                                              {\r
2076 //                                                                      ReConnectCmdSkt();\r
2077                                                                         Sts = DoDownLoad(AskCmdCtrlSkt(), &MainTransPkt, NO, &CancelFlg);\r
2078 //                                                              }\r
2079                                                         }\r
2080 \r
2081                                                         EnableUserOpe();\r
2082 \r
2083                                                         AddTempFileList(Remote);\r
2084                                                         if(Sts/100 == FTP_COMPLETE) {\r
2085                                                                 if (UseDiffViewer == YES) {\r
2086                                                                         AskLocalCurDir(Local, FMAX_PATH);\r
2087                                                                         ReplaceAll(Local, '/', '\\');\r
2088                                                                         SetYenTail(Local);\r
2089                                                                         strcat(Local, Tmp);\r
2090                                                                         ExecViewer2(Local, Remote, App);\r
2091                                                                 } else {\r
2092                                                                         ExecViewer(Remote, App);\r
2093                                                                 }\r
2094                                                         }\r
2095                                                 }\r
2096                                                 else\r
2097                                                         PostMessage(hWndFtp, WM_COMMAND, MAKEWPARAM(MENU_DOWNLOAD, 0), 0);\r
2098                                         }\r
2099                                         else\r
2100                                                 ChangeDir(WIN_REMOTE, Tmp);\r
2101                                 }\r
2102                         }\r
2103                 }\r
2104                 MakeButtonsFocus();\r
2105         }\r
2106         return;\r
2107 }\r
2108 \r
2109 \r
2110 /*----- フォルダの移動 --------------------------------------------------------\r
2111 *\r
2112 *       Parameter\r
2113 *               int Win : ウインドウ番号 (WIN_xxx)\r
2114 *               char *Path : 移動先のパス名\r
2115 *\r
2116 *       Return Value\r
2117 *               なし\r
2118 *\r
2119 *       Note\r
2120 *               フォルダ同時移動の処理も行う\r
2121 *----------------------------------------------------------------------------*/\r
2122 \r
2123 static void ChangeDir(int Win, char *Path)\r
2124 {\r
2125         int Sync;\r
2126         char Local[FMAX_PATH+1];\r
2127         char Remote[FMAX_PATH+1];\r
2128 \r
2129         Sync = AskSyncMoveMode();\r
2130         if(Sync == YES)\r
2131         {\r
2132                 if(strcmp(Path, "..") == 0)\r
2133                 {\r
2134                         AskLocalCurDir(Local, FMAX_PATH);\r
2135                         AskRemoteCurDir(Remote, FMAX_PATH);\r
2136                         if(strcmp(GetFileName(Local), GetFileName(Remote)) != 0)\r
2137                                 Sync = NO;\r
2138                 }\r
2139         }\r
2140 \r
2141         if((Win == WIN_LOCAL) || (Sync == YES))\r
2142         {\r
2143                 if(DoLocalCWD(Path) == FFFTP_SUCCESS)\r
2144                         GetLocalDirForWnd();\r
2145         }\r
2146 \r
2147         if((Win == WIN_REMOTE) || (Sync == YES))\r
2148         {\r
2149                 if(CheckClosedAndReconnect() == FFFTP_SUCCESS)\r
2150                 {\r
2151 #if defined(HAVE_OPENVMS)\r
2152                         /* OpenVMSの場合、".DIR;?"を取る */\r
2153                         if (AskHostType() == HTYPE_VMS)\r
2154                                 ReformVMSDirName(Path, TRUE);\r
2155 #endif\r
2156                         if(DoCWD(Path, YES, NO, YES) < FTP_RETRY)\r
2157                                 GetRemoteDirForWnd(CACHE_NORMAL, &CancelFlg);\r
2158                 }\r
2159         }\r
2160         return;\r
2161 }\r
2162 \r
2163 \r
2164 /*----- ウインドウのサイズ変更の処理 ------------------------------------------\r
2165 *\r
2166 *       Parameter\r
2167 *               なし\r
2168 *\r
2169 *       Return Value\r
2170 *               なし\r
2171 *----------------------------------------------------------------------------*/\r
2172 \r
2173 static void ResizeWindowProc(void)\r
2174 {\r
2175 #if 0\r
2176         RECT Rect;\r
2177         int RemotePosX;\r
2178 \r
2179         GetClientRect(hWndFtp, &Rect);\r
2180         SendMessage(GetSbarWnd(), WM_SIZE, SIZE_RESTORED, MAKELPARAM(Rect.right, Rect.bottom));\r
2181 \r
2182         CalcWinSize();\r
2183         SetWindowPos(GetMainTbarWnd(), 0, 0, 0, WinWidth, TOOLWIN_HEIGHT, SWP_NOACTIVATE | SWP_NOZORDER);\r
2184 \r
2185         SetWindowPos(GetLocalTbarWnd(), 0, 0, TOOLWIN_HEIGHT, LocalWidth, TOOLWIN_HEIGHT, SWP_NOACTIVATE | SWP_NOZORDER);\r
2186         SendMessage(GetLocalTbarWnd(), TB_GETITEMRECT, 3, (LPARAM)&Rect);\r
2187         SetWindowPos(GetLocalHistHwnd(), 0, Rect.right, Rect.top, LocalWidth - Rect.right, 200, SWP_NOACTIVATE | SWP_NOZORDER);\r
2188         SetWindowPos(GetLocalHwnd(), 0, 0, TOOLWIN_HEIGHT*2, LocalWidth, ListHeight, SWP_NOACTIVATE | SWP_NOZORDER);\r
2189 \r
2190         RemotePosX = LocalWidth + SepaWidth;\r
2191         if(SplitVertical == YES)\r
2192                 RemotePosX = 0;\r
2193 \r
2194         SetWindowPos(GetRemoteTbarWnd(), 0, RemotePosX, TOOLWIN_HEIGHT, RemoteWidth, TOOLWIN_HEIGHT, SWP_NOACTIVATE | SWP_NOZORDER);\r
2195         SendMessage(GetRemoteTbarWnd(), TB_GETITEMRECT, 3, (LPARAM)&Rect);\r
2196         SetWindowPos(GetRemoteHistHwnd(), 0, Rect.right, Rect.top, RemoteWidth - Rect.right, 200, SWP_NOACTIVATE | SWP_NOZORDER);\r
2197         SetWindowPos(GetRemoteHwnd(), 0, RemotePosX, TOOLWIN_HEIGHT*2, RemoteWidth, ListHeight, SWP_NOACTIVATE | SWP_NOZORDER);\r
2198 \r
2199         SetWindowPos(GetTaskWnd(), 0, 0, TOOLWIN_HEIGHT*2+ListHeight+SepaWidth, ClientWidth, TaskHeight, SWP_NOACTIVATE | SWP_NOZORDER);\r
2200 #else\r
2201         RECT Rect;\r
2202 \r
2203         GetClientRect(hWndFtp, &Rect);\r
2204         SendMessage(GetSbarWnd(), WM_SIZE, SIZE_RESTORED, MAKELPARAM(Rect.right, Rect.bottom));\r
2205 \r
2206         CalcWinSize();\r
2207         SetWindowPos(GetMainTbarWnd(), 0, 0, 0, Rect.right, TOOLWIN_HEIGHT, SWP_NOACTIVATE | SWP_NOZORDER);\r
2208         SetWindowPos(GetLocalTbarWnd(), 0, 0, TOOLWIN_HEIGHT, LocalWidth, TOOLWIN_HEIGHT, SWP_NOACTIVATE | SWP_NOZORDER);\r
2209         SetWindowPos(GetRemoteTbarWnd(), 0, LocalWidth + SepaWidth, TOOLWIN_HEIGHT, RemoteWidth, TOOLWIN_HEIGHT, SWP_NOACTIVATE | SWP_NOZORDER);\r
2210         SendMessage(GetLocalTbarWnd(), TB_GETITEMRECT, 3, (LPARAM)&Rect);\r
2211         SetWindowPos(GetLocalHistHwnd(), 0, Rect.right, Rect.top, LocalWidth - Rect.right, 200, SWP_NOACTIVATE | SWP_NOZORDER);\r
2212         SendMessage(GetRemoteTbarWnd(), TB_GETITEMRECT, 3, (LPARAM)&Rect);\r
2213         SetWindowPos(GetRemoteHistHwnd(), 0, Rect.right, Rect.top, RemoteWidth - Rect.right, 200, SWP_NOACTIVATE | SWP_NOZORDER);\r
2214         SetWindowPos(GetLocalHwnd(), 0, 0, TOOLWIN_HEIGHT*2, LocalWidth, ListHeight, SWP_NOACTIVATE | SWP_NOZORDER);\r
2215         SetWindowPos(GetRemoteHwnd(), 0, LocalWidth + SepaWidth, TOOLWIN_HEIGHT*2, RemoteWidth, ListHeight, SWP_NOACTIVATE | SWP_NOZORDER);\r
2216         SetWindowPos(GetTaskWnd(), 0, 0, TOOLWIN_HEIGHT*2+ListHeight+SepaWidth, ClientWidth, TaskHeight, SWP_NOACTIVATE | SWP_NOZORDER);\r
2217 #endif\r
2218 \r
2219         return;\r
2220 }\r
2221 \r
2222 \r
2223 /*----- ウインドウの各部分のサイズを計算する ----------------------------------\r
2224 *\r
2225 *       Parameter\r
2226 *               なし\r
2227 *\r
2228 *       Return Value\r
2229 *               なし\r
2230 *----------------------------------------------------------------------------*/\r
2231 \r
2232 static void CalcWinSize(void)\r
2233 {\r
2234         RECT Rect;\r
2235 \r
2236         GetWindowRect(hWndFtp, &Rect);\r
2237 \r
2238         if(Sizing != SW_MAXIMIZE)\r
2239         {\r
2240                 WinWidth = Rect.right - Rect.left;\r
2241                 WinHeight = Rect.bottom - Rect.top;\r
2242         }\r
2243 \r
2244         GetClientRect(hWndFtp, &Rect);\r
2245 \r
2246         ClientWidth = Rect.right;\r
2247         ClientHeight = Rect.bottom;\r
2248 \r
2249         SepaWidth = 4;\r
2250         LocalWidth = max1(0, min1(LocalWidth, ClientWidth - SepaWidth));\r
2251         RemoteWidth = max1(0, ClientWidth - LocalWidth - SepaWidth);\r
2252 //      TaskHeight = min1(TaskHeight, max1(0, ClientHeight - TOOLWIN_HEIGHT * 2 - SepaWidth));\r
2253 \r
2254         GetClientRect(GetSbarWnd(), &Rect);\r
2255 \r
2256         ListHeight = max1(0, ClientHeight - TOOLWIN_HEIGHT * 2 - TaskHeight - SepaWidth - Rect.bottom);\r
2257 \r
2258         return;\r
2259 }\r
2260 \r
2261 \r
2262 #if 0\r
2263 /*----- ウインドウの表示位置を取得する ----------------------------------------\r
2264 *\r
2265 *       Parameter\r
2266 *               HWND hWnd : ウインドウハンドル\r
2267 *\r
2268 *       Return Value\r
2269 *               なし\r
2270 *----------------------------------------------------------------------------*/\r
2271 \r
2272 static void AskWindowPos(HWND hWnd)\r
2273 {\r
2274         WINDOWPLACEMENT WinPlace;\r
2275 \r
2276         WinPlace.length = sizeof(WINDOWPLACEMENT);\r
2277         GetWindowPlacement(hWnd, &WinPlace);\r
2278         WinPosX = WinPlace.rcNormalPosition.left;\r
2279         WinPosY = WinPlace.rcNormalPosition.top;\r
2280 \r
2281         return;\r
2282 }\r
2283 #endif\r
2284 \r
2285 \r
2286 /*----- ディレクトリリストとファイルリストの境界変更処理 ----------------------\r
2287 *\r
2288 *       Parameter\r
2289 *               WPARAM Keys : WM_MOUSEMOVEなどのWPARAMの値\r
2290 *               int x : マウスカーソルのX座標\r
2291 *               int y : マウスカーソルのY座標\r
2292 *\r
2293 *       Return Value\r
2294 *               なし\r
2295 *----------------------------------------------------------------------------*/\r
2296 \r
2297 static void CheckResizeFrame(WPARAM Keys, int x, int y)\r
2298 {\r
2299         RECT Rect;\r
2300         RECT Rect1;\r
2301 \r
2302         if((Resizing == RESIZE_OFF) && (Keys == 0))\r
2303         {\r
2304                 if((x >= LocalWidth) && (x <= LocalWidth + SepaWidth) &&\r
2305                    (y > TOOLWIN_HEIGHT) && (y < (TOOLWIN_HEIGHT * 2 + ListHeight)))\r
2306                 {\r
2307                         /* 境界位置変更用カーソルに変更 */\r
2308                         SetCapture(hWndFtp);\r
2309                         hCursor = LoadCursor(hInstFtp, MAKEINTRESOURCE(resize_lr_csr));\r
2310                         SetCursor(hCursor);\r
2311                         Resizing = RESIZE_PREPARE;\r
2312                         ResizePos = RESIZE_HPOS;\r
2313                 }\r
2314                 else if((y >= TOOLWIN_HEIGHT*2+ListHeight) && (y <= TOOLWIN_HEIGHT*2+ListHeight+SepaWidth))\r
2315                 {\r
2316                         /* 境界位置変更用カーソルに変更 */\r
2317                         SetCapture(hWndFtp);\r
2318                         hCursor = LoadCursor(hInstFtp, MAKEINTRESOURCE(resize_ud_csr));\r
2319                         SetCursor(hCursor);\r
2320                         Resizing = RESIZE_PREPARE;\r
2321                         ResizePos = RESIZE_VPOS;\r
2322                 }\r
2323         }\r
2324         else if(Resizing == RESIZE_PREPARE)\r
2325         {\r
2326                 if(Keys & MK_LBUTTON)\r
2327                 {\r
2328                         /* 境界位置変更開始 */\r
2329                         Resizing = RESIZE_ON;\r
2330                         GetWindowRect(hWndFtp, &Rect);\r
2331                         GetClientRect(GetSbarWnd(), &Rect1);\r
2332                         Rect.left += GetSystemMetrics(SM_CXFRAME);\r
2333                         Rect.right -= GetSystemMetrics(SM_CXFRAME);\r
2334                         Rect.top += TOOLWIN_HEIGHT*2 + GetSystemMetrics(SM_CYMENU) + GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CYFRAME);\r
2335                         Rect.bottom -= GetSystemMetrics(SM_CYFRAME) + Rect1.bottom;\r
2336                         ClipCursor(&Rect);\r
2337                 }\r
2338                 else\r
2339                 {\r
2340                         if(((ResizePos == RESIZE_HPOS) &&\r
2341                                 ((x < LocalWidth) || (x > LocalWidth + SepaWidth) ||\r
2342                                  (y <= TOOLWIN_HEIGHT) || (y >= (TOOLWIN_HEIGHT * 2 + ListHeight)))) ||\r
2343                            ((ResizePos == RESIZE_VPOS) &&\r
2344                                 ((y < TOOLWIN_HEIGHT*2+ListHeight) || (y > TOOLWIN_HEIGHT*2+ListHeight+SepaWidth))))\r
2345                         {\r
2346                                 /* 元のカーソルに戻す */\r
2347                                 ReleaseCapture();\r
2348                                 hCursor = LoadCursor(NULL, IDC_ARROW);\r
2349                                 SetCursor(hCursor);\r
2350                                 Resizing = RESIZE_OFF;\r
2351                         }\r
2352                 }\r
2353         }\r
2354         else if(Resizing == RESIZE_ON)\r
2355         {\r
2356                 if(ResizePos == RESIZE_HPOS)\r
2357                         LocalWidth = x;\r
2358                 else\r
2359                 {\r
2360                         GetClientRect(hWndFtp, &Rect);\r
2361                         GetClientRect(GetSbarWnd(), &Rect1);\r
2362                         TaskHeight = max1(0, Rect.bottom - y - Rect1.bottom);\r
2363                 }\r
2364                 ResizeWindowProc();\r
2365 \r
2366                 if((Keys & MK_LBUTTON) == 0)\r
2367                 {\r
2368                         /* 境界位置変更終了 */\r
2369                         ReleaseCapture();\r
2370                         ClipCursor(NULL);\r
2371                         hCursor = LoadCursor(NULL, IDC_ARROW);\r
2372                         SetCursor(hCursor);\r
2373                         Resizing = RESIZE_OFF;\r
2374                 }\r
2375         }\r
2376         return;\r
2377 }\r
2378 \r
2379 \r
2380 /*----- ファイル一覧情報をビューワで表示 --------------------------------------\r
2381 *\r
2382 *       Parameter\r
2383 *               なし\r
2384 *\r
2385 *       Return Value\r
2386 *               なし\r
2387 *----------------------------------------------------------------------------*/\r
2388 \r
2389 static void DispDirInfo(void)\r
2390 {\r
2391         char Buf[FMAX_PATH+1];\r
2392 \r
2393         MakeCacheFileName(AskCurrentFileListNum(), Buf);\r
2394         ExecViewer(Buf, 0);\r
2395         return;\r
2396 }\r
2397 \r
2398 \r
2399 \r
2400 /*----- ビューワを起動 --------------------------------------------------------\r
2401 *\r
2402 *       Parameter\r
2403 *               char Fname : ファイル名\r
2404 *               int App : アプリケーション番号(-1=関連づけ優先)\r
2405 *\r
2406 *       Return Value\r
2407 *               なし\r
2408 *----------------------------------------------------------------------------*/\r
2409 \r
2410 void ExecViewer(char *Fname, int App)\r
2411 {\r
2412         PROCESS_INFORMATION Info;\r
2413         STARTUPINFO Startup;\r
2414         char AssocProg[FMAX_PATH+1];\r
2415         char ComLine[FMAX_PATH*2+3+1];\r
2416         char CurDir[FMAX_PATH+1];\r
2417 \r
2418         /* FindExecutable()は関連付けられたプログラムのパス名にスペースが        */\r
2419         /* 含まれている時、間違ったパス名を返す事がある。                                        */\r
2420         /* そこで、関連付けられたプログラムの起動はShellExecute()を使う。       */\r
2421 \r
2422         AskLocalCurDir(CurDir, FMAX_PATH);\r
2423 \r
2424         if((App == -1) && (FindExecutable(Fname, NULL, AssocProg) > (HINSTANCE)32))\r
2425         {\r
2426                 DoPrintf("ShellExecute - %s", Fname);\r
2427                 ShellExecute(NULL, "open", Fname, NULL, CurDir, SW_SHOW);\r
2428         }\r
2429         else\r
2430         {\r
2431                 App = max1(0, App);\r
2432                 strcpy(AssocProg, ViewerName[App]);\r
2433 \r
2434                 if(strchr(Fname, ' ') == NULL)\r
2435                         sprintf(ComLine, "%s %s", AssocProg, Fname);\r
2436                 else\r
2437                         sprintf(ComLine, "%s \"%s\"", AssocProg, Fname);\r
2438 \r
2439                 DoPrintf("FindExecutable - %s", ComLine);\r
2440 \r
2441                 memset(&Startup, NUL, sizeof(STARTUPINFO));\r
2442                 Startup.cb = sizeof(STARTUPINFO);\r
2443                 Startup.wShowWindow = SW_SHOW;\r
2444                 if(CreateProcess(NULL, ComLine, NULL, NULL, FALSE, 0, NULL, NULL, &Startup, &Info) == FALSE)\r
2445                 {\r
2446                         SetTaskMsg(MSGJPN182, GetLastError());\r
2447                         SetTaskMsg(">>%s", ComLine);\r
2448                 }\r
2449         }\r
2450         return;\r
2451 }\r
2452 \r
2453 \r
2454 /*----- 差分表示ビューワを起動 ------------------------------------------------\r
2455 *\r
2456 *       Parameter\r
2457 *               char Fname1 : ファイル名\r
2458 *               char Fname2 : ファイル名2\r
2459 *               int App : アプリケーション番号(2 or 3)\r
2460 *\r
2461 *       Return Value\r
2462 *               なし\r
2463 *----------------------------------------------------------------------------*/\r
2464 \r
2465 void ExecViewer2(char *Fname1, char *Fname2, int App)\r
2466 {\r
2467         PROCESS_INFORMATION Info;\r
2468         STARTUPINFO Startup;\r
2469         char AssocProg[FMAX_PATH+1];\r
2470         char ComLine[FMAX_PATH*2+3+1];\r
2471         char CurDir[FMAX_PATH+1];\r
2472 \r
2473         /* FindExecutable()は関連付けられたプログラムのパス名にスペースが        */\r
2474         /* 含まれている時、間違ったパス名を返す事がある。                                        */\r
2475         /* そこで、関連付けられたプログラムの起動はShellExecute()を使う。       */\r
2476 \r
2477         AskLocalCurDir(CurDir, FMAX_PATH);\r
2478 \r
2479         strcpy(AssocProg, ViewerName[App] + 2); /* 先頭の "d " は読み飛ばす */\r
2480 \r
2481         if(strchr(Fname1, ' ') == NULL && strchr(Fname2, ' ') == NULL)\r
2482                 sprintf(ComLine, "%s %s %s", AssocProg, Fname1, Fname2);\r
2483         else\r
2484                 sprintf(ComLine, "%s \"%s\" \"%s\"", AssocProg, Fname1, Fname2);\r
2485 \r
2486         DoPrintf("FindExecutable - %s", ComLine);\r
2487 \r
2488         memset(&Startup, NUL, sizeof(STARTUPINFO));\r
2489         Startup.cb = sizeof(STARTUPINFO);\r
2490         Startup.wShowWindow = SW_SHOW;\r
2491         if(CreateProcess(NULL, ComLine, NULL, NULL, FALSE, 0, NULL, NULL, &Startup, &Info) == FALSE)\r
2492         {\r
2493                 SetTaskMsg(MSGJPN182, GetLastError());\r
2494                 SetTaskMsg(">>%s", ComLine);\r
2495         }\r
2496 \r
2497         return;\r
2498 }\r
2499 \r
2500 \r
2501 /*----- テンポラリファイル名をテンポラリファイルリストに追加 ------------------\r
2502 *\r
2503 *       Parameter\r
2504 *               char *Fname : テンポラリファイル名\r
2505 *\r
2506 *       Return Value\r
2507 *               なし\r
2508 *----------------------------------------------------------------------------*/\r
2509 \r
2510 void AddTempFileList(char *Fname)\r
2511 {\r
2512         TEMPFILELIST *New;\r
2513 \r
2514         if((New = malloc(sizeof(TEMPFILELIST))) != NULL)\r
2515         {\r
2516                 if((New->Fname = malloc(strlen(Fname)+1)) != NULL)\r
2517                 {\r
2518                         strcpy(New->Fname, Fname);\r
2519                         if(TempFiles == NULL)\r
2520                                 New->Next = NULL;\r
2521                         else\r
2522                                 New->Next = TempFiles;\r
2523                         TempFiles = New;\r
2524                 }\r
2525                 else\r
2526                         free(New);\r
2527         }\r
2528         return;\r
2529 }\r
2530 \r
2531 \r
2532 /*----- テンポラリファイルリストに登録されているファイルを全て削除 ------------\r
2533 *\r
2534 *       Parameter\r
2535 *               なし\r
2536 *\r
2537 *       Return Value\r
2538 *               なし\r
2539 *----------------------------------------------------------------------------*/\r
2540 \r
2541 static void DeleteAlltempFile(void)\r
2542 {\r
2543         TEMPFILELIST *Pos;\r
2544         TEMPFILELIST *Next;\r
2545 \r
2546         Pos = TempFiles;\r
2547         while(Pos != NULL)\r
2548         {\r
2549                 DeleteFile(Pos->Fname);\r
2550 \r
2551                 Next = Pos->Next;\r
2552                 free(Pos->Fname);\r
2553                 free(Pos);\r
2554                 Pos = Next;\r
2555         }\r
2556 \r
2557         // OLE D&Dのテンポラリを削除する (2007.9.11 yutaka)\r
2558         doDeleteRemoteFile();\r
2559 \r
2560         return;\r
2561 }\r
2562 \r
2563 \r
2564 /*----- Aboutダイアログボックスのコールバック関数 ------------------------\r
2565 *\r
2566 *       Parameter\r
2567 *               HWND hDlg : ウインドウハンドル\r
2568 *               UINT message : メッセージ番号\r
2569 *               WPARAM wParam : メッセージの WPARAM 引数\r
2570 *               LPARAM lParam : メッセージの LPARAM 引数\r
2571 *\r
2572 *       Return Value\r
2573 *               BOOL TRUE/FALSE\r
2574 *----------------------------------------------------------------------------*/\r
2575 \r
2576 static BOOL CALLBACK AboutDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)\r
2577 {\r
2578         static char Tmp[80];\r
2579         int Ver;\r
2580 \r
2581         switch (message)\r
2582         {\r
2583                 case WM_INITDIALOG :\r
2584                         Ver = GetJreVersion();\r
2585                         if(Ver == -1)\r
2586                                 sprintf(Tmp, MSGJPN183);\r
2587                         else\r
2588                                 sprintf(Tmp, MSGJPN184, Ver / 0x100, Ver % 0x100);\r
2589                         SendDlgItemMessage(hDlg, ABOUT_JRE, WM_SETTEXT, 0, (LPARAM)Tmp);\r
2590                         SendDlgItemMessage(hDlg, ABOUT_URL, EM_LIMITTEXT, 256, 0);\r
2591                         SendDlgItemMessage(hDlg, ABOUT_URL, WM_SETTEXT, 0, (LPARAM)MSGJPN284);\r
2592                         return(TRUE);\r
2593 \r
2594                 case WM_COMMAND :\r
2595                         switch(GET_WM_COMMAND_ID(wParam, lParam))\r
2596                         {\r
2597                                 case IDOK :\r
2598                                 case IDCANCEL :\r
2599                                         EndDialog(hDlg, YES);\r
2600                                         break;\r
2601                         }\r
2602                         return(TRUE);\r
2603         }\r
2604     return(FALSE);\r
2605 }\r
2606 \r
2607 \r
2608 /*----- サウンドを鳴らす ------------------------------------------------------\r
2609 *\r
2610 *       Parameter\r
2611 *               Int num : サウンドの種類 (SND_xxx)\r
2612 *\r
2613 *       Return Value\r
2614 *               なし\r
2615 *----------------------------------------------------------------------------*/\r
2616 \r
2617 void SoundPlay(int Num)\r
2618 {\r
2619         if(Sound[Num].On == YES)\r
2620                 sndPlaySound(Sound[Num].Fname, SND_ASYNC | SND_NODEFAULT);\r
2621 \r
2622         return;\r
2623 }\r
2624 \r
2625 \r
2626 /*----- ヘルプファイルのパス名を返す ------------------------------------------\r
2627 *\r
2628 *       Parameter\r
2629 *               なし\r
2630 *\r
2631 *       Return Value\r
2632 *               char *パス名\r
2633 *----------------------------------------------------------------------------*/\r
2634 \r
2635 char *AskHelpFilePath(void)\r
2636 {\r
2637         return(HelpPath);\r
2638 }\r
2639 \r
2640 \r
2641 /*----- テンポラリファイルのパス名を返す --------------------------------------\r
2642 *\r
2643 *       Parameter\r
2644 *               なし\r
2645 *\r
2646 *       Return Value\r
2647 *               char *パス名\r
2648 *----------------------------------------------------------------------------*/\r
2649 \r
2650 char *AskTmpFilePath(void)\r
2651 {\r
2652         return(TmpPath);\r
2653 }\r
2654 \r
2655 \r
2656 /*----- INIファイルのパス名を返す ---------------------------------------------\r
2657 *\r
2658 *       Parameter\r
2659 *               なし\r
2660 *\r
2661 *       Return Value\r
2662 *               char *パス名\r
2663 *----------------------------------------------------------------------------*/\r
2664 \r
2665 char *AskIniFilePath(void)\r
2666 {\r
2667         return(IniPath);\r
2668 }\r
2669 \r
2670 /*----- INIファイルのみを使うかどうかを返す -----------------------------------\r
2671 *\r
2672 *       Parameter\r
2673 *               なし\r
2674 *\r
2675 *       Return Value\r
2676 *               int ステータス : YES/NO\r
2677 *----------------------------------------------------------------------------*/\r
2678 \r
2679 int AskForceIni(void)\r
2680 {\r
2681         return(ForceIni);\r
2682 }\r
2683 \r
2684 \r
2685 \r
2686 \r
2687 /*----- メッセージ処理 --------------------------------------------------------\r
2688 *\r
2689 *       Parameter\r
2690 *               なし\r
2691 *\r
2692 *       Return Value\r
2693 *               int 終了フラグ (YES=WM_CLOSEが来た/NO)\r
2694 *----------------------------------------------------------------------------*/\r
2695 \r
2696 int BackgrndMessageProc(void)\r
2697 {\r
2698     MSG Msg;\r
2699         int Ret;\r
2700 \r
2701         Ret = NO;\r
2702         while(PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE))\r
2703         {\r
2704                 if(!HtmlHelp(NULL, NULL, HH_PRETRANSLATEMESSAGE, (DWORD)&Msg))\r
2705                 {\r
2706                         /* ディレクトリ名の表示コンボボックスでBSやRETが効くように */\r
2707                         /* コンボボックス内ではアクセラレータを無効にする */\r
2708                         if((Msg.hwnd == GetLocalHistEditHwnd()) ||\r
2709                            (Msg.hwnd == GetRemoteHistEditHwnd()) ||\r
2710                            ((hHelpWin != NULL) && (Msg.hwnd == hHelpWin)) ||\r
2711                            GetHideUI() == YES ||\r
2712                            (TranslateAccelerator(GetMainHwnd(), Accel, &Msg) == 0))\r
2713                         {\r
2714                                 if(Msg.message == WM_QUIT)\r
2715                                 {\r
2716                                         Ret = YES;\r
2717                                         PostQuitMessage(0);\r
2718                                         break;\r
2719                                 }\r
2720                                 TranslateMessage(&Msg);\r
2721                                 DispatchMessage(&Msg);\r
2722                         }\r
2723                 }\r
2724         }\r
2725         return(Ret);\r
2726 }\r
2727 \r
2728 \r
2729 /*----- 自動終了フラグをクリアする --------------------------------------------\r
2730 *\r
2731 *       Parameter\r
2732 *               なし\r
2733 *\r
2734 *       Return Value\r
2735 *               なし\r
2736 *----------------------------------------------------------------------------*/\r
2737 \r
2738 void ResetAutoExitFlg(void)\r
2739 {\r
2740         AutoExit = NO;\r
2741         return;\r
2742 }\r
2743 \r
2744 \r
2745 /*----- 自動終了フラグを返す --------------------------------------------------\r
2746 *\r
2747 *       Parameter\r
2748 *               なし\r
2749 *\r
2750 *       Return Value\r
2751 *               int フラグ (YES/NO)\r
2752 *----------------------------------------------------------------------------*/\r
2753 \r
2754 int AskAutoExit(void)\r
2755 {\r
2756         return(AutoExit);\r
2757 }\r
2758 \r
2759 /*----- ユーザにパスワードを入力させ,それを設定する -----------------------\r
2760 *\r
2761 *       Parameter\r
2762 *               なし\r
2763 *\r
2764 *       Return Value\r
2765 *               int : 0/ユーザキャンセル, 1/設定した, 2/デフォルト設定\r
2766 *----------------------------------------------------------------------------*/\r
2767 int EnterMasterPasswordAndSet( int Res, HWND hWnd )\r
2768 {\r
2769         char buf[MAX_PASSWORD_LEN + 1];\r
2770         char *p;\r
2771         int Flag;\r
2772 \r
2773         buf[0] = NUL;\r
2774         if( InputDialogBox(Res, hWnd, NULL, buf, MAX_PASSWORD_LEN + 1,\r
2775                 &Flag, IDH_HELP_TOPIC_0000064) == YES){\r
2776                 /* 末尾の空白を削除 */\r
2777                 RemoveTailingSpaces(buf);\r
2778                 /* 先頭の空白を削除 */\r
2779                 for( p = buf; *p == ' '; p++ )\r
2780                         ;\r
2781                 \r
2782                 if( p[0] != NUL ){\r
2783                         SetMasterPassword( p );\r
2784                         return 1;\r
2785                 }\r
2786                 else {\r
2787                         /* 空の場合はデフォルト値を設定 */\r
2788                         SetMasterPassword( NULL );\r
2789                         return 2;\r
2790                 }\r
2791         }\r
2792         return 0;\r
2793 }\r
2794 \r
2795 // 暗号化通信対応\r
2796 BOOL __stdcall SSLTimeoutCallback()\r
2797 {\r
2798         Sleep(1);\r
2799         if(BackgrndMessageProc() == YES)\r
2800                 return TRUE;\r
2801         // 念のためツールバーのMENU_ABORTも確認\r
2802 //      if(MainTransPkt.Abort != ABORT_NONE)\r
2803 //      {\r
2804 //              MainTransPkt.Abort = ABORT_NONE;\r
2805 //              return TRUE;\r
2806 //      }\r
2807         return FALSE;\r
2808 }\r
2809 \r