BOOL vmsMediaConvertMgr::LoadState() { CString strFile = fsGetDataFilePath ("mctasks.sav"); HANDLE hFile = CreateFile (strFile, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_HIDDEN, NULL); if (hFile == INVALID_HANDLE_VALUE) return GetFileAttributes (strFile) == DWORD (-1); DWORD dwRequiredSize = ::GetFileSize(hFile, NULL); DWORD dw; std::auto_ptr<BYTE> pbtBufferGuard; fsMcMgrFileHdr hdr; if (FALSE == ReadFile (hFile, &hdr, sizeof (hdr), &dw, NULL)) goto _lErr; if (lstrcmp (hdr.szSig, MCMGRFILE_SIG) || hdr.wVer > MCMGRFILE_CURRENT_VERSION) goto _lErr; dwRequiredSize -= sizeof (hdr); if (dwRequiredSize <= 0) { goto _lErr; } pbtBufferGuard.reset( new BYTE[dwRequiredSize] ); LPBYTE pbtBuffer = pbtBufferGuard.get(); if (pbtBuffer == 0) { goto _lErr; } memset(pbtBuffer, 0, dwRequiredSize); if (!ReadFile (hFile, pbtBuffer, dwRequiredSize, &dw, NULL) || dw != dwRequiredSize) { goto _lErr; } CloseHandle (hFile); if (!loadFromStateBuffer(pbtBuffer, &dwRequiredSize, hdr.wVer)) goto _lErr; return TRUE; _lErr: CloseHandle (hFile); DeleteFile (strFile); return FALSE; }
void vmsAppSettingsStore::LoadSettingsFromFile(LPCSTR pszFile) { m_bUseRegistry = false; HANDLE hFile = CreateFile (pszFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_HIDDEN, NULL); if (hFile == INVALID_HANDLE_VALUE) return; try { DWORD dwRequiredSize = ::GetFileSize(hFile, NULL); DWORD dw = 0; if (dwRequiredSize <= 0) { CloseHandle (hFile); return; } std::auto_ptr<BYTE> pbtBufferGuard( new BYTE[dwRequiredSize] ); LPBYTE pbtBuffer = pbtBufferGuard.get(); if (pbtBuffer == 0) { CloseHandle (hFile); return; } memset(pbtBuffer, 0, dwRequiredSize); if (!ReadFile (hFile, pbtBuffer, dwRequiredSize, &dw, NULL) || dw != dwRequiredSize) { CloseHandle (hFile); return; } if (!loadFromStateBuffer(pbtBuffer, &dwRequiredSize, 0)) { CloseHandle (hFile); return; } CloseHandle (hFile); resetDirty(); } catch (...) { } }
BOOL vmsDownloadsGroupsMgr::LoadFromDisk() { fsString strFile = fsGetDataFilePath ("groups.sav"); if (GetFileAttributes (strFile) == DWORD (-1)) { fsDownloads_GroupsMgr grps; if (FALSE == grps.LoadGroups () || grps.GetCount () == 0) { CreateDefaultGroups (); return TRUE; } for (int i = 0; i < grps.GetCount (); i++) { fsDownloadGroup grp; grps.GetGroup (&grp, i); vmsDownloadsGroupSmartPtr grpNew; grpNew.CreateInstance (); grpNew->strName = grp.szName; grpNew->strOutFolder = grp.szOutFolder; grpNew->strExts = grp.szExts; grpNew->nId = grp.bOther ? GRP_OTHER_ID : m_nGrpNextId++; Add (grpNew, NULL, TRUE); } return TRUE; } DWORD dwRequiredSize = 0; HANDLE hFile = CreateFile (strFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); if (hFile != INVALID_HANDLE_VALUE) { dwRequiredSize = ::GetFileSize(hFile, NULL); vmsDownloadsGroupsFileHdr hdr; DWORD dw; if (ReadFile (hFile, &hdr, sizeof (hdr), &dw, NULL)) { if (hdr.wVer == DLDSGRPSFILE_CURRENT_VERSION && lstrcmp (hdr.szSig, DLDSGRPSFILE_SIG) == 0) { dwRequiredSize -= sizeof(hdr); if (dwRequiredSize <= 0) { CloseHandle (hFile); return FALSE; } std::auto_ptr<BYTE> pbtBufferGuard( new BYTE[dwRequiredSize] ); LPBYTE pbtBuffer = pbtBufferGuard.get(); if (pbtBuffer == 0) { CloseHandle (hFile); return FALSE; } memset(pbtBuffer, 0, dwRequiredSize); if (!ReadFile (hFile, pbtBuffer, dwRequiredSize, &dw, NULL) || dw != dwRequiredSize) { CloseHandle (hFile); return FALSE; } if (!loadFromStateBuffer(pbtBuffer, &dwRequiredSize, hdr.wVer)) { CloseHandle (hFile); return FALSE; } } } CloseHandle (hFile); } if (m_tGroups->GetLeafCount () == 0) CreateDefaultGroups (); return TRUE; }
void vmsAppSettingsStore::LoadSettingsFromFile(LPCTSTR pszFile) { m_bUseRegistry = false; HANDLE hFile = CreateFile (pszFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_HIDDEN, NULL); if (hFile == INVALID_HANDLE_VALUE) return; try { DWORD dwRequiredSize = ::GetFileSize(hFile, NULL); DWORD dw = 0; if (dwRequiredSize <= 0) { CloseHandle (hFile); return; } vmsAppSettingsFileHdr hdr; bool bIsOldVer = false; if (dwRequiredSize < sizeof(hdr)) bIsOldVer = true; if (!bIsOldVer) { if (!ReadFile (hFile, &hdr, sizeof(hdr), &dw, NULL) || dw != sizeof(hdr)) { CloseHandle (hFile); return; } if (strcmp(hdr.szSig, APPSETTINGS_FILE_SIG)) bIsOldVer = true; } if (bIsOldVer) { ::SetFilePointer(hFile, 0, 0, FILE_BEGIN); m_file.LoadFromFile_old(hFile); CloseHandle (hFile); return; } if (hdr.wVer > APPSETTINGS_FILE_CURRENT_VERSION) return; dwRequiredSize -= sizeof(hdr); std::auto_ptr<BYTE> pbtBufferGuard( new BYTE[dwRequiredSize] ); LPBYTE pbtBuffer = pbtBufferGuard.get(); if (pbtBuffer == 0) { CloseHandle (hFile); return; } memset(pbtBuffer, 0, dwRequiredSize); if (!ReadFile (hFile, pbtBuffer, dwRequiredSize, &dw, NULL) || dw != dwRequiredSize) { CloseHandle (hFile); return; } if (!loadFromStateBuffer(pbtBuffer, &dwRequiredSize, 0)) { CloseHandle (hFile); return; } CloseHandle (hFile); resetDirty(); } catch (const std::exception& ex) { ASSERT (FALSE); vmsLogger::WriteLog(_T ("vmsAppSettingsStore::LoadSettingsFromFile ") + tstringFromString(ex.what())); } catch (...) { ASSERT (FALSE); vmsLogger::WriteLog(_T("vmsAppSettingsStore::LoadSettingsFromFile unknown exception")); } }
void CCmdHistorySaver::Load() { DWORD dwRequiredSize = 0; DWORD dw = 0; std::auto_ptr<BYTE> pbtBufferGuard; fsHistFileHdr hdr; _HsMgr.ReadSettings (); HANDLE hFile = CreateFile (fsGetDataFilePath ("history.sav"), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); if (hFile == INVALID_HANDLE_VALUE) { if (GetLastError () != ERROR_FILE_NOT_FOUND) goto _lErr; return; } dwRequiredSize = ::GetFileSize(hFile, NULL); if (!ReadFile (hFile, &hdr, sizeof(hdr), &dw, NULL) || dw != sizeof(hdr)) { goto _lErr; } dwRequiredSize -= sizeof(hdr); if (dwRequiredSize <= 0) { return; } if (hdr.wVer <= 1) { if (INVALID_SET_FILE_POINTER == ::SetFilePointer(hFile, -sizeof(hdr), 0, FILE_CURRENT)) goto _lErr; if (!_LastUrlFiles.ReadFromFile (hFile)) goto _lErr; if (!_LastUrlPaths.ReadFromFile (hFile)) goto _lErr; if (!_LastFolders.ReadFromFile (hFile)) goto _lErr; if (!_LastBatchUrls.ReadFromFile (hFile)) goto _lErr; if (!_LastFind.ReadFromFile (hFile)) goto _lErr; if (!_LastFlashVideoUrls.ReadFromFile (hFile)) goto _lErr; if (!_LastFlashVideoDstFolders.ReadFromFile (hFile)) goto _lErr; CloseHandle (hFile); return; } pbtBufferGuard.reset( new BYTE[dwRequiredSize] ); LPBYTE pbtBuffer = pbtBufferGuard.get(); if (pbtBuffer == 0) { goto _lErr; } memset(pbtBuffer, 0, dwRequiredSize); if (!ReadFile (hFile, pbtBuffer, dwRequiredSize, &dw, NULL) || dw != dwRequiredSize) { goto _lErr; } CloseHandle (hFile); if (!loadFromStateBuffer(pbtBuffer, &dwRequiredSize, hdr.wVer)) goto _lErr; return; _lErr: if (hFile != INVALID_HANDLE_VALUE) CloseHandle (hFile); }
BOOL fsWebPageDownloadsMgr::Load() { m_vWPDs.clear (); HANDLE hFile = CreateFile (fsGetDataFilePath (_T("spider.sav")), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_HIDDEN, NULL); if (hFile == INVALID_HANDLE_VALUE) return FALSE; if (GetLastError () != ERROR_ALREADY_EXISTS) { CloseHandle (hFile); return TRUE; } int cWPD = 0; DWORD dw; fsSpiderFileHdr hdr; WORD wVer = SPIDERFILE_CURRENT_VERSION; DWORD dwRequiredSize = ::GetFileSize(hFile, NULL); if (FALSE == ReadFile (hFile, &hdr, sizeof (hdr), &dw, NULL)) { wVer = 1; } else { if (dw < sizeof(hdr) || strcmp (hdr.szSig, SPIDERFILE_SIG)) { wVer = 1; SetFilePointer (hFile, 0, NULL, FILE_BEGIN); } else { wVer = hdr.wVer; dwRequiredSize -= sizeof (hdr); } } if (wVer == 1) { if (FALSE == ReadFile (hFile, &cWPD, sizeof (cWPD), &dw, NULL)) { CloseHandle (hFile); return FALSE; } for (int i = 0; i < cWPD; i++) { fsWebPageDownloaderPtr wpd; wpd.CreateInstance (); if (FALSE == wpd->Load (hFile, wVer)) { CloseHandle (hFile); return FALSE; } Add (wpd); } resetDirty(); CloseHandle (hFile); return TRUE; } if (dwRequiredSize == 0) { CloseHandle (hFile); return TRUE; } std::auto_ptr<BYTE> pbtBufferGuard( new BYTE[dwRequiredSize] ); LPBYTE pbtBuffer = pbtBufferGuard.get(); if (pbtBuffer == 0) { CloseHandle (hFile); return FALSE; } memset(pbtBuffer, 0, dwRequiredSize); if (!ReadFile (hFile, pbtBuffer, dwRequiredSize, &dw, NULL) || dw != dwRequiredSize) { CloseHandle (hFile); return FALSE; } if (!loadFromStateBuffer(pbtBuffer, &dwRequiredSize, hdr.wVer)) { getPersistObjectChildren ()->removeAllPersistObjects (); m_vWPDs.clear (); CloseHandle (hFile); return FALSE; } resetDirty(); CloseHandle (hFile); return TRUE; }