1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-16 08:09:32 +02:00

Move AbbreviatePath to FileNames

This commit is contained in:
Paul Licameli 2020-12-06 14:53:35 -05:00
parent f07fd5d8bc
commit 4e260389da
6 changed files with 31 additions and 28 deletions

View File

@ -16,6 +16,7 @@ Paul Licameli -- split from ProjectFileIO.cpp
#include <wx/progdlg.h>
#include <wx/string.h>
#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

View File

@ -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));
}

View File

@ -46,7 +46,6 @@ public:
~FileException() override;
static wxString AbbreviatePath(const wxFileName &fileName);
static TranslatableString WriteFailureMessage(const wxFileName &fileName);
protected:

View File

@ -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;
}

View File

@ -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

View File

@ -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"),