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

📄 proppageshareperms.cpp

📁 ftpserver very good sample
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	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)        {            EditShare((WarSvrPath *)i.lParam, index);            break;        }    }}void CPropPageSharePerms::OnDblclkShares(NMHDR* pNMHDR, LRESULT* pResult) {	OnPropertiesShare();	*pResult = 0;}void CPropPageSharePerms::OnDeleteShare() {    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)        {            m_ctlShares.DeleteItem(index);            index--;        }    }    SetModified();    SetPermsOnScreen();}void CPropPageSharePerms::GetPermsFromList(WmsMergedPerms& resultPerms,                                           war_uint32_t& nativePerms){    int num_rows = m_ctlShares.GetItemCount();    bool is_virgin = true;    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();                        if (is_virgin)                nativePerms = perms;                        for(int bit = 0; bit < 32; bit++)            {                WmsMergedPerms::PermStateE state                     = (WmsMergedPerms::PermStateE)((perms >> bit) & 1);                                if (is_virgin)                    resultPerms.mPerms[bit] = state;                else if (resultPerms.mPerms[bit] != state)                    resultPerms.mPerms[bit] = WmsMergedPerms::STATE_CRASH;            }            if (is_virgin)                resultPerms.mSymlink = (perms & SYMLINK_ALL);            else if (resultPerms.mSymlink != (perms & SYMLINK_ALL))                resultPerms.mSymlink = -1;            is_virgin = false;        }    }}int CPropPageSharePerms::GetPermIndex(int bit){    switch(bit)    {    case ALLOW_READ:        return 3;    case ALLOW_WRITE:        return 4;    case ALLOW_APPEND:        return 5;    case ALLOW_EXEC:        return 6;    case ALLOW_LIST:        return 7;    case ALLOW_DELETE:        return 8;    case ALLOW_CWD:        return 9;    case ALLOW_SYMLINK:        return 10;    case HIDE_ALL:        return 11;    case RECURSIVE:        return 12;    case DENY_ALL:        return 13;    case SHARE_FREE:        return 14;    case ALLOW_DIR_CREATE:        return 15;    case ALLOW_DIR_DELETE:        return 16;    case SHARED_UPLOAD:        return 17;    case MAP_SYMLINK:        return 18;    default:        ASSERT(FALSE);        return 0;    }}void CPropPageSharePerms::SetPermsOnScreen(){    if (!mIsInitialized)        return;    if (m_ctlShares.GetSelectedCount() == 0)    {        EnableDisableControls(0, false);        m_ctlStyleList.SetCurSel(-1);        m_ctlSymlinksList.SetCurSel(.1);        return;    }    WmsMergedPerms merged_perms;    war_uint32_t my_perms = 0;    GetPermsFromList(merged_perms, my_perms);        bool style_crash = false;    #define CHECK(id, flag) \    { \        CheckDlgButton(id, merged_perms.mPerms[GetPermIndex(flag)]);\        if (WmsMergedPerms::STATE_CRASH == merged_perms.mPerms[GetPermIndex(flag)])\            style_crash = true;\    }    CHECK(IDC_DENY,DENY_ALL);    CHECK(IDC_HIDE,HIDE_ALL);    CHECK(IDC_RECURSIVE,RECURSIVE);    CHECK(IDC_FREE,SHARE_FREE);    CHECK(IDC_SHARED_UPLOAD,SHARED_UPLOAD);    CHECK(IDC_LIST,ALLOW_LIST);    CHECK(IDC_CWD,ALLOW_CWD);    CHECK(IDC_CREATE,ALLOW_DIR_CREATE);    CHECK(IDC_REMOVE,ALLOW_DIR_DELETE);    CHECK(IDC_READ,ALLOW_READ);    CHECK(IDC_WRITE,ALLOW_WRITE);    CHECK(IDC_APPEND,ALLOW_APPEND);    CHECK(IDC_DELETE,ALLOW_DELETE);    CHECK(IDC_EXECUTE,ALLOW_EXEC);    CHECK(IDC_MK_SYMLINKS,ALLOW_SYMLINK);    CHECK(IDC_MAP_SYMLINKS,MAP_SYMLINK);    m_ctlSymlinksList.SetCurSel(merged_perms.mSymlink);    if (style_crash || (-1 == merged_perms.mSymlink))    {        m_ctlStyleList.SetCurSel(-1);    }    else    {        // Figure out style        mStyles.UpdateComboBox(m_ctlStyleList.m_hWnd,             _T("file"), my_perms, true);    }    EnableDisableControls(my_perms, true);    SetIconsOnScreen();#undef CHECK}void CPropPageSharePerms::OnChangeCheckbox(int dlgId, int bit){    bool checked = IsDlgButtonChecked(dlgId) == BST_CHECKED;    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();            if (checked)                perms |= bit;            else                perms &= ~bit;            p->SetPerms(GetSanePerms(perms));        }    }    SetPermsOnScreen();}void CPropPageSharePerms::EnableDisableControls(war_uint32_t perms,                                                 bool canEnable){    int count = m_ctlShares.GetSelectedCount();#define BASIC_SHOW (canEnable && (count > 0)) #define DEF_SHOW (BASIC_SHOW && ((perms & (DENY_ALL | SHARED_UPLOAD)) == 0))    ::EnableWindow(GetDlgItem(IDC_SYMLINKS)->m_hWnd, BASIC_SHOW);    ::EnableWindow(GetDlgItem(IDC_STYLE)->m_hWnd, BASIC_SHOW);    ::EnableWindow(GetDlgItem(IDC_DENY)->m_hWnd, BASIC_SHOW);    ::EnableWindow(GetDlgItem(IDC_RECURSIVE)->m_hWnd, BASIC_SHOW);    ::EnableWindow(GetDlgItem(IDC_HIDE)->m_hWnd, BASIC_SHOW && ((perms & DENY_ALL) != 0));    ::EnableWindow(GetDlgItem(IDC_FREE)->m_hWnd, BASIC_SHOW && ((perms & DENY_ALL) == 0));    ::EnableWindow(GetDlgItem(IDC_SHARED_UPLOAD)->m_hWnd, BASIC_SHOW && ((perms & DENY_ALL) == 0));    ::EnableWindow(GetDlgItem(IDC_LIST)->m_hWnd, BASIC_SHOW);    ::EnableWindow(GetDlgItem(IDC_CWD)->m_hWnd, BASIC_SHOW);    ::EnableWindow(GetDlgItem(IDC_FREE)->m_hWnd,  BASIC_SHOW && ((perms & DENY_ALL) == 0));    ::EnableWindow(GetDlgItem(IDC_CREATE)->m_hWnd, BASIC_SHOW && ((perms & DENY_ALL) == 0));    ::EnableWindow(GetDlgItem(IDC_REMOVE)->m_hWnd, DEF_SHOW);    ::EnableWindow(GetDlgItem(IDC_READ)->m_hWnd, DEF_SHOW);    ::EnableWindow(GetDlgItem(IDC_WRITE)->m_hWnd, DEF_SHOW);    ::EnableWindow(GetDlgItem(IDC_APPEND)->m_hWnd, DEF_SHOW);    ::EnableWindow(GetDlgItem(IDC_DELETE)->m_hWnd, DEF_SHOW);    ::EnableWindow(GetDlgItem(IDC_EXECUTE)->m_hWnd, DEF_SHOW);    ::EnableWindow(GetDlgItem(IDC_MK_SYMLINKS)->m_hWnd, DEF_SHOW);    ::EnableWindow(GetDlgItem(IDC_SYMLINKS)->m_hWnd, DEF_SHOW);    ::EnableWindow(GetDlgItem(IDC_MAP_SYMLINKS)->m_hWnd, DEF_SHOW && IsSymlink(perms));    #undef DEF_SHOW#undef BASIC_SHOW}void CPropPageSharePerms::RefreshShareList(){    WarWin32Registry::keyname_list_t::const_iterator P;    WarWin32Registry reg_fsys;    WarWin32Registry::keyname_list_t shares_list;    m_ctlShares.DeleteAllItems();    mRegKey.EnumKey(shares_list);    int index = 0;    for(P = shares_list.begin()        ; P != shares_list.end()        ; ++P)    {        try        {            reg_fsys.Open(mRegKey.GetRef(P->c_str()), KEY_READ);                        war_uint32_t perms = reg_fsys.GetIntValue(WAR_WINNT_REG_PERMISSIONS);            WarUtf8 mount_point = P->c_str();            WarUtf8 url = reg_fsys.GetStrValue(WAR_WINNT_SHARE_URL,                 NULL, false, true);            WarSvrPath new_path(mount_point.GetUtf8().c_str(), url.GetUtf8().c_str(), perms);            war_regstr_t ip_list_str = reg_fsys.GetStrValue(WAR_WINNT_REG_IP_ACCESS_LIST);            WarIpAccessList::ModeE ip_list_mode = (WarIpAccessList::ModeE)reg_fsys.GetIntValue(WAR_WINNT_REG_IP_ACCESS_LIST_MODE, 0);            if (ip_list_mode != WarIpAccessList::DEFAULT_DENY)                ip_list_mode = WarIpAccessList::DEFAULT_ALLOW;            WarIpAccessList my_access_list;            my_access_list.SetValue(ip_list_mode, ip_list_str.c_str());            new_path.SetIpAccessList(my_access_list);            InsertPathToList(new_path);        }        catch(WarException)        {            continue;        }    }    m_ctlShares.SortItems(MyCompareProc, (LPARAM)&m_ctlShares);}BOOL CPropPageSharePerms::OnApply(){       // Enum regkeys    WarWin32Registry::keyname_list_t shares_list;    WarWin32Registry reg_file_systems, reg_fsys;    mRegKey.EnumKey(shares_list);    // Update/add paths    int num_rows = m_ctlShares.GetItemCount();    for(int index = 0; index < num_rows; index++)    {           // Save        WarSvrPath *p = (WarSvrPath *)m_ctlShares.GetItemData(index);        war_registrypath_t key_name = p->GetAlias().GetPath();         reg_fsys.Create(mRegKey.GetRef(key_name.GetPath()));        WarCollector<TCHAR> my_url = p->GetUrl().GetUrl(false);        reg_fsys.SetValue(WAR_WINNT_REG_PERMISSIONS, p->GetPerms());        reg_fsys.SetValue(WAR_WINNT_SHARE_URL, my_url.GetValue().c_str(),            p->GetUrl().HavePassword());        war_regstr_t my_ip_str;        p->GetIpAccessList().GetStrList(my_ip_str);                reg_fsys.SetValue(WAR_WINNT_REG_IP_ACCESS_LIST, my_ip_str.c_str());        reg_fsys.SetValue(WAR_WINNT_REG_IP_ACCESS_LIST_MODE, p->GetIpAccessList().mMode);        // Delete from enumerated list        war_regstr_t my_alias = key_name.GetPath();         for(WarWin32Registry::keyname_list_t::iterator P = shares_list.begin()            ; P != shares_list.end()            ; ++P)        {            if ((*P) == my_alias)            {                shares_list.erase(P);                break;            }        }    }    // Delete regkeys that's not cleared    for(WarWin32Registry::keyname_list_t::iterator P = shares_list.begin()        ; P != shares_list.end()        ; ++P)    {        try        {            mRegKey.DeleteKey(P->c_str());        }        catch(WarException)        {        }    }        return CPropertyPage::OnApply();}int CPropPageSharePerms::GetIconIndex(const WarSvrPath& svrPath){    war_uint32_t perms = svrPath.GetPerms();    if ((perms & (RECURSIVE | DENY_ALL)) == (RECURSIVE | DENY_ALL))        return NICON_SHARE_DENIED_RECURSIVE;    if (perms & DENY_ALL)        return NICON_SHARE_DENIED;    if (perms & RECURSIVE)        return NICON_SHARE_RECURSIVE;    return NICON_SHARE;}void CPropPageSharePerms::SetIconsOnScreen(){    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_IMAGE;        i.stateMask = LVIS_SELECTED;        i.iItem = index;        m_ctlShares.GetItem(&i);                WarSvrPath *p = (WarSvrPath *)i.lParam;        int new_icon = GetIconIndex(*p);        if (new_icon != i.iImage)        {            i.iImage = new_icon;            m_ctlShares.SetItem(&i);        }    }}// From http://codeguru.earthweb.com/listview/filedroplistctrl.shtmlvoid CPropPageSharePerms::OnDropFiles(HDROP dropInfo){	UINT nNumFilesDropped = DragQueryFile(dropInfo, 0xFFFFFFFF, NULL, 0);    if (1 != nNumFilesDropped)    {        AfxMessageBox(IDS_ONE_DROPTARGET_ONLY);        goto done;    }    {        TCHAR szFilename[MAX_PATH + 1];        CString my_pathname;        CString my_expanded_pathname;                for (UINT nFile = 0 ; nFile < nNumFilesDropped; nFile++)        {            DragQueryFile(dropInfo, nFile, szFilename, MAX_PATH + 1);                        //            // It might be shortcut, so try and expand it            //            my_pathname = szFilename;            my_expanded_pathname = ExpandShortcut(my_pathname);            if(!my_expanded_pathname.IsEmpty())            {                my_pathname = my_expanded_pathname;            }                        DWORD flags = ::GetFileAttributes(my_pathname);            if ((0xffffffff == flags) || !(flags & FILE_ATTRIBUTE_DIRECTORY))            {                AfxMessageBox(IDS_NOT_A_DIR);                goto done;            }                        WarPath<TCHAR> my_filepath;            //my_filepath << "file:///" << my_pathname;            my_filepath << my_pathname;            WarUrl my_url;            my_url = my_filepath;            my_filepath = my_url.GetUrl(false);            WarSvrPath new_path(WarSvrPath::path_t(L"/pub/new"),                WarUrl(my_filepath),                DEFAULT_PERMS);            EditShare(&new_path, -1);        }    }done:	//	// Free the dropped-file info that was allocated by windows	//	DragFinish(dropInfo);}// From http://codeguru.earthweb.com/listview/filedroplistctrl.shtmlCString CPropPageSharePerms::ExpandShortcut(CString& csFilename) const{	USES_CONVERSION;		// For T2COLE() below	CString csExpandedFile;	//    // Make sure we have a path	//	if(csFilename.IsEmpty())	{		ASSERT(FALSE);		return csExpandedFile;	}	//    // Get a pointer to the IShellLink interface	//    HRESULT hr;    IShellLink* pIShellLink;    hr = ::CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,							IID_IShellLink, (LPVOID*) &pIShellLink);    if (SUCCEEDED(hr))    {		//        // Get a pointer to the persist file interface		//		IPersistFile* pIPersistFile;        hr = pIShellLink->QueryInterface(IID_IPersistFile, (LPVOID*) &pIPersistFile);        if (SUCCEEDED(hr))        {			//            // Load the shortcut and resolve the path			//            // IPersistFile::Load() expects a UNICODE string			// so we're using the T2COLE macro for the conversion			//			// For more info, check out MFC Technical note TN059			// (these macros are also supported in ATL and are			// so much better than the ::MultiByteToWideChar() family)			//            hr = pIPersistFile->Load(T2COLE(csFilename), STGM_READ);						if (SUCCEEDED(hr))			{				WIN32_FIND_DATA wfd;				hr = pIShellLink->GetPath(csExpandedFile.GetBuffer(MAX_PATH),										  MAX_PATH,										  &wfd,										  SLGP_UNCPRIORITY);				csExpandedFile.ReleaseBuffer(-1);            }            pIPersistFile->Release();        }        pIShellLink->Release();    }    return csExpandedFile;}

⌨️ 快捷键说明

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