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
236 New->MaxThreadCount = Host->MaxThreadCount;
\r
237 New->ReuseCmdSkt = Host->ReuseCmdSkt;
\r
239 New->UseMLSD = Host->UseMLSD;
\r
241 New->UseIPv6 = Host->UseIPv6;
\r
246 /*----- ヒストリ情報をホスト情報にセット --------------------------------------
\r
249 * HISTORYDATA *Hist : ヒストリ
\r
250 * HOSTDATA *Host : ホストデータをセットするワーク
\r
254 *----------------------------------------------------------------------------*/
\r
256 void CopyHistoryToHost(HISTORYDATA *Hist, HOSTDATA *Host)
\r
258 CopyDefaultHost(Host);
\r
260 strcpy(Host->HostAdrs, Hist->HostAdrs);
\r
261 strcpy(Host->UserName, Hist->UserName);
\r
262 if(PassToHist == YES)
\r
263 strcpy(Host->PassWord, Hist->PassWord);
\r
265 strcpy(Host->PassWord, "");
\r
266 strcpy(Host->Account, Hist->Account);
\r
267 strcpy(Host->LocalInitDir, Hist->LocalInitDir);
\r
268 strcpy(Host->RemoteInitDir, Hist->RemoteInitDir);
\r
269 strcpy(Host->ChmodCmd, Hist->ChmodCmd);
\r
270 strcpy(Host->LsName, Hist->LsName);
\r
271 strcpy(Host->InitCmd, Hist->InitCmd);
\r
272 Host->Port = Hist->Port;
\r
273 Host->KanjiCode = Hist->KanjiCode;
\r
274 Host->KanaCnv = Hist->KanaCnv;
\r
275 Host->NameKanjiCode = Hist->NameKanjiCode;
\r
276 Host->NameKanaCnv = Hist->NameKanaCnv;
\r
277 Host->Pasv = Hist->Pasv;
\r
278 Host->FireWall = Hist->FireWall;
\r
279 Host->ListCmdOnly = Hist->ListCmdOnly;
\r
280 Host->UseNLST_R = Hist->UseNLST_R;
\r
281 Host->TimeZone = Hist->TimeZone;
\r
282 Host->HostType = Hist->HostType;
\r
283 Host->SyncMove = Hist->SyncMove;
\r
284 Host->NoFullPath = Hist->NoFullPath;
\r
285 Host->Sort = Hist->Sort;
\r
286 Host->Security = Hist->Security;
\r
287 Host->Dialup = Hist->Dialup;
\r
288 Host->DialupAlways = Hist->DialupAlways;
\r
289 Host->DialupNotify = Hist->DialupNotify;
\r
290 strcpy(Host->DialEntry, Hist->DialEntry);
\r
292 Host->UseNoEncryption = Hist->UseNoEncryption;
\r
293 Host->UseFTPES = Hist->UseFTPES;
\r
294 Host->UseFTPIS = Hist->UseFTPIS;
\r
295 Host->UseSFTP = Hist->UseSFTP;
\r
296 strcpy(Host->PrivateKey, Hist->PrivateKey);
\r
298 Host->MaxThreadCount = Hist->MaxThreadCount;
\r
299 Host->ReuseCmdSkt = Hist->ReuseCmdSkt;
\r
301 Host->UseMLSD = Hist->UseMLSD;
\r
303 Host->UseIPv6 = Hist->UseIPv6;
\r
308 /*----- ヒストリ情報の初期値を取得 --------------------------------------------
\r
311 * HISTORYDATA *Set : ヒストリをセットするワーク
\r
315 *----------------------------------------------------------------------------*/
\r
317 void CopyDefaultHistory(HISTORYDATA *Set)
\r
321 CopyDefaultHost(&Host);
\r
322 CopyHostToHistory(&Host, Set);
\r
327 /*----- 全ヒストリをメニューにセット ------------------------------------------
\r
334 *----------------------------------------------------------------------------*/
\r
336 void SetAllHistoryToMenu(void)
\r
341 RemoveAllHistoryFromMenu();
\r
344 for(i = 0; i < HistoryNum; i++)
\r
346 AddOneFnameToMenu(Pos->HostAdrs, Pos->UserName, Pos->RemoteInitDir, i);
\r
353 /*----- ヒストリをメニューに追加 ----------------------------------------------
\r
356 * char *Host : ホスト名
\r
357 * char *User : ユーザ名
\r
358 * char *Remote : ホストのフォルダ
\r
363 *----------------------------------------------------------------------------*/
\r
365 static void AddOneFnameToMenu(char *Host, char *User, char *Remote, int Num)
\r
368 char Tmp[HOST_ADRS_LEN+USER_NAME_LEN+INIT_DIR_LEN+7+1];
\r
370 hMenu = GetSubMenu(GetMenu(GetMainHwnd()), 0);
\r
373 AppendMenu(hMenu, MF_SEPARATOR, 0, NULL);
\r
376 sprintf(Tmp, "&%d %s (%s) %s", Num+1, Host, User, Remote);
\r
378 sprintf(Tmp, "&0 %s (%s) %s", Host, User, Remote);
\r
380 sprintf(Tmp, "&* %s (%s) %s", Host, User, Remote);
\r
382 AppendMenu(hMenu, MF_STRING, MenuHistId[Num], Tmp);
\r
388 /*----- 全ヒストリをメニューから削除 ------------------------------------------
\r
395 *----------------------------------------------------------------------------*/
\r
397 static void RemoveAllHistoryFromMenu(void)
\r
403 hMenu = GetSubMenu(GetMenu(GetMainHwnd()), 0);
\r
404 Cnt = GetMenuItemCount(hMenu);
\r
405 for(i = DEF_FMENU_ITEMS; i < Cnt; i++)
\r
407 DeleteMenu(hMenu, DEF_FMENU_ITEMS, MF_BYPOSITION);
\r
413 /*----- 指定メニューコマンドに対応するヒストリを返す --------------------------
\r
416 * int MenuCmd : 取り出すヒストリに割り当てられたメニューコマンド (MENU_xxx)
\r
417 * HISTORYDATA *Buf : ヒストリデータを返すバッファ
\r
421 * FFFTP_SUCCESS/FFFTP_FAIL
\r
422 *----------------------------------------------------------------------------*/
\r
424 int GetHistoryByCmd(int MenuCmd, HISTORYDATA *Buf)
\r
432 for(i = 0; i < HistoryNum; i++)
\r
434 if(MenuHistId[i] == MenuCmd)
\r
436 memcpy(Buf, Pos, sizeof(HISTORYDATA));
\r
437 Sts = FFFTP_SUCCESS;
\r
445 /*----- 指定番号に対応するヒストリを返す --------------------------------------
\r
449 * HISTORYDATA *Buf : ヒストリデータを返すバッファ
\r
453 * FFFTP_SUCCESS/FFFTP_FAIL
\r
454 *----------------------------------------------------------------------------*/
\r
456 int GetHistoryByNum(int Num, HISTORYDATA *Buf)
\r
458 return(GetHistoryByCmd(MenuHistId[Num], Buf));
\r