Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97 2024-05-30 14:20:35 +03:00
parent a7a1b28765
commit 44a16c1ca1
No known key found for this signature in database
GPG Key ID: 55EF5DA53DB36318

View File

@ -74,7 +74,6 @@
#include <objbase.h> #include <objbase.h>
#include <shlobj.h> #include <shlobj.h>
#else #else
#include <sys/statvfs.h>
#include <utime.h> #include <utime.h>
#endif #endif
@ -809,53 +808,13 @@ QString removeDuplicates(QString a)
return b.join(""); return b.join("");
} }
QString getFileSystemType(const QString& path)
{
QString fileSystemType;
#ifdef Q_OS_WIN
wchar_t volume[MAX_PATH + 1] = { 0 };
if (GetVolumeInformationW((LPCWSTR)path.utf16(), nullptr, 0, nullptr, nullptr, nullptr, volume, MAX_PATH)) {
fileSystemType = QString::fromWCharArray(volume);
}
#elif defined(Q_OS_UNIX)
struct statvfs buf;
if (statvfs(path.toUtf8().constData(), &buf) == 0) {
switch (buf.f_type) {
case 0x4d44: // "MSDOS"
fileSystemType = "FAT32";
break;
case 0x5346544e: // "NTFS"
fileSystemType = "NTFS";
break;
case 0x4244: // "HFS+" or "H+" on some systems
case 0x482b: // "HFS+" or "H+" on some systems
fileSystemType = "HFS+";
break;
case 0x41465342: // "APFS"
fileSystemType = "APFS";
break;
case 0x65735546: // "exFAT"
fileSystemType = "exFAT";
break;
default:
break;
}
}
#endif
return fileSystemType;
}
static const QString BAD_WIN_CHARS = "\"?<>:*|\r\n"; static const QString BAD_WIN_CHARS = "\"?<>:*|\r\n";
static const QString BAD_FAT32_CHARS = "<>:\"|?*+.,;=[]!"; static const QString BAD_FAT_CHARS = "<>:\"|?*+.,;=[]!";
static const QString BAD_NTFS_CHARS = "<>:\"|?*"; static const QString BAD_NTFS_CHARS = "<>:\"|?*";
static const QString BAD_HFS_CHARS = ":"; static const QString BAD_HFS_CHARS = ":";
static const QString BAD_EXFAT_CHARS = "<>:\"|?*";
static const QString BAD_FILENAME_CHARS = static const QString BAD_FILENAME_CHARS = removeDuplicates(BAD_WIN_CHARS + BAD_FAT_CHARS + BAD_NTFS_CHARS + BAD_HFS_CHARS) + "\\/";
removeDuplicates(BAD_WIN_CHARS + BAD_FAT32_CHARS + BAD_NTFS_CHARS + BAD_HFS_CHARS + BAD_EXFAT_CHARS) + "\\/";
QString RemoveInvalidFilenameChars(QString string, QChar replaceWith) QString RemoveInvalidFilenameChars(QString string, QChar replaceWith)
{ {
@ -872,16 +831,35 @@ QString RemoveInvalidPathChars(QString path, QChar replaceWith)
invalidChars = BAD_WIN_CHARS; invalidChars = BAD_WIN_CHARS;
#endif #endif
QString fileSystemType = getFileSystemType(QFileInfo(path).absolutePath()); switch (statFS(path).fsType) {
case FilesystemType::FAT:
if (fileSystemType == "FAT32") { invalidChars += BAD_FAT_CHARS;
invalidChars += BAD_FAT32_CHARS; break;
} else if (fileSystemType == "NTFS") { case FilesystemType::NTFS:
invalidChars += BAD_NTFS_CHARS; invalidChars += BAD_NTFS_CHARS;
} else if (fileSystemType == "HFS+" || fileSystemType == "APFS") { break;
// case FilesystemType::REFS:
// case FilesystemType::EXT:
// case FilesystemType::EXT_2_OLD:
// case FilesystemType::EXT_2_3_4:
// case FilesystemType::XFS:
// case FilesystemType::BTRFS:
// case FilesystemType::NFS:
// case FilesystemType::ZFS:
case FilesystemType::APFS:
/* fallthrough */
case FilesystemType::HFS:
/* fallthrough */
case FilesystemType::HFSPLUS:
/* fallthrough */
case FilesystemType::HFSX:
invalidChars += BAD_HFS_CHARS; invalidChars += BAD_HFS_CHARS;
} else if (fileSystemType == "exFAT") { break;
invalidChars += BAD_EXFAT_CHARS; // case FilesystemType::FUSEBLK:
// case FilesystemType::F2FS:
// case FilesystemType::UNKNOWN:
default:
break;
} }
if (invalidChars.size() != 0) { if (invalidChars.size() != 0) {