Ejemplo n.º 1
0
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;
}
Ejemplo n.º 3
0
void CSitesWnd::LoadSites()
{
	CString strFile = fsGetDataFilePath ("sites.sav");

	if (GetFileAttributes (strFile) == DWORD (-1))
	{
		_DldsMgr.RebuildServerList ();
		return;
	}

	HANDLE hFile = CreateFile (strFile, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);

	if (hFile == INVALID_HANDLE_VALUE) {
		_DldsMgr.RebuildServerList ();
		return;
	}

	try {

		fsSitesFileHdr hdr;
		DWORD dw = 0;
		DWORD dwRequiredSize = ::GetFileSize(hFile, 0);
		BOOL bOldVer = FALSE;

		if (!ReadFile (hFile, &hdr, sizeof (hdr), &dw, NULL)) {
			bOldVer = TRUE;
		} 
		
		if (!bOldVer) {
			if (strcmp (hdr.szSig, SITESFILE_SIG)) {
				bOldVer = TRUE;
			} else if (hdr.wVer > SITESFILE_CURRENT_VERSION) {
				CloseHandle (hFile);
				_DldsMgr.RebuildServerList ();
				return;
			} else if (hdr.wVer < 3) {
				bOldVer = TRUE;
			}
		}

		if (bOldVer) {

			if (!SetFilePointer (hFile, 0, NULL, FILE_BEGIN)) {
				CloseHandle (hFile);
				_DldsMgr.RebuildServerList ();
				return;
			}

			_SitesMgr.LoadFromFile(hFile);

		} else {

			dwRequiredSize -= sizeof(hdr);

			std::auto_ptr<BYTE> pbtBufferGuard( new BYTE[dwRequiredSize] );
			LPBYTE pbtBuffer = pbtBufferGuard.get();
			if (pbtBuffer == 0) {
				CloseHandle (hFile);
				_DldsMgr.RebuildServerList ();
				return;
			}
			memset(pbtBuffer, 0, dwRequiredSize);

			if (!ReadFile (hFile, pbtBuffer, dwRequiredSize, &dw, NULL) || dw != dwRequiredSize) {
				CloseHandle (hFile);
				_DldsMgr.RebuildServerList ();
				return;
			}

			if (!_SitesMgr.loadFromStateBuffer(pbtBuffer, &dwRequiredSize, hdr.wVer)) {
				CloseHandle (hFile);
				_DldsMgr.RebuildServerList ();
				return;
			}

		}

		CloseHandle (hFile);
		_SitesMgr.resetDirty();

	} catch (...) {
		ASSERT (FALSE); 
	}

	_DldsMgr.RebuildServerList ();
}
Ejemplo n.º 4
0
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"));
	}
}
Ejemplo n.º 5
0
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;
}