mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2025-06-12 05:07:46 +02:00
Merge branch 'develop' of github.com:Trial97/PrismLauncher into feature/java-downloader
This commit is contained in:
@ -818,25 +818,78 @@ QString NormalizePath(QString path)
|
||||
}
|
||||
}
|
||||
|
||||
static const QString BAD_PATH_CHARS = "\"?<>:;*|!+\r\n";
|
||||
static const QString BAD_FILENAME_CHARS = BAD_PATH_CHARS + "\\/";
|
||||
QString removeDuplicates(QString a)
|
||||
{
|
||||
auto b = a.split("");
|
||||
b.removeDuplicates();
|
||||
return b.join("");
|
||||
}
|
||||
|
||||
static const QString BAD_WIN_CHARS = "\"?<>:*|\r\n";
|
||||
|
||||
static const QString BAD_FAT_CHARS = "<>:\"|?*+.,;=[]!";
|
||||
static const QString BAD_NTFS_CHARS = "<>:\"|?*";
|
||||
static const QString BAD_HFS_CHARS = ":";
|
||||
|
||||
static const QString BAD_FILENAME_CHARS = removeDuplicates(BAD_WIN_CHARS + BAD_FAT_CHARS + BAD_NTFS_CHARS + BAD_HFS_CHARS) + "\\/";
|
||||
|
||||
QString RemoveInvalidFilenameChars(QString string, QChar replaceWith)
|
||||
{
|
||||
for (int i = 0; i < string.length(); i++)
|
||||
if (string.at(i) < ' ' || BAD_FILENAME_CHARS.contains(string.at(i)))
|
||||
string[i] = replaceWith;
|
||||
|
||||
return string;
|
||||
}
|
||||
|
||||
QString RemoveInvalidPathChars(QString string, QChar replaceWith)
|
||||
QString RemoveInvalidPathChars(QString path, QChar replaceWith)
|
||||
{
|
||||
for (int i = 0; i < string.length(); i++)
|
||||
if (string.at(i) < ' ' || BAD_PATH_CHARS.contains(string.at(i)))
|
||||
string[i] = replaceWith;
|
||||
QString invalidChars;
|
||||
#ifdef Q_OS_WIN
|
||||
invalidChars = BAD_WIN_CHARS;
|
||||
#endif
|
||||
|
||||
return string;
|
||||
// the null character is ignored in this check as it was not a problem until now
|
||||
switch (statFS(path).fsType) {
|
||||
case FilesystemType::FAT:
|
||||
invalidChars += BAD_FAT_CHARS;
|
||||
break;
|
||||
case FilesystemType::NTFS:
|
||||
/* fallthrough */
|
||||
case FilesystemType::REFS: // similar to NTFS(should be available only on windows)
|
||||
invalidChars += BAD_NTFS_CHARS;
|
||||
break;
|
||||
// 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;
|
||||
break;
|
||||
// case FilesystemType::FUSEBLK:
|
||||
// case FilesystemType::F2FS:
|
||||
// case FilesystemType::UNKNOWN:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (invalidChars.size() != 0) {
|
||||
for (int i = 0; i < path.length(); i++) {
|
||||
if (path.at(i) < ' ' || invalidChars.contains(path.at(i))) {
|
||||
path[i] = replaceWith;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
QString DirNameFromString(QString string, QString inDir)
|
||||
|
Reference in New Issue
Block a user