1 /*=============================================================================
\r
5 ===============================================================================
\r
6 / Copyright (C) 1997-2007 Sota. All rights reserved.
\r
8 / Redistribution and use in source and binary forms, with or without
\r
9 / modification, are permitted provided that the following conditions
\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
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
32 #include <winsock2.h>
\r
33 #include <windows.h>
\r
37 #include <mbstring.h>
\r
39 #include <windowsx.h>
\r
40 #include <commctrl.h>
\r
43 //#include <winsock.h>
\r
46 #include "resource.h"
\r
49 /*===== プロトタイプ =====*/
\r
51 static void CopyHostToHistory(HOSTDATA *Host, HISTORYDATA *New);
\r
52 static void AddOneFnameToMenu(char *Host, char *User, char *Remote, int Num);
\r
53 static void RemoveAllHistoryFromMenu(void);
\r
55 /*===== 外部参照 =====*/
\r
58 extern int FileHist;
\r
59 extern int PassToHist;
\r
61 /*===== ローカルなワーク =====*/
\r
63 static HISTORYDATA *HistoryBase = NULL;
\r
64 static int HistoryNum = 0;
\r
66 /* ヒストリのメニュー項目のID */
\r
67 static int MenuHistId[HISTORY_MAX] = {
\r
68 MENU_HIST_1, MENU_HIST_2, MENU_HIST_3, MENU_HIST_4, MENU_HIST_5,
\r
69 MENU_HIST_6, MENU_HIST_7, MENU_HIST_8, MENU_HIST_9, MENU_HIST_10,
\r
70 MENU_HIST_11, MENU_HIST_12, MENU_HIST_13, MENU_HIST_14, MENU_HIST_15,
\r
71 MENU_HIST_16, MENU_HIST_17, MENU_HIST_18, MENU_HIST_19, MENU_HIST_20
\r
76 /*----- ホスト情報をヒストリリストの先頭に追加する ----------------------------
\r
79 * HOSTDATA *Host : ホストデータ
\r
80 * int TrMode : 転送モード
\r
84 *----------------------------------------------------------------------------*/
\r
86 void AddHostToHistory(HOSTDATA *Host, int TrMode)
\r
90 CopyHostToHistory(Host, &New);
\r
92 AddHistoryToHistory(&New);
\r
97 /*----- ヒストリをヒストリリストの先頭に追加する ------------------------------
\r
100 * HISTORYDATA *Hist : ヒストリデータ
\r
104 *----------------------------------------------------------------------------*/
\r
106 void AddHistoryToHistory(HISTORYDATA *Hist)
\r
110 CheckHistoryNum(1);
\r
111 if(FileHist > HistoryNum)
\r
113 New = malloc(sizeof(HISTORYDATA));
\r
116 memcpy(New, Hist, sizeof(HISTORYDATA));
\r
117 New->Next = HistoryBase;
\r
126 /*----- ヒストリの数を返す ----------------------------------------------------
\r
133 *----------------------------------------------------------------------------*/
\r
135 int AskHistoryNum(void)
\r
137 return(HistoryNum);
\r
141 /*----- ヒストリの数をチェックし多すぎたら削除 --------------------------------
\r
144 * int Space : 空けておく個数 (0~)
\r
148 *----------------------------------------------------------------------------*/
\r
150 void CheckHistoryNum(int Space)
\r
157 if(HistoryNum > FileHist-Space)
\r
162 for(i = 0; i < FileHist-Space; i++)
\r
170 HistoryBase = NULL;
\r
186 /*----- ホスト情報をヒストリにセット ------------------------------------------
\r
189 * HOSTDATA *Host : ホストデータ
\r
190 * HISTORYDATA *New : ヒストリをセットするワーク
\r
194 *----------------------------------------------------------------------------*/
\r
196 static void CopyHostToHistory(HOSTDATA *Host, HISTORYDATA *New)
\r
198 strcpy(New->HostAdrs, Host->HostAdrs);
\r
199 strcpy(New->UserName, Host->UserName);
\r
200 if(PassToHist == YES)
\r
201 strcpy(New->PassWord, Host->PassWord);
\r
203 strcpy(New->PassWord, "");
\r
204 strcpy(New->Account, Host->Account);
\r
205 strcpy(New->LocalInitDir, Host->LocalInitDir);
\r
206 strcpy(New->RemoteInitDir, Host->RemoteInitDir);
\r
207 strcpy(New->ChmodCmd, Host->ChmodCmd);
\r
208 strcpy(New->LsName, Host->LsName);
\r
209 strcpy(New->InitCmd, Host->InitCmd);
\r
210 New->Port = Host->Port;
\r
211 New->KanjiCode = Host->KanjiCode;
\r
212 New->KanaCnv = Host->KanaCnv;
\r
213 New->NameKanjiCode = Host->NameKanjiCode;
\r
214 New->NameKanaCnv = Host->NameKanaCnv;
\r
215 New->Pasv = Host->Pasv;
\r
216 New->FireWall = Host->FireWall;
\r
217 New->ListCmdOnly = Host->ListCmdOnly;
\r
218 New->UseNLST_R = Host->UseNLST_R;
\r
219 New->TimeZone = Host->TimeZone;
\r
220 New->HostType = Host->HostType;
\r
221 New->SyncMove = Host->SyncMove;
\r
222 New->NoFullPath = Host->NoFullPath;
\r
223 New->Sort = Host->Sort;
\r
224 New->Security = Host->Security;
\r
225 New->Dialup = Host->Dialup;
\r
226 New->DialupAlways = Host->DialupAlways;
\r
227 New->DialupNotify = Host->DialupNotify;
\r
228 strcpy(New->DialEntry, Host->DialEntry);
\r
230 New->UseNoEncryption = Host->UseNoEncryption;
\r
231 New->UseFTPES = Host->UseFTPES;
\r
232 New->UseFTPIS = Host->UseFTPIS;
\r
233 New->UseSFTP = Host->UseSFTP;
\r
234 strcpy(New->PrivateKey, Host->PrivateKey);
\r
235 New->NoWeakEncryption = Host->NoWeakEncryption;
\r
237 New->MaxThreadCount = Host->MaxThreadCount;
\r
238 New->ReuseCmdSkt = Host->ReuseCmdSkt;
\r
240 New->UseMLSD = Host->UseMLSD;
\r
242 New->NetType = Host->NetType;
\r
244 New->NoopInterval = Host->NoopInterval;
\r
246 New->TransferErrorMode = Host->TransferErrorMode;
\r
247 New->TransferErrorNotify = Host->TransferErrorNotify;
\r
248 // セッションあたりの転送量制限対策
\r
249 New->TransferErrorReconnect = Host->TransferErrorReconnect;
\r
254 /*----- ヒストリ情報をホスト情報にセット --------------------------------------
\r
257 * HISTORYDATA *Hist : ヒストリ
\r
258 * HOSTDATA *Host : ホストデータをセットするワーク
\r
262 *----------------------------------------------------------------------------*/
\r
264 void CopyHistoryToHost(HISTORYDATA *Hist, HOSTDATA *Host)
\r
266 CopyDefaultHost(Host);
\r
268 strcpy(Host->HostAdrs, Hist->HostAdrs);
\r
269 strcpy(Host->UserName, Hist->UserName);
\r
270 if(PassToHist == YES)
\r
271 strcpy(Host->PassWord, Hist->PassWord);
\r
273 strcpy(Host->PassWord, "");
\r
274 strcpy(Host->Account, Hist->Account);
\r
275 strcpy(Host->LocalInitDir, Hist->LocalInitDir);
\r
276 strcpy(Host->RemoteInitDir, Hist->RemoteInitDir);
\r
277 strcpy(Host->ChmodCmd, Hist->ChmodCmd);
\r
278 strcpy(Host->LsName, Hist->LsName);
\r
279 strcpy(Host->InitCmd, Hist->InitCmd);
\r
280 Host->Port = Hist->Port;
\r
281 Host->KanjiCode = Hist->KanjiCode;
\r
282 Host->KanaCnv = Hist->KanaCnv;
\r
283 Host->NameKanjiCode = Hist->NameKanjiCode;
\r
284 Host->NameKanaCnv = Hist->NameKanaCnv;
\r
285 Host->Pasv = Hist->Pasv;
\r
286 Host->FireWall = Hist->FireWall;
\r
287 Host->ListCmdOnly = Hist->ListCmdOnly;
\r
288 Host->UseNLST_R = Hist->UseNLST_R;
\r
289 Host->TimeZone = Hist->TimeZone;
\r
290 Host->HostType = Hist->HostType;
\r
291 Host->SyncMove = Hist->SyncMove;
\r
292 Host->NoFullPath = Hist->NoFullPath;
\r
293 Host->Sort = Hist->Sort;
\r
294 Host->Security = Hist->Security;
\r
295 Host->Dialup = Hist->Dialup;
\r
296 Host->DialupAlways = Hist->DialupAlways;
\r
297 Host->DialupNotify = Hist->DialupNotify;
\r
298 strcpy(Host->DialEntry, Hist->DialEntry);
\r
300 Host->UseNoEncryption = Hist->UseNoEncryption;
\r
301 Host->UseFTPES = Hist->UseFTPES;
\r
302 Host->UseFTPIS = Hist->UseFTPIS;
\r
303 Host->UseSFTP = Hist->UseSFTP;
\r
304 strcpy(Host->PrivateKey, Hist->PrivateKey);
\r
305 Host->NoWeakEncryption = Hist->NoWeakEncryption;
\r
307 Host->MaxThreadCount = Hist->MaxThreadCount;
\r
308 Host->ReuseCmdSkt = Hist->ReuseCmdSkt;
\r
310 Host->UseMLSD = Hist->UseMLSD;
\r
312 Host->NetType = Hist->NetType;
\r
314 Host->NoopInterval = Hist->NoopInterval;
\r
316 Host->TransferErrorMode = Hist->TransferErrorMode;
\r
317 Host->TransferErrorNotify = Hist->TransferErrorNotify;
\r
318 // セッションあたりの転送量制限対策
\r
319 Host->TransferErrorReconnect = Hist->TransferErrorReconnect;
\r
324 /*----- ヒストリ情報の初期値を取得 --------------------------------------------
\r
327 * HISTORYDATA *Set : ヒストリをセットするワーク
\r
331 *----------------------------------------------------------------------------*/
\r
333 void CopyDefaultHistory(HISTORYDATA *Set)
\r
337 CopyDefaultHost(&Host);
\r
338 CopyHostToHistory(&Host, Set);
\r
343 /*----- 全ヒストリをメニューにセット ------------------------------------------
\r
350 *----------------------------------------------------------------------------*/
\r
352 void SetAllHistoryToMenu(void)
\r
357 RemoveAllHistoryFromMenu();
\r
360 for(i = 0; i < HistoryNum; i++)
\r
362 AddOneFnameToMenu(Pos->HostAdrs, Pos->UserName, Pos->RemoteInitDir, i);
\r
369 /*----- ヒストリをメニューに追加 ----------------------------------------------
\r
372 * char *Host : ホスト名
\r
373 * char *User : ユーザ名
\r
374 * char *Remote : ホストのフォルダ
\r
379 *----------------------------------------------------------------------------*/
\r
381 static void AddOneFnameToMenu(char *Host, char *User, char *Remote, int Num)
\r
384 char Tmp[HOST_ADRS_LEN+USER_NAME_LEN+INIT_DIR_LEN+7+1];
\r
386 hMenu = GetSubMenu(GetMenu(GetMainHwnd()), 0);
\r
389 AppendMenu(hMenu, MF_SEPARATOR, 0, NULL);
\r
392 sprintf(Tmp, "&%d %s (%s) %s", Num+1, Host, User, Remote);
\r
394 sprintf(Tmp, "&0 %s (%s) %s", Host, User, Remote);
\r
396 sprintf(Tmp, "&* %s (%s) %s", Host, User, Remote);
\r
398 AppendMenu(hMenu, MF_STRING, MenuHistId[Num], Tmp);
\r
404 /*----- 全ヒストリをメニューから削除 ------------------------------------------
\r
411 *----------------------------------------------------------------------------*/
\r
413 static void RemoveAllHistoryFromMenu(void)
\r
419 hMenu = GetSubMenu(GetMenu(GetMainHwnd()), 0);
\r
420 Cnt = GetMenuItemCount(hMenu);
\r
421 for(i = DEF_FMENU_ITEMS; i < Cnt; i++)
\r
423 DeleteMenu(hMenu, DEF_FMENU_ITEMS, MF_BYPOSITION);
\r
429 /*----- 指定メニューコマンドに対応するヒストリを返す --------------------------
\r
432 * int MenuCmd : 取り出すヒストリに割り当てられたメニューコマンド (MENU_xxx)
\r
433 * HISTORYDATA *Buf : ヒストリデータを返すバッファ
\r
437 * FFFTP_SUCCESS/FFFTP_FAIL
\r
438 *----------------------------------------------------------------------------*/
\r
440 int GetHistoryByCmd(int MenuCmd, HISTORYDATA *Buf)
\r
448 for(i = 0; i < HistoryNum; i++)
\r
450 if(MenuHistId[i] == MenuCmd)
\r
452 memcpy(Buf, Pos, sizeof(HISTORYDATA));
\r
453 Sts = FFFTP_SUCCESS;
\r
461 /*----- 指定番号に対応するヒストリを返す --------------------------------------
\r
465 * HISTORYDATA *Buf : ヒストリデータを返すバッファ
\r
469 * FFFTP_SUCCESS/FFFTP_FAIL
\r
470 *----------------------------------------------------------------------------*/
\r
472 int GetHistoryByNum(int Num, HISTORYDATA *Buf)
\r
474 return(GetHistoryByCmd(MenuHistId[Num], Buf));
\r