OSDN Git Service

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