mirror of
https://github.com/cookiengineer/audacity
synced 2025-07-06 07:29:07 +02:00
Move AbbreviatePath to FileNames
This commit is contained in:
parent
f07fd5d8bc
commit
4e260389da
@ -16,6 +16,7 @@ Paul Licameli -- split from ProjectFileIO.cpp
|
|||||||
#include <wx/progdlg.h>
|
#include <wx/progdlg.h>
|
||||||
#include <wx/string.h>
|
#include <wx/string.h>
|
||||||
|
|
||||||
|
#include "FileNames.h"
|
||||||
#include "Internat.h"
|
#include "Internat.h"
|
||||||
#include "Project.h"
|
#include "Project.h"
|
||||||
#include "FileException.h"
|
#include "FileException.h"
|
||||||
@ -338,7 +339,7 @@ void DBConnection::CheckpointThread()
|
|||||||
if (rc != SQLITE_OK) {
|
if (rc != SQLITE_OK) {
|
||||||
// Can't checkpoint -- maybe the device has too little space
|
// Can't checkpoint -- maybe the device has too little space
|
||||||
wxFileNameWrapper fName{ name };
|
wxFileNameWrapper fName{ name };
|
||||||
auto path = FileException::AbbreviatePath(fName);
|
auto path = FileNames::AbbreviatePath(fName);
|
||||||
auto name = fName.GetFullName();
|
auto name = fName.GetFullName();
|
||||||
auto longname = name + "-wal";
|
auto longname = name + "-wal";
|
||||||
auto message1 = rc == SQLITE_FULL
|
auto message1 = rc == SQLITE_FULL
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#include "Audacity.h"
|
#include "Audacity.h"
|
||||||
#include "FileException.h"
|
#include "FileException.h"
|
||||||
|
#include "FileNames.h"
|
||||||
|
|
||||||
#include "Prefs.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(
|
return format.Format(
|
||||||
AbbreviatePath(fileName), renameTarget.GetFullName() );
|
FileNames::AbbreviatePath(fileName), renameTarget.GetFullName() );
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString FileException::ErrorHelpUrl() const
|
wxString FileException::ErrorHelpUrl() const
|
||||||
@ -56,33 +57,11 @@ wxString FileException::ErrorHelpUrl() const
|
|||||||
return "";
|
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
|
TranslatableString
|
||||||
FileException::WriteFailureMessage(const wxFileName &fileName)
|
FileException::WriteFailureMessage(const wxFileName &fileName)
|
||||||
{
|
{
|
||||||
return XO("Audacity failed to write to a file.\n"
|
return XO("Audacity failed to write to a file.\n"
|
||||||
"Perhaps %s is not writable or the disk is full.\n"
|
"Perhaps %s is not writable or the disk is full.\n"
|
||||||
"For tips on freeing up space, click the help button."
|
"For tips on freeing up space, click the help button."
|
||||||
).Format(AbbreviatePath(fileName));
|
).Format(FileNames::AbbreviatePath(fileName));
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,6 @@ public:
|
|||||||
|
|
||||||
~FileException() override;
|
~FileException() override;
|
||||||
|
|
||||||
static wxString AbbreviatePath(const wxFileName &fileName);
|
|
||||||
static TranslatableString WriteFailureMessage(const wxFileName &fileName);
|
static TranslatableString WriteFailureMessage(const wxFileName &fileName);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -846,7 +846,7 @@ bool FileNames::IsOnFATFileSystem(const FilePath &path)
|
|||||||
wxFileNameWrapper fileName{path};
|
wxFileNameWrapper fileName{path};
|
||||||
if (!fileName.HasVolume())
|
if (!fileName.HasVolume())
|
||||||
return false;
|
return false;
|
||||||
auto volume = fileName.GetVolume() + wxT(":\\");
|
auto volume = AbbreviatePath(fileName) + wxT("\\");
|
||||||
DWORD volumeFlags;
|
DWORD volumeFlags;
|
||||||
wxChar volumeType[64];
|
wxChar volumeType[64];
|
||||||
if (!::GetVolumeInformationW(
|
if (!::GetVolumeInformationW(
|
||||||
@ -864,3 +864,23 @@ bool FileNames::IsOnFATFileSystem(const FilePath &path)
|
|||||||
}
|
}
|
||||||
#endif
|
#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;
|
||||||
|
}
|
||||||
|
@ -213,6 +213,10 @@ namespace FileNames
|
|||||||
|
|
||||||
AUDACITY_DLL_API
|
AUDACITY_DLL_API
|
||||||
bool IsOnFATFileSystem(const FilePath &path);
|
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
|
// Use this macro to wrap all filenames and pathnames that get
|
||||||
|
@ -133,7 +133,7 @@ AudacityProject::AudacityProject()
|
|||||||
auto path = FileNames::TempDir();
|
auto path = FileNames::TempDir();
|
||||||
if (wxGetDiskSpace(path, NULL, &freeSpace)) {
|
if (wxGetDiskSpace(path, NULL, &freeSpace)) {
|
||||||
if (freeSpace < wxLongLong(wxLL(100 * 1048576))) {
|
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) */
|
/* i18n-hint: %s will be replaced by the drive letter (on Windows) */
|
||||||
ShowErrorDialog(nullptr,
|
ShowErrorDialog(nullptr,
|
||||||
XO("Warning"),
|
XO("Warning"),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user