OSDN Git Service

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