From 4e260389da302cc31b09c4ddbb26bb891d1e8aa4 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Sun, 6 Dec 2020 14:53:35 -0500 Subject: [PATCH] Move AbbreviatePath to FileNames --- src/DBConnection.cpp | 3 ++- src/FileException.cpp | 27 +++------------------------ src/FileException.h | 1 - src/FileNames.cpp | 22 +++++++++++++++++++++- src/FileNames.h | 4 ++++ src/Project.cpp | 2 +- 6 files changed, 31 insertions(+), 28 deletions(-) diff --git a/src/DBConnection.cpp b/src/DBConnection.cpp index 6e12c5c50..5eedbbb77 100644 --- a/src/DBConnection.cpp +++ b/src/DBConnection.cpp @@ -16,6 +16,7 @@ Paul Licameli -- split from ProjectFileIO.cpp #include #include +#include "FileNames.h" #include "Internat.h" #include "Project.h" #include "FileException.h" @@ -338,7 +339,7 @@ void DBConnection::CheckpointThread() if (rc != SQLITE_OK) { // Can't checkpoint -- maybe the device has too little space wxFileNameWrapper fName{ name }; - auto path = FileException::AbbreviatePath(fName); + auto path = FileNames::AbbreviatePath(fName); auto name = fName.GetFullName(); auto longname = name + "-wal"; auto message1 = rc == SQLITE_FULL diff --git a/src/FileException.cpp b/src/FileException.cpp index 2ca091889..16c8fea07 100644 --- a/src/FileException.cpp +++ b/src/FileException.cpp @@ -9,6 +9,7 @@ #include "Audacity.h" #include "FileException.h" +#include "FileNames.h" #include "Prefs.h" @@ -36,7 +37,7 @@ XO("Audacity successfully wrote a file in %s but failed to rename it as %s."); } return format.Format( - AbbreviatePath(fileName), renameTarget.GetFullName() ); + FileNames::AbbreviatePath(fileName), renameTarget.GetFullName() ); } wxString FileException::ErrorHelpUrl() const @@ -56,33 +57,11 @@ wxString FileException::ErrorHelpUrl() const return ""; } - -wxString FileException::AbbreviatePath( const wxFileName &fileName ) -{ - wxString target; -#ifdef __WXMSW__ - - // Drive letter plus colon - target = fileName.GetVolume() + wxT(":"); - -#else - - // Shorten the path, arbitrarily to 3 components - auto path = fileName; - path.SetFullName(wxString{}); - while(path.GetDirCount() > 3) - path.RemoveLastDir(); - target = path.GetFullPath(); - -#endif - return target; -} - TranslatableString FileException::WriteFailureMessage(const wxFileName &fileName) { return XO("Audacity failed to write to a file.\n" "Perhaps %s is not writable or the disk is full.\n" "For tips on freeing up space, click the help button." - ).Format(AbbreviatePath(fileName)); + ).Format(FileNames::AbbreviatePath(fileName)); } diff --git a/src/FileException.h b/src/FileException.h index 3bd1d1979..2c096a901 100644 --- a/src/FileException.h +++ b/src/FileException.h @@ -46,7 +46,6 @@ public: ~FileException() override; - static wxString AbbreviatePath(const wxFileName &fileName); static TranslatableString WriteFailureMessage(const wxFileName &fileName); protected: diff --git a/src/FileNames.cpp b/src/FileNames.cpp index 8c8a5fea4..bf04adb03 100644 --- a/src/FileNames.cpp +++ b/src/FileNames.cpp @@ -846,7 +846,7 @@ bool FileNames::IsOnFATFileSystem(const FilePath &path) wxFileNameWrapper fileName{path}; if (!fileName.HasVolume()) return false; - auto volume = fileName.GetVolume() + wxT(":\\"); + auto volume = AbbreviatePath(fileName) + wxT("\\"); DWORD volumeFlags; wxChar volumeType[64]; if (!::GetVolumeInformationW( @@ -864,3 +864,23 @@ bool FileNames::IsOnFATFileSystem(const FilePath &path) } #endif +wxString FileNames::AbbreviatePath( const wxFileName &fileName ) +{ + wxString target; +#ifdef __WXMSW__ + + // Drive letter plus colon + target = fileName.GetVolume() + wxT(":"); + +#else + + // Shorten the path, arbitrarily to 3 components + auto path = fileName; + path.SetFullName(wxString{}); + while(path.GetDirCount() > 3) + path.RemoveLastDir(); + target = path.GetFullPath(); + +#endif + return target; +} diff --git a/src/FileNames.h b/src/FileNames.h index 04ff06f1c..079e027f3 100644 --- a/src/FileNames.h +++ b/src/FileNames.h @@ -213,6 +213,10 @@ namespace FileNames AUDACITY_DLL_API bool IsOnFATFileSystem(const FilePath &path); + + AUDACITY_DLL_API + //! Give enough of the path to identify the device. (On Windows, drive letter plus ':') + wxString AbbreviatePath(const wxFileName &fileName); }; // Use this macro to wrap all filenames and pathnames that get diff --git a/src/Project.cpp b/src/Project.cpp index 5320d4d73..9499c8d2f 100644 --- a/src/Project.cpp +++ b/src/Project.cpp @@ -133,7 +133,7 @@ AudacityProject::AudacityProject() auto path = FileNames::TempDir(); if (wxGetDiskSpace(path, NULL, &freeSpace)) { if (freeSpace < wxLongLong(wxLL(100 * 1048576))) { - auto volume = FileException::AbbreviatePath( path ); + auto volume = FileNames::AbbreviatePath( path ); /* i18n-hint: %s will be replaced by the drive letter (on Windows) */ ShowErrorDialog(nullptr, XO("Warning"),