bool CSVNStatusCache::SaveCache() { #define WRITEVALUETOFILE(x) if (fwrite(&x, sizeof(x), 1, pFile)!=1) goto error; unsigned int value = 0; // save the cache to disk FILE * pFile = NULL; // find a location to write the cache to TCHAR path[MAX_PATH]; //MAX_PATH ok here. if (SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, path)==S_OK) { _tcscat_s(path, MAX_PATH, _T("\\TSVNCache")); if (!PathIsDirectory(path)) CreateDirectory(path, NULL); _tcscat_s(path, MAX_PATH, STATUSCACHEFILENAME); _tfopen_s(&pFile, path, _T("wb")); if (pFile) { value = CACHEDISKVERSION; // 'version' WRITEVALUETOFILE(value); value = (int)m_pInstance->m_directoryCache.size(); WRITEVALUETOFILE(value); for (CCachedDirectory::CachedDirMap::iterator I = m_pInstance->m_directoryCache.begin(); I != m_pInstance->m_directoryCache.end(); ++I) { if (I->second == NULL) { value = 0; WRITEVALUETOFILE(value); continue; } const CString& key = I->first.GetWinPathString(); value = key.GetLength(); WRITEVALUETOFILE(value); if (value) { if (fwrite((LPCTSTR)key, sizeof(TCHAR), value, pFile)!=value) goto error; if (!I->second->SaveToDisk(pFile)) goto error; } } fclose(pFile); } } ATLTRACE(_T("cache saved to disk at %s\n"), path); return true; error: fclose(pFile); if (m_pInstance) { m_pInstance->Stop(); Sleep(100); } delete m_pInstance; m_pInstance = NULL; DeleteFile(path); return false; }
bool CSVNStatusCache::SaveCache() { #define WRITEVALUETOFILE(x) if (fwrite(&x, sizeof(x), 1, pFile)!=1) goto error; unsigned int value = 0; // save the cache to disk FILE * pFile = NULL; // find a location to write the cache to CString path = GetSpecialFolder(FOLDERID_LocalAppData); if (!path.IsEmpty()) { path += L"\\TSVNCache"; if (!PathIsDirectory(path)) CreateDirectory(path, NULL); path += STATUSCACHEFILENAME; _tfopen_s(&pFile, path, L"wb"); if (pFile) { value = CACHEDISKVERSION; // 'version' WRITEVALUETOFILE(value); value = (int)m_pInstance->m_directoryCache.size(); WRITEVALUETOFILE(value); for (CCachedDirectory::CachedDirMap::iterator I = m_pInstance->m_directoryCache.begin(); I != m_pInstance->m_directoryCache.end(); ++I) { if (I->second == NULL) { value = 0; WRITEVALUETOFILE(value); continue; } const CString& key = I->first.GetWinPathString(); value = key.GetLength(); WRITEVALUETOFILE(value); if (value) { if (fwrite((LPCTSTR)key, sizeof(TCHAR), value, pFile)!=value) goto error; if (!I->second->SaveToDisk(pFile)) goto error; } } fclose(pFile); } } CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": cache saved to disk at %s\n", path); return true; error: fclose(pFile); Destroy(); DeleteFile(path); return false; }
BOOL CCachedDirectory::SaveToDisk(FILE * pFile) { AutoLocker lock(m_critSec); #define WRITEVALUETOFILE(x) if (fwrite(&x, sizeof(x), 1, pFile)!=1) return false; unsigned int value = CACHEDIRECTORYDISKVERSION; WRITEVALUETOFILE(value); // 'version' of this save-format value = (int)m_entryCache.size(); WRITEVALUETOFILE(value); // size of the cache map // now iterate through the maps and save every entry. for (CacheEntryMap::iterator I = m_entryCache.begin(); I != m_entryCache.end(); ++I) { const CStringA& key = I->first; value = key.GetLength(); WRITEVALUETOFILE(value); if (value) { if (fwrite((LPCSTR)key, sizeof(char), value, pFile)!=value) return false; if (!I->second.SaveToDisk(pFile)) return false; } } value = (int)m_childDirectories.size(); WRITEVALUETOFILE(value); for (ChildDirStatus::iterator I = m_childDirectories.begin(); I != m_childDirectories.end(); ++I) { value = I->first.GetLength(); WRITEVALUETOFILE(value); if (value) { if (fwrite((LPCSTR)I->first, sizeof(char), value, pFile)!=value) return false; svn_wc_status_kind status = I->second; WRITEVALUETOFILE(status); } } WRITEVALUETOFILE(m_wcDbFileTime); value = m_directoryPath.GetWinPathString().GetLength(); WRITEVALUETOFILE(value); if (value) { if (fwrite(m_directoryPath.GetWinPath(), sizeof(TCHAR), value, pFile)!=value) return false; } if (!m_ownStatus.SaveToDisk(pFile)) return false; WRITEVALUETOFILE(m_currentFullStatus); WRITEVALUETOFILE(m_mostImportantFileStatus); return true; }
bool CGitStatusCache::SaveCache() { if (!CRegStdDWORD(_T("Software\\TortoiseGit\\CacheSave"), TRUE)) return false; #define WRITEVALUETOFILE(x) if (fwrite(&x, sizeof(x), 1, pFile)!=1) goto error; unsigned int value = 0; // save the cache to disk FILE * pFile = NULL; // find a location to write the cache to CString path = CPathUtils::GetLocalAppDataDirectory(); if (!path.IsEmpty()) { path += STATUSCACHEFILENAME; _tfopen_s(&pFile, path, _T("wb")); if (pFile) { value = CACHEDISKVERSION; WRITEVALUETOFILE(value); value = (int)m_pInstance->m_directoryCache.size(); WRITEVALUETOFILE(value); for (CCachedDirectory::CachedDirMap::iterator I = m_pInstance->m_directoryCache.begin(); I != m_pInstance->m_directoryCache.end(); ++I) { if (I->second == NULL) { value = 0; WRITEVALUETOFILE(value); continue; } const CString& key = I->first.GetWinPathString(); value = key.GetLength(); WRITEVALUETOFILE(value); if (value) { if (fwrite((LPCTSTR)key, sizeof(TCHAR), value, pFile)!=value) goto error; if (!I->second->SaveToDisk(pFile)) goto error; } } fclose(pFile); } } CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) _T(": cache saved to disk at %s\n"), path); return true; error: fclose(pFile); Destroy(); DeleteFile(path); return false; }
BOOL CCachedDirectory::SaveToDisk(FILE * pFile) { AutoLocker lock(m_critSec); #define WRITEVALUETOFILE(x) if (fwrite(&x, sizeof(x), 1, pFile)!=1) return false; unsigned int value = GIT_CACHE_VERSION; WRITEVALUETOFILE(value); // 'version' of this save-format value = (int)m_entryCache.size(); WRITEVALUETOFILE(value); // size of the cache map // now iterate through the maps and save every entry. for (const auto& entry : m_entryCache) { const CString& key = entry.first; value = key.GetLength(); WRITEVALUETOFILE(value); if (value) { if (fwrite((LPCTSTR)key, sizeof(TCHAR), value, pFile)!=value) return false; if (!entry.second.SaveToDisk(pFile)) return false; } } value = (int)m_childDirectories.size(); WRITEVALUETOFILE(value); for (const auto& entry : m_childDirectories) { const CString& path = entry.first.GetWinPathString(); value = path.GetLength(); WRITEVALUETOFILE(value); if (value) { if (fwrite((LPCTSTR)path, sizeof(TCHAR), value, pFile)!=value) return false; git_wc_status_kind status = entry.second; WRITEVALUETOFILE(status); } } // WRITEVALUETOFILE(m_propsFileTime); value = m_directoryPath.GetWinPathString().GetLength(); WRITEVALUETOFILE(value); if (value) { if (fwrite(m_directoryPath.GetWinPath(), sizeof(TCHAR), value, pFile)!=value) return false; } if (!m_ownStatus.SaveToDisk(pFile)) return false; WRITEVALUETOFILE(m_currentFullStatus); WRITEVALUETOFILE(m_mostImportantFileStatus); return true; }
bool CStatusCacheEntry::SaveToDisk(FILE * pFile) { #define WRITEVALUETOFILE(x) if (fwrite(&x, sizeof(x), 1, pFile)!=1) return false; #define WRITESTRINGTOFILE(x) if (x.IsEmpty()) {value=0;WRITEVALUETOFILE(value);}else{value=x.GetLength();WRITEVALUETOFILE(value);if (fwrite((LPCSTR)x, sizeof(char), value, pFile)!=value) return false;} unsigned int value = CACHEVERION; WRITEVALUETOFILE(value); // 'version' of this save-format WRITEVALUETOFILE(m_highestPriorityLocalStatus); WRITEVALUETOFILE(m_lastWriteTime); WRITEVALUETOFILE(m_bSet); WRITEVALUETOFILE(m_kind); // now save the status struct (without the entry field, because we don't use that) WRITEVALUETOFILE(m_GitStatus.prop_status); // WRITEVALUETOFILE(m_GitStatus.repos_prop_status); // WRITEVALUETOFILE(m_GitStatus.repos_text_status); WRITEVALUETOFILE(m_GitStatus.text_status); WRITEVALUETOFILE(m_GitStatus.assumeValid); WRITEVALUETOFILE(m_GitStatus.skipWorktree); return true; }