⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 proppageshareperms.cpp

📁 ftpserver very good sample
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// PropPageSharePerms.cpp : implementation file//#include "stdafx.h"#include "warmmcsnapin.h"#include "PropPageSharePerms.h"#include "WarIfAuthModule.h"#include "WarIfServer.h"#include "PropPageShareLocation.h"#include "PropPageIpAccess.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif#define AUTO_BLOCK() WarAutoCounter<int> my_block(mLockedCnt, NULL)/////////////////////////////////////////////////////////////////////////////// CPropPageSharePerms dialogstatic int CALLBACK MyCompareProc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort){   WarSvrPath *left = (WarSvrPath *)lParam1;   WarSvrPath *right = (WarSvrPath *)lParam2;   return left->PathCmp(*right);}CPropPageSharePerms::CPropPageSharePerms(war_if_user_ptr_t& rUserPtr)	: CPropertyPage(CPropPageSharePerms::IDD),    mUserPtr(rUserPtr),    mIsInitialized(false),    mLockedCnt(0){	//{{AFX_DATA_INIT(CPropPageSharePerms)		// NOTE: the ClassWizard will add member initialization here	//}}AFX_DATA_INIT    mStyles.Load(mUserPtr->GetIfAuth().GetSite().GetServer().GetRegKey());    mRegKey.Create(mUserPtr->GetRegKey().GetRef(WAR_WINNT_REG_FILE_SYSTEMS));}CPropPageSharePerms::CPropPageSharePerms(war_if_site_ptr_t& rSitePtr)	: CPropertyPage(CPropPageSharePerms::IDD),    mSitePtr(rSitePtr),    mIsInitialized(false),    mLockedCnt(0){	//{{AFX_DATA_INIT(CPropPageSharePerms)		// NOTE: the ClassWizard will add member initialization here	//}}AFX_DATA_INIT    mStyles.Load(mSitePtr->GetServer().GetRegKey());    mRegKey.Create(mSitePtr->GetRegKey().GetRef(WAR_WINNT_REG_FILE_SYSTEMS));}CPropPageSharePerms::~CPropPageSharePerms(){}void CPropPageSharePerms::DoDataExchange(CDataExchange* pDX){	CPropertyPage::DoDataExchange(pDX);	//{{AFX_DATA_MAP(CPropPageSharePerms)	DDX_Control(pDX, IDC_STYLE, m_ctlStyleList);	DDX_Control(pDX, IDC_SYMLINKS, m_ctlSymlinksList);	DDX_Control(pDX, IDC_SHARES, m_ctlShares);	//}}AFX_DATA_MAP}BEGIN_MESSAGE_MAP(CPropPageSharePerms, CPropertyPage)	//{{AFX_MSG_MAP(CPropPageSharePerms)	ON_NOTIFY(LVN_ITEMCHANGING, IDC_SHARES, OnItemchangingShares)	ON_NOTIFY(LVN_ITEMCHANGED, IDC_SHARES, OnItemchangedShares)	ON_BN_CLICKED(IDC_APPEND, OnAppend)	ON_BN_CLICKED(IDC_CREATE, OnCreate)	ON_BN_CLICKED(IDC_CWD, OnCwd)	ON_BN_CLICKED(IDC_DELETE, OnDelete)	ON_BN_CLICKED(IDC_DENY, OnDeny)	ON_BN_CLICKED(IDC_EXECUTE, OnExecute)	ON_BN_CLICKED(IDC_FREE, OnFree)	ON_BN_CLICKED(IDC_HIDE, OnHide)	ON_BN_CLICKED(IDC_LIST, OnList)	ON_BN_CLICKED(IDC_MAP_SYMLINKS, OnMapSymlinks)	ON_BN_CLICKED(IDC_MK_SYMLINKS, OnMkSymlinks)	ON_BN_CLICKED(IDC_READ, OnRead)	ON_BN_CLICKED(IDC_RECURSIVE, OnRecursive)	ON_BN_CLICKED(IDC_REMOVE, OnRemove)	ON_BN_CLICKED(IDC_SHARED_UPLOAD, OnSharedUpload)	ON_NOTIFY(NM_RCLICK, IDC_SHARES, OnRclickShares)	ON_NOTIFY(NM_DBLCLK, IDC_SHARES, OnDblclkShares)	ON_CBN_SELCHANGE(IDC_STYLE, OnSelchangeStyle)	ON_BN_CLICKED(IDC_WRITE, OnWrite)	ON_CBN_SELCHANGE(IDC_SYMLINKS, OnSelchangeSymlinks)	ON_NOTIFY(LVN_DELETEITEM, IDC_SHARES, OnDeleteitemShares)	ON_COMMAND(ID_NEW_SHARE, OnNewShare)	ON_COMMAND(ID_PROPERTIES_SHARE, OnPropertiesShare)	ON_COMMAND(ID_DELETE_SHARE, OnDeleteShare)	//}}AFX_MSG_MAP    ON_WM_DROPFILES()END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////// CPropPageSharePerms message handlersBOOL CPropPageSharePerms::OnInitDialog() {	CPropertyPage::OnInitDialog();    CString name;    name.LoadString(IDS_SHARE_MOUNTPOINT);    m_ctlShares.InsertColumn(0, name, LVCFMT_LEFT, 150);    name.LoadString(IDS_SHARE_URL);    m_ctlShares.InsertColumn(1, name, LVCFMT_LEFT, 200);	    m_ctlShares.SetExtendedStyle(        m_ctlShares.GetExtendedStyle() | LVS_EX_FULLROWSELECT);    mImageList.Create(IDR_SMICONS, 16, 0, RGB(0, 128, 128));    m_ctlShares.SetImageList(&mImageList, LVSIL_SMALL);    RefreshShareList();    mIsInitialized = true;	SetPermsOnScreen();		return TRUE;  // return TRUE unless you set the focus to a control	              // EXCEPTION: OCX Property Pages should return FALSE}void CPropPageSharePerms::OnItemchangingShares(NMHDR* pNMHDR, LRESULT* pResult) {	NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;		*pResult = 0;}void CPropPageSharePerms::OnItemchangedShares(NMHDR* pNMHDR, LRESULT* pResult) {	NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;    if (!mLockedCnt)        SetPermsOnScreen();		*pResult = 0;}void CPropPageSharePerms::OnAppend() {    SetModified();    OnChangeCheckbox(IDC_APPEND, ALLOW_APPEND);}void CPropPageSharePerms::OnCreate() {    SetModified();	OnChangeCheckbox(IDC_CREATE, ALLOW_DIR_CREATE);}void CPropPageSharePerms::OnCwd() {    SetModified();    OnChangeCheckbox(IDC_CWD, ALLOW_CWD);}void CPropPageSharePerms::OnDelete() {    SetModified();	OnChangeCheckbox(IDC_DELETE, ALLOW_DELETE);}void CPropPageSharePerms::OnDeny() {    SetModified();	OnChangeCheckbox(IDC_DENY, DENY_ALL);}void CPropPageSharePerms::OnExecute() {    SetModified();	OnChangeCheckbox(IDC_EXECUTE, ALLOW_EXEC);}void CPropPageSharePerms::OnFree() {	SetModified();	OnChangeCheckbox(IDC_FREE, SHARE_FREE);}void CPropPageSharePerms::OnHide() {    SetModified();	OnChangeCheckbox(IDC_HIDE, HIDE_ALL);}void CPropPageSharePerms::OnList() {    SetModified();	OnChangeCheckbox(IDC_LIST, ALLOW_LIST);}void CPropPageSharePerms::OnMapSymlinks() {    SetModified();	OnChangeCheckbox(IDC_MAP_SYMLINKS, MAP_SYMLINK);}void CPropPageSharePerms::OnMkSymlinks() {    SetModified();	OnChangeCheckbox(IDC_MK_SYMLINKS, ALLOW_SYMLINK);}void CPropPageSharePerms::OnRead() {    SetModified();	OnChangeCheckbox(IDC_READ, ALLOW_READ);}void CPropPageSharePerms::OnRecursive() {    SetModified();	OnChangeCheckbox(IDC_RECURSIVE, RECURSIVE);}void CPropPageSharePerms::OnRemove() {    SetModified();	OnChangeCheckbox(IDC_REMOVE, ALLOW_DIR_DELETE);}void CPropPageSharePerms::OnSharedUpload() {    SetModified();	OnChangeCheckbox(IDC_SHARED_UPLOAD, SHARED_UPLOAD);}void CPropPageSharePerms::OnWrite() {    SetModified();	OnChangeCheckbox(IDC_WRITE, ALLOW_WRITE);}void CPropPageSharePerms::OnSelchangeSymlinks() {    SetModified();        int num_rows = m_ctlShares.GetItemCount();    for(int index = 0; index < num_rows; index++)    {        LVITEM i;        memset(&i, 0, sizeof(i));        i.mask = LVIF_PARAM | LVIF_STATE;        i.stateMask = LVIS_SELECTED;        i.iItem = index;        m_ctlShares.GetItem(&i);                if (i.state & LVIS_SELECTED)        {            WarSvrPath *p = (WarSvrPath *)i.lParam;            war_uint32_t perms = p->GetPerms();            perms &= ~SYMLINK_ALL;            int sym_index = m_ctlSymlinksList.GetCurSel();            if (0 <= sym_index)            {                perms |= (sym_index & SYMLINK_ALL);                p->SetPerms(perms);            }        }    }    SetPermsOnScreen();}void CPropPageSharePerms::OnRclickShares(NMHDR* pNMHDR, LRESULT* pResult) {    AUTO_BLOCK();	CPoint pos, client_pos;	GetCursorPos(&pos);	client_pos = pos;	UINT flags = 0;	m_ctlShares.ScreenToClient(&client_pos);	int targeted_item = m_ctlShares.HitTest(client_pos, &flags);    CMenu MenuT, *Menu;    MenuT.LoadMenu(IDR_POPUP_SHARES);     Menu = MenuT.GetSubMenu(0);        if (targeted_item >= 0)    {        LVITEM i;        memset(&i, 0, sizeof(i));        i.mask = LVIF_PARAM | LVIF_STATE | LVIF_TEXT | LVIF_IMAGE;        i.iItem = targeted_item;        m_ctlShares.GetItem(&i);        if (i.state & LVIS_SELECTED)        {        }        else         {            // Unselect all and select the item            POSITION pos = m_ctlShares.GetFirstSelectedItemPosition();            while(pos)            {                LVITEM ii;                memset(&ii, 0, sizeof(ii));                ii.iItem = m_ctlShares.GetNextSelectedItem(pos);                ii.mask = LVIF_STATE;                m_ctlShares.GetItem(&ii);                ii.state &= ~LVIS_SELECTED;                m_ctlShares.SetItem(&ii);            }            i.mask = LVIF_STATE;            i.state |= LVIS_SELECTED | LVIS_FOCUSED;            m_ctlShares.SetItem(&i);        }        int num_selected = m_ctlShares.GetSelectedCount();                // Enable available options        Menu->EnableMenuItem(ID_DELETE_SHARE, MF_ENABLED);        if (1 == num_selected)            Menu->EnableMenuItem(ID_PROPERTIES_SHARE, MF_ENABLED);    }        Menu->TrackPopupMenu(TPM_RIGHTBUTTON | TPM_LEFTALIGN, pos.x, pos.y, this);    Menu->DestroyMenu();    	*pResult = 0;}void CPropPageSharePerms::OnSelchangeStyle() {    try    {        int index = SendDlgItemMessage(IDC_STYLE, CB_GETCURSEL, 0, 0);        if (index != CB_ERR)        {            war_uint32_t perms = SendDlgItemMessage(IDC_STYLE, CB_GETITEMDATA, index, 0);            int num_rows = m_ctlShares.GetItemCount();            for(int index = 0; index < num_rows; index++)            {                LVITEM i;                memset(&i, 0, sizeof(i));                i.mask = LVIF_PARAM | LVIF_STATE;                i.stateMask = LVIS_SELECTED;                i.iItem = index;                m_ctlShares.GetItem(&i);                                if (i.state & LVIS_SELECTED)                {                    WarSvrPath *p = (WarSvrPath *)i.lParam;                    p->SetPerms(perms);                }            }        }    }    catch(WarException)    {    }    SetModified();    SetPermsOnScreen();}BOOL CPropPageSharePerms::OnSetActive(){    ::PostMessage(GetParent()->m_hWnd, PSM_SETWIZBUTTONS, 0, PSWIZB_FINISH | PSWIZB_BACK);    return TRUE;}BOOL CPropPageSharePerms::OnWizardFinish(){    return OnApply();}void CPropPageSharePerms::OnDeleteitemShares(NMHDR* pNMHDR, LRESULT* pResult) {	NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;    WarSvrPath *p = (WarSvrPath *)m_ctlShares.GetItemData(        pNMListView->iItem);    if (p)        delete p;    	*pResult = 0;}void CPropPageSharePerms::OnNewShare(){    EditShare(NULL, -1);}void CPropPageSharePerms::EditShare(WarSvrPath *pPath, int itemIndex) {    AUTO_BLOCK();    war_regstr_t ip_list_str;    CPropertySheet my_sheet;    CPropPageShareLocation my_url_dlg;    CPropPageIpAccess my_ip_dlg;    my_sheet.AddPage(&my_url_dlg);    my_sheet.AddPage(&my_ip_dlg);    if (pPath)    {        my_ip_dlg.m_Mode = pPath->GetIpAccessList().mMode;        pPath->GetIpAccessList().GetStrList(ip_list_str);    }    if (!ip_list_str.empty())        my_ip_dlg.mIpList = ip_list_str.c_str();    CString title;    title.LoadString(IDS_PROPERTIES);    my_sheet.SetTitle(title);    my_sheet.m_psh.dwFlags |= PSH_NOAPPLYNOW;    if (pPath)        my_url_dlg.mPath = *pPath;again:    if (my_sheet.DoModal() == IDOK)    {        SetModified();        // See if the path (alias) exist        for(int index = 0; index < m_ctlShares.GetItemCount(); index++)        {            WarSvrPath *p = (WarSvrPath *)m_ctlShares.GetItemData(index);            if ((*p == my_url_dlg.mPath) && (p != pPath))            {                if (AfxMessageBox(IDS_MOUNT_POINT_EXIST, MB_RETRYCANCEL) == IDRETRY)                    goto again;            }        }        if (pPath && (0 <= itemIndex))        {            WarUtf8 alias = my_url_dlg.mPath.GetAlias().GetPath();            WarUtf8 url = my_url_dlg.mPath.GetUrl().GetUrl();            m_ctlShares.SetItemText(itemIndex, 0, alias.GetSysStr().c_str());            m_ctlShares.SetItemText(itemIndex, 1, url.GetSysStr().c_str());            my_url_dlg.mPath.SetPerms(pPath->GetPerms());            *pPath = my_url_dlg.mPath;            WarIpAccessList my_access_list;            my_access_list.SetValue(                (WarIpAccessList::DEFAULT_DENY == my_ip_dlg.m_Mode)                ? WarIpAccessList::DEFAULT_DENY                : WarIpAccessList::DEFAULT_ALLOW,                (LPCTSTR)my_ip_dlg.mIpList);            pPath->SetIpAccessList(my_access_list);        }        else        {            my_url_dlg.mPath.SetPerms(DEFAULT_PERMS);            InsertPathToList(my_url_dlg.mPath);        }        m_ctlShares.SortItems(MyCompareProc, (LPARAM)&m_ctlShares);        // Select the path and unselect anything else        for(index = 0; index < m_ctlShares.GetItemCount(); index++)        {            LVITEM i;            memset(&i, 0, sizeof(i));            i.mask = LVIF_STATE | LVIF_PARAM;            i.iItem = index;            m_ctlShares.GetItem(&i);            WarSvrPath *p = (WarSvrPath *)i.lParam;            i.state = LVIS_SELECTED;            i.stateMask = (*p == my_url_dlg.mPath) ? LVIS_SELECTED : 0;            m_ctlShares.SetItem(&i);        }        SetPermsOnScreen();    }}void CPropPageSharePerms::InsertPathToList(const WarSvrPath& newPath){    AUTO_BLOCK();    WarSvrPath *new_path = new WarSvrPath(newPath);        // Add the path    int new_index = m_ctlShares.InsertItem(        LVIF_IMAGE | LVIF_PARAM | LVIF_TEXT,        0,#ifdef UNICODE        (LPTSTR)new_path->GetAlias().GetPath(),#else        (LPTSTR)mount_point.GetUtf8().c_str(),#endif        0,        0,        GetIconIndex(newPath),        (LPARAM)new_path);        WarCollector<TCHAR> mt_url_str = new_path->GetUrl().GetUrl();    m_ctlShares.SetItemText(new_index, 1, mt_url_str.GetValue().c_str());}void CPropPageSharePerms::OnPropertiesShare() {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -