From 8f20e65167ef9b2bb3a04a026fb4db8440b78ba6 Mon Sep 17 00:00:00 2001 From: "v.audacity" Date: Tue, 28 Sep 2010 05:03:50 +0000 Subject: [PATCH] (bug 20, P2) Fix auto-recovery failures that Gale reported, when auto-recovered projects had been saved to top-level directories, e.g., "E:\dtmf.aup" on Windows. Problem was with file separators. This DirManager code is quite convoluted, touched by multiple chefs, and called from many places, so this fix does not correct the origination(s) of the problem, but doesn't break anything higher up, and is a failsafe against probably multiple errors at higher levels. Make some parameter names clearer vs class vars. Readability is better if the names are not lexicographically exactly the same. --- src/DirManager.cpp | 18 ++++++++++-------- src/DirManager.h | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/DirManager.cpp b/src/DirManager.cpp index 9a249b567..fc781a823 100644 --- a/src/DirManager.cpp +++ b/src/DirManager.cpp @@ -381,8 +381,7 @@ void DirManager::CleanTempDir() RecursivelyRemove(filePathArray, count, true, true, _("Cleaning up temporary files")); } -bool DirManager::SetProject(wxString & projPath, wxString & projName, - bool create) +bool DirManager::SetProject(wxString& newProjPath, wxString& newProjName, const bool bCreate) { wxString oldPath = this->projPath; wxString oldName = this->projName; @@ -391,17 +390,20 @@ bool DirManager::SetProject(wxString & projPath, wxString & projName, if (oldLoc == wxT("")) oldLoc = mytemp; - if (projPath == wxT("")) - projPath = ::wxGetCwd(); + if (newProjPath == wxT("")) + newProjPath = ::wxGetCwd(); - this->projPath = projPath; - this->projName = projName; - this->projFull = projPath + wxFILE_SEP_PATH + projName; + this->projPath = newProjPath; + this->projName = newProjName; + if (newProjPath.Last() == wxFILE_SEP_PATH) + this->projFull = newProjPath + newProjName; + else + this->projFull = newProjPath + wxFILE_SEP_PATH + newProjName; wxString cleanupLoc1=oldLoc; wxString cleanupLoc2=projFull; - if (create) { + if (bCreate) { if (!wxDirExists(projFull)) if (!wxMkdir(projFull)) return false; diff --git a/src/DirManager.h b/src/DirManager.h index 3feac1c29..a3cd3ab6c 100644 --- a/src/DirManager.h +++ b/src/DirManager.h @@ -49,7 +49,7 @@ class DirManager: public XMLTagHandler { // Returns true on success. // If SetProject is told NOT to create the directory // but it doesn't already exist, SetProject fails and returns false. - bool SetProject(wxString & projPath, wxString & projName, bool create); + bool SetProject(wxString& newProjPath, wxString& newProjName, const bool bCreate); wxString GetProjectDataDir(); wxString GetProjectName();