BOOL CSoliDireDoc::OnSaveDocument(LPCTSTR lpszPathName) { CFileException fe; CFile* pFile = NULL; DWORD nFlags = CFile::modeReadWrite | CFile::shareExclusive; if (!is_packed()) nFlags |= CFile::modeCreate; pFile = GetFile(lpszPathName, nFlags, &fe); if (pFile == NULL) { ReportSaveLoadException(lpszPathName, &fe, TRUE, AFX_IDP_INVALID_FILENAME); return FALSE; } CArchive saveArchive(pFile, CArchive::store | CArchive::bNoFlushOnDelete); saveArchive.m_pDocument = this; saveArchive.m_bForceFlat = FALSE; CWaitCursor wait; Serialize(saveArchive); // save me saveArchive.Close(); ReleaseFile(pFile, FALSE); SetModifiedFlag(FALSE); // back to unmodified return TRUE; // success }
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 }
bool WebArchiveAndroid::saveWebArchive(xmlTextWriterPtr writer) { const char* const defaultXmlVersion = 0; const char* const defaultEncoding = 0; const char* const defaultStandalone = 0; int result = xmlTextWriterStartDocument(writer, defaultXmlVersion, defaultEncoding, defaultStandalone); if (result < 0) { LOGD("saveWebArchive: Failed to start document."); return false; } if (!saveArchive(writer, this)) return false; result = xmlTextWriterEndDocument(writer); if (result< 0) { LOGD("saveWebArchive: Failed to end document."); return false; } return true; }
static bool saveArchive(xmlTextWriterPtr writer, PassRefPtr<Archive> archive) { int result = xmlTextWriterStartElement(writer, archiveTag); if (result < 0) { LOGD("saveArchive: Failed to start element."); return false; } result = xmlTextWriterStartElement(writer, mainResourceTag); if (result < 0) { LOGD("saveArchive: Failed to start element."); return false; } if (!saveArchiveResource(writer, archive->mainResource())) return false; result = xmlTextWriterEndElement(writer); if (result < 0) { LOGD("saveArchive: Failed to end element."); return false; } result = xmlTextWriterStartElement(writer, subresourcesTag); if (result < 0) { LOGD("saveArchive: Failed to start element."); return false; } for (Vector<const RefPtr<ArchiveResource> >::iterator subresource = archive->subresources().begin(); subresource != archive->subresources().end(); subresource++) { if (!saveArchiveResource(writer, *subresource)) return false; } result = xmlTextWriterEndElement(writer); if (result < 0) { LOGD("saveArchive: Failed to end element."); return false; } result = xmlTextWriterStartElement(writer, subframesTag); if (result < 0) { LOGD("saveArchive: Failed to start element."); return false; } for (Vector<const RefPtr<Archive> >::iterator subframe = archive->subframeArchives().begin(); subframe != archive->subframeArchives().end(); subframe++) { if (!saveArchive(writer, *subframe)) return false; } result = xmlTextWriterEndElement(writer); if (result < 0) { LOGD("saveArchive: Failed to end element."); return true; } return true; }