示例#1
0
long CMUSHclientDoc::ImportXML(LPCTSTR XML) 
{
long iCount = 0;

  CMemFile f ((unsigned char *)  XML, strlen (XML));
  CArchive ar (&f, CArchive::load);

    try
    {

    if (IsArchiveXML (ar))
      {

      UINT iTriggers = 0;
      UINT iAliases = 0;
      UINT iTimers = 0;
      UINT iMacros = 0;
      UINT iVariables = 0;
      UINT iColours = 0;
      UINT iKeypad = 0;
      UINT iPrinting = 0;

      // do it
      Load_World_XML (ar, 
                      // don't load plugins or general world config here  (note, this sets XML_OVERWRITE)
                      (unsigned long) ~(XML_PLUGINS | XML_NO_PLUGINS | XML_GENERAL), 
                      0,          // load flags
                      &iTriggers,  
                      &iAliases,   
                      &iTimers,    
                      &iMacros,    
                      &iVariables, 
                      &iColours,   
                      &iKeypad,    
                      &iPrinting);  

      iCount =  iTriggers +  
                iAliases +   
                iTimers +    
                iMacros +    
                iVariables + 
                iColours +   
                iKeypad +    
                iPrinting;  

      }
    else
      iCount = -1;    // not in XML

     } // end of try block
  catch (CArchiveException* ) 
    {
    iCount = -1;    // error parsing XML
    }

	return iCount;
}  // end of CMUSHclientDoc::ImportXML
示例#2
0
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 
示例#3
0
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