From c5e454e1099eedc0a995a2bbb02f989276d0d41a Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Sun, 6 Dec 2020 12:23:19 -0500 Subject: [PATCH] Move IsOnFATFileSystem to FileNames --- src/FileNames.cpp | 45 ++++++++++++++++++++++++++++++++++++++++++ src/FileNames.h | 2 ++ src/ProjectFileIO.cpp | 46 +------------------------------------------ 3 files changed, 48 insertions(+), 45 deletions(-) diff --git a/src/FileNames.cpp b/src/FileNames.cpp index d37cebe4e..0df8e79c7 100644 --- a/src/FileNames.cpp +++ b/src/FileNames.cpp @@ -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 +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 +#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 +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 + diff --git a/src/FileNames.h b/src/FileNames.h index 019195d15..04ff06f1c 100644 --- a/src/FileNames.h +++ b/src/FileNames.h @@ -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 diff --git a/src/ProjectFileIO.cpp b/src/ProjectFileIO.cpp index 9a42e790e..752b8f150 100644 --- a/src/ProjectFileIO.cpp +++ b/src/ProjectFileIO.cpp @@ -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 -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 -#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 -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);