OSDN Git Service

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