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
31 #include <windows.h>
\r
35 #include <mbstring.h>
\r
37 #include <windowsx.h>
\r
38 #include <commctrl.h>
\r
40 #include <winsock.h>
\r
43 #include "resource.h"
\r
46 /*===== プロトタイプ =====*/
\r
48 static void CopyHostToHistory(HOSTDATA *Host, HISTORYDATA *New);
\r
49 static void AddOneFnameToMenu(char *Host, char *User, char *Remote, int Num);
\r
50 static void RemoveAllHistoryFromMenu(void);
\r
52 /*===== 外部参照 =====*/
\r
55 extern int FileHist;
\r
56 extern int PassToHist;
\r
58 /*===== ローカルなワーク =====*/
\r
60 static HISTORYDATA *HistoryBase = NULL;
\r
61 static int HistoryNum = 0;
\r
63 /* ヒストリのメニュー項目のID */
\r
64 static int MenuHistId[HISTORY_MAX] = {
\r
65 MENU_HIST_1, MENU_HIST_2, MENU_HIST_3, MENU_HIST_4, MENU_HIST_5,
\r
66 MENU_HIST_6, MENU_HIST_7, MENU_HIST_8, MENU_HIST_9, MENU_HIST_10,
\r
67 MENU_HIST_11, MENU_HIST_12, MENU_HIST_13, MENU_HIST_14, MENU_HIST_15,
\r
68 MENU_HIST_16, MENU_HIST_17, MENU_HIST_18, MENU_HIST_19, MENU_HIST_20
\r
73 /*----- ホスト情報をヒストリリストの先頭に追加する ----------------------------
\r
76 * HOSTDATA *Host : ホストデータ
\r
77 * int TrMode : 転送モード
\r
81 *----------------------------------------------------------------------------*/
\r
83 void AddHostToHistory(HOSTDATA *Host, int TrMode)
\r
87 CopyHostToHistory(Host, &New);
\r
89 AddHistoryToHistory(&New);
\r
94 /*----- ヒストリをヒストリリストの先頭に追加する ------------------------------
\r
97 * HISTORYDATA *Hist : ヒストリデータ
\r
101 *----------------------------------------------------------------------------*/
\r
103 void AddHistoryToHistory(HISTORYDATA *Hist)
\r
107 CheckHistoryNum(1);
\r
108 if(FileHist > HistoryNum)
\r
110 New = malloc(sizeof(HISTORYDATA));
\r
113 memcpy(New, Hist, sizeof(HISTORYDATA));
\r
114 New->Next = HistoryBase;
\r
123 /*----- ヒストリの数を返す ----------------------------------------------------
\r
130 *----------------------------------------------------------------------------*/
\r
132 int AskHistoryNum(void)
\r
134 return(HistoryNum);
\r
138 /*----- ヒストリの数をチェックし多すぎたら削除 --------------------------------
\r
141 * int Space : 空けておく個数 (0~)
\r
145 *----------------------------------------------------------------------------*/
\r
147 void CheckHistoryNum(int Space)
\r
154 if(HistoryNum > FileHist-Space)
\r
159 for(i = 0; i < FileHist-Space; i++)
\r
167 HistoryBase = NULL;
\r
183 /*----- ホスト情報をヒストリにセット ------------------------------------------
\r
186 * HOSTDATA *Host : ホストデータ
\r
187 * HISTORYDATA *New : ヒストリをセットするワーク
\r
191 *----------------------------------------------------------------------------*/
\r
193 static void CopyHostToHistory(HOSTDATA *Host, HISTORYDATA *New)
\r
195 strcpy(New->HostAdrs, Host->HostAdrs);
\r
196 strcpy(New->UserName, Host->UserName);
\r
197 if(PassToHist == YES)
\r
198 strcpy(New->PassWord, Host->PassWord);
\r
200 strcpy(New->PassWord, "");
\r
201 strcpy(New->Account, Host->Account);
\r
202 strcpy(New->LocalInitDir, Host->LocalInitDir);
\r
203 strcpy(New->RemoteInitDir, Host->RemoteInitDir);
\r
204 strcpy(New->ChmodCmd, Host->ChmodCmd);
\r
205 strcpy(New->LsName, Host->LsName);
\r
206 strcpy(New->InitCmd, Host->InitCmd);
\r
207 New->Port = Host->Port;
\r
208 New->KanjiCode = Host->KanjiCode;
\r
209 New->KanaCnv = Host->KanaCnv;
\r
210 New->NameKanjiCode = Host->NameKanjiCode;
\r
211 New->NameKanaCnv = Host->NameKanaCnv;
\r
212 New->Pasv = Host->Pasv;
\r
213 New->FireWall = Host->FireWall;
\r
214 New->ListCmdOnly = Host->ListCmdOnly;
\r
215 New->UseNLST_R = Host->UseNLST_R;
\r
216 New->TimeZone = Host->TimeZone;
\r
217 New->HostType = Host->HostType;
\r
218 New->SyncMove = Host->SyncMove;
\r
219 New->NoFullPath = Host->NoFullPath;
\r
220 New->Sort = Host->Sort;
\r
221 New->Security = Host->Security;
\r
222 New->Dialup = Host->Dialup;
\r
223 New->DialupAlways = Host->DialupAlways;
\r
224 New->DialupNotify = Host->DialupNotify;
\r
225 strcpy(New->DialEntry, Host->DialEntry);
\r
227 New->UseFTPES = Host->UseFTPES;
\r
228 New->UseFTPIS = Host->UseFTPIS;
\r
229 New->UseSFTP = Host->UseSFTP;
\r
231 New->MaxThreadCount = Host->MaxThreadCount;
\r
233 New->UseMLSD = Host->UseMLSD;
\r
238 /*----- ヒストリ情報をホスト情報にセット --------------------------------------
\r
241 * HISTORYDATA *Hist : ヒストリ
\r
242 * HOSTDATA *Host : ホストデータをセットするワーク
\r
246 *----------------------------------------------------------------------------*/
\r
248 void CopyHistoryToHost(HISTORYDATA *Hist, HOSTDATA *Host)
\r
250 CopyDefaultHost(Host);
\r
252 strcpy(Host->HostAdrs, Hist->HostAdrs);
\r
253 strcpy(Host->UserName, Hist->UserName);
\r
254 if(PassToHist == YES)
\r
255 strcpy(Host->PassWord, Hist->PassWord);
\r
257 strcpy(Host->PassWord, "");
\r
258 strcpy(Host->Account, Hist->Account);
\r
259 strcpy(Host->LocalInitDir, Hist->LocalInitDir);
\r
260 strcpy(Host->RemoteInitDir, Hist->RemoteInitDir);
\r
261 strcpy(Host->ChmodCmd, Hist->ChmodCmd);
\r
262 strcpy(Host->LsName, Hist->LsName);
\r
263 strcpy(Host->InitCmd, Hist->InitCmd);
\r
264 Host->Port = Hist->Port;
\r
265 Host->KanjiCode = Hist->KanjiCode;
\r
266 Host->KanaCnv = Hist->KanaCnv;
\r
267 Host->NameKanjiCode = Hist->NameKanjiCode;
\r
268 Host->NameKanaCnv = Hist->NameKanaCnv;
\r
269 Host->Pasv = Hist->Pasv;
\r
270 Host->FireWall = Hist->FireWall;
\r
271 Host->ListCmdOnly = Hist->ListCmdOnly;
\r
272 Host->UseNLST_R = Hist->UseNLST_R;
\r
273 Host->TimeZone = Hist->TimeZone;
\r
274 Host->HostType = Hist->HostType;
\r
275 Host->SyncMove = Hist->SyncMove;
\r
276 Host->NoFullPath = Hist->NoFullPath;
\r
277 Host->Sort = Hist->Sort;
\r
278 Host->Security = Hist->Security;
\r
279 Host->Dialup = Hist->Dialup;
\r
280 Host->DialupAlways = Hist->DialupAlways;
\r
281 Host->DialupNotify = Hist->DialupNotify;
\r
282 strcpy(Host->DialEntry, Hist->DialEntry);
\r
284 Host->UseFTPES = Hist->UseFTPES;
\r
285 Host->UseFTPIS = Hist->UseFTPIS;
\r
286 Host->UseSFTP = Hist->UseSFTP;
\r
288 Host->MaxThreadCount = Hist->MaxThreadCount;
\r
290 Host->UseMLSD = Hist->UseMLSD;
\r
295 /*----- ヒストリ情報の初期値を取得 --------------------------------------------
\r
298 * HISTORYDATA *Set : ヒストリをセットするワーク
\r
302 *----------------------------------------------------------------------------*/
\r
304 void CopyDefaultHistory(HISTORYDATA *Set)
\r
308 CopyDefaultHost(&Host);
\r
309 CopyHostToHistory(&Host, Set);
\r
314 /*----- 全ヒストリをメニューにセット ------------------------------------------
\r
321 *----------------------------------------------------------------------------*/
\r
323 void SetAllHistoryToMenu(void)
\r
328 RemoveAllHistoryFromMenu();
\r
331 for(i = 0; i < HistoryNum; i++)
\r
333 AddOneFnameToMenu(Pos->HostAdrs, Pos->UserName, Pos->RemoteInitDir, i);
\r
340 /*----- ヒストリをメニューに追加 ----------------------------------------------
\r
343 * char *Host : ホスト名
\r
344 * char *User : ユーザ名
\r
345 * char *Remote : ホストのフォルダ
\r
350 *----------------------------------------------------------------------------*/
\r
352 static void AddOneFnameToMenu(char *Host, char *User, char *Remote, int Num)
\r
355 char Tmp[HOST_ADRS_LEN+USER_NAME_LEN+INIT_DIR_LEN+7+1];
\r
357 hMenu = GetSubMenu(GetMenu(GetMainHwnd()), 0);
\r
360 AppendMenu(hMenu, MF_SEPARATOR, 0, NULL);
\r
363 sprintf(Tmp, "&%d %s (%s) %s", Num+1, Host, User, Remote);
\r
365 sprintf(Tmp, "&0 %s (%s) %s", Host, User, Remote);
\r
367 sprintf(Tmp, "&* %s (%s) %s", Host, User, Remote);
\r
369 AppendMenu(hMenu, MF_STRING, MenuHistId[Num], Tmp);
\r
375 /*----- 全ヒストリをメニューから削除 ------------------------------------------
\r
382 *----------------------------------------------------------------------------*/
\r
384 static void RemoveAllHistoryFromMenu(void)
\r
390 hMenu = GetSubMenu(GetMenu(GetMainHwnd()), 0);
\r
391 Cnt = GetMenuItemCount(hMenu);
\r
392 for(i = DEF_FMENU_ITEMS; i < Cnt; i++)
\r
394 DeleteMenu(hMenu, DEF_FMENU_ITEMS, MF_BYPOSITION);
\r
400 /*----- 指定メニューコマンドに対応するヒストリを返す --------------------------
\r
403 * int MenuCmd : 取り出すヒストリに割り当てられたメニューコマンド (MENU_xxx)
\r
404 * HISTORYDATA *Buf : ヒストリデータを返すバッファ
\r
408 * FFFTP_SUCCESS/FFFTP_FAIL
\r
409 *----------------------------------------------------------------------------*/
\r
411 int GetHistoryByCmd(int MenuCmd, HISTORYDATA *Buf)
\r
419 for(i = 0; i < HistoryNum; i++)
\r
421 if(MenuHistId[i] == MenuCmd)
\r
423 memcpy(Buf, Pos, sizeof(HISTORYDATA));
\r
424 Sts = FFFTP_SUCCESS;
\r
432 /*----- 指定番号に対応するヒストリを返す --------------------------------------
\r
436 * HISTORYDATA *Buf : ヒストリデータを返すバッファ
\r
440 * FFFTP_SUCCESS/FFFTP_FAIL
\r
441 *----------------------------------------------------------------------------*/
\r
443 int GetHistoryByNum(int Num, HISTORYDATA *Buf)
\r
445 return(GetHistoryByCmd(MenuHistId[Num], Buf));
\r