From 8de0b5303404fe5cef8362b8c28a5be9cee70154 Mon Sep 17 00:00:00 2001 From: Nick Gammon Date: Fri, 3 Sep 2010 09:46:57 +1000 Subject: [PATCH] Fixed bug where saving new worlds would not go to worlds directory --- doc.cpp | 42 ++++++++++++++++-------------------------- 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/doc.cpp b/doc.cpp index 35282a6f..0052e337 100644 --- a/doc.cpp +++ b/doc.cpp @@ -4886,54 +4886,44 @@ CString str; // we do our own DoSave, because the default one stops at the first space BOOL CMUSHclientDoc::DoSave(LPCTSTR lpszPathName, BOOL bReplace) { - CString newName = lpszPathName; + CString strNewName; // empty name - possibly caused by "save as" - if (newName.IsEmpty ()) + if (lpszPathName == NULL || lpszPathName [0] == 0) { - // if we know the path name, suggest that, otherwise take the mush name - newName = m_strPathName; - if (bReplace && newName.IsEmpty()) + // if we know the path name, suggest that, otherwise take the MUD name + strNewName = m_strPathName; + if (bReplace && strNewName.IsEmpty()) { - newName = m_mush_name; + strNewName = m_mush_name; // fix up name to remove characters that are invalid int i; - while ((i = newName.FindOneOf ("<>\"|?:#%;/\\")) != -1) - newName = newName.Left (i) + newName.Mid (i + 1); + while ((i = strNewName.FindOneOf ("<>\"|?:#%;/\\")) != -1) + strNewName = strNewName.Left (i) + strNewName.Mid (i + 1); + CString strFixedName = Make_Absolute_Path (App.m_strDefaultWorldFileDirectory); + strFixedName += strNewName; + + strNewName = strFixedName; } // end of no path name known CDocTemplate* pTemplate = GetDocTemplate(); ASSERT(pTemplate != NULL); - // save in default world directory - int iCount; - CString strDirectory; - - // find length of current directory - iCount = GetCurrentDirectory (0, NULL); - // get current directory - GetCurrentDirectory (iCount, strDirectory.GetBuffer (iCount)); - strDirectory.ReleaseBuffer (-1); - // change to world directory - SetCurrentDirectory (Make_Absolute_Path (App.m_strDefaultWorldFileDirectory)); - // save world details - - BOOL bResult = AfxGetApp()->DoPromptFileName(newName, + BOOL bResult = AfxGetApp()->DoPromptFileName(strNewName, AFX_IDS_SAVEFILE, OFN_HIDEREADONLY | OFN_PATHMUSTEXIST, FALSE, pTemplate); - // change back to current directory - SetCurrentDirectory (strDirectory); - if (!bResult) return FALSE; // don't even attempt to save } // end of no path name supplied + else + strNewName = lpszPathName; // execute "save" script if (m_ScriptEngine) @@ -4974,7 +4964,7 @@ BOOL CMUSHclientDoc::DoSave(LPCTSTR lpszPathName, BOOL bReplace) m_CurrentPlugin = pSavedPlugin; - BOOL bSuccess = CDocument::DoSave (newName, bReplace); + BOOL bSuccess = CDocument::DoSave (strNewName, bReplace); if (bSuccess) m_bVariablesChanged = false;