BOOL vmsMediaConvertMgr::SaveState()
{
	
	
	
	
	
	
	
	
	
	
	

	if (!isDirty())
		return TRUE;

	CString strFile = fsGetDataFilePath ("mctasks.sav");
	HANDLE hFile = CreateFile (strFile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
		FILE_ATTRIBUTE_HIDDEN, NULL);
	if (hFile == INVALID_HANDLE_VALUE)
		return FALSE;

	DWORD dw;
	std::auto_ptr<BYTE> apbtBufferGuard;

	fsMcMgrFileHdr hdr;
	if (FALSE == WriteFile (hFile, &hdr, sizeof (hdr), &dw, NULL))
		goto _lErr;

	DWORD dwRequiredSize = 0;

	getStateBuffer(0, &dwRequiredSize, false);

	if (dwRequiredSize == 0)
		goto _lErr;

	apbtBufferGuard.reset( new BYTE[dwRequiredSize] );
	LPBYTE pbtBuffer = apbtBufferGuard.get();
	if (pbtBuffer == 0)
		goto _lErr;
	memset(pbtBuffer, 0, dwRequiredSize);

	getStateBuffer(pbtBuffer, &dwRequiredSize, true);

	if (FALSE == WriteFile (hFile, pbtBuffer, dwRequiredSize, &dw, NULL) || dw != dwRequiredSize) {
		goto _lErr;
	}
	CloseHandle (hFile);
	onStateSavedSuccessfully();

	return TRUE;

_lErr:
	CloseHandle (hFile);
	DeleteFile (strFile);
	return FALSE;
}
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"));
	}
}
Example #3
0
void CCmdHistorySaver::Save()
{
	if (!isDirty())
		return;

	DWORD dwRequiredSize = 0;
	DWORD dw = 0;
	std::auto_ptr<BYTE> apbtBufferGuard;
	fsHistFileHdr hdr;

	HANDLE hFile = CreateFile (fsGetDataFilePath ("history.sav"), GENERIC_WRITE, 0, NULL, 
		CREATE_ALWAYS, FILE_ATTRIBUTE_HIDDEN, NULL);

	if (hFile == INVALID_HANDLE_VALUE)
	{
		goto _lErr;
	}

	if (FALSE == WriteFile (hFile, &hdr, sizeof(hdr), &dw, NULL) || dw != sizeof(hdr)) {
		goto _lErr;
	}

	getStateBuffer(0, &dwRequiredSize, false);

	if (dwRequiredSize == 0)
		goto _lErr;

	apbtBufferGuard.reset( new BYTE[dwRequiredSize] );
	LPBYTE pbtBuffer = apbtBufferGuard.get();
	if (pbtBuffer == 0)
		goto _lErr;
	memset(pbtBuffer, 0, dwRequiredSize);

	getStateBuffer(pbtBuffer, &dwRequiredSize, true);

	if (FALSE == WriteFile (hFile, pbtBuffer, dwRequiredSize, &dw, NULL) || dw != dwRequiredSize) {
		goto _lErr;
	}
	CloseHandle (hFile);
	onStateSavedSuccessfully();

	return;

_lErr:
	if (hFile != INVALID_HANDLE_VALUE)
		CloseHandle (hFile);

	DeleteFile (fsGetDataFilePath ("history.sav"));
}
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;
	}
}