OSDN Git Service

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