Exemple #1
0
BOOL CDownloadGroups::Save(BOOL bForce)
{
	if ( ! bForce && m_nBaseCookie == m_nSaveCookie )
		return FALSE;

	CString strTemp = Settings.General.UserPath + _T("\\Data\\DownloadGroups.tmp");
	CString strFile = Settings.General.UserPath + _T("\\Data\\DownloadGroups.dat");

	CFile pFile;
	if ( ! pFile.Open( strTemp, CFile::modeWrite | CFile::modeCreate | CFile::shareExclusive | CFile::osSequentialScan ) )
	{
		DeleteFile( strTemp );
		theApp.Message( MSG_ERROR, _T("Failed to save download groups: %s"), strTemp );
		return FALSE;
	}

	try
	{
		CArchive ar( &pFile, CArchive::store );	// 4 KB buffer
		try
		{
			CQuickLock pTransfersLock( Transfers.m_pSection );
			CQuickLock pLock( m_pSection );

			Serialize( ar );

			m_nSaveCookie = m_nBaseCookie;

			ar.Close();
		}
		catch ( CException* pException )
		{
			ar.Abort();
			pFile.Abort();
			pException->Delete();
			theApp.Message( MSG_ERROR, _T("Failed to save download groups: %s"), strTemp );
			return FALSE;
		}
		pFile.Close();
	}
	catch ( CException* pException )
	{
		pFile.Abort();
		pException->Delete();
		theApp.Message( MSG_ERROR, _T("Failed to save download groups: %s"), strTemp );
		return FALSE;
	}

	if ( ! MoveFileEx( strTemp, strFile, MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING ) )
	{
		DeleteFile( strTemp );
		theApp.Message( MSG_ERROR, _T("Failed to save download groups: %s"), strFile );
		return FALSE;
	}

	return TRUE;
}
Exemple #2
0
BOOL CDibDoc::OnOpenDocument(LPCTSTR lpszPathName)
{
	CFile file;
	CFileException fe;
	if (!file.Open(lpszPathName, CFile::modeRead | CFile::shareDenyWrite, &fe))
	{
		ReportSaveLoadException(lpszPathName, &fe,
			FALSE, AFX_IDP_FAILED_TO_OPEN_DOC);
		return FALSE;
	}

	DeleteContents();
	BeginWaitCursor();

	// replace calls to Serialize with ReadDIBFile function
	TRY
	{
		m_hDIB = ::ReadDIBFile(file);
	}
	CATCH (CFileException, eLoad)
	{
		file.Abort(); // will not throw an exception
		EndWaitCursor();
		ReportSaveLoadException(lpszPathName, eLoad,
			FALSE, AFX_IDP_FAILED_TO_OPEN_DOC);
		m_hDIB = NULL;
		return FALSE;
	}
Exemple #3
0
void CChatPrefs::LoadChatScripts(CString ConfigFile)
{
	CFile File;

	if(File.Open(ConfigFile, CFile::modeRead))
	{
		
		char* buffer;
		buffer = new char[File.GetLength() + 1];

		UINT byteread = File.Read(buffer, File.GetLength());
		buffer[File.GetLength()] = '\0';

		CString Data = buffer;
		while (Data.Find("\r\n") != -1)
		{
			int pos = Data.Find("\r\n");
			CString line = Data.Left(pos);
			
			if(!line.IsEmpty())
				m_pChat->m_RemoteScript.Add(line);
			
			Data = Data.Right(Data.GetLength() - pos - 2);
		}
	
		delete [] buffer;
		File.Abort();

	}
}
Exemple #4
0
BOOL CSecurity::Save()
{
	const CString strFile = Settings.General.DataPath + _T("Security.dat");
	const CString strTemp = Settings.General.DataPath + _T("Security.tmp");

	CFile pFile;
	if ( pFile.Open( strTemp, CFile::modeWrite | CFile::modeCreate | CFile::shareExclusive | CFile::osSequentialScan ) )
	{
		try
		{
			CArchive ar( &pFile, CArchive::store, 131072 );	// 128 KB buffer
			try
			{
				{
					CQuickLock oLock( m_pSection );

					Serialize( ar );
					ar.Close();
				}

				pFile.Close();

				if ( MoveFileEx( strTemp, strFile, MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING ) )
					return TRUE;	// Success
			}
			catch ( CException* pException )
			{
				ar.Abort();
				pFile.Abort();
				pException->Delete();
			}
		}
		catch ( CException* pException )
		{
			pFile.Abort();
			pException->Delete();
		}

		pFile.Close();
		DeleteFile( strTemp );
	}

	theApp.Message( MSG_ERROR, _T("Failed to save security rules: %s"), strFile );
	return FALSE;
}
Exemple #5
0
void CChatPrefs::LoadChatAliases(CString ConfigFile)
{
	CFile File;

	
	if(File.Open(ConfigFile, CFile::modeRead))
	{
		char* buffer;
		buffer = new char[File.GetLength() + 1];

		UINT byteread = File.Read(buffer, File.GetLength());
		buffer[File.GetLength()] = '\0';

		CString Data = buffer;
		
		// Parse the data
		CString ParseList;
		
		while (Data.Find("\r\n") != -1)
		{
			int pos = Data.Find("\r\n");
			
			CString LineText;
			LineText = Data.Left(pos + 2);
			Data = Data.Right(Data.GetLength() - pos - 2);
		
			int epos = LineText.Find('=');
			if (epos != -1)
			{
				LineText = LineText.Right(LineText.GetLength() - epos - 1);
				ParseList += LineText;
			}
		}
		
		// Put list of aliases in map
		m_pChat->m_AliasMap.RemoveAll();
	
		int pos  = ParseList.Find("\r\n");
		int lpos = 0;
		CString command;

		while (pos != -1)
		{
			command = ParseList.Left(pos);
			ParseList = ParseList.Right(ParseList.GetLength() - pos - 2);
			pos = ParseList.Find("\r\n");		

			if (command.Find(' ') != -1)
				m_pChat->m_AliasMap.SetAt(command.Left(command.Find(' ')), command.Right(command.GetLength() - command.Find(' ') - 1));
		}
		
		delete [] buffer;
		File.Abort();
	}
}
Exemple #6
0
BOOL CDownloadGroups::Load()
{
	CString strFile = Settings.General.UserPath + _T("\\Data\\DownloadGroups.dat");

	CFile pFile;
	if ( pFile.Open( strFile, CFile::modeRead | CFile::shareDenyWrite | CFile::osSequentialScan ) )
	{
		try
		{
			CArchive ar( &pFile, CArchive::load );	// 4 KB buffer
			try
			{
				CQuickLock pTransfersLock( Transfers.m_pSection );
				CQuickLock pLock( m_pSection );

				Serialize( ar );

				ar.Close();
			}
			catch ( CException* pException )
			{
				ar.Abort();
				pFile.Abort();
				pException->Delete();
				theApp.Message( MSG_ERROR, _T("Failed to load download groups: %s"), strFile );
			}
			pFile.Close();
		}
		catch ( CException* pException )
		{
			pFile.Abort();
			pException->Delete();
			theApp.Message( MSG_ERROR, _T("Failed to load download groups: %s"), strFile );
		}
	}
	else
		theApp.Message( MSG_ERROR, _T("Failed to load download groups: %s"), strFile );

	m_nSaveCookie = m_nBaseCookie;

	return TRUE;
}
Exemple #7
0
BOOL CSecurity::Load()
{
	const CString strFile = Settings.General.DataPath + _T("Security.dat");

	CFile pFile;
	if ( pFile.Open( strFile, CFile::modeRead | CFile::shareDenyWrite | CFile::osSequentialScan ) )
	{
		try
		{
			CArchive ar( &pFile, CArchive::load, 131072 );	// 128 KB buffer
			try
			{
				CQuickLock oLock( m_pSection );

				Serialize( ar );

				ar.Close();

				pFile.Close();

				return TRUE;	// Success
			}
			catch ( CException* pException )
			{
				ar.Abort();
				pFile.Abort();
				pException->Delete();
			}
		}
		catch ( CException* pException )
		{
			pFile.Abort();
			pException->Delete();
		}

		pFile.Close();
	}

	theApp.Message( MSG_ERROR, _T("Failed to load security rules: %s"), strFile );
	return FALSE;
}
Exemple #8
0
	virtual BOOL Write (const CString& filename)
	{
		if (CBCGPBaseInfoWriter::IsFileReadOnly (filename))
		{
			//CFileParser::ReportSaveLoadException (filename, NULL, TRUE, IDP_ERROR_FILE_READONLY);
			return FALSE;
		}

		CFile* pFile = new CStdioFile;
		CFileException fe;

		if (!pFile->Open (filename, GetFlags (), &fe))
		{
			delete pFile;

			//CFileParser::ReportSaveLoadException (filename, &fe, TRUE, AFX_IDP_FAILED_TO_SAVE_DOC);
			return FALSE;
		}

		BOOL bResult = FALSE;

		TRY
		{
			CWaitCursor wait;

			bResult = Write (*pFile);
			
			pFile->Close();
			delete pFile;
		}
		CATCH_ALL(e)
		{
			pFile->Abort();
			delete pFile;
		}
		END_CATCH_ALL

		return bResult;
	}
Exemple #9
0
// 保存数据到图像文件
// 2005.12.9
BOOL CMyDib::SaveToFile(LPCTSTR lpszPathName)
{
	DWORD dWord = 0;
    CFile file;
    //打开文件
    if (!file.Open(lpszPathName, CFile::modeCreate |
        CFile::modeReadWrite | CFile::shareExclusive))
    {
        return FALSE;
    }

    TRY
    {
        //保存为DIB图像
        dWord = Save(file);
        
        file.Close();
    }
    //保存失败
    CATCH (CException, eSave)
    {
        file.Abort();
        return FALSE;
    }
void CInitialConfigDlg::OnBnClickedButtonOK()
{
	// TODO: 在此添加控件通知处理程序代码
	UpdateData(TRUE);

	const CString notFound=_T("");
	const CString sectionNode=_T("NodeInfo");
	const CString sectionTrack=_T("TrackInfo");
	const CString sectionProtocol=_T("Protocol");
	const CString sectionTimeSeq=_T("TimeSeqence");
	const CString sectionLink=_T("Link");
	const CString sectionBaseband=_T("Baseband");
	CFileFind finder;
	
	m_EditNodeIDStr.Trim();
	CString configPath=_T(".\\config[")+m_EditNodeIDStr+_T("].ini");//获取文件名
	if(!finder.FindFile(configPath))
	{
		CFile fileConfig;
		try
		{
			fileConfig.Open(configPath,CFile::modeCreate|CFile::modeWrite);//如没有文件则新建一个
			fileConfig.Close();
		}
		catch(CFileException *e)
		{
			CString errStr;
			errStr.Format(_T("文件创建失败:%d"),e->m_cause);
			MessageBox(errStr);
			fileConfig.Abort();
			e->Delete();
		}
	}
	CString valueStr;
	
	//NodeInfo
	//NodeType
	::WritePrivateProfileString(sectionNode,_T("NodeType"),m_ComboNodeTypeStr,configPath);
	//NodeID
	::WritePrivateProfileString(sectionNode,_T("NodeID"),m_EditNodeIDStr,configPath);
	//IntfMac
	CString intfMAC;
	intfMAC.Format(_T("%d"),0x000000000001+_ttoi(m_EditNodeIDStr));
	::WritePrivateProfileString(sectionNode,_T("IntfMac"),intfMAC,configPath);

	//TrackInfo
	float Longt,Lat,Ht;
	CString PositionStr;
	//InitialPosition
	Longt=_ttof(m_EditInitPos_LongtStr);
	Lat=_ttof(m_EditInitPos_LatStr);
	Ht=_ttof(m_EditInitPos_HtStr);
	PositionStr.Format(_T("(%.2f,%.2f,%.2f)"),Longt,Lat,Ht);
	::WritePrivateProfileString(sectionTrack,_T("InitialPositon"),PositionStr,configPath);
	//DestinatePosition
	Longt=_ttof(m_EditDstPos_LongtStr);
	Lat=_ttof(m_EditDstPos_LatStr);
	Ht=_ttof(m_EditDstPos_HtStr);
	PositionStr.Format(_T("(%.2f,%.2f,%.2f)"),Longt,Lat,Ht);
	::WritePrivateProfileString(sectionTrack,_T("DestinatePositon"),PositionStr,configPath);
	//TrackType
	::WritePrivateProfileString(sectionTrack,_T("TrackType"),m_ComboTrackTypeStr,configPath);
	//VelocityRange
	float Vinf=_ttof(m_EditVinfStr);
	float Vsup=_ttof(m_EditVsupStr);
	CString VStr;
	VStr.Format(_T("(%.2f,%.2f"),Vinf,Vsup);
	::WritePrivateProfileString(sectionTrack,_T("Velocity"),VStr,configPath);
	//RuleOfVelocityChange
	::WritePrivateProfileString(sectionTrack,_T("VRule"),m_ComboVRuleStr,configPath);
		
	//ProtocolInfo
	//MessageFormat
	::WritePrivateProfileString(sectionProtocol,_T("MessageFormat"),m_ComboMsgFormatStr,configPath);
	::WritePrivateProfileString(sectionProtocol,_T("isRelayTransmission"),m_ComboRelayTranStr,configPath);
	//ScheduleAlgorithm
	::WritePrivateProfileString(sectionProtocol,_T("ScheduleAlgorithm"),m_ComboScheAlgoStr,configPath);
	//NetworkManage
	::WritePrivateProfileString(sectionProtocol,_T("NetworkManage"),m_ComboNetworkManageStr,configPath);
	//isErrorControl
	::WritePrivateProfileString(sectionProtocol,_T("isErrorControl"),m_ComboErrCtrlStr,configPath);

	//TimeSequenceInfo
	//TimeSlot
	::WritePrivateProfileString(sectionTimeSeq,_T("TimeSlot"),m_ComboTimeSlotStr,configPath);
	//numSlots
	::WritePrivateProfileString(sectionTimeSeq,_T("numSlots"),m_ComboNumSlotStr,configPath);
	//numNetworks
	::WritePrivateProfileString(sectionTimeSeq,_T("numNetworks"),m_ComboNumNetworkStr,configPath);
	//SlotsDistribution
	::WritePrivateProfileString(sectionTimeSeq,_T("SlotsDistribution"),m_ComboSlotDistStr,configPath);
	//SubSlotValue
	::WritePrivateProfileString(sectionTimeSeq,_T("SubSlotValue"),m_ComboSlotValueStr,configPath);

	//LinkInfo
	//LinkType
	::WritePrivateProfileString(sectionLink,_T("LinkType"),m_ComboLinkTypeStr,configPath);
	//ServiceSource
	::WritePrivateProfileString(sectionLink,_T("ServiceSource"),m_ComboServiceSrcStr,configPath);

	numNodes=_ttoi(m_EditNodeIDStr);
	m_EditNodeIDStr.Format(_T("%d"),++numNodes);
	_CEditSetText(IDC_EDIT_Config_Node_ID,m_EditNodeIDStr);
}