void CBoxHolder::Serialize(CArchive &ar) { CBox* box=NULL; int n; CString st; CObject::Serialize(ar); if (ar.IsStoring()){ n=m_Children.GetSize(); ar << n; for (int i=0; i<n; i++){ box=GetBox(i); st=box->Signature(); if (st=="") st=box->ClassName(); TRACE("Serialize Class Name: %s\n", st); ar << st; box->Serialize(ar); } } else{ ar >> n; for (int i=0; i<n; i++){ ar >> st; box=CFactory::instance(st); if (box==NULL) AfxThrowArchiveException(CArchiveException::generic,""); box->Serialize(ar); AddBox(box); } } }
void COXChildFrameState::Serialize(CArchive& ar) { ASSERT_VALID(this); // Check the version // (If version == -1, the version is unknown, this occurs when Serialize() is called directly) if (ar.IsLoading()) { m_nSerializeSchemaVersionLoad = (int)ar.GetObjectSchema(); if (m_nSerializeSchemaVersion < m_nSerializeSchemaVersionLoad) { TRACE1("COXChildFrameState::Serialize : Unexpected schema version : %i, throwing CArchiveException\n", m_nSerializeSchemaVersionLoad); AfxThrowArchiveException(CArchiveException::badSchema); } } // Call base class implementation CObject::Serialize(ar); // Serialize all data if (ar.IsStoring()) StoreProperties(ar); else LoadProperties(ar); ASSERT_VALID(this); }
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); } }
void CRectItem::Serialize(CArchive& ar) { CRect rect; // IMPORTANT: when using "easy" serialize -- call base class FIRST! // (not strictly necessary, but a good idea) COleClientItem::Serialize(ar); // now store/retrieve data specific to CRectItem if (ar.IsStoring()) { WORD w = 0x5500; // magic value ar << w << m_ptPos << m_sizeIcon << m_sizeIconExtent << m_sizeContent << m_sizeContentExtent; } else { WORD w; ar >> w >> m_ptPos >> m_sizeIcon >> m_sizeIconExtent >> m_sizeContent >> m_sizeContentExtent; if (w != 0x5500) { TRACE0("Bad magic number in front of an item wnd\n"); AfxThrowArchiveException(CArchiveException::genericException); } } }
void CProject::Serialize(CArchive& ar) { if (ar.IsStoring()) { ar << ARCHIVE_SIG; ar << m_Version; StoreHistory(ar); ar << m_HistPos; ar << m_ThumbSize; StoreBool(ar, m_CycleColors); ar << m_ColorCycleRate; } else { UINT sig; ar >> sig; ar >> m_Version; if (sig != ARCHIVE_SIG || m_Version > ARCHIVE_VERSION) AfxThrowArchiveException(CArchiveException::badIndex, ar.m_strFileName); LoadHistory(ar); ar >> m_HistPos; ar >> m_ThumbSize; LoadBool(ar, m_CycleColors); ar >> m_ColorCycleRate; } m_RecInfo.Serialize(ar); m_Snapshot.Serialize(ar); }
void CXTPTaskPanelItems::DoPropExchange(CXTPPropExchange* pPX) { m_pPanel->SetLockRedraw(TRUE); try { pPX->m_dwData = (DWORD_PTR)m_pPanel; CXTPPropExchangeEnumeratorPtr pEnumerator(pPX->GetEnumerator(_T("Item"))); POSITION pos = pEnumerator->GetPosition(GetCount()); if (pPX->IsStoring()) { for (int i = 0; i < GetCount(); i++) { CXTPTaskPanelItem* pItem = GetAt(i); CXTPPropExchangeSection sec(pEnumerator->GetNext(pos)); PX_Object(&sec, pItem, GetDefaultItemClass()); } } else { Clear(FALSE); while (pos) { CXTPTaskPanelItem* pItem = NULL; CXTPPropExchangeSection sec(pEnumerator->GetNext(pos)); PX_Object(&sec, pItem, GetDefaultItemClass()); if (!pItem) AfxThrowArchiveException(CArchiveException::badClass); pItem->m_pItems = this; pItem->OnInserted(); m_arrItems.Add(pItem); } } } catch (COleException* pEx) { TRACE(_T("CXTPTaskPanelItems::Serialize. OLE exception: %x\r\n"), pEx->m_sc); pEx->Delete (); } catch (CArchiveException* pEx) { TRACE(_T("CXTPTaskPanelItems::Serialize. Archive exception\r\n")); pEx->Delete (); } m_pPanel->SetLockRedraw(FALSE); }
inline SimpleFragment SerializeIn(CArchive& ar, int version) { try { if ( version >= 29 ) { u64 begin, length; ar >> begin >> length; if ( begin + length < begin ) AfxThrowArchiveException( CArchiveException::generic ); return SimpleFragment( begin, begin + length ); } else { u32 begin, length; ar >> begin >> length; if ( begin + length < begin ) AfxThrowArchiveException( CArchiveException::generic ); return SimpleFragment( begin, begin + length ); } }
void CGXGridCellData::Serialize(CArchive& ar) { static const WORD wVersion = 1; WORD wActualVersion = wVersion; ASSERT_VALID(this); if (ar.IsStoring()) { ar << wVersion; } else { // Check for version first ar >> wActualVersion; if( wActualVersion != wVersion ) { // Wrong version #ifdef _DEBUG TRACE0( "Incompatible format while reading CGXGridCellData" ); TRACE2("in %s at line %d\n", THIS_FILE, __LINE__); ASSERT(0); // ASSERTION-> Incompatible format while reading CGXData object ->END #endif AfxThrowArchiveException(CArchiveException::badSchema); return; } } if (ar.IsStoring()) { if ( m_bSingleMode && m_pDefCaptionStyle ) { m_pDefCaptionStyle->Serialize ( ar ); // ar << m_pDefCaptionStyle; return; } ar << m_nRows, ar << m_nCols; } else { // loading if ( m_bSingleMode && m_pDefCaptionStyle ) { m_pDefCaptionStyle->Serialize ( ar ); // ar >> m_pDefCaptionStyle; return; } ar >> m_nRows, ar >> m_nCols; } m_apapCellStyle.Serialize(ar); }
void CXTPFlowGraphPages::DoPropExchange(CXTPPropExchange* pPX) { CXTPPropExchangeEnumeratorPtr pEnumRecords(pPX->GetEnumerator(_T("Page"))); if (pPX->IsStoring()) { int nCount = (int)GetCount(); POSITION pos = pEnumRecords->GetPosition((DWORD)nCount); for (int i = 0; i < nCount; i++) { CXTPFlowGraphPage* pPage = GetAt(i); ASSERT(pPage); CXTPPropExchangeSection sec(pEnumRecords->GetNext(pos)); PX_Object(&sec, pPage, RUNTIME_CLASS(CXTPFlowGraphPage)); BOOL bActive = m_pControl->GetActivePage() == pPage; PX_Bool(&sec, _T("Active"), bActive, FALSE); } } else { RemoveAll(); POSITION pos = pEnumRecords->GetPosition(); CXTPFlowGraphPage* pActivePage = NULL; while (pos) { CXTPFlowGraphPage* pPage = NULL; CXTPPropExchangeSection sec(pEnumRecords->GetNext(pos)); if (!sec->ExchangeObjectInstance((CObject*&)pPage, RUNTIME_CLASS(CXTPFlowGraphPage))) AfxThrowArchiveException(CArchiveException::badClass); pPage->m_pControl = m_pControl; pPage->DoPropExchange(&sec); m_arrPages.Add(pPage); BOOL bActive = FALSE; PX_Bool(&sec, _T("Active"), bActive, FALSE); if (bActive) pActivePage = pPage; } m_pControl->SetActivePage(pActivePage); } }
void CEditView::ReadFromArchive(CArchive& ar, UINT nLen) // Read certain amount of text from the file, assume at least nLen // characters (not bytes) are in the file. { ASSERT_VALID(this); LPVOID hText = LocalAlloc(LMEM_MOVEABLE, (nLen+1)*sizeof(TCHAR)); if (hText == NULL) AfxThrowMemoryException(); LPTSTR lpszText = (LPTSTR)LocalLock(hText); ASSERT(lpszText != NULL); if (ar.Read(lpszText, nLen*sizeof(TCHAR)) != nLen*sizeof(TCHAR)) { LocalUnlock(hText); LocalFree(hText); AfxThrowArchiveException(CArchiveException::endOfFile); } // Replace the editing edit buffer with the newly loaded data lpszText[nLen] = '\0'; #ifndef _UNICODE if (afxData.bWin32s) { // set the text with SetWindowText, then free BOOL bResult = ::SetWindowText(m_hWnd, lpszText); LocalUnlock(hText); LocalFree(hText); // make sure that SetWindowText was successful if (!bResult || ::GetWindowTextLength(m_hWnd) < (int)nLen) AfxThrowMemoryException(); // remove old shadow buffer delete[] m_pShadowBuffer; m_pShadowBuffer = NULL; m_nShadowSize = 0; ASSERT_VALID(this); return; } #endif LocalUnlock(hText); HLOCAL hOldText = GetEditCtrl().GetHandle(); ASSERT(hOldText != NULL); LocalFree(hOldText); GetEditCtrl().SetHandle((HLOCAL)(UINT)(DWORD)hText); Invalidate(); ASSERT_VALID(this); }
void CRecordInfo::Serialize(CArchive& ar) { if (ar.IsStoring()) { ar << ARCHIVE_VERSION; ar << sizeof(RECORD_INFO); ar.Write(&GetBaseInfo(), sizeof(RECORD_INFO)); } else { int Version; ar >> Version; if (Version > ARCHIVE_VERSION) AfxThrowArchiveException(CArchiveException::badIndex, ar.m_strFileName); int BaseInfoSize; ar >> BaseInfoSize; ar.Read(&GetBaseInfo(), BaseInfoSize); } }
void CJobList::Serialize(CArchive& ar) { if (ar.IsStoring()) { ar << ARCHIVE_SIG; ar << m_Version; m_Info.Serialize(ar); ar << m_NextID; } else { int sig; ar >> sig; ar >> m_Version; if (sig != ARCHIVE_SIG || m_Version > ARCHIVE_VERSION) AfxThrowArchiveException(CArchiveException::badIndex, ar.m_strFileName); m_Info.Serialize(ar); ar >> m_NextID; } }
void COleDocument::SaveToStorage(CObject* pObject) { ASSERT(m_lpRootStg != NULL); // create Contents stream COleStreamFile file; CFileException fe; if (!file.CreateStream(m_lpRootStg, _T("Contents"), CFile::modeReadWrite|CFile::shareExclusive|CFile::modeCreate, &fe)) { if (fe.m_cause == CFileException::fileNotFound) AfxThrowArchiveException(CArchiveException::badSchema); else AfxThrowFileException(fe.m_cause, fe.m_lOsError); } // save to Contents stream CArchive saveArchive(&file, CArchive::store | CArchive::bNoFlushOnDelete); saveArchive.m_pDocument = this; saveArchive.m_bForceFlat = FALSE; TRY { // save the contents if (pObject != NULL) pObject->Serialize(saveArchive); else Serialize(saveArchive); saveArchive.Close(); file.Close(); // commit the root storage SCODE sc = m_lpRootStg->Commit(STGC_ONLYIFCURRENT); if (sc != S_OK) AfxThrowOleException(sc); } CATCH_ALL(e) { file.Abort(); // will not throw an exception CommitItems(FALSE); // abort save in progress NO_CPP_EXCEPTION(saveArchive.Abort()); THROW_LAST(); } END_CATCH_ALL }
void COptionsInfo::Serialize(CArchive& ar) { CEngineOptions::Serialize(ar); // serialize base class if (ar.IsStoring()) { ar << ARCHIVE_VERSION; ar << sizeof(OPTIONS_INFO); ar.Write(&GetBaseInfo(), sizeof(OPTIONS_INFO)); ar << m_MidiDevName; } else { int Version; ar >> Version; if (Version > ARCHIVE_VERSION) AfxThrowArchiveException(CArchiveException::badIndex, ar.m_strFileName); int BaseInfoSize; ar >> BaseInfoSize; ar.Read(&GetBaseInfo(), BaseInfoSize); ar >> m_MidiDevName; } }
void CXTPRibbonControlTab::DoPropExchange(CXTPPropExchange* pPX) { if (pPX->IsStoring()) { long nCount = (long)m_arrItems.GetSize(); int i; CXTPPropExchangeEnumeratorPtr pEnumerator(pPX->GetEnumerator(_T("Tab"))); POSITION posEnum = pEnumerator->GetPosition(nCount, FALSE); for (i = 0; i < nCount; i++) { CXTPRibbonTab* pTab = (CXTPRibbonTab*)GetItem(i); CXTPPropExchangeSection secItem(pEnumerator->GetNext(posEnum)); PX_Object(&secItem, pTab, RUNTIME_CLASS(CXTPRibbonTab)); } } else { CXTPPropExchangeEnumeratorPtr pEnumerator(pPX->GetEnumerator(_T("Tab"))); POSITION posEnum = pEnumerator->GetPosition(0, FALSE); DeleteAllItems(); while (posEnum) { CXTPPropExchangeSection secItem(pEnumerator->GetNext(posEnum)); secItem->m_pOwner = this; CXTPRibbonTab* pTab = NULL; PX_Object(&secItem, pTab, RUNTIME_CLASS(CXTPRibbonTab)); if (!pTab) AfxThrowArchiveException(CArchiveException::badClass); AddItem(GetItemCount(), pTab); } } }
void CEditView::Serialize(CArchive& ar) // Read and write CEditView object to archive, with length prefix. { ASSERT_VALID(this); ASSERT(m_hWnd != NULL); if (ar.IsStoring()) { UINT nLen = GetBufferLength(); ar << (DWORD)nLen; WriteToArchive(ar); } else { DWORD dwLen; ar >> dwLen; if (dwLen > nMaxSize) AfxThrowArchiveException(CArchiveException::badIndex); UINT nLen = (UINT)dwLen; ReadFromArchive(ar, nLen); } ASSERT_VALID(this); }
void COleDocument::LoadFromStorage() { ASSERT(m_lpRootStg != NULL); // open Contents stream COleStreamFile file; CFileException fe; if (!file.OpenStream(m_lpRootStg, _T("Contents"), CFile::modeRead|CFile::shareExclusive, &fe) && !file.CreateStream(m_lpRootStg, _T("Contents"), CFile::modeRead|CFile::shareExclusive|CFile::modeCreate, &fe)) { if (fe.m_cause == CFileException::fileNotFound) AfxThrowArchiveException(CArchiveException::badSchema); else AfxThrowFileException(fe.m_cause, fe.m_lOsError); } // load it with CArchive (loads from Contents stream) CArchive loadArchive(&file, CArchive::load | CArchive::bNoFlushOnDelete); loadArchive.m_pDocument = this; loadArchive.m_bForceFlat = FALSE; TRY { if (file.GetLength() != 0) Serialize(loadArchive); // load main contents loadArchive.Close(); file.Close(); } CATCH_ALL(e) { file.Abort(); // will not throw an exception DeleteContents(); // removed failed contents NO_CPP_EXCEPTION(loadArchive.Abort()); THROW_LAST(); } END_CATCH_ALL }
void CXTPReportColumns::DoPropExchange(CXTPPropExchange* pPX) { int nItemIndex; CString strInternalName; if (pPX->IsStoring()) { int nCount = GetCount(); CXTPPropExchangeEnumeratorPtr pEnumerator(pPX->GetEnumerator(_T("Column"))); POSITION pos = pEnumerator->GetPosition(nCount, FALSE); for (int nColumn = 0; nColumn < nCount; nColumn++) { CXTPReportColumn* pColumn = GetAt(nColumn); CXTPPropExchangeSection secColumn(pEnumerator->GetNext(pos)); nItemIndex = pColumn->GetItemIndex(); strInternalName = pColumn->GetInternalName(); PX_Int(&secColumn, _T("ItemIndex"), nItemIndex); PX_String(&secColumn, _T("InternalName"), strInternalName); pColumn->DoPropExchange(&secColumn); } } else { CXTPPropExchangeEnumeratorPtr pEnumerator(pPX->GetEnumerator(_T("Column"))); POSITION pos = pEnumerator->GetPosition(0, FALSE); CXTPReportColumn tmpColumn(0, _T(""), 0); int i = 0; while (pos) { CXTPPropExchangeSection secColumn(pEnumerator->GetNext(pos)); CXTPReportColumn* pColumn = NULL; PX_Int(&secColumn, _T("ItemIndex"), nItemIndex, -1); if (pPX->GetSchema() > _XTP_SCHEMA_1100) { PX_String(&secColumn, _T("InternalName"), strInternalName); if (!strInternalName.IsEmpty()) { pColumn = Find(strInternalName); if (!pColumn && pPX->GetSchema() < _XTP_SCHEMA_1500) // before 15.0 release internal name was equal to caption { for (int nColumn = 0; nColumn < GetCount(); nColumn++) { CXTPReportColumn* p = GetAt(nColumn); if (p->GetCaption() == strInternalName) { pColumn = p; break; } } } // column data is exists but column is not in the collection. if (!pColumn) { // just read data to skeep (to be safe for array serialization) tmpColumn.DoPropExchange(&secColumn); continue; } } } if (!pColumn) pColumn = Find(nItemIndex); if (!pColumn) AfxThrowArchiveException(CArchiveException::badIndex); pColumn->DoPropExchange(&secColumn); ChangeColumnOrder(i, IndexOf(pColumn)); i++; } } CXTPPropExchangeSection secGroupsOrder(pPX->GetSection(_T("GroupsOrder"))); m_pGroupsOrder->DoPropExchange(&secGroupsOrder); CXTPPropExchangeSection secSortOrder(pPX->GetSection(_T("SortOrder"))); m_pSortOrder->DoPropExchange(&secSortOrder); }
void CGXGridCellStylePtrArrayPtrArray::Serialize(CArchive& ar) { // Serializes only existing elements, // e.g. 1 xxx 2 xxx 3 xxx 7 xxx 22 xxx DWORD_MAX, // where xxx is a CGXGridCellStylePtrArray object and DWORD_MAX identifies the end of serialization static const WORD wVersion = 1; WORD wActualVersion = wVersion; ASSERT_VALID(this); if (ar.IsStoring()) { ar << wVersion; } else { // Check for version first ar >> wActualVersion; if( wActualVersion != wVersion ) { // Wrong version #ifdef _DEBUG TRACE0( "Incompatible format while reading CGXGridCellStylePtrArrayPtrArray " ); TRACE2("in %s at line %d\n", THIS_FILE, __LINE__); ASSERT(0); // ASSERTION-> Incompatible format while reading CGXGridCellStylePtrArrayPtrArray object ->END #endif AfxThrowArchiveException(CArchiveException::badSchema); return; } } const DWORD dwTerm = 0xFFFFFFFF; if (ar.IsStoring()) { // storing DWORD dwSize = (DWORD)GetSize(); ar << dwSize; for (int index = 0; index <= GetUpperBound(); index++) { CGXGridCellStylePtrArray* pStylePtrArray = GetAt(index); if (pStylePtrArray) { ar << (DWORD) index; pStylePtrArray->Serialize(ar); } } ar << dwTerm; } else { // loading DeleteAll(); DWORD dwSize; ar >> dwSize; SetSize((int) dwSize); DWORD dwIndex; ar >> dwIndex; while (dwIndex != dwTerm) { CGXGridCellStylePtrArray* pStylePtrArray = new CGXGridCellStylePtrArray; pStylePtrArray->Serialize(ar); SetAt((int) dwIndex, pStylePtrArray); // Next id ar >> dwIndex; } } }
// ************************************************************************** // Serialize () // // Description: // Save or load project settings. // // Parameters: // CArchive &ar The archive to save or load project settings. // // Returns: // void // ************************************************************************** void CKDocument::Serialize (CArchive &ar) { // Be prepared to catch exceptions: try { // Save project: if (ar.IsStoring ()) { // Save the number of server object first so we will know how // many to load later: ar << m_cdwServers; // Now serialize each server object. Start with head of linked // list and work our way to end: CKServer *pServer = m_pServerHead; // Keep looping until we hit end of linked list, indicated by // a NULL pointer: while (pServer) { // Serialize server object: pServer->Serialize (ar); // Get pointer to next server in linked list: pServer = pServer->GetNext (); } } // Else load project: else { // First get the number of servers to load: DWORD cdwServers; ar >> cdwServers; // Loop over servers: for (DWORD dwIndex = 0; dwIndex < cdwServers; dwIndex++) { // Create a reusable pointer to a CKServer object: CKServer *pServer = NULL; // Instantiate a new CKServer object: pServer = new CKServer (); // Load it's settings from archive: pServer->Serialize (ar); // Add the server to the project: AddServer (pServer); } } } // Catch archive exceptions. Any object exceptions thrown will be // self-deleted by the object so we do not have to worry about memory // leaks at this outer-level. catch (CArchiveException *ae) { // Make a copy of the cause of the exception before we delete it: int nCause = ae->m_cause; // Delete the exception: ae->Delete (); // Re-throw the exception to be processed by the framework: AfxThrowArchiveException (nCause); } // Catch any other kind of excetion and re-throw it to be processed // by the framework: catch (...) { AfxThrowArchiveException (CArchiveException::generic); } }
void CUSBLogView::OnEditPaste(void) { if(!IsClipboardFormatAvailable(GetApp().m_uClipboardFormat)) { TRACE("OnEditPaste(): no suitable clipboard format available!\n"); return; } // we need a focused URB as well... int nFocusedURB = m_Log.FindFocusedURB(); if(-1 == nFocusedURB) { nFocusedURB = 0; } if(!AfxGetMainWnd()->OpenClipboard()) { TRACE("Error while opening clipboard!\n"); return; } // from here on, we have to close the clipboard // before exiting this function, otherwise other // applications might not get a chance to copy/paste // stuff! HANDLE hBinary = NULL; PVOID pData = NULL; try { hBinary = GetClipboardData(GetApp().m_uClipboardFormat); if(NULL == hBinary) { AfxThrowNotSupportedException(); } pData = GlobalLock(hBinary); { CMyMemFile memFile(pData); CArchive ar(&memFile, CArchive::load); DWORD dwVersion = ar.ReadCount(); if(_VERSION_DWORD_ != dwVersion) { AfxThrowNotSupportedException(); } DWORD nURBCnt = ar.ReadCount(); TRACE("Pasting %d URBs...\n", nURBCnt); CUSBLogDoc *pDoc = GetDocument(); int nInsertLocation = nFocusedURB; while(0 < nURBCnt) { CRuntimeClass *pClass = ar.ReadClass(); if(!pClass->IsDerivedFrom(RUNTIME_CLASS(CURB))) { TRACE("unknown runtime class!\n"); AfxThrowArchiveException(CArchiveException::badClass); } CURB *pURB = (CURB*) pClass->CreateObject(); ASSERT(NULL != pURB); pURB->SetChunkAllocator(&pDoc->m_arURB.m_ChunkAllocator); pURB->Serialize(ar); pDoc->m_arURB.InsertAt(nInsertLocation, pURB); nInsertLocation++; --nURBCnt; } pDoc->UpdateAllViews(NULL, 1); OnEditSelectNone(); m_Log.SetFocusedURB(nFocusedURB); } GlobalUnlock(hBinary); hBinary = NULL; CloseClipboard(); } catch(...) { if((NULL != pData) && (NULL != hBinary)) { GlobalUnlock(hBinary); } CloseClipboard(); throw; } }
// ************************************************************************** // Serialize () // // Description: // Save or load server properties. // // Parameters: // CArchive &ar The archive to save or load server properties. // // Returns: // void // ************************************************************************** void CKServer::Serialize (CArchive &ar) { // Save server properties: if (ar.IsStoring ()) { ////////////////////////////// // Save archive properties // ////////////////////////////// // Output current archive version. If we add server properties that // must be made persistent, then we will have to update the archive // version so we know how to read the additional data. ar << CURRENT_VERSION; ////////////////////////////// // Save server properties // ////////////////////////////// // Output info about associated OPC Server: ar << m_strProgID << m_strRemoteMachine; // Output flags in bit field: ar.Write (&m_bfFlags, sizeof (m_bfFlags)); // Output number of groups so we will know how many block of group // data follows when we read this archive later: ar << m_cdwGroups; ////////////////////////////////// // Serialize all of our groups // ////////////////////////////////// //Start with head of linked list: CKGroup *pGroup = m_pGroupHead; // Keep looping we hit the end of the link list (where pGroup will be NULL): while (pGroup) { // Call group's serialize function so that it can add its properties // to the archive: pGroup->Serialize (ar); // Process next group next time around: pGroup = pGroup->GetNext (); } } // Load server properties: else { DWORD dwSchema; DWORD dwIndex; ////////////////////////////// // Load archive properties // ////////////////////////////// ar >> dwSchema; // dwSchema is really the archive version. switch (dwSchema) { case VERSION_1: ////////////////////////////// // Load server properties // ////////////////////////////// // Input info about associated OPC Server: ar >> m_strProgID >> m_strRemoteMachine; // Input flags in bit field: ar.Read (&m_bfFlags, sizeof (m_bfFlags)); // Input number of groups so we will know how many block of group // data follows: ar >> m_cdwGroups; ////////////////////////////////// // Serialize all of our groups // ////////////////////////////////// // Start with an empty linked list: ASSERT (m_pGroupHead == NULL); // Loop over expected number of groups: for (dwIndex = 0; dwIndex < m_cdwGroups; dwIndex++) { CKGroup *pGroup = NULL; // Wrap group serialization with exception handler in case // there is a problem, such as bad archive version etc. try { // Instantiate a new CKGroup (with this server as it's parent): pGroup = new CKGroup (this); // Call the group's serialize function so that it can read // its properties from the archive: pGroup->Serialize (ar); // New groups are added to the head of the linked list. // That means new the groups's "next" group is old head of list, pGroup->SetNext (m_pGroupHead); // and the new group is the old head of list's "previous" group, if (m_pGroupHead) m_pGroupHead->SetPrev (pGroup); // and that new group is now the new "head" of list. m_pGroupHead = pGroup; } catch (...) { // There was a problem reading group properties. Delete // this object and throw another exception. This exception // must be handled by the calling function. delete this; AfxThrowArchiveException (CArchiveException::generic); } } break; default: // Unexpected archive version. Delete this object and // throw an exception that indicates this. This exception // must be handled by the calling function. delete this; AfxThrowArchiveException (CArchiveException::badSchema); break; } } }
BOOL CMUSHclientDoc::Load_Set (const int set_type, CString strFileName, CWnd * parent_window) { BOOL replace = TRUE; if (strFileName.IsEmpty ()) { CString suggested_name = m_mush_name, filter, title, suggested_extension; CString filename; if (Set_Up_Set_Strings (set_type, suggested_name, filter, title, suggested_extension)) return TRUE; // bad set_type CFileDialog filedlg (TRUE, // loading the file suggested_extension, // default extension "", // suggested name OFN_HIDEREADONLY | OFN_FILEMUSTEXIST, filter, // filter parent_window); // parent window filedlg.m_ofn.lpstrTitle = title; filedlg.m_ofn.lpstrFile = filename.GetBuffer (_MAX_PATH); // needed!! (for Win32s) if (App.platform == VER_PLATFORM_WIN32s) strcpy (filedlg.m_ofn.lpstrFile, ""); else strcpy (filedlg.m_ofn.lpstrFile, suggested_name); ChangeToFileBrowsingDirectory (); int nResult = filedlg.DoModal(); ChangeToStartupDirectory (); if (nResult!= IDOK) return TRUE; // cancelled dialog // since they can have any number of triggers, aliases and timers, ask them // whether they want to add this file to an existing list (if any) if (set_type == TRIGGER && !m_TriggerMap.IsEmpty ()) { if (::TMessageBox ("Replace existing triggers?\n" "If you reply \"No\", then triggers from the file" " will be added to existing triggers", MB_YESNO | MB_ICONQUESTION) == IDNO) replace = FALSE; } else if (set_type == ALIAS && !m_AliasMap.IsEmpty ()) { if (::TMessageBox ("Replace existing aliases?\n" "If you reply \"No\", then aliases from the file" " will be added to existing aliases", MB_YESNO | MB_ICONQUESTION) == IDNO) replace = FALSE; } else if (set_type == TIMER && !m_TimerMap.IsEmpty ()) { if (::TMessageBox ("Replace existing timers?\n" "If you reply \"No\", then timers from the file" " will be added to existing timers", MB_YESNO | MB_ICONQUESTION) == IDNO) replace = FALSE; } strFileName = filedlg.GetPathName (); } // end of no filename suppliedl CFile * f = NULL; CArchive * ar = NULL; try { f = new CFile (strFileName, CFile::modeRead | CFile::shareDenyWrite); ar = new CArchive(f, CArchive::load); if (IsArchiveXML (*ar)) { switch (set_type) { case TRIGGER: if (replace) DELETE_MAP (m_TriggerMap, CTrigger); Load_World_XML (*ar, XML_TRIGGERS | XML_NO_PLUGINS); break; case ALIAS: if (replace) DELETE_MAP (m_AliasMap, CAlias); Load_World_XML (*ar, XML_ALIASES | XML_NO_PLUGINS); break; case COLOUR: Load_World_XML (*ar, XML_COLOURS | XML_NO_PLUGINS); break; case MACRO: Load_World_XML (*ar, XML_MACROS | XML_NO_PLUGINS); break; case TIMER: if (replace) DELETE_MAP (m_TimerMap, CTimer); Load_World_XML (*ar, XML_TIMERS | XML_NO_PLUGINS); break; } // end of switch } // end of XML load else { ::TMessageBox ("File does not have a valid MUSHclient XML signature.", MB_ICONSTOP); AfxThrowArchiveException (CArchiveException::badSchema); } // end of not XML } // end of try block // even on an exception we will return a "good" status, because the triggers etc. // may well have been deleted by now, so we need to redraw the lists catch (CFileException * e) { ::UMessageBox (TFormat ("Unable to open or read %s", (LPCTSTR) strFileName), MB_ICONEXCLAMATION); e->Delete (); } // end of catching a file exception catch (CMemoryException * e) { ::TMessageBox ("Insufficient memory to do this operation", MB_ICONEXCLAMATION); e->Delete (); } // end of catching a memory exception catch (CArchiveException * e) { ::UMessageBox (TFormat ("The file %s is not in the correct format", (LPCTSTR) strFileName), MB_ICONEXCLAMATION); e->Delete (); } // end of catching an archive exception delete ar; // delete archive delete f; // delete file SetModifiedFlag (TRUE); // document has now changed return false; // OK return } // end of CMUSHclientDoc::load_set
void CXTPReportRecord::DoPropExchange(CXTPPropExchange* pPX) { PX_Bool(pPX, _T("Locked"), m_bLocked); PX_Bool(pPX, _T("Editable"), m_bEditable); BOOL bPreview = m_pPreviewItem != NULL; PX_Bool(pPX, _T("Preview"), bPreview); int nCount = GetItemCount(); CXTPPropExchangeEnumeratorPtr pEnumItems(pPX->GetEnumerator(_T("Item"))); if (pPX->IsStoring()) { POSITION posItem = pEnumItems->GetPosition((DWORD)nCount); for (int i = 0; i < nCount; i++) { CXTPReportRecordItem* pItem = GetItem(i); ASSERT(pItem); if (!pItem) AfxThrowArchiveException(CArchiveException::badClass); CXTPPropExchangeSection secItem(pEnumItems->GetNext(posItem)); PX_Object(&secItem, pItem, RUNTIME_CLASS(CXTPReportRecordItem)); } } else { RemoveAll(); POSITION posItem = pEnumItems->GetPosition(); while (posItem) { CXTPReportRecordItem* pItem = NULL; CXTPPropExchangeSection sec(pEnumItems->GetNext(posItem)); PX_Object(&sec, pItem, RUNTIME_CLASS(CXTPReportRecordItem)); if (!pItem) AfxThrowArchiveException(CArchiveException::badClass); AddItem(pItem); } } //------------------------------------------------------------ if (bPreview) { CXTPPropExchangeSection secPreviewItem(pPX->GetSection(_T("PreviewItem"))); if (pPX->IsLoading()) { CMDTARGET_RELEASE(m_pPreviewItem); } PX_Object(&secPreviewItem, m_pPreviewItem, RUNTIME_CLASS(CXTPReportRecordItemPreview)); if (m_pPreviewItem && pPX->IsLoading()) { m_pPreviewItem->m_pRecord = this; } } //------------------------------------------------------------ if (pPX->GetSchema() > _XTP_SCHEMA_1041) { BOOL bHasChildren = HasChildren(); PX_Bool(pPX, _T("HasChildren"), bHasChildren, FALSE); if (bHasChildren) { CXTPPropExchangeSection secChildren(pPX->GetSection(_T("Children"))); GetChilds()->_DoPropExchange(&secChildren); } else if (m_pChildren) { m_pChildren->RemoveAll(); } } }