ApplicationDlg.cpp 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273
  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 "LYFZReceiveMsgApp.h"
  18. #include "LYFZReceiveMsg.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 CLYFZReceiveMsgApp theApp;
  30. extern CLYFZReceiveMsg 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_LYFZReceiveMsg);
  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. m_wndStatusBar.SetPaneText(0, "FTP服务已启动", TRUE);
  314. SetOnlineLed(TRUE);
  315. SetOfflineLed(FALSE);
  316. }
  317. else
  318. CDialog::OnCancel ();
  319. }
  320. /********************************************************************/
  321. /* */
  322. /* Function name : OnUpdateServerStart */
  323. /* Description : Update 'Start' status */
  324. /* */
  325. /********************************************************************/
  326. void CApplicationDlg::OnUpdateServerStart(CCmdUI* pCmdUI)
  327. {
  328. pCmdUI->Enable(!theServer.IsActive());
  329. }
  330. /********************************************************************/
  331. /* */
  332. /* Function name : OnServerStop */
  333. /* Description : Stop FTP server */
  334. /* */
  335. /********************************************************************/
  336. //停止服务器
  337. void CApplicationDlg::OnServerStop()
  338. {
  339. theServer.Stop();
  340. m_wndStatusBar.SetPaneText(0, "FTP服务已停止", TRUE);
  341. SetOnlineLed(FALSE);
  342. SetOfflineLed(TRUE);
  343. }
  344. /********************************************************************/
  345. /* */
  346. /* Function name : OnUpdateServerStop */
  347. /* Description : Update 'Stop' status */
  348. /* */
  349. /********************************************************************/
  350. void CApplicationDlg::OnUpdateServerStop(CCmdUI* pCmdUI)
  351. {
  352. pCmdUI->Enable(theServer.IsActive());
  353. }
  354. /********************************************************************/
  355. /* */
  356. /* Function name : OnKickIdle */
  357. /* Description : Make ON_UPDATE_COMMAND_UI work for this dialog. */
  358. /* */
  359. /********************************************************************/
  360. LRESULT CApplicationDlg::OnKickIdle(WPARAM wParam, LPARAM lParam)
  361. {
  362. UpdateDialogControls(this, FALSE);
  363. CMenu* pMainMenu = GetMenu();
  364. CCmdUI cmdUI;
  365. // update menu enable/disable state
  366. for (UINT n = 0; n < pMainMenu->GetMenuItemCount(); ++n)
  367. {
  368. CMenu* pSubMenu = pMainMenu->GetSubMenu(n);
  369. cmdUI.m_nIndexMax = pSubMenu->GetMenuItemCount();
  370. for (UINT i = 0; i < cmdUI.m_nIndexMax;++i)
  371. {
  372. cmdUI.m_nIndex = i;
  373. cmdUI.m_nID = pSubMenu->GetMenuItemID(i);
  374. cmdUI.m_pMenu = pSubMenu;
  375. cmdUI.DoUpdate(this, FALSE);
  376. }
  377. }
  378. // enable/disable toolbar buttons
  379. if (m_wndToolBar.IsWindowVisible())
  380. {
  381. // OnUpdateCmdUI expects a CFrameWnd pointer, so let's fake it ..
  382. CFrameWnd *pParent = (CFrameWnd *)this;
  383. if (pParent)
  384. m_wndToolBar.OnUpdateCmdUI(pParent, TRUE);
  385. }
  386. return Default();
  387. }
  388. /********************************************************************/
  389. /* */
  390. /* Function name : OnHelpAbout */
  391. /* Description : Show Aboutbox. */
  392. /* */
  393. /********************************************************************/
  394. void CApplicationDlg::OnHelpAbout()
  395. {
  396. CAboutDlg dlg;
  397. dlg.DoModal();
  398. }
  399. /********************************************************************/
  400. /* */
  401. /* Function name : OnServerExit */
  402. /* Description : Let's get out of here... */
  403. /* */
  404. /********************************************************************/
  405. void CApplicationDlg::OnServerExit()
  406. {
  407. OnCancel();
  408. }
  409. /********************************************************************/
  410. /* */
  411. /* Function name : CApplicationDlg::SetupOutlookBar */
  412. /* Description : Initialize listview, change color/iconspacing to */
  413. /* make it look a little bit like the outlook bar. */
  414. /* */
  415. /********************************************************************/
  416. void CApplicationDlg::SetupOutlookBar()
  417. {
  418. // create Imagelist
  419. m_ImageList.Create(32, 32, ILC_COLOR16|ILC_MASK,1, 4);
  420. HICON hIcon = ::LoadIcon (AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_LOG));
  421. m_ImageList.Add(hIcon);
  422. hIcon = ::LoadIcon (AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ONLINE_USERS));
  423. m_ImageList.Add(hIcon);
  424. hIcon = ::LoadIcon (AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_CONFIGURATION));
  425. m_ImageList.Add(hIcon);
  426. hIcon = ::LoadIcon (AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_STATISTICS));
  427. m_ImageList.Add(hIcon);
  428. hIcon = ::LoadIcon (AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_SECURITY));
  429. m_ImageList.Add(hIcon);
  430. m_OutlookBar.SetImageList(&m_ImageList, LVSIL_NORMAL);
  431. CRect rc;
  432. m_OutlookBar.GetClientRect(rc);
  433. // set new icon spacing
  434. m_OutlookBar.SetIconSpacing(rc.Width(), 64);
  435. // change colors
  436. m_OutlookBar.SetTextColor(RGB(255,255,255));
  437. m_OutlookBar.SetTextBkColor(RGB(128,128,128));
  438. m_OutlookBar.SetBkColor(RGB(128,128,128));
  439. // insert items
  440. m_OutlookBar.InsertColumn(0, "OutlookBar");
  441. m_OutlookBar.InsertItem(0, "服务器日志", 0);
  442. m_OutlookBar.InsertItem(1, "在线用户", 1);
  443. /* m_OutlookBar.InsertItem(2, "Configuration", 2);
  444. m_OutlookBar.InsertItem(3, "Statistics", 3);
  445. m_OutlookBar.InsertItem(4, "Security", 4);*/
  446. // m_OutlookBar.SetExtendedStyle(LVS_EX_TRACKSELECT);
  447. }
  448. /********************************************************************/
  449. /* */
  450. /* Function name : CApplicationDlg::MoveChilds */
  451. /* Description : Move child windows into place holder area. */
  452. /* */
  453. /********************************************************************/
  454. void CApplicationDlg::MoveChilds()
  455. {
  456. // position property pages
  457. CRect rcDlgs;
  458. // get dialog area rect
  459. GetDlgItem(IDC_DIALOG_AREA)->GetWindowRect(rcDlgs);
  460. ScreenToClient(rcDlgs);
  461. m_ConfigurationPage.MoveWindow(rcDlgs);
  462. m_TracePage.MoveWindow(rcDlgs);
  463. m_OnlineUsersPage.MoveWindow(rcDlgs);
  464. m_StatisticsPage.MoveWindow(rcDlgs);
  465. m_SecurityPage.MoveWindow(rcDlgs);
  466. }
  467. /********************************************************************/
  468. /* */
  469. /* Function name : CApplicationDlg::ActivatePage */
  470. /* Description : Called when an icon on the outlookbar is pressed.*/
  471. /* */
  472. /********************************************************************/
  473. void CApplicationDlg::ActivatePage(int nIndex)
  474. {
  475. switch(nIndex)
  476. {
  477. case 0:
  478. m_OnlineUsersPage.ShowWindow(SW_HIDE);
  479. m_ConfigurationPage.ShowWindow(SW_HIDE);
  480. m_StatisticsPage.ShowWindow(SW_HIDE);
  481. m_SecurityPage.ShowWindow(SW_HIDE);
  482. m_TracePage.ShowWindow(SW_SHOW);
  483. m_InfobarCtrl.SetText("服务器日志");
  484. break;
  485. case 1:
  486. m_TracePage.ShowWindow(SW_HIDE);
  487. m_ConfigurationPage.ShowWindow(SW_HIDE);
  488. m_StatisticsPage.ShowWindow(SW_HIDE);
  489. m_SecurityPage.ShowWindow(SW_HIDE);
  490. m_OnlineUsersPage.ShowWindow(SW_SHOW);
  491. m_InfobarCtrl.SetText("在线用户");
  492. break;
  493. case 2:
  494. m_OnlineUsersPage.ShowWindow(SW_HIDE);
  495. m_TracePage.ShowWindow(SW_HIDE);
  496. m_StatisticsPage.ShowWindow(SW_HIDE);
  497. m_SecurityPage.ShowWindow(SW_HIDE);
  498. m_ConfigurationPage.ShowWindow(SW_SHOW);
  499. m_InfobarCtrl.SetText("Configuration");
  500. break;
  501. case 3:
  502. m_OnlineUsersPage.ShowWindow(SW_HIDE);
  503. m_TracePage.ShowWindow(SW_HIDE);
  504. m_ConfigurationPage.ShowWindow(SW_HIDE);
  505. m_SecurityPage.ShowWindow(SW_HIDE);
  506. m_StatisticsPage.ShowWindow(SW_SHOW);
  507. m_InfobarCtrl.SetText("Statistics");
  508. break;
  509. case 4:
  510. m_OnlineUsersPage.ShowWindow(SW_HIDE);
  511. m_TracePage.ShowWindow(SW_HIDE);
  512. m_ConfigurationPage.ShowWindow(SW_HIDE);
  513. m_SecurityPage.ShowWindow(SW_SHOW);
  514. m_StatisticsPage.ShowWindow(SW_HIDE);
  515. m_InfobarCtrl.SetText("Security");
  516. break;
  517. default:
  518. break;
  519. }
  520. MoveChilds();
  521. }
  522. /********************************************************************/
  523. /* */
  524. /* Function name : CApplicationDlg::OnClickOutlookBar */
  525. /* Description : User clicked on our listview -> activate page. */
  526. /* */
  527. /********************************************************************/
  528. void CApplicationDlg::OnClickOutlookBar(NMHDR* pNMHDR, LRESULT* pResult)
  529. {
  530. // get index of selected item
  531. int nIndex = m_OutlookBar.GetNextItem(-1, LVNI_ALL | LVNI_SELECTED);
  532. if(nIndex == -1)
  533. return;
  534. ActivatePage(nIndex);
  535. *pResult = 0;
  536. }
  537. /********************************************************************/
  538. /* */
  539. /* Function name : CApplicationDlg::OnKeydownOutlookBar */
  540. /* Description : User pressed a key -> activate page. */
  541. /* */
  542. /********************************************************************/
  543. void CApplicationDlg::OnKeydownOutlookBar(NMHDR* pNMHDR, LRESULT* pResult)
  544. {
  545. LV_KEYDOWN* pLVKeyDow = (LV_KEYDOWN*)pNMHDR;
  546. // get index of selected item
  547. int nIndex = m_OutlookBar.GetNextItem(-1, LVNI_ALL | LVNI_SELECTED);
  548. if(nIndex == -1)
  549. return;
  550. if (pLVKeyDow->wVKey == VK_DOWN)
  551. {
  552. if (m_OutlookBar.GetItemCount()-1 > nIndex)
  553. {
  554. ActivatePage(nIndex+1);
  555. }
  556. }
  557. else
  558. if (pLVKeyDow->wVKey == VK_UP)
  559. {
  560. if (nIndex > 0)
  561. {
  562. ActivatePage(nIndex-1);
  563. }
  564. }
  565. else
  566. if (pLVKeyDow->wVKey == VK_NEXT)
  567. {
  568. ActivatePage(m_OutlookBar.GetItemCount()-1);
  569. }
  570. else
  571. if (pLVKeyDow->wVKey == VK_PRIOR)
  572. {
  573. ActivatePage(0);
  574. }
  575. *pResult = 0;
  576. }
  577. /********************************************************************/
  578. /* */
  579. /* Function name : CreateStatusbar */
  580. /* Description : This function creates a statusbar on a dialogbox.*/
  581. /* */
  582. /********************************************************************/
  583. BOOL CApplicationDlg::CreateStatusbar()
  584. {
  585. // Create the Toolbar and attach the resource
  586. if(!m_wndToolBar.Create(this) || !m_wndToolBar.LoadToolBar(IDR_TOOLBAR1))
  587. {
  588. TRACE0("Failed to Create Dialog Toolbar\n");
  589. return FALSE;
  590. }
  591. m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() | CBRS_SIZE_DYNAMIC | CBRS_TOOLTIPS | CBRS_FLYBY);
  592. // Make it flat.
  593. m_wndToolBar.ModifyStyle(0, m_wndToolBar.GetStyle()|TBSTYLE_FLAT);
  594. // Create status bar at the bottom of the dialog window
  595. if (m_wndStatusBar.Create(this))
  596. {
  597. m_wndStatusBar.SetIndicators(auIDStatusBar, sizeof(auIDStatusBar)/sizeof(UINT));
  598. m_wndStatusBar.SetPaneText(0, "FTP Server is offline", TRUE);
  599. // Make a sunken or recessed border around the first pane
  600. m_wndStatusBar.SetPaneInfo(0, m_wndStatusBar.GetItemID(0), SBPS_STRETCH, NULL );
  601. SetOnlineLed(FALSE);
  602. SetOfflineLed(FALSE);
  603. m_wndStatusBar.SetPaneInfo(m_wndStatusBar.CommandToIndex(ID_INDICATOR_ONLINELED),ID_INDICATOR_ONLINELED, SBPS_NOBORDERS, 14);
  604. // m_wndStatusBar.GetStatusBarCtrl().SetTipText(m_wndStatusBar.CommandToIndex(ID_INDICATOR_ONLINELED), "This status light is green when the server is online");
  605. m_wndStatusBar.SetPaneInfo(m_wndStatusBar.CommandToIndex(ID_INDICATOR_OFFLINELED),ID_INDICATOR_OFFLINELED, SBPS_NOBORDERS, 14);
  606. // m_wndStatusBar.GetStatusBarCtrl().SetTipText(m_wndStatusBar.CommandToIndex(ID_INDICATOR_OFFLINELED), "This status light is green when the server is online");
  607. }
  608. // We need to resize the dialog to make room for control bars.
  609. // First, figure out how big the control bars are.
  610. CRect rcClientStart;
  611. CRect rcClientNow;
  612. GetClientRect(rcClientStart);
  613. RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0, reposQuery, rcClientNow);
  614. // Now move all the controls so they are in the same relative
  615. // position within the remaining client area as they would be
  616. // with no control bars.
  617. CPoint ptOffset(rcClientNow.left - rcClientStart.left, rcClientNow.top - rcClientStart.top);
  618. CRect rcChild;
  619. CWnd* pwndChild = GetWindow(GW_CHILD);
  620. while (pwndChild)
  621. {
  622. pwndChild->GetWindowRect(rcChild);
  623. ScreenToClient(rcChild);
  624. rcChild.OffsetRect(ptOffset);
  625. pwndChild->MoveWindow(rcChild, FALSE);
  626. pwndChild = pwndChild->GetNextWindow();
  627. }
  628. // Adjust the dialog window dimensions
  629. CRect rcWindow;
  630. GetWindowRect(rcWindow);
  631. rcWindow.right += rcClientStart.Width() - rcClientNow.Width();
  632. rcWindow.bottom += rcClientStart.Height() - rcClientNow.Height();
  633. MoveWindow(rcWindow, FALSE);
  634. // And position the control bars
  635. RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
  636. return TRUE;
  637. }
  638. /********************************************************************/
  639. /* */
  640. /* Function name : OnUserAccounts */
  641. /* Description : Show user accounts. */
  642. /* */
  643. /********************************************************************/
  644. void CApplicationDlg::OnUserAccounts()
  645. {
  646. CUserAccountsDlg dlg;
  647. theServer.m_UserManager.GetUserList(dlg.m_UserArray);
  648. if (dlg.DoModal() == IDOK)
  649. {
  650. theServer.m_UserManager.UpdateUserList(dlg.m_UserArray);
  651. }
  652. }
  653. /********************************************************************/
  654. /* */
  655. /* Function name : OnFTPUserConnected */
  656. /* Description : A user has connected to our server. */
  657. /* */
  658. /********************************************************************/
  659. void CApplicationDlg::OnFTPUserConnected(DWORD nThreadID, LPCTSTR lpszUser, LPCSTR lpszAddress)
  660. {
  661. m_OnlineUsersPage.AddUser(nThreadID, lpszUser, lpszAddress);
  662. }
  663. /********************************************************************/
  664. /* */
  665. /* Function name : OnFTPUserDisconnected */
  666. /* Description : A user has disconnected from our server. */
  667. /* */
  668. /********************************************************************/
  669. void CApplicationDlg::OnFTPUserDisconnected(DWORD nThreadID, LPCTSTR lpszUser)
  670. {
  671. m_OnlineUsersPage.RemoveUser(nThreadID);
  672. }
  673. /********************************************************************/
  674. /* */
  675. /* Function name : OnFTPStatusChange */
  676. /* Description : FTP Status changed. */
  677. /* */
  678. /********************************************************************/
  679. void CApplicationDlg::OnFTPStatusChange(int nType, LPCTSTR lpszText)
  680. {
  681. m_TracePage.AddTraceLine(nType, lpszText);
  682. switch(nType)
  683. {
  684. case 3:
  685. theApp.m_LogFile << error_lvl << date << time << lpszText << endl;
  686. break;
  687. default:
  688. theApp.m_LogFile << trace_lvl << date << time << lpszText << endl;
  689. break;
  690. }
  691. }
  692. /********************************************************************/
  693. /* */
  694. /* Function name : OnFTPReceivedBytesChange */
  695. /* Description : Number of received bytes has changed. */
  696. /* */
  697. /********************************************************************/
  698. void CApplicationDlg::OnFTPReceivedBytesChange(int nBytes)
  699. {
  700. m_StatisticsPage.SetValue(6, FormatSize(nBytes, 0));
  701. CString strStatus;
  702. strStatus.Format("%s received", FormatSize(nBytes, 0));
  703. m_wndStatusBar.SetPaneText(m_wndStatusBar.CommandToIndex(ID_INDICATOR_DATA_RECEIVED), strStatus, TRUE);
  704. CClientDC dc(this);
  705. CSize size = dc.GetTextExtent(strStatus);
  706. m_wndStatusBar.SetPaneInfo(m_wndStatusBar.CommandToIndex(ID_INDICATOR_DATA_RECEIVED), ID_INDICATOR_DATA_RECEIVED, SBPS_NORMAL, size.cx);
  707. }
  708. /********************************************************************/
  709. /* */
  710. /* Function name : OnFTPSentBytesChange */
  711. /* Description : Number of sent bytes has changed. */
  712. /* */
  713. /********************************************************************/
  714. void CApplicationDlg::OnFTPSentBytesChange(int nBytes)
  715. {
  716. m_StatisticsPage.SetValue(7, FormatSize(nBytes, 0));
  717. CString strStatus;
  718. strStatus.Format("%s sent", FormatSize(nBytes, 0));
  719. m_wndStatusBar.SetPaneText(m_wndStatusBar.CommandToIndex(ID_INDICATOR_DATA_SEND), strStatus, TRUE);
  720. CClientDC dc(this);
  721. CSize size = dc.GetTextExtent(strStatus);
  722. m_wndStatusBar.SetPaneInfo(m_wndStatusBar.CommandToIndex(ID_INDICATOR_DATA_SEND), ID_INDICATOR_DATA_SEND, SBPS_NORMAL, size.cx);
  723. }
  724. /********************************************************************/
  725. /* */
  726. /* Function name : OnViewTrace */
  727. /* Description : Handle menu selection. */
  728. /* */
  729. /********************************************************************/
  730. void CApplicationDlg::OnViewTrace()
  731. {
  732. ActivatePage(0);
  733. }
  734. /********************************************************************/
  735. /* */
  736. /* Function name : OnViewOnlineUsers */
  737. /* Description : Handle menu selection. */
  738. /* */
  739. /********************************************************************/
  740. void CApplicationDlg::OnViewOnlineUsers()
  741. {
  742. ActivatePage(1);
  743. }
  744. /********************************************************************/
  745. /* */
  746. /* Function name : OnViewConfiguration */
  747. /* Description : Handle menu selection. */
  748. /* */
  749. /********************************************************************/
  750. void CApplicationDlg::OnViewConfiguration()
  751. {
  752. ActivatePage(2);
  753. }
  754. /********************************************************************/
  755. /* */
  756. /* Function name : OnViewStatistics */
  757. /* Description : Handle menu selection. */
  758. /* */
  759. /********************************************************************/
  760. void CApplicationDlg::OnViewStatistics()
  761. {
  762. ActivatePage(3);
  763. }
  764. /********************************************************************/
  765. /* */
  766. /* Function name : OnViewSecurity */
  767. /* Description : Handle menu selection. */
  768. /* */
  769. /********************************************************************/
  770. void CApplicationDlg::OnViewSecurity()
  771. {
  772. ActivatePage(4);
  773. }
  774. /********************************************************************/
  775. /* */
  776. /* Function name : OnUpdateViewTrace */
  777. /* Description : Update menu state of Trace item. */
  778. /* */
  779. /********************************************************************/
  780. void CApplicationDlg::OnUpdateViewTrace(CCmdUI* pCmdUI)
  781. {
  782. pCmdUI->SetRadio(m_TracePage.IsWindowVisible());
  783. }
  784. /********************************************************************/
  785. /* */
  786. /* Function name : OnUpdateViewOnlineUsers */
  787. /* Description : Update menu state of Online Users item. */
  788. /* */
  789. /********************************************************************/
  790. void CApplicationDlg::OnUpdateViewOnlineUsers(CCmdUI* pCmdUI)
  791. {
  792. pCmdUI->SetRadio(m_OnlineUsersPage.IsWindowVisible());
  793. }
  794. /********************************************************************/
  795. /* */
  796. /* Function name : OnUpdateViewConfiguration */
  797. /* Description : Update menu state of Configuration item. */
  798. /* */
  799. /********************************************************************/
  800. void CApplicationDlg::OnUpdateViewConfiguration(CCmdUI* pCmdUI)
  801. {
  802. pCmdUI->SetRadio(m_ConfigurationPage.IsWindowVisible());
  803. }
  804. /********************************************************************/
  805. /* */
  806. /* Function name : OnUpdateViewStatistics */
  807. /* Description : Update menu state of Statistics item. */
  808. /* */
  809. /********************************************************************/
  810. void CApplicationDlg::OnUpdateViewStatistics(CCmdUI* pCmdUI)
  811. {
  812. pCmdUI->SetRadio(m_StatisticsPage.IsWindowVisible());
  813. }
  814. /********************************************************************/
  815. /* */
  816. /* Function name : OnUpdateViewSecurity */
  817. /* Description : Update menu state of Security item. */
  818. /* */
  819. /********************************************************************/
  820. void CApplicationDlg::OnUpdateViewSecurity(CCmdUI* pCmdUI)
  821. {
  822. pCmdUI->SetRadio(m_SecurityPage.IsWindowVisible());
  823. }
  824. /********************************************************************/
  825. /* */
  826. /* Function name : PreTranslateMessage */
  827. /* Description : Needed to make tooltips work. */
  828. /* */
  829. /********************************************************************/
  830. BOOL CApplicationDlg::PreTranslateMessage(MSG* pMsg)
  831. {
  832. // enable tooltips
  833. if (m_hWnd)
  834. {
  835. if (IsWindow(m_ToolTipCtrl.m_hWnd))
  836. m_ToolTipCtrl.RelayEvent(pMsg);
  837. }
  838. return CDialogResize::PreTranslateMessage(pMsg);
  839. }
  840. /********************************************************************/
  841. /* */
  842. /* Function name : OnToolTipText */
  843. /* Description : Tooltip handler for this dialog. */
  844. /* */
  845. /********************************************************************/
  846. BOOL CApplicationDlg::OnToolTipText(UINT, NMHDR* pNMHDR, LRESULT* pResult)
  847. {
  848. ASSERT(pNMHDR->code == TTN_NEEDTEXTA || pNMHDR->code == TTN_NEEDTEXTW);
  849. // need to handle both ANSI and UNICODE versions of the message
  850. TOOLTIPTEXTA* pTTTA = (TOOLTIPTEXTA*)pNMHDR;
  851. TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR;
  852. TCHAR szFullText[256];
  853. CString cstTipText;
  854. CString cstStatusText;
  855. UINT nID = pNMHDR->idFrom;
  856. if (pNMHDR->code == TTN_NEEDTEXTA && (pTTTA->uFlags & TTF_IDISHWND) ||
  857. pNMHDR->code == TTN_NEEDTEXTW && (pTTTW->uFlags & TTF_IDISHWND))
  858. {
  859. // idFrom is actually the HWND of the tool
  860. nID = ((UINT)(WORD)::GetDlgCtrlID((HWND)nID));
  861. }
  862. if (nID != 0) // will be zero on a separator
  863. {
  864. AfxLoadString(nID, szFullText);
  865. // this is the command id, not the button index
  866. AfxExtractSubString(cstTipText, szFullText, 1, '\n');
  867. AfxExtractSubString(cstStatusText, szFullText, 0, '\n');
  868. }
  869. // Non-UNICODE Strings only are shown in the tooltip window...
  870. if (pNMHDR->code == TTN_NEEDTEXTA)
  871. lstrcpyn(pTTTA->szText, cstTipText,
  872. (sizeof(pTTTA->szText)/sizeof(pTTTA->szText[0])));
  873. else
  874. _mbstowcsz(pTTTW->szText, cstTipText,
  875. (sizeof(pTTTW->szText)/sizeof(pTTTW->szText[0])));
  876. *pResult = 0;
  877. // bring the tooltip window above other popup windows
  878. ::SetWindowPos(pNMHDR->hwndFrom, HWND_TOP, 0, 0, 0, 0, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE);
  879. // message was handled
  880. return TRUE;
  881. }
  882. /********************************************************************/
  883. /* */
  884. /* Function name : SetOnlineLed */
  885. /* Description : Turn online LED on/off. */
  886. /* */
  887. /********************************************************************/
  888. void CApplicationDlg::SetOnlineLed(BOOL bOnline)
  889. {
  890. HICON hIcon = (HICON)::LoadImage(AfxGetInstanceHandle(),
  891. bOnline ? MAKEINTRESOURCE(IDI_LED_GREEN) : MAKEINTRESOURCE(IDI_LED_OFF),
  892. IMAGE_ICON, 16, 16, LR_SHARED);
  893. m_wndStatusBar.GetStatusBarCtrl().SetIcon(m_wndStatusBar.CommandToIndex(ID_INDICATOR_ONLINELED), hIcon);
  894. m_wndStatusBar.GetStatusBarCtrl().Invalidate();
  895. m_wndStatusBar.GetStatusBarCtrl().UpdateWindow();
  896. DestroyIcon(hIcon);
  897. }
  898. /********************************************************************/
  899. /* */
  900. /* Function name : SetOfflineLed */
  901. /* Description : Turn offline LED on/off. */
  902. /* */
  903. /********************************************************************/
  904. void CApplicationDlg::SetOfflineLed(BOOL bOffline)
  905. {
  906. HICON hIcon = (HICON)::LoadImage(AfxGetInstanceHandle(),
  907. bOffline ? MAKEINTRESOURCE(IDI_LED_RED) : MAKEINTRESOURCE(IDI_LED_OFF),
  908. IMAGE_ICON, 16, 16, LR_SHARED);
  909. m_wndStatusBar.GetStatusBarCtrl().SetIcon(m_wndStatusBar.CommandToIndex(ID_INDICATOR_OFFLINELED), hIcon);
  910. m_wndStatusBar.GetStatusBarCtrl().Invalidate();
  911. m_wndStatusBar.GetStatusBarCtrl().UpdateWindow();
  912. DestroyIcon(hIcon);
  913. }
  914. /********************************************************************/
  915. /* */
  916. /* Function name : OnUpdateApply */
  917. /* Description : Update FTP server parameters. */
  918. /* */
  919. /********************************************************************/
  920. void CApplicationDlg::OnApply()
  921. {
  922. m_ConfigurationPage.UpdateData();
  923. theServer.SetPort(m_ConfigurationPage.m_nPort);
  924. theServer.SetMaxUsers(m_ConfigurationPage.m_nMaxUsers);
  925. theServer.SetTimeout(m_ConfigurationPage.m_nTimeout);
  926. theServer.SetWelcomeMessage(m_ConfigurationPage.m_strWelcomeMessage);
  927. theServer.SetGoodbyeMessage(m_ConfigurationPage.m_strGoodbyeMessage);
  928. SetWindowText(m_ConfigurationPage.m_strApplicationName);
  929. // set log level
  930. theApp.m_LogFile.SetLogLevel(m_ConfigurationPage.m_nLogLevel);
  931. OnFTPStatusChange(0, "FTP Server configuration updated.");
  932. }
  933. void CApplicationDlg::OnFTPStatisticChange(int nType, int nValue)
  934. {
  935. m_StatisticsPage.SetValue(nType, nValue);
  936. }
  937. /********************************************************************/
  938. /* */
  939. /* Function name : FormatSize */
  940. /* Description : Format size, the way explorer diplays it */
  941. /* */
  942. /********************************************************************/
  943. char* CApplicationDlg::FormatSize(DWORD dwSizeLow, DWORD dwSizeHigh)
  944. {
  945. static char szBuff[100];
  946. unsigned __int64 nFileSize = ((unsigned __int64)(((DWORD)(dwSizeLow)) |
  947. ((unsigned __int64)((DWORD)(dwSizeHigh))) << 32));
  948. unsigned __int64 kb = 0;
  949. if (nFileSize > 1024)
  950. {
  951. kb = nFileSize / 1024;
  952. if (nFileSize % 1024)
  953. kb++;
  954. }
  955. // make it a string
  956. _ui64tot(kb, szBuff, 10);
  957. // add thousand seperators
  958. int nLength = lstrlen(szBuff);
  959. if (nLength > 3)
  960. {
  961. LPCTSTR ptr = szBuff;
  962. ptr += (nLength-1);
  963. char szTemp[100];
  964. LPTSTR ptrTemp = szTemp;
  965. for(int i=0; i<nLength; i++)
  966. {
  967. if (i && ((i % 3) == 0))
  968. {
  969. if (*ptrTemp != ',')
  970. {
  971. *ptrTemp = ',';
  972. ptrTemp = _tcsinc(ptrTemp);
  973. }
  974. }
  975. *ptrTemp = *ptr;
  976. ptrTemp = _tcsinc(ptrTemp);
  977. ptr = _tcsdec(szBuff, ptr);
  978. }
  979. // terminate string
  980. *ptrTemp = '\0';
  981. // reverse string
  982. _tcsrev(szTemp);
  983. lstrcpy(szBuff, szTemp);
  984. }
  985. // add 'KB' to it
  986. lstrcat(szBuff, " KB");
  987. return szBuff;
  988. }
  989. /********************************************************************/
  990. /* */
  991. /* Function name : OnAccountWizard */
  992. /* Description : Launch New Account Wizard */
  993. /* */
  994. /********************************************************************/
  995. void CApplicationDlg::OnAccountWizard()
  996. {
  997. CBitmap bmpHeader, bmpWatermark;
  998. VERIFY(bmpHeader.LoadBitmap(IDB_BANNER));
  999. VERIFY(bmpWatermark.LoadBitmap(IDB_WATERMARK));
  1000. // show windows 2000-like wizard
  1001. CWizardSheet wizSheet("New Account Wizard", this, 0, bmpWatermark, NULL, bmpHeader);
  1002. wizSheet.m_psh.hInstance = ::GetModuleHandle(NULL);
  1003. if (wizSheet.DoModal() == ID_WIZFINISH)
  1004. {
  1005. CArray<CUser, CUser&> m_UserArray;
  1006. theServer.m_UserManager.GetUserList(m_UserArray);
  1007. int nIndex = -1;
  1008. for (int i=0; i<m_UserArray.GetSize(); i++)
  1009. {
  1010. // if it already exists -> update it
  1011. if (m_UserArray[i].m_strName.CompareNoCase(wizSheet.m_Page1.m_strAccountName) == 0)
  1012. {
  1013. nIndex = i;
  1014. break;
  1015. }
  1016. }
  1017. // add new account ?
  1018. if (nIndex == -1)
  1019. {
  1020. CUser user;
  1021. nIndex = m_UserArray.Add(user);
  1022. }
  1023. m_UserArray[nIndex].m_bAccountDisabled = FALSE;
  1024. m_UserArray[nIndex].m_strName = wizSheet.m_Page1.m_strAccountName;
  1025. m_UserArray[nIndex].m_strPassword = wizSheet.m_Page2.m_strPassword;
  1026. // add home directory
  1027. CDirectory directory;
  1028. directory.m_strDir = wizSheet.m_Page3.m_strHomeDirectory;
  1029. directory.m_strAlias = "";
  1030. directory.m_bIsHomeDir = TRUE;
  1031. directory.m_bAllowCreateDirectory = wizSheet.m_Page4.m_bAllowCreateDirectory;
  1032. directory.m_bAllowDelete = wizSheet.m_Page4.m_bAllowDelete;
  1033. directory.m_bAllowDownload = wizSheet.m_Page4.m_bAllowDownload;
  1034. directory.m_bAllowRename = wizSheet.m_Page4.m_bAllowRename;
  1035. directory.m_bAllowUpload = wizSheet.m_Page4.m_bAllowUpload;
  1036. directory.m_strAlias = "";
  1037. m_UserArray[nIndex].m_DirectoryArray.Add(directory);
  1038. // update
  1039. theServer.m_UserManager.UpdateUserList(m_UserArray);
  1040. }
  1041. }
  1042. void CApplicationDlg::OnCancel()
  1043. {
  1044. // TODO: Add extra cleanup here
  1045. }
  1046. void CApplicationDlg::OnOK()
  1047. {
  1048. // TODO: Add extra validation here
  1049. }
  1050. extern int g_port;
  1051. void CApplicationDlg::OnTimer(UINT nIDEvent)
  1052. {
  1053. // TODO: Add your message handler code here and/or call default settimer
  1054. if(nIDEvent==1)
  1055. {
  1056. KillTimer(1);
  1057. WriteLogin("无数据到达,重新启动");
  1058. OnServerStop();
  1059. CString sport;
  1060. sport.Format("%d", g_port-8380);
  1061. ShellExecute(NULL, _T("open"), g_mainpath+"\\LYFZReceiveMsg.exe", sport, NULL, SW_SHOWNORMAL);
  1062. CDialog::OnCancel ();
  1063. }
  1064. else if(nIDEvent==2)
  1065. {
  1066. KillTimer(2);
  1067. OnServerStop();
  1068. CString sport;
  1069. sport.Format("%d", g_port-8380);
  1070. ShellExecute(NULL, _T("open"), g_mainpath+"\\LYFZReceiveMsg.exe", sport, NULL, SW_SHOWNORMAL);
  1071. CDialog::OnCancel ();
  1072. }
  1073. }