void vmsAppSettingsStore::SaveSettingsToFile(LPCTSTR pszFile) { if (!isDirty()) return; HANDLE hFile = CreateFile (pszFile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_HIDDEN, NULL); if (hFile == INVALID_HANDLE_VALUE) return; vmsAppSettingsFileHdr hdr; DWORD dw; if (!WriteFile (hFile, &hdr, sizeof(hdr), &dw, NULL) || dw != sizeof(hdr)) { CloseHandle (hFile); return; } try { DWORD dwRequiredSize = 0; DWORD dw = 0; getStateBuffer(0, &dwRequiredSize, false); if (dwRequiredSize == 0) return; std::auto_ptr<BYTE> apbtBufferGuard( new BYTE[dwRequiredSize] ); LPBYTE pbtBuffer = apbtBufferGuard.get(); if (pbtBuffer == 0) return; memset(pbtBuffer, 0, dwRequiredSize); getStateBuffer(pbtBuffer, &dwRequiredSize, true); if (FALSE == WriteFile (hFile, pbtBuffer, dwRequiredSize, &dw, NULL) || dw != dwRequiredSize) { CloseHandle (hFile); return; } CloseHandle (hFile); onStateSavedSuccessfully(); } catch (const std::exception& ex) { ASSERT (FALSE); vmsLogger::WriteLog(_T("vmsAppSettingsStore::SaveSettingsToFile ") + tstringFromString(ex.what())); } catch (...) { ASSERT (FALSE); vmsLogger::WriteLog(_T("vmsAppSettingsStore::SaveSettingsToFile unknown exception")); } }
void CSitesWnd::SaveSites() { if (!_SitesMgr.isDirty()) return; CString strFile = fsGetDataFilePath ("sites.sav"); HANDLE hFile = CreateFile (strFile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_HIDDEN, NULL); if (hFile == INVALID_HANDLE_VALUE) return; DWORD dw; fsSitesFileHdr hdr; DWORD dwRequiredSize = 0; if (!WriteFile (hFile, &hdr, sizeof (hdr), &dw, NULL)) { CloseHandle (hFile); return; } _SitesMgr.getStateBuffer(0, &dwRequiredSize, false); if (dwRequiredSize == 0) return; std::auto_ptr<BYTE> apbtBufferGuard( new BYTE[dwRequiredSize] ); LPBYTE pbtBuffer = apbtBufferGuard.get(); if (pbtBuffer == 0) return; memset(pbtBuffer, 0, dwRequiredSize); _SitesMgr.getStateBuffer(pbtBuffer, &dwRequiredSize, true); if (FALSE == WriteFile (hFile, pbtBuffer, dwRequiredSize, &dw, NULL) || dw != dwRequiredSize) { CloseHandle (hFile); return; } CloseHandle (hFile); _SitesMgr.onStateSavedSuccessfully(); }
void vmsAppSettingsStore::SaveSettingsToFile(LPCSTR pszFile) { if (!isDirty()) return; HANDLE hFile = CreateFile (pszFile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_HIDDEN, NULL); if (hFile == INVALID_HANDLE_VALUE) return; try { DWORD dwRequiredSize = 0; DWORD dw = 0; getStateBuffer(0, &dwRequiredSize, false); if (dwRequiredSize == 0) return; std::auto_ptr<BYTE> apbtBufferGuard( new BYTE[dwRequiredSize] ); LPBYTE pbtBuffer = apbtBufferGuard.get(); if (pbtBuffer == 0) return; memset(pbtBuffer, 0, dwRequiredSize); getStateBuffer(pbtBuffer, &dwRequiredSize, true); if (FALSE == WriteFile (hFile, pbtBuffer, dwRequiredSize, &dw, NULL) || dw != dwRequiredSize) { CloseHandle (hFile); return; } CloseHandle (hFile); onStateSavedSuccessfully(); } catch (...) { } }
BOOL vmsDownloadsGroupsMgr::SaveToDisk() { fsString strFile = fsGetDataFilePath ("groups.sav"); if (!isDirty()) return TRUE; HANDLE hFile = CreateFile (strFile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_HIDDEN, NULL); if (hFile == INVALID_HANDLE_VALUE) return FALSE; vmsDownloadsGroupsFileHdr hdr; DWORD dw; if (FALSE == WriteFile (hFile, &hdr, sizeof (hdr), &dw, NULL)) { CloseHandle (hFile); return FALSE; } DWORD dwRequiredSize = 0; getStateBuffer(0, &dwRequiredSize, false); if (dwRequiredSize == 0) return FALSE; std::auto_ptr<BYTE> apbtBufferGuard( new BYTE[dwRequiredSize] ); LPBYTE pbtBuffer = apbtBufferGuard.get(); if (pbtBuffer == 0) return FALSE; memset(pbtBuffer, 0, dwRequiredSize); getStateBuffer(pbtBuffer, &dwRequiredSize, true); if (FALSE == WriteFile (hFile, pbtBuffer, dwRequiredSize, &dw, NULL) || dw != dwRequiredSize) { CloseHandle (hFile); return FALSE; } CloseHandle (hFile); onStateSavedSuccessfully(); return TRUE; }
BOOL fsWebPageDownloadsMgr::Save() { if (!isDirty()) return TRUE; HANDLE hFile = CreateFile (fsGetDataFilePath (_T("spider.sav")), GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_HIDDEN, NULL); if (hFile == INVALID_HANDLE_VALUE) return FALSE; try { DWORD dw = 0; fsSpiderFileHdr hdr; if (FALSE == WriteFile (hFile, &hdr, sizeof (hdr), &dw, NULL)) { CloseHandle (hFile); return FALSE; } DWORD dwRequiredSize = 0; getStateBuffer(0, &dwRequiredSize, false); if (dwRequiredSize == 0) return FALSE; std::auto_ptr<BYTE> apbtBufferGuard( new BYTE[dwRequiredSize] ); LPBYTE pbtBuffer = apbtBufferGuard.get(); if (pbtBuffer == 0) return FALSE; memset(pbtBuffer, 0, dwRequiredSize); getStateBuffer(pbtBuffer, &dwRequiredSize, true); if (FALSE == WriteFile (hFile, pbtBuffer, dwRequiredSize, &dw, NULL) || dw != dwRequiredSize) { CloseHandle (hFile); return FALSE; } CloseHandle (hFile); hFile = INVALID_HANDLE_VALUE; onStateSavedSuccessfully(); return TRUE; } catch (const std::exception& ex) { ASSERT (FALSE); vmsLogger::WriteLog(_T ("fsWebPageDownloadsMgr::Save ") + tstringFromString(ex.what())); if (hFile != INVALID_HANDLE_VALUE) CloseHandle (hFile); return FALSE; } catch (...) { ASSERT (FALSE); vmsLogger::WriteLog(_T("fsWebPageDownloadsMgr::Save unknown exception")); if (hFile != INVALID_HANDLE_VALUE) CloseHandle (hFile); return FALSE; } }