1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273 |
- #include "stdafx.h"
- #include "LYFZReceiveMsgApp.h"
- #include "LYFZReceiveMsg.h"
- #include "ApplicationDlg.h"
- #include "UserAccountsDlg.h"
- #include "WizardPages.h"
- #include "AboutDlg.h"
- #include <afxpriv.h>
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- extern CLYFZReceiveMsgApp theApp;
- extern CLYFZReceiveMsg theServer;
- static UINT auIDStatusBar[] =
- {
- ID_SEPARATOR,
- ID_INDICATOR_DATA_RECEIVED,
- ID_INDICATOR_DATA_SEND,
- ID_INDICATOR_ONLINELED,
- ID_INDICATOR_OFFLINELED
- };
- CApplicationDlg::CApplicationDlg(CWnd* pParent )
- : CDialogResize(CApplicationDlg::IDD, pParent)
- {
-
-
- m_hIcon = AfxGetApp()->LoadIcon(IDI_LYFZReceiveMsg);
- m_bInitialized = FALSE;
- }
- CApplicationDlg::~CApplicationDlg()
- {
- }
-
- void CApplicationDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialogResize::DoDataExchange(pDX);
-
- DDX_Control(pDX, IDC_INFOBAR, m_InfobarCtrl);
- DDX_Control(pDX, IDC_OUTLOOKBAR, m_OutlookBar);
-
- }
- BEGIN_MESSAGE_MAP(CApplicationDlg, CDialogResize)
-
- ON_WM_SYSCOMMAND()
- ON_WM_SIZE()
- ON_WM_DESTROY()
- ON_COMMAND(ID_SERVER_START, OnServerStart)
- ON_UPDATE_COMMAND_UI(ID_SERVER_START, OnUpdateServerStart)
- ON_COMMAND(ID_SERVER_STOP, OnServerStop)
- ON_UPDATE_COMMAND_UI(ID_SERVER_STOP, OnUpdateServerStop)
- ON_COMMAND(ID_SERVER_EXIT, OnServerExit)
- ON_NOTIFY(NM_CLICK, IDC_OUTLOOKBAR, OnClickOutlookBar)
- ON_NOTIFY(LVN_KEYDOWN, IDC_OUTLOOKBAR, OnKeydownOutlookBar)
- ON_COMMAND(ID_USER_ACCOUNTS, OnUserAccounts)
- ON_WM_CLOSE()
- ON_COMMAND(IDC_VIEW_TRACE, OnViewTrace)
- ON_COMMAND(IDC_VIEW_ONLINE_USERS, OnViewOnlineUsers)
- ON_COMMAND(IDC_VIEW_CONFIGURATION, OnViewConfiguration)
- ON_UPDATE_COMMAND_UI(IDC_VIEW_TRACE, OnUpdateViewTrace)
- ON_UPDATE_COMMAND_UI(IDC_VIEW_ONLINE_USERS, OnUpdateViewOnlineUsers)
- ON_UPDATE_COMMAND_UI(IDC_VIEW_CONFIGURATION, OnUpdateViewConfiguration)
- ON_COMMAND(ID_HELP_ABOUT, OnHelpAbout)
- ON_COMMAND(IDC_VIEW_STATISTICS, OnViewStatistics)
- ON_UPDATE_COMMAND_UI(IDC_VIEW_STATISTICS, OnUpdateViewStatistics)
- ON_COMMAND(IDC_VIEW_SECURITY, OnViewSecurity)
- ON_UPDATE_COMMAND_UI(IDC_VIEW_SECURITY, OnUpdateViewSecurity)
- ON_COMMAND(ID_ACCOUNT_WIZARD, OnAccountWizard)
- ON_WM_TIMER()
-
- ON_MESSAGE(WM_KICKIDLE, OnKickIdle)
- ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, OnToolTipText)
- ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, OnToolTipText)
- ON_COMMAND(IDC_APPLY, OnApply)
- END_MESSAGE_MAP()
- BEGIN_DLGRESIZE_MAP(CApplicationDlg)
- DLGRESIZE_CONTROL(IDC_OUTLOOKBAR, DLSZ_SIZE_Y)
- DLGRESIZE_CONTROL(IDC_DIALOG_AREA, DLSZ_SIZE_X | DLSZ_SIZE_Y)
- DLGRESIZE_CONTROL(AFX_IDW_STATUS_BAR, DLSZ_MOVE_Y | DLSZ_SIZE_X)
- DLGRESIZE_CONTROL(AFX_IDW_TOOLBAR, DLSZ_SIZE_X)
- DLGRESIZE_CONTROL(IDC_STATIC1, DLSZ_SIZE_X)
- DLGRESIZE_CONTROL(IDC_INFOBAR, DLSZ_SIZE_X)
- END_DLGRESIZE_MAP()
-
- BOOL CApplicationDlg::OnInitDialog()
- {
- CDialogResize::OnInitDialog();
-
- SetupOutlookBar();
-
- CreateStatusbar();
- CRect rect;
- GetDlgItem(IDC_STATIC1)->GetWindowRect(rect);
- ScreenToClient(rect);
- rect.right+=4;
- GetDlgItem(IDC_STATIC1)->MoveWindow(rect);
- InitResizing(FALSE);
- int s, t, b, r, l;
-
- if (1)
- {
-
- if ( -1 != (s = AfxGetApp()->GetProfileInt("Settings", "FrameStatus", -1)) &&
- -1 != (t = AfxGetApp()->GetProfileInt("Settings", "FrameTop", -1)) &&
- -1 != (l = AfxGetApp()->GetProfileInt("Settings", "FrameLeft", -1)) &&
- -1 != (b = AfxGetApp()->GetProfileInt("Settings", "FrameBottom", -1)) &&
- -1 != (r = AfxGetApp()->GetProfileInt("Settings", "FrameRight", -1))
- )
- {
- WINDOWPLACEMENT wp;
-
- wp.showCmd = s;
-
- wp.rcNormalPosition.bottom = b;
- wp.rcNormalPosition.right = r;
-
-
- RECT workArea;
- SystemParametersInfo(SPI_GETWORKAREA, 0, &workArea, 0);
- l += workArea.left;
- t += workArea.top;
-
- int max_x = GetSystemMetrics(SM_CXSCREEN) -
- GetSystemMetrics(SM_CXICON);
- int max_y = GetSystemMetrics(SM_CYSCREEN) -
- GetSystemMetrics(SM_CYICON);
- wp.rcNormalPosition.top = min(t, max_y);
- wp.rcNormalPosition.left = min(l, max_x);
- SetWindowPlacement(&wp);
- }
- }
-
- m_TracePage.Create(IDD_PROPPAGE_TRACE, this);
- m_OnlineUsersPage.Create(IDD_PROPPAGE_ONLINE, this);
- m_ConfigurationPage.Create(IDD_PROPPAGE_CONFIGURATION, this);
- m_StatisticsPage.Create(IDD_PROPPAGE_STATISTICS, this);
- m_SecurityPage.Create(IDD_PROPPAGE_SECURITY, this);
-
- ActivatePage(0);
-
- SetIcon(m_hIcon, TRUE);
- SetIcon(m_hIcon, FALSE);
-
- m_ConfigurationPage.m_nPort = 21;
- m_ConfigurationPage.m_nMaxUsers = 100;
- m_ConfigurationPage.m_nTimeout = 10;
- m_ConfigurationPage.m_strWelcomeMessage = "Welcome to LYFZ FTP Server";
- m_ConfigurationPage.m_strGoodbyeMessage = "Bye";
- m_ConfigurationPage.m_bLaunchOnStartup = 1;
- m_ConfigurationPage.m_bStartInTray = 1;
- m_ConfigurationPage.m_bAutoActivate = 1;
- m_ConfigurationPage.m_nLogLevel = 1;
- m_ConfigurationPage.m_strApplicationName = "利亚方舟-短信接收";
-
- m_ConfigurationPage.UpdateData(FALSE);
- SetWindowText(m_ConfigurationPage.m_strApplicationName);
-
- theApp.m_LogFile.SetLogLevel(m_ConfigurationPage.m_nLogLevel);
-
- m_ToolTipCtrl.Create(this);
- m_ToolTipCtrl.Activate(TRUE);
-
- if (m_ConfigurationPage.m_bStartInTray)
- {
- PostMessage(WM_SYSCOMMAND, SC_MINIMIZE, 0);
-
- CRect rect;
- GetWindowRect(rect);
- SetWindowPos(&CWnd::wndTop, rect.left, rect.top, rect.Width(), rect.Height(), SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE);
- }
- theServer.Initialize(this);
- if (1)
- {
- OnServerStart();
- }
- m_bInitialized = TRUE;
- SetTimer(2, 60*60*1000, NULL);
- return TRUE;
- }
-
- void CApplicationDlg::OnSysCommand(UINT nID, LPARAM lParam)
- {
- switch(nID)
- {
- case SC_MINIMIZE:
-
- ShowWindow(SW_HIDE);
- break;
- default:
- CDialog::OnSysCommand(nID, lParam);
- break;
- }
- }
-
- void CApplicationDlg::OnSize(UINT nType, int cx, int cy)
- {
- CDialogResize::OnSize(nType, cx, cy);
- if (m_bInitialized)
- MoveChilds();
- }
-
- void CApplicationDlg::OnClose()
- {
- if (1)
- {
-
- WINDOWPLACEMENT wp;
- GetWindowPlacement(&wp);
- AfxGetApp()->WriteProfileInt("Settings", "FrameStatus", wp.showCmd);
- AfxGetApp()->WriteProfileInt("Settings", "FrameTop", wp.rcNormalPosition.top);
- AfxGetApp()->WriteProfileInt("Settings", "FrameLeft", wp.rcNormalPosition.left);
- AfxGetApp()->WriteProfileInt("Settings", "FrameBottom", wp.rcNormalPosition.bottom);
- AfxGetApp()->WriteProfileInt("Settings", "FrameRight", wp.rcNormalPosition.right);
- }
- ShowWindow(0);
- }
-
- void CApplicationDlg::OnDestroy()
- {
- OnServerStop();
- CDialogResize::OnDestroy();
- }
-
- void CApplicationDlg::OnServerStart()
- {
- m_ConfigurationPage.UpdateData();
- theServer.SetPort(m_ConfigurationPage.m_nPort);
- theServer.SetMaxUsers(m_ConfigurationPage.m_nMaxUsers);
- theServer.SetTimeout(m_ConfigurationPage.m_nTimeout);
- theServer.SetWelcomeMessage(m_ConfigurationPage.m_strWelcomeMessage);
- theServer.SetGoodbyeMessage(m_ConfigurationPage.m_strGoodbyeMessage);
- theServer.SetStatisticsInterval(5000);
- BOOL bBlockAll = AfxGetApp()->GetProfileInt("Settings", "BlockAll", 0);
- theServer.SetSecurityMode(!bBlockAll);
- if (theServer.Start())
- {
- m_wndStatusBar.SetPaneText(0, "FTP服务已启动", TRUE);
- SetOnlineLed(TRUE);
- SetOfflineLed(FALSE);
- }
- else
- CDialog::OnCancel ();
- }
-
- void CApplicationDlg::OnUpdateServerStart(CCmdUI* pCmdUI)
- {
- pCmdUI->Enable(!theServer.IsActive());
- }
-
- void CApplicationDlg::OnServerStop()
- {
- theServer.Stop();
- m_wndStatusBar.SetPaneText(0, "FTP服务已停止", TRUE);
- SetOnlineLed(FALSE);
- SetOfflineLed(TRUE);
- }
-
- void CApplicationDlg::OnUpdateServerStop(CCmdUI* pCmdUI)
- {
- pCmdUI->Enable(theServer.IsActive());
- }
-
- LRESULT CApplicationDlg::OnKickIdle(WPARAM wParam, LPARAM lParam)
- {
- UpdateDialogControls(this, FALSE);
- CMenu* pMainMenu = GetMenu();
- CCmdUI cmdUI;
-
- for (UINT n = 0; n < pMainMenu->GetMenuItemCount(); ++n)
- {
- CMenu* pSubMenu = pMainMenu->GetSubMenu(n);
- cmdUI.m_nIndexMax = pSubMenu->GetMenuItemCount();
- for (UINT i = 0; i < cmdUI.m_nIndexMax;++i)
- {
- cmdUI.m_nIndex = i;
- cmdUI.m_nID = pSubMenu->GetMenuItemID(i);
- cmdUI.m_pMenu = pSubMenu;
- cmdUI.DoUpdate(this, FALSE);
- }
- }
-
- if (m_wndToolBar.IsWindowVisible())
- {
-
- CFrameWnd *pParent = (CFrameWnd *)this;
- if (pParent)
- m_wndToolBar.OnUpdateCmdUI(pParent, TRUE);
- }
- return Default();
- }
-
-
- void CApplicationDlg::OnHelpAbout()
- {
- CAboutDlg dlg;
- dlg.DoModal();
- }
-
-
- void CApplicationDlg::OnServerExit()
- {
- OnCancel();
- }
-
- void CApplicationDlg::SetupOutlookBar()
- {
-
- m_ImageList.Create(32, 32, ILC_COLOR16|ILC_MASK,1, 4);
- HICON hIcon = ::LoadIcon (AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_LOG));
- m_ImageList.Add(hIcon);
- hIcon = ::LoadIcon (AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ONLINE_USERS));
- m_ImageList.Add(hIcon);
- hIcon = ::LoadIcon (AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_CONFIGURATION));
- m_ImageList.Add(hIcon);
- hIcon = ::LoadIcon (AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_STATISTICS));
- m_ImageList.Add(hIcon);
- hIcon = ::LoadIcon (AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_SECURITY));
- m_ImageList.Add(hIcon);
- m_OutlookBar.SetImageList(&m_ImageList, LVSIL_NORMAL);
- CRect rc;
- m_OutlookBar.GetClientRect(rc);
-
- m_OutlookBar.SetIconSpacing(rc.Width(), 64);
-
- m_OutlookBar.SetTextColor(RGB(255,255,255));
- m_OutlookBar.SetTextBkColor(RGB(128,128,128));
- m_OutlookBar.SetBkColor(RGB(128,128,128));
-
- m_OutlookBar.InsertColumn(0, "OutlookBar");
- m_OutlookBar.InsertItem(0, "服务器日志", 0);
- m_OutlookBar.InsertItem(1, "在线用户", 1);
-
-
- }
-
- void CApplicationDlg::MoveChilds()
- {
-
- CRect rcDlgs;
-
- GetDlgItem(IDC_DIALOG_AREA)->GetWindowRect(rcDlgs);
- ScreenToClient(rcDlgs);
- m_ConfigurationPage.MoveWindow(rcDlgs);
- m_TracePage.MoveWindow(rcDlgs);
- m_OnlineUsersPage.MoveWindow(rcDlgs);
- m_StatisticsPage.MoveWindow(rcDlgs);
- m_SecurityPage.MoveWindow(rcDlgs);
- }
- void CApplicationDlg::ActivatePage(int nIndex)
- {
- switch(nIndex)
- {
- case 0:
- m_OnlineUsersPage.ShowWindow(SW_HIDE);
- m_ConfigurationPage.ShowWindow(SW_HIDE);
- m_StatisticsPage.ShowWindow(SW_HIDE);
- m_SecurityPage.ShowWindow(SW_HIDE);
- m_TracePage.ShowWindow(SW_SHOW);
- m_InfobarCtrl.SetText("服务器日志");
- break;
- case 1:
- m_TracePage.ShowWindow(SW_HIDE);
- m_ConfigurationPage.ShowWindow(SW_HIDE);
- m_StatisticsPage.ShowWindow(SW_HIDE);
- m_SecurityPage.ShowWindow(SW_HIDE);
- m_OnlineUsersPage.ShowWindow(SW_SHOW);
- m_InfobarCtrl.SetText("在线用户");
- break;
- case 2:
- m_OnlineUsersPage.ShowWindow(SW_HIDE);
- m_TracePage.ShowWindow(SW_HIDE);
- m_StatisticsPage.ShowWindow(SW_HIDE);
- m_SecurityPage.ShowWindow(SW_HIDE);
- m_ConfigurationPage.ShowWindow(SW_SHOW);
- m_InfobarCtrl.SetText("Configuration");
- break;
- case 3:
- m_OnlineUsersPage.ShowWindow(SW_HIDE);
- m_TracePage.ShowWindow(SW_HIDE);
- m_ConfigurationPage.ShowWindow(SW_HIDE);
- m_SecurityPage.ShowWindow(SW_HIDE);
- m_StatisticsPage.ShowWindow(SW_SHOW);
- m_InfobarCtrl.SetText("Statistics");
- break;
- case 4:
- m_OnlineUsersPage.ShowWindow(SW_HIDE);
- m_TracePage.ShowWindow(SW_HIDE);
- m_ConfigurationPage.ShowWindow(SW_HIDE);
- m_SecurityPage.ShowWindow(SW_SHOW);
- m_StatisticsPage.ShowWindow(SW_HIDE);
- m_InfobarCtrl.SetText("Security");
- break;
- default:
- break;
- }
- MoveChilds();
- }
- void CApplicationDlg::OnClickOutlookBar(NMHDR* pNMHDR, LRESULT* pResult)
- {
-
- int nIndex = m_OutlookBar.GetNextItem(-1, LVNI_ALL | LVNI_SELECTED);
- if(nIndex == -1)
- return;
- ActivatePage(nIndex);
- *pResult = 0;
- }
- void CApplicationDlg::OnKeydownOutlookBar(NMHDR* pNMHDR, LRESULT* pResult)
- {
- LV_KEYDOWN* pLVKeyDow = (LV_KEYDOWN*)pNMHDR;
-
- int nIndex = m_OutlookBar.GetNextItem(-1, LVNI_ALL | LVNI_SELECTED);
- if(nIndex == -1)
- return;
- if (pLVKeyDow->wVKey == VK_DOWN)
- {
- if (m_OutlookBar.GetItemCount()-1 > nIndex)
- {
- ActivatePage(nIndex+1);
- }
- }
- else
- if (pLVKeyDow->wVKey == VK_UP)
- {
- if (nIndex > 0)
- {
- ActivatePage(nIndex-1);
- }
- }
- else
- if (pLVKeyDow->wVKey == VK_NEXT)
- {
- ActivatePage(m_OutlookBar.GetItemCount()-1);
- }
- else
- if (pLVKeyDow->wVKey == VK_PRIOR)
- {
- ActivatePage(0);
- }
- *pResult = 0;
- }
-
- BOOL CApplicationDlg::CreateStatusbar()
- {
-
- if(!m_wndToolBar.Create(this) || !m_wndToolBar.LoadToolBar(IDR_TOOLBAR1))
- {
- TRACE0("Failed to Create Dialog Toolbar\n");
- return FALSE;
- }
- m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() | CBRS_SIZE_DYNAMIC | CBRS_TOOLTIPS | CBRS_FLYBY);
-
- m_wndToolBar.ModifyStyle(0, m_wndToolBar.GetStyle()|TBSTYLE_FLAT);
-
- if (m_wndStatusBar.Create(this))
- {
- m_wndStatusBar.SetIndicators(auIDStatusBar, sizeof(auIDStatusBar)/sizeof(UINT));
- m_wndStatusBar.SetPaneText(0, "FTP Server is offline", TRUE);
-
- m_wndStatusBar.SetPaneInfo(0, m_wndStatusBar.GetItemID(0), SBPS_STRETCH, NULL );
- SetOnlineLed(FALSE);
- SetOfflineLed(FALSE);
- m_wndStatusBar.SetPaneInfo(m_wndStatusBar.CommandToIndex(ID_INDICATOR_ONLINELED),ID_INDICATOR_ONLINELED, SBPS_NOBORDERS, 14);
-
- m_wndStatusBar.SetPaneInfo(m_wndStatusBar.CommandToIndex(ID_INDICATOR_OFFLINELED),ID_INDICATOR_OFFLINELED, SBPS_NOBORDERS, 14);
-
- }
-
-
- CRect rcClientStart;
- CRect rcClientNow;
- GetClientRect(rcClientStart);
- RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0, reposQuery, rcClientNow);
-
-
-
- CPoint ptOffset(rcClientNow.left - rcClientStart.left, rcClientNow.top - rcClientStart.top);
- CRect rcChild;
- CWnd* pwndChild = GetWindow(GW_CHILD);
- while (pwndChild)
- {
- pwndChild->GetWindowRect(rcChild);
- ScreenToClient(rcChild);
- rcChild.OffsetRect(ptOffset);
- pwndChild->MoveWindow(rcChild, FALSE);
- pwndChild = pwndChild->GetNextWindow();
- }
-
- CRect rcWindow;
- GetWindowRect(rcWindow);
- rcWindow.right += rcClientStart.Width() - rcClientNow.Width();
- rcWindow.bottom += rcClientStart.Height() - rcClientNow.Height();
- MoveWindow(rcWindow, FALSE);
-
- RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
- return TRUE;
- }
-
-
- void CApplicationDlg::OnUserAccounts()
- {
- CUserAccountsDlg dlg;
- theServer.m_UserManager.GetUserList(dlg.m_UserArray);
- if (dlg.DoModal() == IDOK)
- {
- theServer.m_UserManager.UpdateUserList(dlg.m_UserArray);
- }
- }
- void CApplicationDlg::OnFTPUserConnected(DWORD nThreadID, LPCTSTR lpszUser, LPCSTR lpszAddress)
- {
- m_OnlineUsersPage.AddUser(nThreadID, lpszUser, lpszAddress);
- }
- void CApplicationDlg::OnFTPUserDisconnected(DWORD nThreadID, LPCTSTR lpszUser)
- {
- m_OnlineUsersPage.RemoveUser(nThreadID);
- }
-
-
- void CApplicationDlg::OnFTPStatusChange(int nType, LPCTSTR lpszText)
- {
- m_TracePage.AddTraceLine(nType, lpszText);
- switch(nType)
- {
- case 3:
- theApp.m_LogFile << error_lvl << date << time << lpszText << endl;
- break;
- default:
- theApp.m_LogFile << trace_lvl << date << time << lpszText << endl;
- break;
- }
- }
-
-
- void CApplicationDlg::OnFTPReceivedBytesChange(int nBytes)
- {
- m_StatisticsPage.SetValue(6, FormatSize(nBytes, 0));
- CString strStatus;
- strStatus.Format("%s received", FormatSize(nBytes, 0));
- m_wndStatusBar.SetPaneText(m_wndStatusBar.CommandToIndex(ID_INDICATOR_DATA_RECEIVED), strStatus, TRUE);
- CClientDC dc(this);
- CSize size = dc.GetTextExtent(strStatus);
- m_wndStatusBar.SetPaneInfo(m_wndStatusBar.CommandToIndex(ID_INDICATOR_DATA_RECEIVED), ID_INDICATOR_DATA_RECEIVED, SBPS_NORMAL, size.cx);
- }
-
-
- void CApplicationDlg::OnFTPSentBytesChange(int nBytes)
- {
- m_StatisticsPage.SetValue(7, FormatSize(nBytes, 0));
- CString strStatus;
- strStatus.Format("%s sent", FormatSize(nBytes, 0));
- m_wndStatusBar.SetPaneText(m_wndStatusBar.CommandToIndex(ID_INDICATOR_DATA_SEND), strStatus, TRUE);
- CClientDC dc(this);
- CSize size = dc.GetTextExtent(strStatus);
- m_wndStatusBar.SetPaneInfo(m_wndStatusBar.CommandToIndex(ID_INDICATOR_DATA_SEND), ID_INDICATOR_DATA_SEND, SBPS_NORMAL, size.cx);
- }
-
-
- void CApplicationDlg::OnViewTrace()
- {
- ActivatePage(0);
- }
-
-
- void CApplicationDlg::OnViewOnlineUsers()
- {
- ActivatePage(1);
- }
-
-
- void CApplicationDlg::OnViewConfiguration()
- {
- ActivatePage(2);
- }
-
-
- void CApplicationDlg::OnViewStatistics()
- {
- ActivatePage(3);
- }
-
-
- void CApplicationDlg::OnViewSecurity()
- {
- ActivatePage(4);
- }
-
-
- void CApplicationDlg::OnUpdateViewTrace(CCmdUI* pCmdUI)
- {
- pCmdUI->SetRadio(m_TracePage.IsWindowVisible());
- }
-
-
- void CApplicationDlg::OnUpdateViewOnlineUsers(CCmdUI* pCmdUI)
- {
- pCmdUI->SetRadio(m_OnlineUsersPage.IsWindowVisible());
- }
-
-
- void CApplicationDlg::OnUpdateViewConfiguration(CCmdUI* pCmdUI)
- {
- pCmdUI->SetRadio(m_ConfigurationPage.IsWindowVisible());
- }
-
-
- void CApplicationDlg::OnUpdateViewStatistics(CCmdUI* pCmdUI)
- {
- pCmdUI->SetRadio(m_StatisticsPage.IsWindowVisible());
- }
-
-
- void CApplicationDlg::OnUpdateViewSecurity(CCmdUI* pCmdUI)
- {
- pCmdUI->SetRadio(m_SecurityPage.IsWindowVisible());
- }
-
- BOOL CApplicationDlg::PreTranslateMessage(MSG* pMsg)
- {
-
- if (m_hWnd)
- {
- if (IsWindow(m_ToolTipCtrl.m_hWnd))
- m_ToolTipCtrl.RelayEvent(pMsg);
- }
- return CDialogResize::PreTranslateMessage(pMsg);
- }
-
- BOOL CApplicationDlg::OnToolTipText(UINT, NMHDR* pNMHDR, LRESULT* pResult)
- {
- ASSERT(pNMHDR->code == TTN_NEEDTEXTA || pNMHDR->code == TTN_NEEDTEXTW);
-
- TOOLTIPTEXTA* pTTTA = (TOOLTIPTEXTA*)pNMHDR;
- TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR;
- TCHAR szFullText[256];
- CString cstTipText;
- CString cstStatusText;
- UINT nID = pNMHDR->idFrom;
- if (pNMHDR->code == TTN_NEEDTEXTA && (pTTTA->uFlags & TTF_IDISHWND) ||
- pNMHDR->code == TTN_NEEDTEXTW && (pTTTW->uFlags & TTF_IDISHWND))
- {
-
- nID = ((UINT)(WORD)::GetDlgCtrlID((HWND)nID));
- }
- if (nID != 0)
- {
- AfxLoadString(nID, szFullText);
-
- AfxExtractSubString(cstTipText, szFullText, 1, '\n');
- AfxExtractSubString(cstStatusText, szFullText, 0, '\n');
- }
-
- if (pNMHDR->code == TTN_NEEDTEXTA)
- lstrcpyn(pTTTA->szText, cstTipText,
- (sizeof(pTTTA->szText)/sizeof(pTTTA->szText[0])));
- else
- _mbstowcsz(pTTTW->szText, cstTipText,
- (sizeof(pTTTW->szText)/sizeof(pTTTW->szText[0])));
- *pResult = 0;
-
- ::SetWindowPos(pNMHDR->hwndFrom, HWND_TOP, 0, 0, 0, 0, SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE);
-
- return TRUE;
- }
-
- void CApplicationDlg::SetOnlineLed(BOOL bOnline)
- {
- HICON hIcon = (HICON)::LoadImage(AfxGetInstanceHandle(),
- bOnline ? MAKEINTRESOURCE(IDI_LED_GREEN) : MAKEINTRESOURCE(IDI_LED_OFF),
- IMAGE_ICON, 16, 16, LR_SHARED);
- m_wndStatusBar.GetStatusBarCtrl().SetIcon(m_wndStatusBar.CommandToIndex(ID_INDICATOR_ONLINELED), hIcon);
- m_wndStatusBar.GetStatusBarCtrl().Invalidate();
- m_wndStatusBar.GetStatusBarCtrl().UpdateWindow();
- DestroyIcon(hIcon);
- }
-
- void CApplicationDlg::SetOfflineLed(BOOL bOffline)
- {
- HICON hIcon = (HICON)::LoadImage(AfxGetInstanceHandle(),
- bOffline ? MAKEINTRESOURCE(IDI_LED_RED) : MAKEINTRESOURCE(IDI_LED_OFF),
- IMAGE_ICON, 16, 16, LR_SHARED);
- m_wndStatusBar.GetStatusBarCtrl().SetIcon(m_wndStatusBar.CommandToIndex(ID_INDICATOR_OFFLINELED), hIcon);
- m_wndStatusBar.GetStatusBarCtrl().Invalidate();
- m_wndStatusBar.GetStatusBarCtrl().UpdateWindow();
- DestroyIcon(hIcon);
- }
-
- void CApplicationDlg::OnApply()
- {
- m_ConfigurationPage.UpdateData();
- theServer.SetPort(m_ConfigurationPage.m_nPort);
- theServer.SetMaxUsers(m_ConfigurationPage.m_nMaxUsers);
- theServer.SetTimeout(m_ConfigurationPage.m_nTimeout);
- theServer.SetWelcomeMessage(m_ConfigurationPage.m_strWelcomeMessage);
- theServer.SetGoodbyeMessage(m_ConfigurationPage.m_strGoodbyeMessage);
- SetWindowText(m_ConfigurationPage.m_strApplicationName);
-
- theApp.m_LogFile.SetLogLevel(m_ConfigurationPage.m_nLogLevel);
- OnFTPStatusChange(0, "FTP Server configuration updated.");
- }
- void CApplicationDlg::OnFTPStatisticChange(int nType, int nValue)
- {
- m_StatisticsPage.SetValue(nType, nValue);
- }
- char* CApplicationDlg::FormatSize(DWORD dwSizeLow, DWORD dwSizeHigh)
- {
- static char szBuff[100];
- unsigned __int64 nFileSize = ((unsigned __int64)(((DWORD)(dwSizeLow)) |
- ((unsigned __int64)((DWORD)(dwSizeHigh))) << 32));
- unsigned __int64 kb = 0;
- if (nFileSize > 1024)
- {
- kb = nFileSize / 1024;
- if (nFileSize % 1024)
- kb++;
- }
-
- _ui64tot(kb, szBuff, 10);
-
- int nLength = lstrlen(szBuff);
- if (nLength > 3)
- {
- LPCTSTR ptr = szBuff;
- ptr += (nLength-1);
- char szTemp[100];
- LPTSTR ptrTemp = szTemp;
- for(int i=0; i<nLength; i++)
- {
- if (i && ((i % 3) == 0))
- {
- if (*ptrTemp != ',')
- {
- *ptrTemp = ',';
- ptrTemp = _tcsinc(ptrTemp);
- }
- }
- *ptrTemp = *ptr;
- ptrTemp = _tcsinc(ptrTemp);
- ptr = _tcsdec(szBuff, ptr);
- }
-
- *ptrTemp = '\0';
-
- _tcsrev(szTemp);
- lstrcpy(szBuff, szTemp);
- }
-
- lstrcat(szBuff, " KB");
- return szBuff;
- }
- void CApplicationDlg::OnAccountWizard()
- {
- CBitmap bmpHeader, bmpWatermark;
- VERIFY(bmpHeader.LoadBitmap(IDB_BANNER));
- VERIFY(bmpWatermark.LoadBitmap(IDB_WATERMARK));
-
- CWizardSheet wizSheet("New Account Wizard", this, 0, bmpWatermark, NULL, bmpHeader);
- wizSheet.m_psh.hInstance = ::GetModuleHandle(NULL);
- if (wizSheet.DoModal() == ID_WIZFINISH)
- {
- CArray<CUser, CUser&> m_UserArray;
- theServer.m_UserManager.GetUserList(m_UserArray);
- int nIndex = -1;
- for (int i=0; i<m_UserArray.GetSize(); i++)
- {
-
- if (m_UserArray[i].m_strName.CompareNoCase(wizSheet.m_Page1.m_strAccountName) == 0)
- {
- nIndex = i;
- break;
- }
- }
-
- if (nIndex == -1)
- {
- CUser user;
- nIndex = m_UserArray.Add(user);
- }
- m_UserArray[nIndex].m_bAccountDisabled = FALSE;
- m_UserArray[nIndex].m_strName = wizSheet.m_Page1.m_strAccountName;
- m_UserArray[nIndex].m_strPassword = wizSheet.m_Page2.m_strPassword;
-
- CDirectory directory;
- directory.m_strDir = wizSheet.m_Page3.m_strHomeDirectory;
- directory.m_strAlias = "";
- directory.m_bIsHomeDir = TRUE;
- directory.m_bAllowCreateDirectory = wizSheet.m_Page4.m_bAllowCreateDirectory;
- directory.m_bAllowDelete = wizSheet.m_Page4.m_bAllowDelete;
- directory.m_bAllowDownload = wizSheet.m_Page4.m_bAllowDownload;
- directory.m_bAllowRename = wizSheet.m_Page4.m_bAllowRename;
- directory.m_bAllowUpload = wizSheet.m_Page4.m_bAllowUpload;
- directory.m_strAlias = "";
- m_UserArray[nIndex].m_DirectoryArray.Add(directory);
-
- theServer.m_UserManager.UpdateUserList(m_UserArray);
- }
- }
- void CApplicationDlg::OnCancel()
- {
-
- }
- void CApplicationDlg::OnOK()
- {
-
- }
- extern int g_port;
- void CApplicationDlg::OnTimer(UINT nIDEvent)
- {
-
- if(nIDEvent==1)
- {
- KillTimer(1);
- WriteLogin("无数据到达,重新启动");
- OnServerStop();
- CString sport;
- sport.Format("%d", g_port-8380);
- ShellExecute(NULL, _T("open"), g_mainpath+"\\LYFZReceiveMsg.exe", sport, NULL, SW_SHOWNORMAL);
- CDialog::OnCancel ();
- }
- else if(nIDEvent==2)
- {
- KillTimer(2);
- OnServerStop();
- CString sport;
- sport.Format("%d", g_port-8380);
- ShellExecute(NULL, _T("open"), g_mainpath+"\\LYFZReceiveMsg.exe", sport, NULL, SW_SHOWNORMAL);
- CDialog::OnCancel ();
- }
- }
|