ApplicationDlg.cpp 39 KB

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