Skip to content

Commit

Permalink
Fixed bug where saving new worlds would not go to worlds directory
Browse files Browse the repository at this point in the history
  • Loading branch information
nickgammon committed Sep 2, 2010
1 parent 1e85109 commit 8de0b53
Showing 1 changed file with 16 additions and 26 deletions.
42 changes: 16 additions & 26 deletions doc.cpp
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 8de0b53

Please sign in to comment.