当前位置: 首页>>代码示例>>C++>>正文


C++ CCachedDirectory::LoadFromDisk方法代码示例

本文整理汇总了C++中CCachedDirectory::LoadFromDisk方法的典型用法代码示例。如果您正苦于以下问题:C++ CCachedDirectory::LoadFromDisk方法的具体用法?C++ CCachedDirectory::LoadFromDisk怎么用?C++ CCachedDirectory::LoadFromDisk使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CCachedDirectory的用法示例。


在下文中一共展示了CCachedDirectory::LoadFromDisk方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Create

void CGitStatusCache::Create()
{
    ATLASSERT(m_pInstance == NULL);
    m_pInstance = new CGitStatusCache;

    m_pInstance->watcher.SetFolderCrawler(&m_pInstance->m_folderCrawler);
#define LOADVALUEFROMFILE(x) if (fread(&x, sizeof(x), 1, pFile)!=1) goto exit;
#define LOADVALUEFROMFILE2(x) if (fread(&x, sizeof(x), 1, pFile)!=1) goto error;
    unsigned int value = (unsigned int)-1;
    FILE * pFile = NULL;
    // find the location of the cache
    TCHAR path[MAX_PATH];		//MAX_PATH ok here.
    TCHAR path2[MAX_PATH];
    if (SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, path)==S_OK)
    {
        _tcscat_s(path, MAX_PATH, _T("\\TGitCache"));
        if (!PathIsDirectory(path))
        {
            if (CreateDirectory(path, NULL)==0)
                goto error;
        }
        _tcscat_s(path, MAX_PATH, _T("\\cache"));
        // in case the cache file is corrupt, we could crash while
        // reading it! To prevent crashing every time once that happens,
        // we make a copy of the cache file and use that copy to read from.
        // if that copy is corrupt, the original file won't exist anymore
        // and the second time we start up and try to read the file,
        // it's not there anymore and we start from scratch without a crash.
        _tcscpy_s(path2, MAX_PATH, path);
        _tcscat_s(path2, MAX_PATH, _T("2"));
        DeleteFile(path2);
        CopyFile(path, path2, FALSE);
        DeleteFile(path);
        pFile = _tfsopen(path2, _T("rb"), _SH_DENYNO);
        if (pFile)
        {
            try
            {
                LOADVALUEFROMFILE(value);
                if (value != 2)
                {
                    goto error;
                }
                int mapsize = 0;
                LOADVALUEFROMFILE(mapsize);
                for (int i=0; i<mapsize; ++i)
                {
                    LOADVALUEFROMFILE2(value);
                    if (value > MAX_PATH)
                        goto error;
                    if (value)
                    {
                        CString sKey;
                        if (fread(sKey.GetBuffer(value+1), sizeof(TCHAR), value, pFile)!=value)
                        {
                            sKey.ReleaseBuffer(0);
                            goto error;
                        }
                        sKey.ReleaseBuffer(value);
                        CCachedDirectory * cacheddir = new CCachedDirectory();
                        if (cacheddir == NULL)
                            goto error;
                        if (!cacheddir->LoadFromDisk(pFile))
                            goto error;
                        CTGitPath KeyPath = CTGitPath(sKey);
                        if (m_pInstance->IsPathAllowed(KeyPath))
                        {
                            m_pInstance->m_directoryCache[KeyPath] = cacheddir;
                            // only add the path to the watch list if it is versioned
                            if ((cacheddir->GetCurrentFullStatus() != git_wc_status_unversioned)&&(cacheddir->GetCurrentFullStatus() != git_wc_status_none))
                                m_pInstance->watcher.AddPath(KeyPath, false);
                            // do *not* add the paths for crawling!
                            // because crawled paths will trigger a shell
                            // notification, which makes the desktop flash constantly
                            // until the whole first time crawling is over
                            // m_pInstance->AddFolderForCrawling(KeyPath);
                        }
                    }
                }
            }
            catch (CAtlException)
            {
                goto error;
            }
        }
    }
exit:
    if (pFile)
        fclose(pFile);
    DeleteFile(path2);
    m_pInstance->watcher.ClearInfoMap();
    ATLTRACE("cache loaded from disk successfully!\n");
    return;
error:
    if (pFile)
        fclose(pFile);
    DeleteFile(path2);
    m_pInstance->watcher.ClearInfoMap();
    Destroy();
    m_pInstance = new CGitStatusCache;
//.........这里部分代码省略.........
开发者ID:hfeeki,项目名称:TortoiseGit,代码行数:101,代码来源:GITStatusCache.cpp


注:本文中的CCachedDirectory::LoadFromDisk方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。