OSDN Git Service

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