aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRachel Powers <508861+Ryex@users.noreply.github.com>2023-04-03 17:14:06 -0700
committerRachel Powers <508861+Ryex@users.noreply.github.com>2023-04-03 17:14:06 -0700
commit5b50b806ec5954aa3822443969d22ea79faa07c5 (patch)
treea66ade07315680fbd2d433e0a71fca1099f5b0a7
parent538092b72728fa34bafc873e16abaa7f318a945c (diff)
downloadPrismLauncher-5b50b806ec5954aa3822443969d22ea79faa07c5.tar.gz
PrismLauncher-5b50b806ec5954aa3822443969d22ea79faa07c5.tar.bz2
PrismLauncher-5b50b806ec5954aa3822443969d22ea79faa07c5.zip
refactor: remove data duplication in statis FS Names
Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com>
-rw-r--r--launcher/CMakeLists.txt12
-rw-r--r--launcher/FileSystem.cpp22
-rw-r--r--launcher/FileSystem.h70
3 files changed, 35 insertions, 69 deletions
diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt
index b47f5746..03d3fcbf 100644
--- a/launcher/CMakeLists.txt
+++ b/launcher/CMakeLists.txt
@@ -1123,17 +1123,17 @@ if(WIN32)
add_library(filelink_logic STATIC ${LINKEXE_SOURCES})
target_include_directories(filelink_logic PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(filelink_logic
- systeminfo
+ # systeminfo
BuildConfig
- Qt${QT_VERSION_MAJOR}::Widgets
+ # Qt${QT_VERSION_MAJOR}::Widgets
ghcFilesystem::ghc_filesystem
)
target_link_libraries(filelink_logic
Qt${QT_VERSION_MAJOR}::Core
- Qt${QT_VERSION_MAJOR}::Xml
- Qt${QT_VERSION_MAJOR}::Network
- Qt${QT_VERSION_MAJOR}::Concurrent
- ${Launcher_QT_LIBS}
+ # Qt${QT_VERSION_MAJOR}::Xml
+ # Qt${QT_VERSION_MAJOR}::Network
+ # Qt${QT_VERSION_MAJOR}::Concurrent
+ # ${Launcher_QT_LIBS}
)
add_executable("${Launcher_Name}_filelink" WIN32 filelink/main.cpp)
diff --git a/launcher/FileSystem.cpp b/launcher/FileSystem.cpp
index c046ee86..869fbe36 100644
--- a/launcher/FileSystem.cpp
+++ b/launcher/FileSystem.cpp
@@ -955,29 +955,29 @@ QString getFilesystemTypeName(FilesystemType type)
{
auto iter = s_filesystem_type_names.constFind(type);
if (iter != s_filesystem_type_names.constEnd()) {
- return iter.value();
+ return iter.value().constFirst();
}
return getFilesystemTypeName(FilesystemType::UNKNOWN);
}
FilesystemType getFilesystemTypeFuzzy(const QString& name)
{
- auto iter = s_filesystem_type_names_inverse.constFind(name.toUpper());
- if (iter != s_filesystem_type_names_inverse.constEnd()) {
- return iter.value();
+ for (auto iter = s_filesystem_type_names.constBegin(); iter != s_filesystem_type_names.constEnd(); ++iter) {
+ auto fs_names = iter.value();
+ for (auto fs_name : fs_names) {
+ if (name.toUpper().contains(fs_name.toUpper()))
+ return iter.key();
+ }
}
return FilesystemType::UNKNOWN;
}
FilesystemType getFilesystemType(const QString& name)
{
- for (auto fs_type_pair : s_filesystem_type_names_inverse.toStdMap()) {
- auto fs_type_name = fs_type_pair.first;
- auto fs_type = fs_type_pair.second;
-
- if (name.toUpper().contains(fs_type_name.toUpper())) {
- return fs_type;
- }
+ for (auto iter = s_filesystem_type_names.constBegin(); iter != s_filesystem_type_names.constEnd(); ++iter) {
+ auto fs_names = iter.value();
+ if(fs_names.contains(name.toUpper()))
+ return iter.key();
}
return FilesystemType::UNKNOWN;
}
diff --git a/launcher/FileSystem.h b/launcher/FileSystem.h
index 47044d93..cb581d0c 100644
--- a/launcher/FileSystem.h
+++ b/launcher/FileSystem.h
@@ -360,58 +360,24 @@ enum class FilesystemType {
* QMap is ordered
*
*/
-static const QMap<FilesystemType, QString> s_filesystem_type_names = {
- {FilesystemType::FAT, QStringLiteral("FAT")},
- {FilesystemType::NTFS, QStringLiteral("NTFS")},
- {FilesystemType::REFS, QStringLiteral("REFS")},
- {FilesystemType::EXT, QStringLiteral("EXT")},
- {FilesystemType::EXT_2_OLD, QStringLiteral("EXT_2_OLD")},
- {FilesystemType::EXT_2_3_4, QStringLiteral("EXT2/3/4")},
- {FilesystemType::XFS, QStringLiteral("XFS")},
- {FilesystemType::BTRFS, QStringLiteral("BTRFS")},
- {FilesystemType::NFS, QStringLiteral("NFS")},
- {FilesystemType::ZFS, QStringLiteral("ZFS")},
- {FilesystemType::APFS, QStringLiteral("APFS")},
- {FilesystemType::HFS, QStringLiteral("HFS")},
- {FilesystemType::HFSPLUS, QStringLiteral("HFSPLUS")},
- {FilesystemType::HFSX, QStringLiteral("HFSX")},
- {FilesystemType::FUSEBLK, QStringLiteral("FUSEBLK")},
- {FilesystemType::F2FS, QStringLiteral("F2FS")},
- {FilesystemType::UNKNOWN, QStringLiteral("UNKNOWN")}
-};
-
-
-/**
- * @brief Ordered Mapping of reported filesystem names to enum types
- * this mapping is non exsaustive, it just attempts to capture the many way these filesystems could be reported.
- * all keys are in uppercase, use `QString.toUpper()` or equivalent during lookup.
- *
- * QMap is ordered
- *
- */
-static const QMap<QString, FilesystemType> s_filesystem_type_names_inverse = {
- {QStringLiteral("FAT"), FilesystemType::FAT},
- {QStringLiteral("NTFS"), FilesystemType::NTFS},
- {QStringLiteral("REFS"), FilesystemType::REFS},
- {QStringLiteral("EXT2_OLD"), FilesystemType::EXT_2_OLD},
- {QStringLiteral("EXT_2_OLD"), FilesystemType::EXT_2_OLD},
- {QStringLiteral("EXT2"), FilesystemType::EXT_2_3_4},
- {QStringLiteral("EXT3"), FilesystemType::EXT_2_3_4},
- {QStringLiteral("EXT4"), FilesystemType::EXT_2_3_4},
- {QStringLiteral("EXT2/3/4"), FilesystemType::EXT_2_3_4},
- {QStringLiteral("EXT_2_3_4"), FilesystemType::EXT_2_3_4},
- {QStringLiteral("EXT"), FilesystemType::EXT}, // must come after all other EXT variants to prevent greedy detection
- {QStringLiteral("XFS"), FilesystemType::XFS},
- {QStringLiteral("BTRFS"), FilesystemType::BTRFS},
- {QStringLiteral("NFS"), FilesystemType::NFS},
- {QStringLiteral("ZFS"), FilesystemType::ZFS},
- {QStringLiteral("APFS"), FilesystemType::APFS},
- {QStringLiteral("HFSPLUS"), FilesystemType::HFSPLUS},
- {QStringLiteral("HFSX"), FilesystemType::HFSX},
- {QStringLiteral("HFS"), FilesystemType::HFS},
- {QStringLiteral("FUSEBLK"), FilesystemType::FUSEBLK},
- {QStringLiteral("F2FS"), FilesystemType::F2FS},
- {QStringLiteral("UNKNOWN"), FilesystemType::UNKNOWN}
+static const QMap<FilesystemType, QStringList> s_filesystem_type_names = {
+ {FilesystemType::FAT, { "FAT" }},
+ {FilesystemType::NTFS, { "NTFS" }},
+ {FilesystemType::REFS, { "REFS" }},
+ {FilesystemType::EXT_2_OLD, { "EXT_2_OLD", "EXT2_OLD" }},
+ {FilesystemType::EXT_2_3_4, { "EXT2/3/4", "EXT_2_3_4", "EXT2", "EXT3", "EXT4" }},
+ {FilesystemType::EXT, { "EXT" }},
+ {FilesystemType::XFS, { "XFS" }},
+ {FilesystemType::BTRFS, { "BTRFS" }},
+ {FilesystemType::NFS, { "NFS" }},
+ {FilesystemType::ZFS, { "ZFS" }},
+ {FilesystemType::APFS, { "APFS" }},
+ {FilesystemType::HFS, { "HFS" }},
+ {FilesystemType::HFSPLUS, { "HFSPLUS" }},
+ {FilesystemType::HFSX, { "HFSX" }},
+ {FilesystemType::FUSEBLK, { "FUSEBLK" }},
+ {FilesystemType::F2FS, { "F2FS" }},
+ {FilesystemType::UNKNOWN, { "UNKNOWN" }}
};
/**