Exemplo n.º 1
0
void CFormulaParser::ParseFile(CArchive& formula_file) {
  InitNewParse();
  p_function_collection->DeleteAll(false, true);
  p_function_collection->SetTitle(formula_file.GetFile()->GetFileName());
  p_function_collection->SetPath(formula_file.GetFile()->GetFilePath());
  while (true) {
    int starting_line = _formula_file_splitter.starting_line_of_current_function();
    _formula_file_splitter.ScanForNextFunctionOrList(formula_file);
    CString function_header = _formula_file_splitter.GetFunctionHeader(); 
    if (function_header.GetLength() <= 0) {
	    write_log(preferences.debug_parser(), 
	      "[FormulaParser] Empty function received. Parse finished.\n");
	    goto ExitLoop;
    }
    if (!VerifyFunctionHeader(function_header)) {
      // Skip this function
      continue;
    }
    ParseSingleFormula(_formula_file_splitter.GetFunctionText(), starting_line);
  }
ExitLoop:
  FinishParse();
  // Dump function collection to log
  write_log(preferences.debug_formula() || preferences.debug_parser(),
    "[CFormulaParser] ParseFile() done: %s\n",
    formula_file.GetFile()->GetFileName());
  p_function_collection->Dump();
}
Exemplo n.º 2
0
void COpenHoldemDoc::ReadFormula(CArchive& ar) 
{
	// Clear everything
	p_formula->ClearFormula();

	// There are two types of formulas
	//   * ohf 
	//   * whf and optional whx
	// In the latter case we have to read both files. 
	p_formula->ReadFormulaFile(ar, true);

	CFile *cf_whf = ar.GetFile();  
	CString CSpath = cf_whf->GetFilePath(); 

	if (IsWinHoldemFormat(CSpath))
		{
			CFile *cf_whf = ar.GetFile();
			CFile cf_whx; 
			CString CSpath = cf_whf->GetFilePath();
			CSpath.Replace(".whf", ".whx");

			if (cf_whx.Open(CSpath, CFile::modeNoTruncate | CFile::modeRead| CFile::shareDenyWrite)) 
			{ 
				CArchive ar_whx(&cf_whx, CArchive::load);   
				// Read whx file, too. //???	
				p_formula->ReadFormulaFile(ar_whx, false);	
			}
	}

	// Check and add missing...
	p_formula->CheckForDefaultFormulaEntries();
}
Exemplo n.º 3
0
/*************************************************************************
 *
 * \函数名称:
 *   Serialize()
 *
 * \输入参数:
 *   CArchive&	ar			- 指向应用程序归档对象
 *
 * \返回值:
 *   无
 *
 * \说明:
 *   该函数进行串行化过程,将CDib数据进行读入或者写出
 *
 ************************************************************************
 */
void CDib::Serialize(CArchive& ar)
{
	DWORD dwPos;

	// 获得此归档文件的CFile对象指针
	dwPos = ar.GetFile()->GetPosition();
	TRACE("CDib::Serialize -- pos = %d\n", dwPos);

	// 从归档文件缓冲区中冲掉未写入数据
	ar.Flush();

	// 重新获得此归档文件的CFile对象指针
	dwPos = ar.GetFile()->GetPosition();
	TRACE("CDib::Serialize -- pos = %d\n", dwPos);

	// 确定归档文件是否被存储,是则进行存储	
	if(ar.IsStoring()) {
		Write(ar.GetFile());
	}

	// 否则进行加载
	else {
		Read(ar.GetFile());
	}
}
Exemplo n.º 4
0
void	CDib::Serialize(CArchive&	ar)
{
    ar.Flush();
    if(ar.IsStoring())
        Write(ar.GetFile());
    else
        Read(ar.GetFile());
}
Exemplo n.º 5
0
void CChordEaseDoc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		WriteSongText(*ar.GetFile(), m_SongText);
	}
	else
	{
		ReadSongText(*ar.GetFile(), m_SongText);
	}
}
Exemplo n.º 6
0
void CDib::Serialize(CArchive& ar)
{
	DWORD dwPos;
	dwPos = ar.GetFile()->GetPosition();
	TRACE(_T("CDib::Serialize -- pos = %d\n"), dwPos);
	ar.Flush();
	dwPos = ar.GetFile()->GetPosition();
	TRACE(_T("CDib::Serialize -- pos = %d\n"), dwPos);
	if(ar.IsStoring()) {
		Write(ar.GetFile());
	}
	else {
		Read(ar.GetFile());
	}
}
Exemplo n.º 7
0
void CMyFirstDocWindowDoc::Serialize(CArchive& ar)
{
	// CEditView contains an edit control which handles all serialization
	if (!m_viewList.IsEmpty())
	{
		reinterpret_cast<CEditView*>(m_viewList.GetHead())->SerializeRaw(ar);
	}
#ifdef SHARED_HANDLERS

	if (m_viewList.IsEmpty() && ar.IsLoading())
	{
		CFile* pFile = ar.GetFile();
		pFile->Seek(0, FILE_BEGIN);
		ULONGLONG nFileSizeBytes = pFile->GetLength();
		ULONGLONG nFileSizeChars = nFileSizeBytes/sizeof(TCHAR);
		LPTSTR lpszText = (LPTSTR)malloc(((size_t)nFileSizeChars + 1) * sizeof(TCHAR));
		if (lpszText != NULL)
		{
			ar.Read(lpszText, (UINT)nFileSizeBytes);
			lpszText[nFileSizeChars] = '\0';
			m_strThumbnailContent = lpszText;
			m_strSearchContent = lpszText;
		}
	}
#endif
}
Exemplo n.º 8
0
void CGelDoc::Serialize(CArchive& ar)
{
	CFile* pFile = ar.GetFile();

	if (ar.IsStoring())
	{
		pFile->Seek(0L, CFile::begin);
		pFile->Write(m_abyTransform, sizeof(m_abyTransform));
	}
	else
	{
		int i;
		for (i = 0; i < 256; i++)
			m_abySelection[i] = 0xFF;
		BYTE byMask = m_pUntransformed->GetPixel(CPoint(0, 0));
		m_abySelection[byMask] = 0x00;

		pFile->Seek(0L, CFile::begin);
		DWORD dwSize = pFile->Read(m_abyTransform, sizeof(m_abyTransform));

		ApplyGel();

		if (sizeof(m_abyTransform) != dwSize)
			AfxThrowArchiveException(CArchiveException::generic);
	}
}
Exemplo n.º 9
0
void CResourceListDoc::Serialize(CArchive& ar)
{
    if (ar.IsStoring())
    {
        // There is nothing to save.
        int x = 0;
    }
    else
    {
        CFile *pFile = ar.GetFile();

        // Set the current directory, so we know where to look for the resource files.
        // If not, clicking on an item in the recent documents list won't work
        CString path = pFile->GetFilePath();
        path.MakeLower();
        int iFileOffset = path.Find(TEXT("\\resource.map"));
        if (iFileOffset > 0)
        {
            path.SetAt(iFileOffset, 0); // Null terminate it

            // Set this folder as our new game folder
            CResourceMap &map = theApp.GetResourceMap();
            map.SetGameFolder((PCSTR)path);

            theApp.LogInfo(TEXT("Open game: %s"), (PCTSTR)path);

            UpdateAllViews(NULL, VIEWUPDATEHINT_RESOURCEMAPCHANGED, pFile);
        }
        else
        {
            AfxMessageBox(TEXT("SCI game resources must be called resource.map"), MB_OK | MB_ICONEXCLAMATION);
        }
    }
}
Exemplo n.º 10
0
void CShowPalDoc::Serialize(CArchive& ar)
{
    if (ar.IsStoring()) {
        ASSERT(1); // We don't do this.
    } else {
        // Get the file from the archive.
        CFile* fp = ar.GetFile();
        ASSERT(fp);
        ar.Flush();
        // Load the DIB from the file.
        CDIB dib;
        if (!dib.Load(fp)) {
            AfxMessageBox("Failed to load DIB file");
            return;
        }
        // Create the palette from the DIB.
        if (m_pPal) delete m_pPal;
        m_pPal = new CDIBPal;
        ASSERT(m_pPal);
        if (!m_pPal->Create(&dib)) {
            AfxMessageBox("Failed to create palette from DIB file");
            delete m_pPal;
            m_pPal = NULL;
        }
    }
}
Exemplo n.º 11
0
void CEditView::SerializeRaw( CArchive &ar )
/******************************************/
{
    if( ar.IsStoring() ) {
        int     nLength = ::GetWindowTextLength( m_hWnd );
        LPCTSTR lpszBuffer = LockBuffer();
        if( lpszBuffer != NULL ) {
            ar.Write( lpszBuffer, nLength );
        }
    } else {
        CFile *pFile = ar.GetFile();
        ASSERT( pFile != NULL );

        ULONGLONG   nLength = pFile->GetLength();
        LRESULT     lLimit = ::SendMessage( m_hWnd, EM_GETLIMITTEXT, 0, 0L );
        if( nLength > lLimit ) {
            throw new CArchiveException( CArchiveException::badIndex );
        } else if( nLength == 0LL ) {
            ::SetWindowText( m_hWnd, NULL );
        } else {
            LPTSTR lpszBuffer = new TCHAR[nLength + 1];
            ar.Read( lpszBuffer, (UINT)nLength * sizeof( TCHAR ) );
            lpszBuffer[nLength] = _T('\0');
            ::SetWindowText( m_hWnd, lpszBuffer );
        }
    }
}
Exemplo n.º 12
0
// returns true if archive turns out to be XML
bool IsArchiveXML (CArchive& ar)
  {

  // auto-detect XML files

  char buf [500],     // should be even number of bytes in case Unicode
       buf2 [500];

  memset (buf, 0, sizeof (buf));
  ar.GetFile ()->Read (buf, sizeof (buf) - 2);   // allow for Unicode 00 00
  ar.GetFile ()->SeekToBegin ();  // back to start for further serialisation

  // look for Unicode (FF FE)
  if ((unsigned char) buf [0] == 0xFF &&
      (unsigned char) buf [1] == 0xFE)
    WideCharToMultiByte (CP_UTF8, 0, (LPCWSTR) &buf [2], -1, buf2, sizeof buf2, NULL, NULL);
  else
    // look for UTF-8 indicator bytes (EF BB BF)
    if ((unsigned char) buf [0] == 0xEF &&
        (unsigned char) buf [1] == 0xBB &&
        (unsigned char) buf [2] == 0xBF)
      strcpy (buf2, &buf [3]);   // skip them
  else 
    strcpy (buf2, buf);

  char * p = buf2;

  // skip leading whitespace
  while (isspace (*p))
    p++;

  // can't see them squeezing much into less than 15 chars
  //  (eg. minimum would be <macros></macros> )
  if (strlen (p) < 15)
    return false;

  for (int i = 0; i < NUMITEMS (sigs); i++)
    if (COMPARE_MEMORY (sigs [i]))
      return true;

  return false;

  } // end of IsArchiveXML
Exemplo n.º 13
0
// DIB is stored as a standard Windows bitmap file 
void CDIB::Serialize(CArchive& ar)
{
    ar.Flush();
    CFile *fp = ar.GetFile();

    if (ar.IsStoring()) {
        Save(fp);
    } else {
        Load(fp);
    }
}
Exemplo n.º 14
0
void CmdwEditorDoc::Serialize(CArchive& ar)
{
	POSITION pos = this->GetFirstViewPosition();
	CView* cv = NULL;
	CEditView* pEv = NULL;
	
	do {
		cv = this->GetNextView(pos);
		if( cv != NULL && cv->IsKindOf(RUNTIME_CLASS(CEditView))) {
			pEv = (CEditView*)cv;  
			break;
		}
	} while(cv != NULL);

	if(pEv == NULL) return;

	//CString htmlpath;
	CFile *pCF = ar.GetFile();
	//if(pCF != NULL)
	//	htmlpath = pCF->GetFilePath() + _T(".html");

	if (ar.IsStoring())
	{
		// TODO: add storing code here
		/**
			unicode data 修改後儲存時轉換回 utf-8
			再由sundown 轉換成 html,通知 HtmlView 顯示
		*/
		LPCTSTR lpszText = pEv->LockBuffer();
		ASSERT(lpszText != NULL);
		UINT nLen = pEv->GetBufferLength();
		TRY
		{
			//ar.Write(lpszText, nLen*sizeof(TCHAR));
			getEditText(lpszText, nLen);

			pCF->SeekToBegin();
			pCF->Write(mib_utf8->data, mib_utf8->size);

			m_bHtmlExisted = convMd2Html((LPCTSTR)m_htmlPath, m_cssPath);
			this->UpdateAllViews(NULL, (LPARAM)(LPCTSTR)m_htmlPath, NULL);
		}
		CATCH_ALL(e)
		{
			pEv->UnlockBuffer();
			THROW_LAST();
		}
		END_CATCH_ALL

		pEv->UnlockBuffer();
	}
Exemplo n.º 15
0
void CKaiDoc::Serialize (CArchive& ar)
{
    CFile * pco_file = ar.GetFile();

    ULONGLONG qwLength = pco_file->GetLength();
    if (qwLength > INT_MAX)
    {
        AfxMessageBox (_T("File too long."), MB_ICONEXCLAMATION);
        return;
    }

    bool b_result = true;
    if (ar.IsStoring())
    {
        b_result = pco_Doc_->b_Store (*pco_file);
        if (b_result)
        {
//            SetModifiedFlag(0);
            v_ClearModified();
            pco_Doc_->b_Imported_ = false;
        }
    }
    else
    {
        pco_Doc_->b_Unrenderable_ = false;

        unsigned int ui_version = 0;
        b_result = pco_Doc_->b_CheckDocFormat (*pco_file, ui_version);
        if (b_result)
        {
            b_result = pco_Doc_->b_Load (*pco_file);
        }
        else
        {
            b_result = pco_Doc_->b_ImportTextFile (*pco_file);
            if (b_result)
            {
//                SetModifiedFlag();
                v_SetModified();
            }
            else
            {
                pco_Doc_->b_Unrenderable_ = true;
            }
        }
        if (!b_result)
        {
            AfxMessageBox (_T("Unable to read this file."), MB_ICONEXCLAMATION);
        }
    }
}
Exemplo n.º 16
0
Arquivo: BZDoc.cpp Projeto: tnzk/bz
void CBZDoc::Serialize(CArchive& ar)
{
    MEMORYSTATUS ms;
    GlobalMemoryStatus(&ms);

    CFile *pFile = ar.GetFile();
    ar.Flush();

    if (ar.IsLoading())	{
        // TODO: add loading code here
        m_dwTotal = GetFileLength(pFile);
#ifdef FILE_MAPPING
        if(IsFileMapping()) {
            if(!MapView()) return;
        } else
#endif //FILE_MAPPING
        {
            if(!(m_pData = (LPBYTE)MemAlloc(m_dwTotal))) {
                AfxMessageBox(IDS_ERR_MALLOC);
                return;
            }
            DWORD len = pFile->Read(m_pData, m_dwTotal);
            if(len < m_dwTotal) {
                AfxMessageBox(IDS_ERR_READFILE);
                MemFree(m_pData);	// ###1.61
                m_pData = NULL;
                return;
            }
            m_bReadOnly = options.bReadOnlyOpen;
        }
    } else {
        // TODO: add storing code here
#ifdef FILE_MAPPING
        if(IsFileMapping()) {
            BOOL bResult = (m_pMapStart) ? ::FlushViewOfFile(m_pMapStart, m_dwMapSize) : ::FlushViewOfFile(m_pData, m_dwTotal);
            if(!bResult) {
                ErrorMessageBox();
            }
        } else
#endif //FILE_MAPPING
            pFile->Write(m_pData, m_dwTotal);
        m_dwUndoSaved = m_dwUndo;		// ###1.54
        TouchDoc();
        /*		if(m_pUndo) {
        			MemFree(m_pUndo);
        			m_pUndo = NULL;
        		}
        */
    }
}
Exemplo n.º 17
0
void CPMPTxtDoc::Serialize(CArchive& ar)
{
	CString str;
	if (ar.IsStoring())
	{
		// TODO: add storing code here
		POSITION pos = this->GetFirstViewPosition();
		CPMPTxtView * p_cPMPTxtView = (CPMPTxtView *)this->GetNextView(pos);
		p_cPMPTxtView->m_ctrlRichEdit->GetWindowTextA(str);
		ar.Write(str,str.GetLength());
	}
	else
	{
		// TODO: add loading code here
		m_PathName = ar.m_strFileName;
		m_realfilename = ar.GetFile()->GetFileName();
		long size = 0;
		long filesize =  ar.GetFile()->GetLength();
		// 允许打开一个不超过20M的文本文件
		
		if(ar.GetFile()->GetLength()<=1024*1024*20){
			char * temp = (char * )malloc(sizeof(char)*filesize + 1);
			while(ar.ReadString(m_text)){
				m_text.Append("\n");
				strcpy(temp+size,m_text.GetBuffer(0));
				m_text.ReleaseBuffer();
				size+=m_text.GetLength();
			}
			//m_textContent.Add(temp);
			m_text = temp;
			free(temp);
		}else{
			::MessageBox(NULL,_T("Too large to open"),_T("Message"),MB_OK);
		}
	}
}
Exemplo n.º 18
0
void CSoliDireDoc::Serialize(CArchive& ar)
{
	ar.Flush();
	CFile* fp = ar.GetFile( );
	if (ar.IsStoring())
	{
		if (is_packed() && IsModified())
			pack_added_file(fp);
		else	
			pack_all_file(fp);// pack the file
	}
	else
	{
		read_file(fp);
	}
}
Exemplo n.º 19
0
void CSgviewerDoc::Serialize(CArchive& ar)
{
	CSgviewerApp::getApp().setPause( true );

	if (ar.IsStoring())
	{
		// TODO: add storing code here
	}
	else
	{
		try
		{
			CFile* file = ar.GetFile();
			if ( file )
			{
				Texture::flushTextures();

				CString pathstr = file->GetFilePath();
				String path = (const char*)pathstr;
				String dir = File(path).getParent();
				P(DirectoryInputStreamArchive) arch = new DirectoryInputStreamArchive;
				arch->addPath( dir );

				P(ModelFileCache) modelcache = new ModelFileCache( arch );
				P(SceneFile) sf = new SceneFile( path, modelcache, arch );
				modelcache->clear();
				scene = sf->scene();
				name = path;
				cube1 = cube2 = 0;

				prepareDoc();
			}
		}
		catch ( Throwable& e )
		{
			char buf[1000];
			e.getMessage().format().getBytes( buf, sizeof(buf), "ASCII-7" );
			if ( CSgviewerApp::getApp().m_pMainWnd )
				CSgviewerApp::getApp().m_pMainWnd->MessageBox( buf, "Error - sgviewer", MB_OK|MB_ICONERROR|MB_SYSTEMMODAL );
			else
				MessageBox( 0, buf, "Error - sgviewer", MB_OK|MB_ICONERROR|MB_SYSTEMMODAL );
		}
	}

	CSgviewerApp::getApp().setPause( false );
}
Exemplo n.º 20
0
LPSTREAM AFXAPI _AfxGetArchiveStream(CArchive& ar, CArchiveStream& stm)
{
	// Obtain direct access to the archive's LPSTREAM.
	ar.Flush();
	CFile* pFile = ar.GetFile();
	ASSERT(pFile != NULL);
	LPSTREAM pstm;
	if (pFile->IsKindOf(RUNTIME_CLASS(COleStreamFile)))
	{
		pstm = ((COleStreamFile*)pFile)->m_lpStream;
		ASSERT(pstm != NULL);
	}
	else
	{
		ASSERT(stm.m_pArchive == NULL || stm.m_pArchive == &ar);
		stm.m_pArchive = &ar;
		pstm = &stm;
	}
	return pstm;
}
Exemplo n.º 21
0
void CPLYEditorDoc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		// TODO: add storing code here
	}
	else
	{
		// TODO: add loading code here
		CFile* cfile = ar.GetFile();
		
		CString filename = cfile->GetFilePath(); // return full path and filename
									  //::MessageBox(0, filename, L"Hello", MB_OK);
		char fn[200];
		strcpy(fn, CStringA(filename).GetString());
		Mesh* m = readFile(fn);
		theApp.AddToRecentFileList(filename.GetString());
		this->LMesh.push_back(m);
		this->UpdateAllViews(NULL);
	}
}
Exemplo n.º 22
0
void CMorphwizardDoc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
	}
	else
	{
	   	// ask username
		CDlgLogin dlgLogin;
		if( dlgLogin.DoModal() != IDOK )
			throw CExpc("No login information");

		CGriIni cIni;
		cIni.Init();
		CWizardProgressMeter meter(m_Wizard);
		bool ret = GetWizard()->load_wizard(ar.GetFile()->GetFilePath(), dlgLogin.m_name);
		
		SetInputLanguage(GetWizard()->m_Language);

		cIni.Exit();
	}
}
Exemplo n.º 23
0
void CStorageDoc::Serialize (CArchive& ar) {
	CString strCaption = "aIm DIAS Storage v. 2.0";
	if (ar.IsStoring ()) {
		ar << strCaption;
		ar << m_nDimX << m_nDimY << m_nBPP << m_nChannels << (ubyte)m_nColorModel;
		ar << (ubyte)m_blAcceptFromView << (ubyte)m_blForceSettings;
		ar << (ubyte)m_blShowImages << (ubyte)m_blShowPatches << (ubyte)m_blShowMarks << (ubyte)m_blShowMeters;
		ar << (ubyte)m_blImgVRuler << (ubyte)m_blImgHRuler << (ubyte)m_blImgGrid << (ubyte)m_blRptVRuler << (ubyte)m_blRptHRuler << (ubyte)m_blRptGrid;
		ar << m_nImgZoom << m_nRptZoom;
		ar << m_rectPlacement << m_nPanelWidth << m_nPanelActive << (ubyte)m_blShowNames;
		ar << m_nImgNo << m_nDataNo << m_nRptNo;
		Images.Serialize (ar);
		Surveis.Serialize (ar);
		// #### TODO: Add Reports serialization here
	} else {
		DeleteContents ();
		m_strName = ar.GetFile()->GetFileTitle ();
		ar >> strCaption;
		if (strCaption != "aIm DIAS Storage v. 2.0") {
			MessageBox (theApp.m_pMainWnd->m_hWnd, theApp.LoadString (IDS_ERR_DOC_VERSION), theApp.LoadString (IDS_ERR_DOC), MB_OK | MB_ICONERROR);
			return;
		}
		(int&)m_nColorModel = 0;
		ar >> m_nDimX >> m_nDimY >> m_nBPP >> m_nChannels >> (ubyte&)m_nColorModel;
		ar >> (ubyte&)m_blAcceptFromView >> (ubyte&)m_blForceSettings;
		ar >> (ubyte&)m_blShowImages >> (ubyte&)m_blShowPatches >> (ubyte&)m_blShowMarks >> (ubyte&)m_blShowMeters;
		ar >> (ubyte&)m_blImgVRuler >> (ubyte&)m_blImgHRuler >> (ubyte&)m_blImgGrid >> (ubyte&)m_blRptVRuler >> (ubyte&)m_blRptHRuler >> (ubyte&)m_blRptGrid;
		ar >> m_nImgZoom >> m_nRptZoom;
		ar >> m_rectPlacement >> m_nPanelWidth >> m_nPanelActive >> (ubyte&)m_blShowNames;
		ar >> m_nImgNo >> m_nDataNo >> m_nRptNo;
		Images.m_pDoc = this;
		Surveis.m_pDoc = this;
		Images.Serialize (ar);
		Surveis.Serialize (ar);
		UpdateAll ();
		// #### TODO: Add Reports serialization here
	}
}
Exemplo n.º 24
0
void CEditView::SerializeRaw(CArchive& ar)
	// Read/Write object as stand-alone file.
{
	ASSERT_VALID(this);
	if (ar.IsStoring())
	{
		WriteToArchive(ar);
	}
	else
	{
		CFile* pFile = ar.GetFile();
		ASSERT(pFile->GetPosition() == 0);
		DWORD nFileSize = pFile->GetLength();
		if (nFileSize/sizeof(TCHAR) > nMaxSize)
		{
			AfxMessageBox(AFX_IDP_FILE_TOO_LARGE);
			AfxThrowUserException();
		}
		// ReadFromArchive takes the number of characters as argument
		ReadFromArchive(ar, (UINT)nFileSize/sizeof(TCHAR));
	}
	ASSERT_VALID(this);
}
Exemplo n.º 25
0
void CDrawDoc::Serialize(CArchive& ar)
{

	if (ar.IsStoring())
	{
		// Save non-text objects into EMF format for printing
		if (!StoreForPrinting(ar))
			{
			// write empty header
			SEPFILEHEADER header;
			memset(&header, 0, sizeof(SEPFILEHEADER));
			ar.Write(&header, sizeof(SEPFILEHEADER));
			}

		// Save other document contents
		ar << m_paperColor;
		m_objects.Serialize(ar);
	}
	else
	{
		// skip the spooler-time structure
		CFile* pfile = ar.GetFile();
		if (pfile == NULL) return;
		SEPFILEHEADER header;
		pfile -> Read(&header, sizeof(SEPFILEHEADER));
		pfile -> Seek(header.dwEmfSize + header.dwTextRecords * sizeof(TEXTBOX), CFile::current);
		
		// get the visual objects
		ar >> m_paperColor;
		m_objects.Serialize(ar);
	}

	// By calling the base class COleDocument, we enable serialization
	//  of the container document's COleClientItem objects automatically.
	COleDocument::Serialize(ar);
}
void CvoronoiDoc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		// TODO: 在此添加存储代码
		if (img.IsNull())
		{
			AfxMessageBox(_T("No file to be saved!"));
		}
		else{
			
			CString strFilter;
			strFilter="位图文件|*.bmp|JPEG 图像文件|*.jpg|GIF 图像文件|*.gif|PNG 图像文件|*.png||"; 
			CFileDialog dlg(FALSE,NULL,NULL,NULL,strFilter);
			if (IDOK !=dlg.DoModal())
			 return;

			//如果保存时为指定扩展名,则添加一个
			CString strFileName;
			CString strExtension;

			strFileName=dlg.m_ofn.lpstrFile;
			if (dlg.m_ofn.nFileExtension!=0)
			{
				switch (dlg.m_ofn.nFilterIndex)
				{
				case 1:
					strExtension="BMP";
					break;
				case 2:
					strExtension="JPG";
					break;
				case 3:
					strExtension="GIF";
					break;
				case 4:
					strExtension="PNG";
					break;
				default:

					break;
				}
			strFileName =strFileName+_T(".")+strExtension;
			}
			//图像保存
			HRESULT hReslt=img.Save(strFileName);
			if (FAILED(hReslt))
			{
				AfxMessageBox(_T("Save File failed!Sorry~"));
			}
		}
	}
	else
	{
		// TODO: 在此添加加载代码
		if (!img.IsNull())
		{
			img.Destroy();
		}
		else
			img.Load(ar.GetFile()->GetFilePath());
	}
}
Exemplo n.º 27
0
BOOL CEasyBDoc::ReadFilePLL(CArchive& ar) 
{	
	const int DealDataLen = 772;   // number of bytes for a deal
	// read in the file
	CString strBuf;
	int nSize = ar.GetFile()->GetLength();
	PBYTE pBuf = (PBYTE) strBuf.GetBuffer(nSize);
	int numBytesRead = ar.Read(pBuf, nSize);
	ASSERT(numBytesRead == nSize);

    // Check first 2 bytes
	if(pBuf[0] != 0x01 || pBuf[1] != 0x04) {
		AfxMessageBox("The File is not in PLL format.");
		AfxThrowFileException(CFileException::generic);
	}

	int nbrDeals = numBytesRead / DealDataLen;
	if(nbrDeals > 1) {
		AfxMessageBox("EasyBridge currently only reads first deal.");
	}
	// Ok, now parse the hands - we'll only get the first deal
	pGameRecord = new CGameRecord;
	
	const int FirstByte = 48;  // first byte of hands
	int dealer = pBuf[FirstByte + 32]; // 0=N, 1=E, 2=S, 3=W
	const Position PPL2EB[] = {NORTH, EAST, SOUTH, WEST};
	dealer = PPL2EB[dealer];  // convert
	pGameRecord->m_nDealer = dealer;  // save

	int vulner = pBuf[FirstByte + 33];
	CString theDeal[4][4];      // hands and suits
	const int bb[] = {1,2,4,8,16,32,64,128}; // bit test masks
	const char * LowFaceValue[] = {"2", "3", "4", "5", "6", "7", "8", "9"};
	const char * HighFaceValue[] = {"T", "J", "Q", "K", "A"};

	for(int jj = 0; jj < 16; jj++) {
		char byte1 = pBuf[FirstByte+(jj*2)+1];  // High card flags T-A
		char byte2 = pBuf[FirstByte+(jj*2)+0];  // Low card flags 2-9 
		int handIdx = jj / 4;
		int suitIdx = 3 - (jj % 4);
		// First get the High cards from byte1
    	int kk; // NCR-FFS added here, removed below
		for(/*int*/ kk = 4; kk >=0; kk--) {
			if((byte1 & bb[kk]) != 0)
				theDeal[handIdx][suitIdx] += HighFaceValue[kk];
		} // end for(kk) thru High card byte
		// now the low cards
		for(kk = 7; kk >=0; kk--) {
			if((byte2 & bb[kk]) != 0)
				theDeal[handIdx][suitIdx] += LowFaceValue[kk];
		} // end for(kk) thru Low card byte

	} // end jj

	// Now build the deal a la PBN
	CString aDeal = "N:";
	for (int i = 0; i < 4; i++) {
		aDeal += theDeal[i][0] + "." +theDeal[i][1] + "." +theDeal[i][2] + "." +theDeal[i][3] 
			      + ((i < 3) ? " " : "");  // nothing at the end
    }
/*
	// Hard code for testing
	pGameRecord->m_nDealer = NORTH; //SOUTH=0, WEST=1, NORTH=2, EAST=3,
	pGameRecord->m_nVulnerability = EAST_WEST; //NEITHER=-1, NORTH_SOUTH=0, EAST_WEST=1, BOTH=2
	// Following deal from N-Sbid1H_Make4H.pbn
	CString aDeal = "S:KQ62.Q97.K765.52 94.AKJ4.Q92.JT97 875.852.AJT3.K63 AJT3.T63.84.AQ84";

	// Following from EasyBridgeGame2.pbn   hand order: W N E S
//	CString aDeal = "W:6.A852.KT43.Q965 A532.94.AJ85.A74 KQJ87.3.Q62.KT83 T94.KQJT76.97.J2";
//	pGameRecord->m_nDealer = EAST; //SOUTH=0, WEST=1, NORTH=2, EAST=3,
*/
	pGameRecord->SetTagValue("DEAL", aDeal);  //NOTE ALL CAPS for Keys!!! <<<<<<
	pGameRecord->SetTagValue("BOARD", "1");   // Hardcoded value ???

//	AssignCardsPBN(aDeal);  // use this method
//	theApp.SetValue(tbGameInProgress, FALSE);

	pGameRecord->AnalyzePlayRecord();
//	if(pGameRecord->IsValid()) {  // this only for PBN
		m_gameRecords.Add(pGameRecord);
//	}

	return TRUE;
}
Exemplo n.º 28
0
//
// PreloadPBNFile()
//
// - preload the PBN file and strip comments
//
int CEasyBDoc::PreloadPBNFile(CArchive& ar, CStringArray& strLines)
{
	int numLinesRead = 0;
	strLines.RemoveAll();

	// read in the file
	CString strBuf;
	int nSize = ar.GetFile()->GetLength();
	PBYTE pBuf = (PBYTE) strBuf.GetBuffer(nSize);
	int numBytesRead = ar.Read(pBuf, nSize);
	ASSERT(numBytesRead == nSize);
	strBuf.ReleaseBuffer(nSize);

	// check for export tag
	int nPos = strBuf.Find(_T("% EXPORT"));
	if (nPos < 0)   // NCR_PBNI allow as first line (was < 1)
	{
		AfxMessageBox("The Files is not in PBN Export format.");
//		AfxThrowFileException(CFileException::generic);
		isExportFile = false;  // NCR_PBNI Not export file - fewer tags required
	}

	// remove comments
	nPos = strBuf.Find(_T('{'));
	while(nPos >= 0)
	{
		// see if this comment started a new line
		bool bNewLine = false;
		if ((nPos > 0) && ((strBuf[nPos-1] == _T('\n')) || (strBuf[nPos-1] == _T('\r'))))
			bNewLine = true;

		// find the end of the comment section
		CString strMid = strBuf.Mid(nPos);
		int nEnd = strMid.Find(_T('}'));
		ASSERT(nEnd >= 0);

		// search for the next nonspace character
		nEnd++;
		int nLen = strMid.GetLength();
		// NCR test if comment at end of file
		if(nLen == nEnd)
			break;		// NCR exit if at end
		while ((nEnd < nLen) && (_istspace(strMid[nEnd])))
			nEnd++;

		// and trim and re-combine
		if ((nEnd < nLen) && (strMid[nEnd] == _T('[')) && !bNewLine)
			strBuf = strBuf.Left(nPos) + _T('\n') + strMid.Mid(nEnd);
		else
			strBuf = strBuf.Left(nPos) + strMid.Mid(nEnd);
		nPos = strBuf.Find(_T('{'));
	} // end while() removing comment

	// remove '!' suffixes
	strBuf.Remove(_T('!'));

	// remove any question marks that are not preceded by a quote character
	// '?' characters may be used in tag values as well as used for quality ratings
	for(int i=0;i<strBuf.GetLength();i++)
	{
		if ((i > 0) && (strBuf[i] == _T('?')) && (strBuf[i-1] != _T('\"')))
		{
			strBuf = strBuf.Left(i) + strBuf.Mid(i+1);
			i--;
		}
	}

	// organize into lines
	int nLen, nIndex = -1;
	BOOL bEmptyLineAdded = FALSE;
	do
	{
		// locate the end of the current line
		nLen = strBuf.GetLength();
		nIndex = -1;
		for(int i=0;i<nLen;i++)
		{
			if ((strBuf[i] == _T('\r')) || (strBuf[i] == _T('\n')))
			{
				nIndex = i;
				break;
			}
		}
		// add the line if not empty
		if (nIndex >= 0)
		{
			// add the string if it's not a comment
			if (strBuf[0] != _T('%'))
			{
				// test for an empty line by removing whitespace
				CString strTest = strBuf.Left(nIndex);
				strTest.TrimLeft();
				if (strTest.IsEmpty())
				{
					if (!bEmptyLineAdded)
					{
						strLines.Add(_T(""));
						bEmptyLineAdded = TRUE;
						numLinesRead++;
					}
				}
				else
				{
					// it's a nonblank line
					// trim any rest-of-line comments
					int nPos = strTest.Find(_T(';'));
					if (nPos >= 0)
						strTest = strTest.Left(nPos);

					// and add the line
					strLines.Add(strTest);
					bEmptyLineAdded = FALSE;
					numLinesRead++;
				}
			}

			// and skip over the CF/LF pair
			int nCharCount = 0;
			while ( (nIndex < nLen) && ((strBuf[nIndex] == _T('\r')) || (strBuf[nIndex] == _T('\n'))) )
			{
				nIndex++;
				nCharCount++;
			}

			// if more than one CR/LF pair (or two LF's) was found, add an empty line
			if ( ( (nCharCount > 2) || ((nIndex >= 2) && (strBuf[nIndex-1] == _T('\n')) && (strBuf[nIndex-2] == _T('\n'))) ) && 
				   (!bEmptyLineAdded))
			{
				strLines.Add(_T(""));
				numLinesRead++;
				bEmptyLineAdded = TRUE;
			}

			// chop off the part of the string that was read
			if (nIndex < nLen)
			{
				strBuf = strBuf.Mid(nIndex);
			}
			else
			{
				// reached the end of file
				strBuf.Empty();
				// add an empty line just to make sure
				strLines.Add(_T(""));
				numLinesRead++;
				bEmptyLineAdded = TRUE;
			}
		}
	}
	while ((nIndex >= 0) && !strBuf.IsEmpty());

	// done
	return numLinesRead;
}
Exemplo n.º 29
0
void CResourceMapDoc::Serialize(CArchive& ar)
{
    if (ar.IsStoring())
    {
        // There is nothing to save.
        int x = 0;
    }
    else
    {
        CFile *pFile = ar.GetFile();

        // Set the current directory, so we know where to look for the resource files.
        // If not, clicking on an item in the recent documents list won't work
        CString path = pFile->GetFilePath();
        path.MakeLower();
        int iFileOffset = path.Find(TEXT("\\resource.map"));
        if (iFileOffset > 0)
        {
            path.SetAt(iFileOffset, 0); // Null terminate it

            // Set this folder as our new game folder
            CResourceMap &map = theApp.GetResourceMap();
            map.SetGameFolder(path);

            // Close it.  We only wanted the path.
            pFile->Close();

            // Clear the current view.
            _DeleteAllResourceData();
            _DeleteAllPics();

            CResourceEnumerator *pEnum;
            if (SUCCEEDED(map.CreateEnumerator(RTF_PIC, &pEnum)))
            {
                CResourceData *pData;
                while (S_OK == pEnum->Next(&pData))
                {
                    // TODO: try catch, and free pData?

                    // Add these resource datas.
                    _resources.Add(pData);

                    // And create a pic from them.
                    CPic *ppic = new CPic();
                    if (ppic)
                    {
                        if (SUCCEEDED(ppic->InitFromResource(pData)))
                        {
                            _pics.Add(ppic);
                        }
                        else
                        {
                            delete ppic;
                        }
                    }
                }

#ifdef DEBUG
                INT_PTR iSizeMemory = 0;
                for (INT_PTR i = 0; i < _pics.GetSize(); i++)
                {
                    CPic *ppic = _pics.GetAt(i);
                    iSizeMemory += ppic->GetMemorySize();
                }
                TCHAR sz[MAX_PATH];
                StringCchPrintf(sz, ARRAYSIZE(sz), TEXT("Memory size of pics: %d"), iSizeMemory);
                OutputDebugString(sz);
#endif 

                SetModifiedFlag(TRUE);
                UpdateAllViews(NULL, VIEWUPDATEHINT_RESOURCEMAPCHANGED);

                delete pEnum;
            }

        }
        else
        {
            AfxMessageBox(TEXT("SCI game resources must be called resource.map"), MB_OK | MB_ICONEXCLAMATION);
        }
    }
}
Exemplo n.º 30
0
// COpenHoldemDoc serialization
void COpenHoldemDoc::Serialize(CArchive& ar) 
{
	// Extra caution, in case we want to load a formula,
	// while the autoplayer is engaged.
	// This currently can only happen via the MRU-list.
	// The alternative way would be to disable that list...
	//
	// MainFrame.cpp:
	// ON_UPDATE_COMMAND_UI_RANGE(ID_FILE_MRU_FILE1, ID_FILE_MRU_FILE16, &CMainFrame::OnUpdateLRUList)
	//
	// void CMainFrame::OnUpdateLRUList(CCmdUI *pCmdUI)
	// {
	//	pCmdUI->Enable(!p_autoplayer->autoplayer_engaged());
	// }
	//
	// Unfortunatelly this does not work, 
	// but removes the list and replaces it once with the default: "Recent file".
	//
	// And there's very little information about both
	// ON_UPDATE_COMMAND_UI_RANGE and temporary disabling of MRU-lists.
	//
	// So we decided to go that route.
	//
	if (p_autoplayer->autoplayer_engaged())
	{
		// This error can happen only in interactive mode,
		// so there's no need to turn that Messagebox off
		// depending on prefs.disable_msgbox()
		OH_MessageBox("Can't load a formula while autoplayer engaged.", "ERROR", 0);
		return;
	}
	CMainFrame		*pMyMainWnd  = (CMainFrame *) (theApp.m_pMainWnd);

	// Writing a file
	if (ar.IsStoring()) 
	{
		// Store archive in the new OpenHoldem format
		bool use_new_OHF_format = !IsWinHoldemFormat(ar.GetFile()->GetFileName());
		p_formula->WriteFormula(ar);
		// Do not close this archive here.
		// It's expected to stay open at this point!
		if (IsWinHoldemFormat(ar.GetFile()->GetFileName())) 
		{	
			// If the file was in the old WHF format,
			// store it also in the new OHF format.
			CString the_new_FileName = GetPathName();
			the_new_FileName.Replace("whf", "ohf");		
			// Notification
			OH_MessageBox_Interactive("Converting file formats\n{whf, whx} -> {ohf}",
				"File Conversion", MB_OK | MB_ICONINFORMATION);	
			// Open new style formula (OHF)	
			CFile OHF_File;
			OHF_File.Open(the_new_FileName, CFile::modeCreate | CFile::modeWrite);
			CArchive OHF_Archive(&OHF_File, CArchive::store);
			// Write new style formula (OHF) in any case
			p_formula->WriteFormula(OHF_Archive);
			// Close archive and file
			OHF_Archive.Close();
			OHF_File.Close();		
		}
	}
	// Reading a file
	else 
	{
		// Kill the formula dialog, if it is open
		if(m_formulaScintillaDlg) 
		{
			delete m_formulaScintillaDlg;
			m_formulaScintillaDlg	=	NULL;
			pMyMainWnd->m_MainToolBar.GetToolBarCtrl().CheckButton(ID_MAIN_TOOLBAR_FORMULA, false);
		}

		// Read ohf / whf file
		ReadFormula(ar);
		SetModifiedFlag(false);

		p_formula->set_formula_name(ar.GetFile()->GetFileName());

		// Try to unload dll
		p_dll_extension->UnloadDll();

		// Create hand list matrices
		p_formula->CreateHandListMatrices();

		// Create parse trees for newly loaded formula
		p_formula->ParseAllFormula(pMyMainWnd->GetSafeHwnd(), prefs.disable_msgbox());

		// Load dll, if set in preferences
		if (prefs.dll_load_on_startup())
			p_dll_extension->LoadDll("");
		if (prefs.simple_window_title() && theApp.m_pMainWnd)
			theApp.m_pMainWnd->PostMessage(WMA_SETWINDOWTEXT, 0, (LPARAM)NULL);
	}
}