1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-12-24 17:41:13 +01:00

Move IsOnFATFileSystem to FileNames

This commit is contained in:
Paul Licameli
2020-12-06 12:23:19 -05:00
parent 0bd21e171c
commit c5e454e109
3 changed files with 48 additions and 45 deletions

View File

@@ -815,3 +815,48 @@ wxString FileNames::UnsavedProjectFileName()
return fn.GetFullPath();
}
// How to detect whether the file system of a path is FAT
// No apparent way to do it with wxWidgets
#if defined(__DARWIN__)
#include <sys/mount.h>
bool FileNames::IsOnFATFileSystem(const FilePath &path)
{
struct statfs fs;
if (statfs(path.c_str(), &fs))
// Error from statfs
return false;
return 0 == strcmp(fs.f_fstypename, "msdos");
}
#elif defined(__linux__)
#include <sys/statfs.h>
#include "/usr/include/linux/magic.h"
bool FileNames::IsOnFATFileSystem(const FilePath &path)
{
struct statfs fs;
if (statfs(path.c_str(), &fs))
// Error from statfs
return false;
return fs.f_type == MSDOS_SUPER_MAGIC;
}
#elif defined(_WIN32)
#include <fileapi.h>
bool FileNames::IsOnFATFileSystem(const FilePath &path)
{
DWORD volumeFlags;
wxChar volumeType[64];
if (!::GetVolumeInformation(
path.c_str(), NULL, 0, NULL, NULL,
&volumeFlags,
volumeType,
WXSIZEOF(volumeType)))
return false;
return wxString(volumeType).Upper().find(wxT("FAT")) != wxString::npos;
}
#else
bool FileNames::IsOnFATFileSystem(const FilePath &path)
{
return false;
}
#endif

View File

@@ -211,6 +211,8 @@ namespace FileNames
// File extension used for unsaved/temporary project files
wxString UnsavedProjectExtension();
AUDACITY_DLL_API
bool IsOnFATFileSystem(const FilePath &path);
};
// Use this macro to wrap all filenames and pathnames that get

View File

@@ -2236,56 +2236,12 @@ bool ProjectFileIO::IsRecovered() const
return mRecovered;
}
// How to detect whether the file system of a path is FAT
// No apparent way to do it with wxWidgets
#if defined(__DARWIN__)
#include <sys/mount.h>
static bool IsOnFATFileSystem(const FilePath &path)
{
struct statfs fs;
if (statfs(path.c_str(), &fs))
// Error from statfs
return false;
return 0 == strcmp(fs.f_fstypename, "msdos");
}
#elif defined(__linux__)
#include <sys/statfs.h>
#include "/usr/include/linux/magic.h"
static bool IsOnFATFileSystem(const FilePath &path)
{
struct statfs fs;
if (statfs(path.c_str(), &fs))
// Error from statfs
return false;
return fs.f_type == MSDOS_SUPER_MAGIC;
}
#elif defined(_WIN32)
#include <fileapi.h>
static bool IsOnFATFileSystem(const FilePath &path)
{
DWORD volumeFlags;
wxChar volumeType[64];
if (!::GetVolumeInformation(
path.c_str(), NULL, 0, NULL, NULL,
&volumeFlags,
volumeType,
WXSIZEOF(volumeType)))
return false;
return wxString(volumeType).Upper().find(wxT("FAT")) != wxString::npos;
}
#else
static bool IsOnFATFileSystem(const FilePath &path)
{
return false;
}
#endif
wxLongLong ProjectFileIO::GetFreeDiskSpace() const
{
wxLongLong freeSpace;
if (wxGetDiskSpace(wxPathOnly(mFileName), NULL, &freeSpace))
{
if (IsOnFATFileSystem(mFileName)) {
if (FileNames::IsOnFATFileSystem(mFileName)) {
// 4 GiB per-file maximum
constexpr auto limit = 1ll << 32;
auto length = wxFileName::GetSize(mFileName);