void CActivityDoc::OnFileOpen() { #ifdef _DEBUG // ListAccelerators (this, 4); // for documenting menus, accelerators #endif CString title; VERIFY(title.LoadString(AFX_IDS_OPENFILE)); CString fileName; CFileDialog dlgFile (TRUE, // loading the file "mcl", // default extension "", // suggested name OFN_HIDEREADONLY | OFN_FILEMUSTEXIST, "World or text files (*.mcl;*.txt)|*.mcl;*.txt|All files (*.*)|*.*||", // filter NULL); // parent window dlgFile.m_ofn.lpstrTitle = title; dlgFile.m_ofn.lpstrFile = fileName.GetBuffer(_MAX_PATH); // use default world file directory dlgFile.m_ofn.lpstrInitialDir = Make_Absolute_Path (App.m_strDefaultWorldFileDirectory); ChangeToFileBrowsingDirectory (); int nResult = dlgFile.DoModal(); ChangeToStartupDirectory (); fileName.ReleaseBuffer(); if (nResult != IDOK) return; App.OpenDocumentFile (dlgFile.m_ofn.lpstrFile); }
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
BOOL CMUSHclientDoc::OnNewDocument() { if (!CDocument::OnNewDocument()) return FALSE; SetDefaults (false); // set up numeric/boolean defaults SetAlphaDefaults (false); // set up alpha defaults if (App.m_TypeOfNewDocument == App.eNormalNewDocument) // only ask on normal new world { int i = ::TMessageBox ("Preload world defaults from an existing world?", MB_YESNOCANCEL | MB_ICONQUESTION); if (i == IDCANCEL) return FALSE; if (i == IDYES) while (TRUE) // loop until successful read of file, or cancel { // Get file CString strFilter(MAKEINTRESOURCE(IDS_OPEN_WORLD_FILTER)); CString strTitle(MAKEINTRESOURCE(IDS_OPEN_WORLD_TITLE)); CFileDialog dlg(TRUE, // TRUE for FileOpen NULL, // default extension NULL, // no initial file name OFN_HIDEREADONLY|OFN_FILEMUSTEXIST, strFilter); dlg.m_ofn.lpstrTitle = strTitle; // use default world file directory dlg.m_ofn.lpstrInitialDir = Make_Absolute_Path (App.m_strDefaultWorldFileDirectory); ChangeToFileBrowsingDirectory (); int nResult = dlg.DoModal(); ChangeToStartupDirectory (); if (nResult != IDOK) break; CString strFileName = dlg.GetPathName(); CWaitCursor wait; try { // Open existing world file CFile fileWorld(strFileName, CFile::modeRead|CFile::shareDenyWrite); CArchive ar(&fileWorld, CArchive::load); try { Serialize (ar); } catch(CException* e) { ::TMessageBox ("Unexpected file format - invalid world file", MB_ICONEXCLAMATION); e->Delete(); ar.Close(); continue; } ar.Close(); } catch(CException* e) { ::TMessageBox ("Unable to open world file", MB_ICONEXCLAMATION); e->Delete(); continue; } // if we got here, we successfully loaded the world! SetModifiedFlag (); m_strWorldID = GetUniqueID (); // new world ID break; } // end of preloading defaults } // end of normal new world // if defaults are wanted, overwrite what we loaded with them :) if (m_bLoaded) OnFileReloaddefaults (); else { if (!App.m_strDefaultColoursFile.IsEmpty ()) { m_bUseDefaultColours = true; Load_Set (COLOUR, App.m_strDefaultColoursFile, &Frame); } if (!App.m_strDefaultTriggersFile.IsEmpty ()) { m_bUseDefaultTriggers = true; Load_Set (TRIGGER, App.m_strDefaultTriggersFile, &Frame); } if (!App.m_strDefaultAliasesFile.IsEmpty ()) { m_bUseDefaultAliases = true; Load_Set (ALIAS, App.m_strDefaultAliasesFile, &Frame); } if (!App.m_strDefaultTimersFile.IsEmpty ()) { m_bUseDefaultTimers = true; Load_Set (TIMER, App.m_strDefaultTimersFile, &Frame); } if (!App.m_strDefaultMacrosFile.IsEmpty ()) { m_bUseDefaultMacros = true; Load_Set (MACRO, App.m_strDefaultMacrosFile, &Frame); } if (!App.m_strDefaultInputFont.IsEmpty ()) { m_bUseDefaultInputFont = true; m_input_font_height = App.m_iDefaultInputFontHeight; m_input_font_name = App.m_strDefaultInputFont; m_input_font_italic = App.m_iDefaultInputFontItalic; m_input_font_weight = App.m_iDefaultInputFontWeight; m_input_font_charset = App.m_iDefaultInputFontCharset; } // end of input font override if (!App.m_strDefaultOutputFont.IsEmpty ()) { m_bUseDefaultOutputFont = true; m_font_height = App.m_iDefaultOutputFontHeight; m_font_name = App.m_strDefaultOutputFont; m_font_weight = FW_NORMAL; m_font_charset = App.m_iDefaultOutputFontCharset; } // end of output font override } // end of not loading an existing world m_bLoaded = false; // not really loaded - effectively a new world // get name and IP address, give up if cancelled if (App.m_TypeOfNewDocument == App.eQuickConnect) // pop up nice simple dialog box { CQuickConnectDlg dlg; dlg.m_iPort = 4000; dlg.m_strWorldName = "Untitled world"; dlg.m_strAddress = ""; if (dlg.DoModal () != IDOK) return FALSE; m_server = dlg.m_strAddress; m_port = dlg.m_iPort; m_mush_name = dlg.m_strWorldName; // save auto connect flag, then set to true, to make sure we connect unsigned int savebAutoConnectWorlds = App.m_bAutoConnectWorlds; App.m_bAutoConnectWorlds = TRUE; SetUpOutputWindow (); OpenSession (); App.m_bAutoConnectWorlds = savebAutoConnectWorlds; SetModifiedFlag (); return TRUE; } // end of quick connect if (App.m_TypeOfNewDocument == App.eTelnetFromNetscape) // just do it { // get rid of telnet stuff CString strCommandLine = ::Replace (App.m_lpCmdLine, "telnet://", ""); int iSpace = strCommandLine.FindOneOf (" :"); if (iSpace == -1) { m_server = strCommandLine; m_mush_name = strCommandLine; m_port = 23; } else { m_server = strCommandLine.Left (iSpace); m_mush_name = m_server; m_port = atoi (strCommandLine.Mid (iSpace + 1)); } // save auto connect flag, then set to true, to make sure we connect unsigned int savebAutoConnectWorlds = App.m_bAutoConnectWorlds; App.m_bAutoConnectWorlds = TRUE; SetUpOutputWindow (); OpenSession (); App.m_bAutoConnectWorlds = savebAutoConnectWorlds; SetModifiedFlag (); return TRUE; } // end of telnet called from netscape navigator // we have to do this *before* getting the preferences SetUpOutputWindow (); if (!GamePreferences (ePageGeneral)) return FALSE; if(m_mush_name.IsEmpty ()) { ::TMessageBox("Your world name cannot be blank.", MB_ICONEXCLAMATION); return FALSE; } if(m_server.IsEmpty ()) { ::TMessageBox("The world TCP/IP address cannot be blank.", MB_ICONEXCLAMATION); return FALSE; } OpenSession (); return TRUE; }
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