diff --git a/src/FileNames.cpp b/src/FileNames.cpp index 49cd44fe5..0f8ea7899 100644 --- a/src/FileNames.cpp +++ b/src/FileNames.cpp @@ -370,6 +370,18 @@ FilePath FileNames::PathFromAddr(void *addr) return name.GetFullPath(); } + +bool FileNames::IsPathAvailable( const FilePath & Path){ + if( Path.IsEmpty() ) + return false; +#ifndef __WIN32__ + return true; +#else + wxFileNameWrapper filePath( Path ); + return filePath.DirExists() && !filePath.FileExists(); +#endif +} + wxFileNameWrapper FileNames::DefaultToDocumentsFolder(const wxString &preference) { wxFileNameWrapper result; @@ -380,18 +392,18 @@ wxFileNameWrapper FileNames::DefaultToDocumentsFolder(const wxString &preference result.SetPath( gPrefs->Read( preference, defaultPath.GetPath( wxPATH_GET_VOLUME ) ) ); // MJB: Bug 1899 & Bug 2007. Only create directory if the result is the default path - bool bIsDefaultPath = result == defaultPath; + bool bIsDefaultPath = result == defaultPath; if( !bIsDefaultPath ) { // IF the prefs directory doesn't exist - (Deleted by our user perhaps?) // or exists as a file // THEN fallback to using the default directory. - bIsDefaultPath = !result.DirExists() || result.FileExists(); + bIsDefaultPath = !IsPathAvailable( result.GetPath(wxPATH_GET_VOLUME ) ); if( bIsDefaultPath ) { result.SetPath( defaultPath.GetPath( wxPATH_GET_VOLUME ) ); - gPrefs->Write( preference, defaultPath.GetPath( wxPATH_GET_VOLUME ) ); - gPrefs->Flush(); + // Don't write to gPrefs. + // We typically do it later, (if directory actually gets used) } } if ( bIsDefaultPath ) diff --git a/src/FileNames.h b/src/FileNames.h index f4b427393..d75e17b2f 100644 --- a/src/FileNames.h +++ b/src/FileNames.h @@ -78,6 +78,7 @@ public: // Obtain name of loaded module that contains address static FilePath PathFromAddr(void *addr); + static bool IsPathAvailable( const FilePath & Path); static wxFileNameWrapper DefaultToDocumentsFolder (const wxString &preference); diff --git a/src/Project.cpp b/src/Project.cpp index 4ac811d18..40908594b 100644 --- a/src/Project.cpp +++ b/src/Project.cpp @@ -4404,7 +4404,7 @@ bool AudacityProject::SaveAs(bool bWantSaveCopy /*= false*/, bool bLossless /*= bWantSaveCopy = true; // Bug 1304: Set a default file path if none was given. For Save/SaveAs - if( filename.GetFullPath().empty() ){ + if( !FileNames::IsPathAvailable( filename.GetFullPath() ) ){ bHasPath = false; filename = FileNames::DefaultToDocumentsFolder(wxT("/SaveAs/Path")); }