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

📄 view.cpp

📁 很好用的ftp源码
💻 CPP
📖 第 1 页 / 共 4 页
字号:

        // I don't care about resizing to zero.
        // I don't think the user will ever need it and it casues
        // bug #198695 where the addressband goes blank.  This is because
        // defview will call us thru each of the two places:
        // 1) CFtpFolder::CreateViewObject() (Old URL)
        // 2) CDefView::CreateViewWindow2()->CFtpView::_OnSize() (Old URL)
        // 3) DV_UpdateStatusBar()->CFtpView::_OnUpdateStatusBar() (New URL)
        // 4) ReleaseWindowLV()->WndSize()->CFtpView::_OnSize() (Old URL)
        // #4 makes us update the URL and replace #3 which is valid.
    }
    
    return hr;
}


/*****************************************************************************\
    FUNCTION: _OnThisIDList

    DESCRIPTION:
\*****************************************************************************/
HRESULT CFtpView::_OnThisIDList(LPITEMIDLIST * ppidl)
{
    HRESULT hr = S_FALSE;

    if (EVAL(ppidl))
    {
        *ppidl = ILClone(m_pff->GetPublicRootPidlReference());
        hr = S_OK;
    }

    return hr;
}


/*****************************************************************************\
    FUNCTION: _OnUpdateStatusBar

    DESCRIPTION:
\*****************************************************************************/
HRESULT CFtpView::_OnUpdateStatusBar(void)
{
    HRESULT hr = S_FALSE;
    LPCITEMIDLIST pidl = m_pff->GetPrivatePidlReference();

    if (EVAL(pidl))
    {
        TCHAR szUserName[INTERNET_MAX_USER_NAME_LENGTH];
        BOOL fAnnonymousLogin = TRUE;

        hr = FtpPidl_GetUserName(pidl, szUserName, ARRAYSIZE(szUserName));
        if (SUCCEEDED(hr) && szUserName[0])
            fAnnonymousLogin = FALSE;

        if (m_psb)
        {
            // Even if the above call fails, we set the user name to clear out
            // any old invalid values.
            m_psb->SetUserName(szUserName, fAnnonymousLogin);
        }

        EVAL(SUCCEEDED(_SetStatusBarZone(m_psb, m_pff->m_pfs)));
    }

    return hr;
}


/*****************************************************************************\
    FUNCTION: SetRedirectPidl

    DESCRIPTION:
        See the comments in _OnBackGroundEnumDone().
\*****************************************************************************/
HRESULT CFtpView::SetRedirectPidl(LPCITEMIDLIST pidlRedirect)
{
    ENTERCRITICAL;
    Pidl_Set(&m_pidlRedirect, pidlRedirect);
    LEAVECRITICAL;
    return S_OK;
}


/*****************************************************************************\
    FUNCTION: DummyHintCallback

    DESCRIPTION:
        Doesn't do anything; simply forces the connection to be established
    and the motd to be obtained.
\*****************************************************************************/
HRESULT CFtpView::DummyHintCallback(HWND hwnd, CFtpFolder * pff, HINTERNET hint, LPVOID pv1, LPVOID pv2)
{
    return S_OK;
}


/*****************************************************************************\
    FUNCTION: _InitStatusBar

    DESCRIPTION:
        Obtains and initializes the status bar window.
    It is not an error if the viewer does not provide a status bar.
\*****************************************************************************/
void CFtpView::_InitStatusBar(void)
{
    if (m_psb)
        m_psb->SetStatusMessage(IDS_EMPTY, 0);
}


/*****************************************************************************\
    FUNCTION: _OnWindowCreated (from shell32.IShellView)

    DESCRIPTION:
        When the window is created, we get the motd.  Very soon thereafter,
    DefView is going to ask for the IEnumIDList, which will now be
    in the cache.  (GROSS!  Screws up background enumeration!)

    Do this only if we don't already have a motd.
\*****************************************************************************/
HRESULT CFtpView::_OnWindowCreated(void)
{
    HRESULT hr = S_FALSE;

#ifdef _SOMEDAY_FIGURE_OUT_MOTD
/** Currently Turned off
    CFtpDir * pfd = m_pff->GetFtpDir();

    if (EVAL(pfd))
    {
        if (!CFtpDir_IsRoot(pfd))
        {
            CFtpSite * pfs = pfd->GetFtpSite();

            ASSERT(pfs);
            if (!pfs->QueryMotd())
            {
#ifdef HACKHACK_WHAT_THE_HELL       // Gotta clean this
                // This forcdes a connexn to see if there is a motd
                pfd->WithHint(&m_psb, hwndOwner, DummyHintCallback, NULL);
#endif
            }
            if (pfs->QueryNewMotd())
            {
                //  If we can't set the timeout, tough.  All that
                //  happens is you don't get to see the motd.  Boo hoo.
#pragma message("BUGBUG -- This is busted!")
                SetDelayedAction(ShowMotd, pfv, &pfv->m_hgtiWelcome);
            }
            hr = S_FALSE;
        }
        pfd->Release();
    }
***/
#endif /* SOMEDAY_FIGURE_OUT_MOTD */

    return hr;
}


/*****************************************************************************\
    FUNCTION: _OnDefItemCount (from shell32.IShellView)

    DESCRIPTION:
        _UNDOCUMENTED_: This callback and its parameters are not documented.

    Called to advise the browser of how many items we might have.  This
    allows preliminary UI to appear while we are busy enumerating
    the contents.
\*****************************************************************************/
HRESULT CFtpView::_OnDefItemCount(LPINT pi)
{
    *pi = 20;
    return S_OK;
}


/*****************************************************************************\
    FUNCTION: _OnDidDragDrop

    DESCRIPTION:
        Called to advise the browser that somebody did a drag/drop operation
    on objects in the folder.  If the effect was DROPEFFECT_MOVE, then
    we delete the source, if we aren't still doing the copy asynch on a
    background thread.

    RETURN VALUES:
        S_OK: We take responsibility of deleting the files which we can
              do here in the synch case, or in IAsynchOperation::EndOperation()
              in the asynch case.
        S_FALSE: We didn't do the delete but it's OK for the caller to do it.
                 so the caller needs to display UI and then delete via
                 IContextMenu->InvokeCommand(-delete-).
\*****************************************************************************/
HRESULT CFtpView::_OnDidDragDrop(DROPEFFECT de, IDataObject * pdo)
{
    HRESULT hr = S_OK;

    if (DROPEFFECT_MOVE == de)
    {
        IAsyncOperation * pao;

        hr = pdo->QueryInterface(IID_IAsyncOperation, (void **) &pao);
        if (SUCCEEDED(hr))
        {
            BOOL fInAsyncOp = TRUE;

            hr = pao->InOperation(&fInAsyncOp);
            hr = S_OK;  // Don't have caller do the delete.
            if (FALSE == fInAsyncOp)
            {
#ifdef FEATURE_CUT_MOVE
                CLSID clsid;
                BOOL fDoDelete = TRUE;
                CFtpObj * pfo = (CFtpObj *) pdo;

                // Is the destination the recycle bin?
                if (SUCCEEDED(DataObj_GetDropTarget(pdo, &clsid)) &&
                    IsEqualCLSID(clsid, CLSID_RecycleBin))
                {
                    // Yes, so we need to first inform the user that drops to the
                    // Recycle bin are perminate deletes and the user can't undo
                    // the operation.
                    if (IDYES != SHMessageBox(m_hwndOwner, NULL, IDS_RECYCLE_IS_PERM_WARNING, IDS_FTPERR_TITLE, (MB_ICONQUESTION | MB_YESNO)))
                        fDoDelete = FALSE;
                }

                // We didn't do the operation aynch so we need to DELETE the
                // files now to complete the MOVE operation (MOVE=Copy + Delete).
                if (fDoDelete)
                {
                    Misc_DeleteHfpl(m_pff, m_hwndOwner, pfo->GetHfpl());    // Will fail on permission denied.
                }

#else // FEATURE_CUT_MOVE
                hr = S_FALSE;   // Have parent do the delete.
#endif //FEATURE_CUT_MOVE
            }

            pao->Release();
        }
        else
            hr = S_OK;  // Don't have caller delete.  IAsyncOperation::EndOperation() will.
    }

    return hr;
}



//===========================
// *** IFtpWebView Interface ***
//===========================

/*****************************************************************************\
    FUNCTION: IFtpWebView::get_MessageOfTheDay

    DESCRIPTION:
\*****************************************************************************/
HRESULT CFtpView::get_MessageOfTheDay(BSTR * pbstr)
{
    HRESULT hr = S_FALSE;

    if (EVAL(pbstr))
    {
        *pbstr = NULL;

        if (EVAL(m_pff))
        {
            TCHAR szDefault[MAX_PATH];
            LPCTSTR pszMOTD = szDefault;
            CFtpGlob * pfg = m_pff->GetSiteMotd();

            szDefault[0] = 0;
            if (pfg)
                pszMOTD = pfg->GetHGlobAsTCHAR();

            // if we were not able to get the message of the day
            // from CFtpFolder or it was empty, display "None"
            if ((pszMOTD == szDefault) || (!pszMOTD[0]))
            {
                pszMOTD = szDefault;
                LoadString(HINST_THISDLL, IDS_NO_MESSAGEOFTHEDAY, szDefault, ARRAYSIZE(szDefault));
            }

            *pbstr = TCharSysAllocString(pszMOTD);

            if (pfg)
                pfg->Release();

            hr = S_OK;
        }
    }
    else
        hr = E_INVALIDARG;

    ASSERT_POINTER_MATCHES_HRESULT(*pbstr, hr);
    return hr;
}


/*****************************************************************************\
    FUNCTION: IFtpWebView::get_Server

    DESCRIPTION:
\*****************************************************************************/
HRESULT CFtpView::get_Server(BSTR * pbstr)
{
    HRESULT hr = S_FALSE;

    if (EVAL(pbstr))
    {
        *pbstr = NULL;

        if (EVAL(m_pff))
        {
            TCHAR szServer[INTERNET_MAX_HOST_NAME_LENGTH];

            if (SUCCEEDED(FtpPidl_GetServer(m_pff->GetPrivatePidlReference(), szServer, ARRAYSIZE(szServer))))
            {
                *pbstr = TCharSysAllocString(szServer);
                if (*pbstr)
                    hr = S_OK;
            }
        }
    }
    else
        hr = E_INVALIDARG;

//    ASSERT_POINTER_MATCHES_HRESULT(*pbstr, hr);
    return hr;
}


/*****************************************************************************\
    FUNCTION: IFtpWebView::get_Directory

    DESCRIPTION:
\*****************************************************************************/
HRESULT CFtpView::get_Directory(BSTR * pbstr)
{
    HRESULT hr = S_FALSE;

    if (EVAL(pbstr))
    {
        *pbstr = NULL;

        if (EVAL(m_pff))
        {
            TCHAR szUrlPath[INTERNET_MAX_PATH_LENGTH];

            if (EVAL(SUCCEEDED(GetDisplayPathFromPidl(m_pff->GetPrivatePidlReference(), szUrlPath, ARRAYSIZE(szUrlPath), FALSE))))
            {
                *pbstr = TCharSysAllocString(szUrlPath);
                if (*pbstr)
                    hr = S_OK;
            }
        }
    }
    else
        hr = E_INVALIDARG;

    ASSERT_POINTER_MATCHES_HRESULT(*pbstr, hr);
    return hr;
}


/*****************************************************************************\
    FUNCTION: IFtpWebView::get_UserName

    DESCRIPTION:
\*****************************************************************************/
HRESULT CFtpView::get_UserName(BSTR * pbstr)
{
    HRESULT hr = S_FALSE;

    if (EVAL(pbstr))
    {
        *pbstr = NULL;

        if (EVAL(m_pff))
        {
            TCHAR szUserName[INTERNET_MAX_USER_NAME_LENGTH];

⌨️ 快捷键说明

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