OSDN Git Service

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