ApplicationDlg.cpp 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281
  1. /****************************************************************/
  2. /* */
  3. /* ApplicationDlg.cpp */
  4. /* */
  5. /* Implementation of the CApplicationDlg class. */
  6. /* This class is a part of the FTP Server. */
  7. /* */
  8. /* Programmed by LYFZ van der Meer */
  9. /* Copyright LYFZ Software Solutions 2002 */
  10. /* http://www.LYFZvandermeer.nl */
  11. /* */
  12. /* Last updated: 10 july 2002 */
  13. /* */
  14. /****************************************************************/
  15. //在ApplicationDlg.cpp文件中实现主窗口界面的设计。及其主窗口相应控件的功能和参数的映射。
  16. #include "stdafx.h"
  17. #include "LYFZIPReceiveApp.h"
  18. #include "LYFZIPReceive.h"
  19. #include "ApplicationDlg.h"
  20. #include "UserAccountsDlg.h"
  21. #include "WizardPages.h"
  22. #include "AboutDlg.h"
  23. #include <afxpriv.h>
  24. #ifdef _DEBUG
  25. #define new DEBUG_NEW
  26. #undef THIS_FILE
  27. static char THIS_FILE[] = __FILE__;
  28. #endif
  29. extern CLYFZIPReceiveApp theApp;
  30. extern CLYFZIPReceive theServer;
  31. static UINT auIDStatusBar[] =
  32. {
  33. ID_SEPARATOR,
  34. ID_INDICATOR_DATA_RECEIVED,
  35. ID_INDICATOR_DATA_SEND,
  36. ID_INDICATOR_ONLINELED,
  37. ID_INDICATOR_OFFLINELED
  38. };
  39. /********************************************************************/
  40. /* */
  41. /* Function name : CApplicationDlg::CApplicationDlg */
  42. /* Description : Constructor */
  43. /* */
  44. /********************************************************************/
  45. CApplicationDlg::CApplicationDlg(CWnd* pParent /*=NULL*/)
  46. : CDialogResize(CApplicationDlg::IDD, pParent)
  47. {
  48. //{{AFX_DATA_INIT(CApplicationDlg)
  49. //}}AFX_DATA_INIT
  50. m_hIcon = AfxGetApp()->LoadIcon(IDI_LYFZIPReceive);
  51. m_bInitialized = FALSE;
  52. }
  53. /********************************************************************/
  54. /* */
  55. /* Function name : CApplicationDlg::~CApplicationDlg */
  56. /* Description : Destructor */
  57. /* */
  58. /********************************************************************/
  59. CApplicationDlg::~CApplicationDlg()
  60. {
  61. }
  62. /********************************************************************/
  63. /* */
  64. /* Function name : CApplicationDlg::DoDataExchange */
  65. /* Description : Called by the framework to exchange and validate */
  66. /* dialog data. */
  67. /* */
  68. /********************************************************************/
  69. void CApplicationDlg::DoDataExchange(CDataExchange* pDX)
  70. {
  71. CDialogResize::DoDataExchange(pDX);
  72. //{{AFX_DATA_MAP(CApplicationDlg)
  73. DDX_Control(pDX, IDC_INFOBAR, m_InfobarCtrl);
  74. DDX_Control(pDX, IDC_OUTLOOKBAR, m_OutlookBar);
  75. //}}AFX_DATA_MAP
  76. }
  77. BEGIN_MESSAGE_MAP(CApplicationDlg, CDialogResize)
  78. //{{AFX_MSG_MAP(CApplicationDlg)
  79. ON_WM_SYSCOMMAND()
  80. ON_WM_SIZE()
  81. ON_WM_DESTROY()
  82. ON_COMMAND(ID_SERVER_START, OnServerStart)
  83. ON_UPDATE_COMMAND_UI(ID_SERVER_START, OnUpdateServerStart)
  84. ON_COMMAND(ID_SERVER_STOP, OnServerStop)
  85. ON_UPDATE_COMMAND_UI(ID_SERVER_STOP, OnUpdateServerStop)
  86. ON_COMMAND(ID_SERVER_EXIT, OnServerExit)
  87. ON_NOTIFY(NM_CLICK, IDC_OUTLOOKBAR, OnClickOutlookBar)
  88. ON_NOTIFY(LVN_KEYDOWN, IDC_OUTLOOKBAR, OnKeydownOutlookBar)
  89. ON_COMMAND(ID_USER_ACCOUNTS, OnUserAccounts)
  90. ON_WM_CLOSE()
  91. ON_COMMAND(IDC_VIEW_TRACE, OnViewTrace)
  92. ON_COMMAND(IDC_VIEW_ONLINE_USERS, OnViewOnlineUsers)
  93. ON_COMMAND(IDC_VIEW_CONFIGURATION, OnViewConfiguration)
  94. ON_UPDATE_COMMAND_UI(IDC_VIEW_TRACE, OnUpdateViewTrace)
  95. ON_UPDATE_COMMAND_UI(IDC_VIEW_ONLINE_USERS, OnUpdateViewOnlineUsers)
  96. ON_UPDATE_COMMAND_UI(IDC_VIEW_CONFIGURATION, OnUpdateViewConfiguration)
  97. ON_COMMAND(ID_HELP_ABOUT, OnHelpAbout)
  98. ON_COMMAND(IDC_VIEW_STATISTICS, OnViewStatistics)
  99. ON_UPDATE_COMMAND_UI(IDC_VIEW_STATISTICS, OnUpdateViewStatistics)
  100. ON_COMMAND(IDC_VIEW_SECURITY, OnViewSecurity)
  101. ON_UPDATE_COMMAND_UI(IDC_VIEW_SECURITY, OnUpdateViewSecurity)
  102. ON_COMMAND(ID_ACCOUNT_WIZARD, OnAccountWizard)
  103. ON_WM_TIMER()
  104. //}}AFX_MSG_MAP
  105. ON_MESSAGE(WM_KICKIDLE, OnKickIdle)
  106. ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, OnToolTipText)
  107. ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, OnToolTipText)
  108. ON_COMMAND(IDC_APPLY, OnApply)
  109. END_MESSAGE_MAP()
  110. BEGIN_DLGRESIZE_MAP(CApplicationDlg)
  111. DLGRESIZE_CONTROL(IDC_OUTLOOKBAR, DLSZ_SIZE_Y)
  112. DLGRESIZE_CONTROL(IDC_DIALOG_AREA, DLSZ_SIZE_X | DLSZ_SIZE_Y)
  113. DLGRESIZE_CONTROL(AFX_IDW_STATUS_BAR, DLSZ_MOVE_Y | DLSZ_SIZE_X)
  114. DLGRESIZE_CONTROL(AFX_IDW_TOOLBAR, DLSZ_SIZE_X)
  115. DLGRESIZE_CONTROL(IDC_STATIC1, DLSZ_SIZE_X)
  116. DLGRESIZE_CONTROL(IDC_INFOBAR, DLSZ_SIZE_X)
  117. END_DLGRESIZE_MAP()
  118. /********************************************************************/
  119. /* */
  120. /* Function name : CApplicationDlg::OnInitDialog */
  121. /* Description : Called by the framework in response to the */
  122. /* WM_INITDIALOG message. */
  123. /* */
  124. /********************************************************************/
  125. BOOL CApplicationDlg::OnInitDialog()
  126. {
  127. CDialogResize::OnInitDialog();
  128. // setup listview ctrl, so that it looks like the outbar control
  129. SetupOutlookBar();
  130. // Add statusbar to the dialog
  131. CreateStatusbar();
  132. CRect rect;
  133. GetDlgItem(IDC_STATIC1)->GetWindowRect(rect);
  134. ScreenToClient(rect);
  135. rect.right+=4;
  136. GetDlgItem(IDC_STATIC1)->MoveWindow(rect);
  137. InitResizing(FALSE);
  138. int s, t, b, r, l;
  139. // ShowWindow(SW_SHOWMAXIMIZED);
  140. if (1)//AfxGetApp()->GetProfileInt("Settings", "SavePosition", 1))
  141. {
  142. // only restore if there is a previously saved position
  143. if ( -1 != (s = AfxGetApp()->GetProfileInt("Settings", "FrameStatus", -1)) &&
  144. -1 != (t = AfxGetApp()->GetProfileInt("Settings", "FrameTop", -1)) &&
  145. -1 != (l = AfxGetApp()->GetProfileInt("Settings", "FrameLeft", -1)) &&
  146. -1 != (b = AfxGetApp()->GetProfileInt("Settings", "FrameBottom", -1)) &&
  147. -1 != (r = AfxGetApp()->GetProfileInt("Settings", "FrameRight", -1))
  148. )
  149. {
  150. WINDOWPLACEMENT wp;
  151. // restore the window's status
  152. wp.showCmd = s;
  153. // restore the window's width and height
  154. wp.rcNormalPosition.bottom = b;
  155. wp.rcNormalPosition.right = r;
  156. // the following correction is needed when the taskbar is
  157. // at the left or top and it is not "auto-hidden"
  158. RECT workArea;
  159. SystemParametersInfo(SPI_GETWORKAREA, 0, &workArea, 0);
  160. l += workArea.left;
  161. t += workArea.top;
  162. // make sure the window is not completely out of sight
  163. int max_x = GetSystemMetrics(SM_CXSCREEN) -
  164. GetSystemMetrics(SM_CXICON);
  165. int max_y = GetSystemMetrics(SM_CYSCREEN) -
  166. GetSystemMetrics(SM_CYICON);
  167. wp.rcNormalPosition.top = min(t, max_y);
  168. wp.rcNormalPosition.left = min(l, max_x);
  169. SetWindowPlacement(&wp);
  170. }
  171. }
  172. // create property pages
  173. m_TracePage.Create(IDD_PROPPAGE_TRACE, this);
  174. m_OnlineUsersPage.Create(IDD_PROPPAGE_ONLINE, this);
  175. m_ConfigurationPage.Create(IDD_PROPPAGE_CONFIGURATION, this);
  176. m_StatisticsPage.Create(IDD_PROPPAGE_STATISTICS, this);
  177. m_SecurityPage.Create(IDD_PROPPAGE_SECURITY, this);
  178. // activate main page
  179. ActivatePage(0);
  180. // Set the icon for this dialog.
  181. SetIcon(m_hIcon, TRUE); // Set big icon
  182. SetIcon(m_hIcon, FALSE); // Set small icon
  183. // get registry values
  184. m_ConfigurationPage.m_nPort = 21;//AfxGetApp()->GetProfileInt("Settings", "Port", 21);
  185. m_ConfigurationPage.m_nMaxUsers = 100;//AfxGetApp()->GetProfileInt("Settings", "MaxUsers", 50);
  186. m_ConfigurationPage.m_nTimeout = 10;//AfxGetApp()->GetProfileInt("Settings", "Timeout", 5);
  187. m_ConfigurationPage.m_strWelcomeMessage = "Welcome to LYFZ FTP Server";
  188. m_ConfigurationPage.m_strGoodbyeMessage = "Bye";
  189. m_ConfigurationPage.m_bLaunchOnStartup = 1;
  190. m_ConfigurationPage.m_bStartInTray = 1;
  191. m_ConfigurationPage.m_bAutoActivate = 1;
  192. m_ConfigurationPage.m_nLogLevel = 1;
  193. m_ConfigurationPage.m_strApplicationName = "利亚方舟域名接收";
  194. /* m_ConfigurationPage.m_nPort = AfxGetApp()->GetProfileInt("Settings", "Port", 21);
  195. m_ConfigurationPage.m_nMaxUsers = AfxGetApp()->GetProfileInt("Settings", "MaxUsers", 50);
  196. m_ConfigurationPage.m_nTimeout = AfxGetApp()->GetProfileInt("Settings", "Timeout", 5);
  197. m_ConfigurationPage.m_strWelcomeMessage = AfxGetApp()->GetProfileString("Settings", "WelcomeMsg", "Welcome to LYFZ FTP Server");
  198. m_ConfigurationPage.m_strGoodbyeMessage = AfxGetApp()->GetProfileString("Settings", "GoodbyeMsg", "Bye");
  199. m_ConfigurationPage.m_bLaunchOnStartup = AfxGetApp()->GetProfileInt("Settings", "LaunchOnStartup", 1);
  200. m_ConfigurationPage.m_bStartInTray = AfxGetApp()->GetProfileInt("Settings", "StartInTray", 1);
  201. m_ConfigurationPage.m_bAutoActivate = AfxGetApp()->GetProfileInt("Settings", "AutoActivate", 1);
  202. m_ConfigurationPage.m_nLogLevel = AfxGetApp()->GetProfileInt("Settings", "LogLevel", 1);
  203. m_ConfigurationPage.m_strApplicationName = AfxGetApp()->GetProfileString("Settings", "AppName", "LYFZ FTP Server");
  204. */
  205. m_ConfigurationPage.UpdateData(FALSE);
  206. SetWindowText(m_ConfigurationPage.m_strApplicationName);
  207. // set log level
  208. theApp.m_LogFile.SetLogLevel(m_ConfigurationPage.m_nLogLevel);
  209. // and finally, let's add some tooltips
  210. m_ToolTipCtrl.Create(this);
  211. m_ToolTipCtrl.Activate(TRUE);
  212. // minimize at startup ?
  213. if (m_ConfigurationPage.m_bStartInTray)
  214. {
  215. PostMessage(WM_SYSCOMMAND, SC_MINIMIZE, 0);
  216. // this seems to be a workaround to let the statement above to get working
  217. CRect rect;
  218. GetWindowRect(rect);
  219. SetWindowPos(&CWnd::wndTop, rect.left, rect.top, rect.Width(), rect.Height(), SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE);
  220. }
  221. theServer.Initialize(this);
  222. if (1)//m_ConfigurationPage.m_bAutoActivate)
  223. {
  224. OnServerStart();
  225. }
  226. m_bInitialized = TRUE;
  227. SetTimer(2, 60*60*1000, NULL);
  228. return TRUE;
  229. }
  230. /********************************************************************/
  231. /* */
  232. /* Function name : CApplicationDlg::OnSysCommand */
  233. /* Description : Here we catch the minimizing */
  234. /* */
  235. /********************************************************************/
  236. void CApplicationDlg::OnSysCommand(UINT nID, LPARAM lParam)
  237. {
  238. switch(nID)
  239. {
  240. case SC_MINIMIZE:
  241. // do not minimize to the taskbar
  242. ShowWindow(SW_HIDE);
  243. break;
  244. default:
  245. CDialog::OnSysCommand(nID, lParam);
  246. break;
  247. }
  248. }
  249. /********************************************************************/
  250. /* */
  251. /* Function name : OnSize */
  252. /* Description : Handle WM_SIZE message */
  253. /* */
  254. /********************************************************************/
  255. void CApplicationDlg::OnSize(UINT nType, int cx, int cy)
  256. {
  257. CDialogResize::OnSize(nType, cx, cy);
  258. if (m_bInitialized)
  259. MoveChilds();
  260. }
  261. /********************************************************************/
  262. /* */
  263. /* Function name : OnClose */
  264. /* Description : Hide the dialogbox (instead of closing it) */
  265. /* */
  266. /********************************************************************/
  267. void CApplicationDlg::OnClose()
  268. {
  269. if (1)//AfxGetApp()->GetProfileInt("Settings", "SavePosition", 1))
  270. {
  271. // Save main window position
  272. WINDOWPLACEMENT wp;
  273. GetWindowPlacement(&wp);
  274. AfxGetApp()->WriteProfileInt("Settings", "FrameStatus", wp.showCmd);
  275. AfxGetApp()->WriteProfileInt("Settings", "FrameTop", wp.rcNormalPosition.top);
  276. AfxGetApp()->WriteProfileInt("Settings", "FrameLeft", wp.rcNormalPosition.left);
  277. AfxGetApp()->WriteProfileInt("Settings", "FrameBottom", wp.rcNormalPosition.bottom);
  278. AfxGetApp()->WriteProfileInt("Settings", "FrameRight", wp.rcNormalPosition.right);
  279. }
  280. ShowWindow(0);
  281. }
  282. /********************************************************************/
  283. /* */
  284. /* Function name : OnDestroy */
  285. /* Description : Handle WM_DESTROY message */
  286. /* */
  287. /********************************************************************/
  288. void CApplicationDlg::OnDestroy()
  289. {
  290. OnServerStop();
  291. CDialogResize::OnDestroy();
  292. }
  293. /********************************************************************/
  294. /* */
  295. /* Function name : OnServerStart */
  296. /* Description : Start FTP server -> start listening on port 21 */
  297. /* */
  298. /********************************************************************/
  299. //启动FTP服务器,使其在21号端口侦听
  300. void CApplicationDlg::OnServerStart()
  301. {
  302. m_ConfigurationPage.UpdateData();
  303. theServer.SetPort(m_ConfigurationPage.m_nPort);
  304. theServer.SetMaxUsers(m_ConfigurationPage.m_nMaxUsers);
  305. theServer.SetTimeout(m_ConfigurationPage.m_nTimeout);
  306. theServer.SetWelcomeMessage(m_ConfigurationPage.m_strWelcomeMessage);
  307. theServer.SetGoodbyeMessage(m_ConfigurationPage.m_strGoodbyeMessage);
  308. theServer.SetStatisticsInterval(5000);
  309. BOOL bBlockAll = AfxGetApp()->GetProfileInt("Settings", "BlockAll", 0);
  310. theServer.SetSecurityMode(!bBlockAll);
  311. if (theServer.Start())
  312. {
  313. MyLock lock("ytSoftKeyaccessxiao");
  314. if(ytSoftKey.Ini()==0)
  315. {
  316. g_bDogOK=1;
  317. }
  318. m_wndStatusBar.SetPaneText(0, "FTP服务已启动", TRUE);
  319. SetOnlineLed(TRUE);
  320. SetOfflineLed(FALSE);
  321. }
  322. else
  323. CDialog::OnCancel ();
  324. }
  325. /********************************************************************/
  326. /* */
  327. /* Function name : OnUpdateServerStart */
  328. /* Description : Update 'Start' status */
  329. /* */
  330. /********************************************************************/
  331. void CApplicationDlg::OnUpdateServerStart(CCmdUI* pCmdUI)
  332. {
  333. pCmdUI->Enable(!theServer.IsActive());
  334. }
  335. /********************************************************************/
  336. /* */
  337. /* Function name : OnServerStop */
  338. /* Description : Stop FTP server */
  339. /* */
  340. /********************************************************************/
  341. //停止服务器
  342. void CApplicationDlg::OnServerStop()
  343. {
  344. theServer.Stop();
  345. m_wndStatusBar.SetPaneText(0, "FTP服务已停止", TRUE);
  346. SetOnlineLed(FALSE);
  347. SetOfflineLed(TRUE);
  348. }
  349. /********************************************************************/
  350. /* */
  351. /* Function name : OnUpdateServerStop */
  352. /* Description : Update 'Stop' status */
  353. /* */
  354. /********************************************************************/
  355. void CApplicationDlg::OnUpdateServerStop(CCmdUI* pCmdUI)
  356. {
  357. pCmdUI->Enable(theServer.IsActive());
  358. }
  359. /********************************************************************/
  360. /* */
  361. /* Function name : OnKickIdle */
  362. /* Description : Make ON_UPDATE_COMMAND_UI work for this dialog. */
  363. /* */
  364. /********************************************************************/
  365. LRESULT CApplicationDlg::OnKickIdle(WPARAM wParam, LPARAM lParam)
  366. {
  367. UpdateDialogControls(this, FALSE);
  368. CMenu* pMainMenu = GetMenu();
  369. CCmdUI cmdUI;
  370. // update menu enable/disable state
  371. for (UINT n = 0; n < pMainMenu->GetMenuItemCount(); ++n)
  372. {
  373. CMenu* pSubMenu = pMainMenu->GetSubMenu(n);
  374. cmdUI.m_nIndexMax = pSubMenu->GetMenuItemCount();
  375. for (UINT i = 0; i < cmdUI.m_nIndexMax;++i)
  376. {
  377. cmdUI.m_nIndex = i;
  378. cmdUI.m_nID = pSubMenu->GetMenuItemID(i);
  379. cmdUI.m_pMenu = pSubMenu;
  380. cmdUI.DoUpdate(this, FALSE);
  381. }
  382. }
  383. // enable/disable toolbar buttons
  384. if (m_wndToolBar.IsWindowVisible())
  385. {
  386. // OnUpdateCmdUI expects a CFrameWnd pointer, so let's fake it ..
  387. CFrameWnd *pParent = (CFrameWnd *)this;
  388. if (pParent)
  389. m_wndToolBar.OnUpdateCmdUI(pParent, TRUE);
  390. }
  391. return Default();
  392. }
  393. /********************************************************************/
  394. /* */
  395. /* Function name : OnHelpAbout */
  396. /* Description : Show Aboutbox. */
  397. /* */
  398. /********************************************************************/
  399. void CApplicationDlg::OnHelpAbout()
  400. {
  401. CAboutDlg dlg;
  402. dlg.DoModal();
  403. }
  404. /********************************************************************/
  405. /* */
  406. /* Function name : OnServerExit */
  407. /* Description : Let's get out of here... */
  408. /* */
  409. /********************************************************************/
  410. void CApplicationDlg::OnServerExit()
  411. {
  412. OnCancel();
  413. }
  414. /********************************************************************/
  415. /* */
  416. /* Function name : CApplicationDlg::SetupOutlookBar */
  417. /* Description : Initialize listview, change color/iconspacing to */
  418. /* make it look a little bit like the outlook bar. */
  419. /* */
  420. /********************************************************************/
  421. void CApplicationDlg::SetupOutlookBar()
  422. {
  423. // create Imagelist
  424. m_ImageList.Create(32, 32, ILC_COLOR16|ILC_MASK,1, 4);
  425. HICON hIcon = ::LoadIcon (AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_LOG));
  426. m_ImageList.Add(hIcon);
  427. hIcon = ::LoadIcon (AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ONLINE_USERS));
  428. m_ImageList.Add(hIcon);
  429. hIcon = ::LoadIcon (AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_CONFIGURATION));
  430. m_ImageList.Add(hIcon);
  431. hIcon = ::LoadIcon (AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_STATISTICS));
  432. m_ImageList.Add(hIcon);
  433. hIcon = ::LoadIcon (AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_SECURITY));
  434. m_ImageList.Add(hIcon);
  435. m_OutlookBar.SetImageList(&m_ImageList, LVSIL_NORMAL);
  436. CRect rc;
  437. m_OutlookBar.GetClientRect(rc);
  438. // set new icon spacing
  439. m_OutlookBar.SetIconSpacing(rc.Width(), 64);
  440. // change colors
  441. m_OutlookBar.SetTextColor(RGB(255,255,255));
  442. m_OutlookBar.SetTextBkColor(RGB(128,128,128));
  443. m_OutlookBar.SetBkColor(RGB(128,128,128));
  444. // insert items
  445. m_OutlookBar.InsertColumn(0, "OutlookBar");
  446. m_OutlookBar.InsertItem(0, "服务器日志", 0);
  447. m_OutlookBar.InsertItem(1, "在线用户", 1);
  448. /* m_OutlookBar.InsertItem(2, "Configuration", 2);
  449. m_OutlookBar.InsertItem(3, "Statistics", 3);
  450. m_OutlookBar.InsertItem(4, "Security", 4);*/
  451. // m_OutlookBar.SetExtendedStyle(LVS_EX_TRACKSELECT);
  452. }
  453. /********************************************************************/
  454. /* */
  455. /* Function name : CApplicationDlg::MoveChilds */
  456. /* Description : Move child windows into place holder area. */
  457. /* */
  458. /********************************************************************/
  459. void CApplicationDlg::MoveChilds()
  460. {
  461. // position property pages
  462. CRect rcDlgs;
  463. // get dialog area rect
  464. GetDlgItem(IDC_DIALOG_AREA)->GetWindowRect(rcDlgs);
  465. ScreenToClient(rcDlgs);
  466. m_ConfigurationPage.MoveWindow(rcDlgs);
  467. m_TracePage.MoveWindow(rcDlgs);
  468. m_OnlineUsersPage.MoveWindow(rcDlgs);
  469. m_StatisticsPage.MoveWindow(rcDlgs);
  470. m_SecurityPage.MoveWindow(rcDlgs);
  471. }
  472. /********************************************************************/
  473. /* */
  474. /* Function name : CApplicationDlg::ActivatePage */
  475. /* Description : Called when an icon on the outlookbar is pressed.*/
  476. /* */
  477. /********************************************************************/
  478. void CApplicationDlg::ActivatePage(int nIndex)
  479. {
  480. switch(nIndex)
  481. {
  482. case 0:
  483. m_OnlineUsersPage.ShowWindow(SW_HIDE);
  484. m_ConfigurationPage.ShowWindow(SW_HIDE);
  485. m_StatisticsPage.ShowWindow(SW_HIDE);
  486. m_SecurityPage.ShowWindow(SW_HIDE);
  487. m_TracePage.ShowWindow(SW_SHOW);
  488. m_InfobarCtrl.SetText("服务器日志");
  489. break;
  490. case 1:
  491. m_TracePage.ShowWindow(SW_HIDE);
  492. m_ConfigurationPage.ShowWindow(SW_HIDE);
  493. m_StatisticsPage.ShowWindow(SW_HIDE);
  494. m_SecurityPage.ShowWindow(SW_HIDE);
  495. m_OnlineUsersPage.ShowWindow(SW_SHOW);
  496. m_InfobarCtrl.SetText("在线用户");
  497. break;
  498. case 2:
  499. m_OnlineUsersPage.ShowWindow(SW_HIDE);
  500. m_TracePage.ShowWindow(SW_HIDE);
  501. m_StatisticsPage.ShowWindow(SW_HIDE);
  502. m_SecurityPage.ShowWindow(SW_HIDE);
  503. m_ConfigurationPage.ShowWindow(SW_SHOW);
  504. m_InfobarCtrl.SetText("Configuration");
  505. break;
  506. case 3:
  507. m_OnlineUsersPage.ShowWindow(SW_HIDE);
  508. m_TracePage.ShowWindow(SW_HIDE);
  509. m_ConfigurationPage.ShowWindow(SW_HIDE);
  510. m_SecurityPage.ShowWindow(SW_HIDE);
  511. m_StatisticsPage.ShowWindow(SW_SHOW);
  512. m_InfobarCtrl.SetText("Statistics");
  513. break;
  514. case 4:
  515. m_OnlineUsersPage.ShowWindow(SW_HIDE);
  516. m_TracePage.ShowWindow(SW_HIDE);
  517. m_ConfigurationPage.ShowWindow(SW_HIDE);
  518. m_SecurityPage.ShowWindow(SW_SHOW);
  519. m_StatisticsPage.ShowWindow(SW_HIDE);
  520. m_InfobarCtrl.SetText("Security");
  521. break;
  522. default:
  523. break;
  524. }
  525. MoveChilds();
  526. }
  527. /********************************************************************/
  528. /* */
  529. /* Function name : CApplicationDlg::OnClickOutlookBar */
  530. /* Description : User clicked on our listview -> activate page. */
  531. /* */
  532. /********************************************************************/
  533. void CApplicationDlg::OnClickOutlookBar(NMHDR* pNMHDR, LRESULT* pResult)
  534. {
  535. // get index of selected item
  536. int nIndex = m_OutlookBar.GetNextItem(-1, LVNI_ALL | LVNI_SELECTED);
  537. if(nIndex == -1)
  538. return;
  539. ActivatePage(nIndex);
  540. *pResult = 0;
  541. }
  542. /********************************************************************/
  543. /* */
  544. /* Function name : CApplicationDlg::OnKeydownOutlookBar */
  545. /* Description : User pressed a key -> activate page. */
  546. /* */
  547. /********************************************************************/
  548. void CApplicationDlg::OnKeydownOutlookBar(NMHDR* pNMHDR, LRESULT* pResult)
  549. {
  550. LV_KEYDOWN* pLVKeyDow = (LV_KEYDOWN*)pNMHDR;
  551. // get index of selected item
  552. int nIndex = m_OutlookBar.GetNextItem(-1, LVNI_ALL | LVNI_SELECTED);
  553. if(nIndex == -1)
  554. return;
  555. if (pLVKeyDow->wVKey == VK_DOWN)
  556. {
  557. if (m_OutlookBar.GetItemCount()-1 > nIndex)
  558. {
  559. ActivatePage(nIndex+1);
  560. }
  561. }
  562. else
  563. if (pLVKeyDow->wVKey == VK_UP)
  564. {
  565. if (nIndex > 0)
  566. {
  567. ActivatePage(nIndex-1);
  568. }
  569. }
  570. else
  571. if (pLVKeyDow->wVKey == VK_NEXT)
  572. {
  573. ActivatePage(m_OutlookBar.GetItemCount()-1);
  574. }
  575. else
  576. if (pLVKeyDow->wVKey == VK_PRIOR)
  577. {
  578. ActivatePage(0);
  579. }
  580. *pResult = 0;
  581. }
  582. /********************************************************************/
  583. /* */
  584. /* Function name : CreateStatusbar */
  585. /* Description : This function creates a statusbar on a dialogbox.*/
  586. /* */
  587. /********************************************************************/
  588. BOOL CApplicationDlg::CreateStatusbar()
  589. {
  590. // Create the Toolbar and attach the resource
  591. if(!m_wndToolBar.Create(this) || !m_wndToolBar.LoadToolBar(IDR_TOOLBAR1))
  592. {
  593. TRACE0("Failed to Create Dialog Toolbar\n");
  594. return FALSE;
  595. }
  596. m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() | CBRS_SIZE_DYNAMIC | CBRS_TOOLTIPS | CBRS_FLYBY);
  597. // Make it flat.
  598. m_wndToolBar.ModifyStyle(0, m_wndToolBar.GetStyle()|TBSTYLE_FLAT);
  599. // Create status bar at the bottom of the dialog window
  600. if (m_wndStatusBar.Create(this))
  601. {
  602. m_wndStatusBar.SetIndicators(auIDStatusBar, sizeof(auIDStatusBar)/sizeof(UINT));
  603. m_wndStatusBar.SetPaneText(0, "FTP Server is offline", TRUE);
  604. // Make a sunken or recessed border around the first pane
  605. m_wndStatusBar.SetPaneInfo(0, m_wndStatusBar.GetItemID(0), SBPS_STRETCH, NULL );
  606. SetOnlineLed(FALSE);
  607. SetOfflineLed(FALSE);
  608. m_wndStatusBar.SetPaneInfo(m_wndStatusBar.CommandToIndex(ID_INDICATOR_ONLINELED),ID_INDICATOR_ONLINELED, SBPS_NOBORDERS, 14);
  609. // m_wndStatusBar.GetStatusBarCtrl().SetTipText(m_wndStatusBar.CommandToIndex(ID_INDICATOR_ONLINELED), "This status light is green when the server is online");
  610. m_wndStatusBar.SetPaneInfo(m_wndStatusBar.CommandToIndex(ID_INDICATOR_OFFLINELED),ID_INDICATOR_OFFLINELED, SBPS_NOBORDERS, 14);
  611. // m_wndStatusBar.GetStatusBarCtrl().SetTipText(m_wndStatusBar.CommandToIndex(ID_INDICATOR_OFFLINELED), "This status light is green when the server is online");
  612. }
  613. // We need to resize the dialog to make room for control bars.
  614. // First, figure out how big the control bars are.
  615. CRect rcClientStart;
  616. CRect rcClientNow;
  617. GetClientRect(rcClientStart);
  618. RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0, reposQuery, rcClientNow);
  619. // Now move all the controls so they are in the same relative
  620. // position within the remaining client area as they would be
  621. // with no control bars.
  622. CPoint ptOffset(rcClientNow.left - rcClientStart.left, rcClientNow.top - rcClientStart.top);
  623. CRect rcChild;
  624. CWnd* pwndChild = GetWindow(GW_CHILD);
  625. while (pwndChild)
  626. {
  627. pwndChild->GetWindowRect(rcChild);
  628. ScreenToClient(rcChild);
  629. rcChild.OffsetRect(ptOffset);
  630. pwndChild->MoveWindow(rcChild, FALSE);
  631. pwndChild = pwndChild->GetNextWindow();
  632. }
  633. // Adjust the dialog window dimensions
  634. CRect rcWindow;
  635. GetWindowRect(rcWindow);
  636. rcWindow.right += rcClientStart.Width() - rcClientNow.Width();
  637. rcWindow.bottom += rcClientStart.Height() - rcClientNow.Height();
  638. MoveWindow(rcWindow, FALSE);
  639. // And position the control bars
  640. RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
  641. return TRUE;
  642. }
  643. /********************************************************************/
  644. /* */
  645. /* Function name : OnUserAccounts */
  646. /* Description : Show user accounts. */
  647. /* */
  648. /********************************************************************/
  649. void CApplicationDlg::OnUserAccounts()
  650. {
  651. CUserAccountsDlg dlg;
  652. theServer.m_UserManager.GetUserList(dlg.m_UserArray);
  653. if (dlg.DoModal() == IDOK)
  654. {
  655. theServer.m_UserManager.UpdateUserList(dlg.m_UserArray);
  656. }
  657. }
  658. /********************************************************************/
  659. /* */
  660. /* Function name : OnFTPUserConnected */
  661. /* Description : A user has connected to our server. */
  662. /* */
  663. /********************************************************************/
  664. void CApplicationDlg::OnFTPUserConnected(DWORD nThreadID, LPCTSTR lpszUser, LPCSTR lpszAddress)
  665. {
  666. m_OnlineUsersPage.AddUser(nThreadID, lpszUser, lpszAddress);
  667. }
  668. /********************************************************************/
  669. /* */
  670. /* Function name : OnFTPUserDisconnected */
  671. /* Description : A user has disconnected from our server. */
  672. /* */
  673. /********************************************************************/
  674. void CApplicationDlg::OnFTPUserDisconnected(DWORD nThreadID, LPCTSTR lpszUser)
  675. {
  676. m_OnlineUsersPage.RemoveUser(nThreadID);
  677. }
  678. /********************************************************************/
  679. /* */
  680. /* Function name : OnFTPStatusChange */
  681. /* Description : FTP Status changed. */
  682. /* */
  683. /********************************************************************/
  684. void CApplicationDlg::OnFTPStatusChange(int nType, LPCTSTR lpszText)
  685. {
  686. m_TracePage.AddTraceLine(nType, lpszText);
  687. switch(nType)
  688. {
  689. case 3:
  690. theApp.m_LogFile << error_lvl << date << time << lpszText << endl;
  691. break;
  692. default:
  693. theApp.m_LogFile << trace_lvl << date << time << lpszText << endl;
  694. break;
  695. }
  696. }
  697. /********************************************************************/
  698. /* */
  699. /* Function name : OnFTPReceivedBytesChange */
  700. /* Description : Number of received bytes has changed. */
  701. /* */
  702. /********************************************************************/
  703. void CApplicationDlg::OnFTPReceivedBytesChange(int nBytes)
  704. {
  705. m_StatisticsPage.SetValue(6, FormatSize(nBytes, 0));
  706. CString strStatus;
  707. strStatus.Format("%s received", FormatSize(nBytes, 0));
  708. m_wndStatusBar.SetPaneText(m_wndStatusBar.CommandToIndex(ID_INDICATOR_DATA_RECEIVED), strStatus, TRUE);
  709. CClientDC dc(this);
  710. CSize size = dc.GetTextExtent(strStatus);
  711. m_wndStatusBar.SetPaneInfo(m_wndStatusBar.CommandToIndex(ID_INDICATOR_DATA_RECEIVED), ID_INDICATOR_DATA_RECEIVED, SBPS_NORMAL, size.cx);
  712. }
  713. /********************************************************************/
  714. /* */
  715. /* Function name : OnFTPSentBytesChange */
  716. /* Description : Number of sent bytes has changed. */
  717. /* */
  718. /********************************************************************/
  719. void CApplicationDlg::OnFTPSentBytesChange(int nBytes)
  720. {
  721. m_StatisticsPage.SetValue(7, FormatSize(nBytes, 0));
  722. CString strStatus;
  723. strStatus.Format("%s sent", FormatSize(nBytes, 0));
  724. m_wndStatusBar.SetPaneText(m_wndStatusBar.CommandToIndex(ID_INDICATOR_DATA_SEND), strStatus, TRUE);
  725. CClientDC dc(this);
  726. CSize size = dc.GetTextExtent(strStatus);
  727. m_wndStatusBar.SetPaneInfo(m_wndStatusBar.CommandToIndex(ID_INDICATOR_DATA_SEND), ID_INDICATOR_DATA_SEND, SBPS_NORMAL, size.cx);
  728. }
  729. /********************************************************************/
  730. /* */
  731. /* Function name : OnViewTrace */
  732. /* Description : Handle menu selection. */
  733. /* */
  734. /********************************************************************/
  735. void CApplicationDlg::OnViewTrace()
  736. {
  737. ActivatePage(0);
  738. }
  739. /********************************************************************/
  740. /* */
  741. /* Function name : OnViewOnlineUsers */
  742. /* Description : Handle menu selection. */
  743. /* */
  744. /********************************************************************/
  745. void CApplicationDlg::OnViewOnlineUsers()
  746. {
  747. ActivatePage(1);
  748. }
  749. /********************************************************************/
  750. /* */
  751. /* Function name : OnViewConfiguration */
  752. /* Description : Handle menu selection. */
  753. /* */
  754. /********************************************************************/
  755. void CApplicationDlg::OnViewConfiguration()
  756. {
  757. ActivatePage(2);
  758. }
  759. /********************************************************************/
  760. /* */
  761. /* Function name : OnViewStatistics */
  762. /* Description : Handle menu selection. */
  763. /* */
  764. /********************************************************************/
  765. void CApplicationDlg::OnViewStatistics()
  766. {
  767. ActivatePage(3);
  768. }
  769. /********************************************************************/
  770. /* */
  771. /* Function name : OnViewSecurity */
  772. /* Description : Handle menu selection. */
  773. /* */
  774. /********************************************************************/
  775. void CApplicationDlg::OnViewSecurity()
  776. {
  777. ActivatePage(4);
  778. }
  779. /********************************************************************/
  780. /* */
  781. /* Function name : OnUpdateViewTrace */
  782. /* Description : Update menu state of Trace item. */
  783. /* */
  784. /********************************************************************/
  785. void CApplicationDlg::OnUpdateViewTrace(CCmdUI* pCmdUI)
  786. {
  787. pCmdUI->SetRadio(m_TracePage.IsWindowVisible());
  788. }
  789. /********************************************************************/
  790. /* */
  791. /* Function name : OnUpdateViewOnlineUsers */
  792. /* Description : Update menu state of Online Users item. */
  793. /* */
  794. /********************************************************************/
  795. void CApplicationDlg::OnUpdateViewOnlineUsers(CCmdUI* pCmdUI)
  796. {
  797. pCmdUI->SetRadio(m_OnlineUsersPage.IsWindowVisible());
  798. }
  799. /********************************************************************/
  800. /* */
  801. /* Function name : OnUpdateViewConfiguration */
  802. /* Description : Update menu state of Configuration item. */
  803. /* */
  804. /********************************************************************/
  805. void CApplicationDlg::OnUpdateViewConfiguration(CCmdUI* pCmdUI)
  806. {
  807. pCmdUI->SetRadio(m_ConfigurationPage.IsWindowVisible());
  808. }
  809. /********************************************************************/
  810. /* */
  811. /* Function name : OnUpdateViewStatistics */
  812. /* Description : Update menu state of Statistics item. */
  813. /* */
  814. /********************************************************************/
  815. void CApplicationDlg::OnUpdateViewStatistics(CCmdUI* pCmdUI)
  816. {
  817. pCmdUI->SetRadio(m_StatisticsPage.IsWindowVisible());
  818. }
  819. /********************************************************************/
  820. /* */
  821. /* Function name : OnUpdateViewSecurity */
  822. /* Description : Update menu state of Security item. */
  823. /* */
  824. /********************************************************************/
  825. void CApplicationDlg::OnUpdateViewSecurity(CCmdUI* pCmdUI)
  826. {
  827. pCmdUI->SetRadio(m_SecurityPage.IsWindowVisible());
  828. }
  829. /********************************************************************/
  830. /* */
  831. /* Function name : PreTranslateMessage */
  832. /* Description : Needed to make tooltips work. */
  833. /* */
  834. /********************************************************************/
  835. BOOL CApplicationDlg::PreTranslateMessage(MSG* pMsg)
  836. {
  837. // enable tooltips
  838. if (m_hWnd)
  839. {
  840. if (IsWindow(m_ToolTipCtrl.m_hWnd))
  841. m_ToolTipCtrl.RelayEvent(pMsg);
  842. }
  843. return CDialogResize::PreTranslateMessage(pMsg);
  844. }
  845. /********************************************************************/
  846. /* */
  847. /* Function name : OnToolTipText */
  848. /* Description : Tooltip handler for this dialog. */
  849. /* */
  850. /********************************************************************/
  851. BOOL CApplicationDlg::OnToolTipText(UINT, NMHDR* pNMHDR, LRESULT* pResult)
  852. {
  853. ASSERT(pNMHDR->code == TTN_NEEDTEXTA || pNMHDR->code == TTN_NEEDTEXTW);
  854. // need to handle both ANSI and UNICODE versions of the message
  855. TOOLTIPTEXTA* pTTTA = (TOOLTIPTEXTA*)pNMHDR;
  856. TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR;
  857. TCHAR szFullText[256];
  858. CString cstTipText;
  859. CString cstStatusText;
  860. UINT nID = pNMHDR->idFrom;
  861. if (pNMHDR->code == TTN_NEEDTEXTA && (pTTTA->uFlags & TTF_IDISHWND) ||
  862. pNMHDR->code == TTN_NEEDTEXTW && (pTTTW->uFlags & TTF_IDISHWND))
  863. {
  864. // idFrom is actually the HWND of the tool
  865. nID = ((UINT)(WORD)::GetDlgCtrlID((HWND)nID));
  866. }
  867. if (nID != 0) // will be zero on a separator
  868. {
  869. AfxLoadString(nID, szFullText);
  870. // this is the command id, not the button index
  871. AfxExtractSubString(cstTipText, szFullText, 1, '\n');
  872. AfxExtractSubString(cstStatusText, szFullText, 0, '\n');
  873. }
  874. // Non-UNICODE Strings only are shown in the tooltip window...
  875. if (pNMHDR->code == TTN_NEEDTEXTA)
  876. lstrcpyn(pTTTA->szText, cstTipText,
  877. (sizeof(pTTTA->szText)/sizeof(pTTTA->szText[0])));
  878. else
  879. _mbstowcsz(pTTTW->szText, cstTipText,
  880. (sizeof(pTTTW->szText)/sizeof(pTTTW->szText[0])));
  881. *pResult = 0;
  882. // bring the tooltip window above other popup windows
  883. ::SetWindowPos(pNMHDR->hwndFrom, HWND_TOP, 0, 0, 0, 0, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE);
  884. // message was handled
  885. return TRUE;
  886. }
  887. /********************************************************************/
  888. /* */
  889. /* Function name : SetOnlineLed */
  890. /* Description : Turn online LED on/off. */
  891. /* */
  892. /********************************************************************/
  893. void CApplicationDlg::SetOnlineLed(BOOL bOnline)
  894. {
  895. HICON hIcon = (HICON)::LoadImage(AfxGetInstanceHandle(),
  896. bOnline ? MAKEINTRESOURCE(IDI_LED_GREEN) : MAKEINTRESOURCE(IDI_LED_OFF),
  897. IMAGE_ICON, 16, 16, LR_SHARED);
  898. m_wndStatusBar.GetStatusBarCtrl().SetIcon(m_wndStatusBar.CommandToIndex(ID_INDICATOR_ONLINELED), hIcon);
  899. m_wndStatusBar.GetStatusBarCtrl().Invalidate();
  900. m_wndStatusBar.GetStatusBarCtrl().UpdateWindow();
  901. DestroyIcon(hIcon);
  902. }
  903. /********************************************************************/
  904. /* */
  905. /* Function name : SetOfflineLed */
  906. /* Description : Turn offline LED on/off. */
  907. /* */
  908. /********************************************************************/
  909. void CApplicationDlg::SetOfflineLed(BOOL bOffline)
  910. {
  911. HICON hIcon = (HICON)::LoadImage(AfxGetInstanceHandle(),
  912. bOffline ? MAKEINTRESOURCE(IDI_LED_RED) : MAKEINTRESOURCE(IDI_LED_OFF),
  913. IMAGE_ICON, 16, 16, LR_SHARED);
  914. m_wndStatusBar.GetStatusBarCtrl().SetIcon(m_wndStatusBar.CommandToIndex(ID_INDICATOR_OFFLINELED), hIcon);
  915. m_wndStatusBar.GetStatusBarCtrl().Invalidate();
  916. m_wndStatusBar.GetStatusBarCtrl().UpdateWindow();
  917. DestroyIcon(hIcon);
  918. }
  919. /********************************************************************/
  920. /* */
  921. /* Function name : OnUpdateApply */
  922. /* Description : Update FTP server parameters. */
  923. /* */
  924. /********************************************************************/
  925. void CApplicationDlg::OnApply()
  926. {
  927. m_ConfigurationPage.UpdateData();
  928. theServer.SetPort(m_ConfigurationPage.m_nPort);
  929. theServer.SetMaxUsers(m_ConfigurationPage.m_nMaxUsers);
  930. theServer.SetTimeout(m_ConfigurationPage.m_nTimeout);
  931. theServer.SetWelcomeMessage(m_ConfigurationPage.m_strWelcomeMessage);
  932. theServer.SetGoodbyeMessage(m_ConfigurationPage.m_strGoodbyeMessage);
  933. SetWindowText(m_ConfigurationPage.m_strApplicationName);
  934. // set log level
  935. theApp.m_LogFile.SetLogLevel(m_ConfigurationPage.m_nLogLevel);
  936. OnFTPStatusChange(0, "FTP Server configuration updated.");
  937. }
  938. void CApplicationDlg::OnFTPStatisticChange(int nType, int nValue)
  939. {
  940. m_StatisticsPage.SetValue(nType, nValue);
  941. }
  942. /********************************************************************/
  943. /* */
  944. /* Function name : FormatSize */
  945. /* Description : Format size, the way explorer diplays it */
  946. /* */
  947. /********************************************************************/
  948. char* CApplicationDlg::FormatSize(DWORD dwSizeLow, DWORD dwSizeHigh)
  949. {
  950. static char szBuff[100];
  951. unsigned __int64 nFileSize = ((unsigned __int64)(((DWORD)(dwSizeLow)) |
  952. ((unsigned __int64)((DWORD)(dwSizeHigh))) << 32));
  953. unsigned __int64 kb = 0;
  954. if (nFileSize > 1024)
  955. {
  956. kb = nFileSize / 1024;
  957. if (nFileSize % 1024)
  958. kb++;
  959. }
  960. // make it a string
  961. _ui64tot(kb, szBuff, 10);
  962. // add thousand seperators
  963. int nLength = lstrlen(szBuff);
  964. if (nLength > 3)
  965. {
  966. LPCTSTR ptr = szBuff;
  967. ptr += (nLength-1);
  968. char szTemp[100];
  969. LPTSTR ptrTemp = szTemp;
  970. for(int i=0; i<nLength; i++)
  971. {
  972. if (i && ((i % 3) == 0))
  973. {
  974. if (*ptrTemp != ',')
  975. {
  976. *ptrTemp = ',';
  977. ptrTemp = _tcsinc(ptrTemp);
  978. }
  979. }
  980. *ptrTemp = *ptr;
  981. ptrTemp = _tcsinc(ptrTemp);
  982. ptr = _tcsdec(szBuff, ptr);
  983. }
  984. // terminate string
  985. *ptrTemp = '\0';
  986. // reverse string
  987. _tcsrev(szTemp);
  988. lstrcpy(szBuff, szTemp);
  989. }
  990. // add 'KB' to it
  991. lstrcat(szBuff, " KB");
  992. return szBuff;
  993. }
  994. /********************************************************************/
  995. /* */
  996. /* Function name : OnAccountWizard */
  997. /* Description : Launch New Account Wizard */
  998. /* */
  999. /********************************************************************/
  1000. void CApplicationDlg::OnAccountWizard()
  1001. {
  1002. CBitmap bmpHeader, bmpWatermark;
  1003. VERIFY(bmpHeader.LoadBitmap(IDB_BANNER));
  1004. VERIFY(bmpWatermark.LoadBitmap(IDB_WATERMARK));
  1005. // show windows 2000-like wizard
  1006. CWizardSheet wizSheet("New Account Wizard", this, 0, bmpWatermark, NULL, bmpHeader);
  1007. wizSheet.m_psh.hInstance = ::GetModuleHandle(NULL);
  1008. if (wizSheet.DoModal() == ID_WIZFINISH)
  1009. {
  1010. CArray<CUser, CUser&> m_UserArray;
  1011. theServer.m_UserManager.GetUserList(m_UserArray);
  1012. int nIndex = -1;
  1013. for (int i=0; i<m_UserArray.GetSize(); i++)
  1014. {
  1015. // if it already exists -> update it
  1016. if (m_UserArray[i].m_strName.CompareNoCase(wizSheet.m_Page1.m_strAccountName) == 0)
  1017. {
  1018. nIndex = i;
  1019. break;
  1020. }
  1021. }
  1022. // add new account ?
  1023. if (nIndex == -1)
  1024. {
  1025. CUser user;
  1026. nIndex = m_UserArray.Add(user);
  1027. }
  1028. m_UserArray[nIndex].m_bAccountDisabled = FALSE;
  1029. m_UserArray[nIndex].m_strName = wizSheet.m_Page1.m_strAccountName;
  1030. m_UserArray[nIndex].m_strPassword = wizSheet.m_Page2.m_strPassword;
  1031. // add home directory
  1032. CDirectory directory;
  1033. directory.m_strDir = wizSheet.m_Page3.m_strHomeDirectory;
  1034. directory.m_strAlias = "";
  1035. directory.m_bIsHomeDir = TRUE;
  1036. directory.m_bAllowCreateDirectory = wizSheet.m_Page4.m_bAllowCreateDirectory;
  1037. directory.m_bAllowDelete = wizSheet.m_Page4.m_bAllowDelete;
  1038. directory.m_bAllowDownload = wizSheet.m_Page4.m_bAllowDownload;
  1039. directory.m_bAllowRename = wizSheet.m_Page4.m_bAllowRename;
  1040. directory.m_bAllowUpload = wizSheet.m_Page4.m_bAllowUpload;
  1041. directory.m_strAlias = "";
  1042. m_UserArray[nIndex].m_DirectoryArray.Add(directory);
  1043. // update
  1044. theServer.m_UserManager.UpdateUserList(m_UserArray);
  1045. }
  1046. }
  1047. void CApplicationDlg::OnCancel()
  1048. {
  1049. // TODO: Add extra cleanup here
  1050. }
  1051. void CApplicationDlg::OnOK()
  1052. {
  1053. // TODO: Add extra validation here setwindowtext
  1054. }
  1055. extern int g_port;
  1056. void CApplicationDlg::OnTimer(UINT nIDEvent)
  1057. {
  1058. // TODO: Add your message handler code here and/or call default
  1059. if(nIDEvent==1)
  1060. {
  1061. KillTimer(1);
  1062. WriteLogin("无数据到达,重新启动");
  1063. OnServerStop();
  1064. CString sport;
  1065. sport.Format("%d", g_port-8387);
  1066. ShellExecute(NULL, _T("open"), g_mainpath+"\\LYFZIPReceive.exe", sport, NULL, SW_SHOWNORMAL);
  1067. CDialog::OnCancel ();
  1068. }
  1069. else if(nIDEvent==2)
  1070. {
  1071. KillTimer(2);
  1072. OnServerStop();
  1073. CString sport;
  1074. sport.Format("%d", g_port-8387);
  1075. ShellExecute(NULL, _T("open"), g_mainpath+"\\LYFZIPReceive.exe", sport, NULL, SW_SHOWNORMAL);
  1076. CDialog::OnCancel ();
  1077. }
  1078. }