refactor: remove data duplication in statis FS Names
Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com>
This commit is contained in:
parent
538092b727
commit
5b50b806ec
@ -1123,17 +1123,17 @@ if(WIN32)
|
|||||||
add_library(filelink_logic STATIC ${LINKEXE_SOURCES})
|
add_library(filelink_logic STATIC ${LINKEXE_SOURCES})
|
||||||
target_include_directories(filelink_logic PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
target_include_directories(filelink_logic PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
target_link_libraries(filelink_logic
|
target_link_libraries(filelink_logic
|
||||||
systeminfo
|
# systeminfo
|
||||||
BuildConfig
|
BuildConfig
|
||||||
Qt${QT_VERSION_MAJOR}::Widgets
|
# Qt${QT_VERSION_MAJOR}::Widgets
|
||||||
ghcFilesystem::ghc_filesystem
|
ghcFilesystem::ghc_filesystem
|
||||||
)
|
)
|
||||||
target_link_libraries(filelink_logic
|
target_link_libraries(filelink_logic
|
||||||
Qt${QT_VERSION_MAJOR}::Core
|
Qt${QT_VERSION_MAJOR}::Core
|
||||||
Qt${QT_VERSION_MAJOR}::Xml
|
# Qt${QT_VERSION_MAJOR}::Xml
|
||||||
Qt${QT_VERSION_MAJOR}::Network
|
# Qt${QT_VERSION_MAJOR}::Network
|
||||||
Qt${QT_VERSION_MAJOR}::Concurrent
|
# Qt${QT_VERSION_MAJOR}::Concurrent
|
||||||
${Launcher_QT_LIBS}
|
# ${Launcher_QT_LIBS}
|
||||||
)
|
)
|
||||||
|
|
||||||
add_executable("${Launcher_Name}_filelink" WIN32 filelink/main.cpp)
|
add_executable("${Launcher_Name}_filelink" WIN32 filelink/main.cpp)
|
||||||
|
@ -955,29 +955,29 @@ QString getFilesystemTypeName(FilesystemType type)
|
|||||||
{
|
{
|
||||||
auto iter = s_filesystem_type_names.constFind(type);
|
auto iter = s_filesystem_type_names.constFind(type);
|
||||||
if (iter != s_filesystem_type_names.constEnd()) {
|
if (iter != s_filesystem_type_names.constEnd()) {
|
||||||
return iter.value();
|
return iter.value().constFirst();
|
||||||
}
|
}
|
||||||
return getFilesystemTypeName(FilesystemType::UNKNOWN);
|
return getFilesystemTypeName(FilesystemType::UNKNOWN);
|
||||||
}
|
}
|
||||||
|
|
||||||
FilesystemType getFilesystemTypeFuzzy(const QString& name)
|
FilesystemType getFilesystemTypeFuzzy(const QString& name)
|
||||||
{
|
{
|
||||||
auto iter = s_filesystem_type_names_inverse.constFind(name.toUpper());
|
for (auto iter = s_filesystem_type_names.constBegin(); iter != s_filesystem_type_names.constEnd(); ++iter) {
|
||||||
if (iter != s_filesystem_type_names_inverse.constEnd()) {
|
auto fs_names = iter.value();
|
||||||
return iter.value();
|
for (auto fs_name : fs_names) {
|
||||||
|
if (name.toUpper().contains(fs_name.toUpper()))
|
||||||
|
return iter.key();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return FilesystemType::UNKNOWN;
|
return FilesystemType::UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
FilesystemType getFilesystemType(const QString& name)
|
FilesystemType getFilesystemType(const QString& name)
|
||||||
{
|
{
|
||||||
for (auto fs_type_pair : s_filesystem_type_names_inverse.toStdMap()) {
|
for (auto iter = s_filesystem_type_names.constBegin(); iter != s_filesystem_type_names.constEnd(); ++iter) {
|
||||||
auto fs_type_name = fs_type_pair.first;
|
auto fs_names = iter.value();
|
||||||
auto fs_type = fs_type_pair.second;
|
if(fs_names.contains(name.toUpper()))
|
||||||
|
return iter.key();
|
||||||
if (name.toUpper().contains(fs_type_name.toUpper())) {
|
|
||||||
return fs_type;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return FilesystemType::UNKNOWN;
|
return FilesystemType::UNKNOWN;
|
||||||
}
|
}
|
||||||
|
@ -360,58 +360,24 @@ enum class FilesystemType {
|
|||||||
* QMap is ordered
|
* QMap is ordered
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static const QMap<FilesystemType, QString> s_filesystem_type_names = {
|
static const QMap<FilesystemType, QStringList> s_filesystem_type_names = {
|
||||||
{FilesystemType::FAT, QStringLiteral("FAT")},
|
{FilesystemType::FAT, { "FAT" }},
|
||||||
{FilesystemType::NTFS, QStringLiteral("NTFS")},
|
{FilesystemType::NTFS, { "NTFS" }},
|
||||||
{FilesystemType::REFS, QStringLiteral("REFS")},
|
{FilesystemType::REFS, { "REFS" }},
|
||||||
{FilesystemType::EXT, QStringLiteral("EXT")},
|
{FilesystemType::EXT_2_OLD, { "EXT_2_OLD", "EXT2_OLD" }},
|
||||||
{FilesystemType::EXT_2_OLD, QStringLiteral("EXT_2_OLD")},
|
{FilesystemType::EXT_2_3_4, { "EXT2/3/4", "EXT_2_3_4", "EXT2", "EXT3", "EXT4" }},
|
||||||
{FilesystemType::EXT_2_3_4, QStringLiteral("EXT2/3/4")},
|
{FilesystemType::EXT, { "EXT" }},
|
||||||
{FilesystemType::XFS, QStringLiteral("XFS")},
|
{FilesystemType::XFS, { "XFS" }},
|
||||||
{FilesystemType::BTRFS, QStringLiteral("BTRFS")},
|
{FilesystemType::BTRFS, { "BTRFS" }},
|
||||||
{FilesystemType::NFS, QStringLiteral("NFS")},
|
{FilesystemType::NFS, { "NFS" }},
|
||||||
{FilesystemType::ZFS, QStringLiteral("ZFS")},
|
{FilesystemType::ZFS, { "ZFS" }},
|
||||||
{FilesystemType::APFS, QStringLiteral("APFS")},
|
{FilesystemType::APFS, { "APFS" }},
|
||||||
{FilesystemType::HFS, QStringLiteral("HFS")},
|
{FilesystemType::HFS, { "HFS" }},
|
||||||
{FilesystemType::HFSPLUS, QStringLiteral("HFSPLUS")},
|
{FilesystemType::HFSPLUS, { "HFSPLUS" }},
|
||||||
{FilesystemType::HFSX, QStringLiteral("HFSX")},
|
{FilesystemType::HFSX, { "HFSX" }},
|
||||||
{FilesystemType::FUSEBLK, QStringLiteral("FUSEBLK")},
|
{FilesystemType::FUSEBLK, { "FUSEBLK" }},
|
||||||
{FilesystemType::F2FS, QStringLiteral("F2FS")},
|
{FilesystemType::F2FS, { "F2FS" }},
|
||||||
{FilesystemType::UNKNOWN, QStringLiteral("UNKNOWN")}
|
{FilesystemType::UNKNOWN, { "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}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user