void CMUSHclientDoc::Serialize_World_XML (CArchive& ar) { if (ar.IsStoring()) { CPlugin * pSavedPlugin = m_CurrentPlugin; m_CurrentPlugin = NULL; // make sure we save main triggers etc. try { // ensure world has an ID if (m_strWorldID.IsEmpty ()) m_strWorldID = GetUniqueID (); Save_World_XML (ar, (unsigned long) ~0); // save all options // ensure all plugins save their state right now :) for (PluginListIterator pit = m_PluginList.begin (); pit != m_PluginList.end (); ++pit) (*pit)->SaveState (); } // end of try catch (CException *) { m_CurrentPlugin = pSavedPlugin; throw; } m_CurrentPlugin = pSavedPlugin; } else { // loading Load_World_XML (ar, (unsigned long) ~(XML_PLUGINS | XML_NO_PLUGINS | XML_PASTE_DUPLICATE | XML_IMPORT_MAIN_FILE_ONLY)); // load all options, except plugins m_bLoaded = true; // this world has been loaded from disk } } // end of CMUSHclientDoc::Serialize_World_XML
BOOL CMUSHclientDoc::Save_Set (const int set_type, CWnd * parent_window) { CString suggested_name = m_mush_name, filter, title, suggested_extension; CFile * f = NULL; CArchive * ar = NULL; BOOL error = TRUE; CString sig; CString filename; if (Set_Up_Set_Strings (set_type, suggested_name, filter, title, suggested_extension)) return TRUE; // bad set_type CFileDialog filedlg (FALSE, // saving the file suggested_extension, // default extension "", // suggested name OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, filter, // filter parent_window); // parent window // fix up name to remove characters that are invalid int i; while ((i = suggested_name.FindOneOf ("<>\"|?:#%;/\\")) != -1) suggested_name = suggested_name.Left (i) + suggested_name.Mid (i + 1); 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 CPlugin * pSavedPlugin = m_CurrentPlugin; m_CurrentPlugin = NULL; // make sure we save main triggers etc. try { f = new CFile (filedlg.GetPathName (), CFile::modeCreate | CFile::modeReadWrite); ar = new CArchive(f, CArchive::store); switch (set_type) { case TRIGGER: Save_World_XML (*ar, XML_TRIGGERS); break; case ALIAS: Save_World_XML (*ar, XML_ALIASES); break; case COLOUR: Save_World_XML (*ar, XML_COLOURS); break; case MACRO: Save_World_XML (*ar, XML_MACROS); break; case TIMER: Save_World_XML (*ar, XML_TIMERS); break; } // end of switch error = FALSE; } // end of try block catch (CFileException * e) { ::TMessageBox ("Unable to create the requested file", 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) { ::TMessageBox ("There was a problem in the data format", MB_ICONEXCLAMATION); e->Delete (); } // end of catching an archive exception m_CurrentPlugin = pSavedPlugin; delete ar; // delete archive delete f; // delete file return error; // OK return } // end of CMUSHclientDoc::save_set