aboutsummaryrefslogtreecommitdiff
path: root/libs/uibase/src/filesystemutilities.cpp
diff options
context:
space:
mode:
authorSulfurNitride <SulfurNitride@users.noreply.github.com>2026-02-11 02:37:39 -0600
committerSulfurNitride <SulfurNitride@users.noreply.github.com>2026-02-11 02:37:39 -0600
commit7ee008e150bc5bcf76082d726f719ee0fdfda982 (patch)
tree27fb39be241fdb5ac2734c574de678977d1856d0 /libs/uibase/src/filesystemutilities.cpp
Fluorine Manager: full Linux port of Mod Organizer 2
Complete native Linux port with FUSE-based virtual filesystem, Proton/umu-run integration, and Flatpak packaging. Key features: - FUSE VFS replacing Windows USVFS (in-process + standalone helper for Flatpak) - Proton/GE-Proton/umu-run launcher with env var forwarding - Flatpak support (sandbox-aware VFS, NXM handler, umu-run) - Wine prefix management UI - Case-insensitive path resolution for Linux filesystems - QSettings-safe INI handling (avoids Bethesda INI corruption) - Portable instance support with auto-generated launcher scripts Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Diffstat (limited to 'libs/uibase/src/filesystemutilities.cpp')
-rw-r--r--libs/uibase/src/filesystemutilities.cpp68
1 files changed, 68 insertions, 0 deletions
diff --git a/libs/uibase/src/filesystemutilities.cpp b/libs/uibase/src/filesystemutilities.cpp
new file mode 100644
index 0000000..6a01324
--- /dev/null
+++ b/libs/uibase/src/filesystemutilities.cpp
@@ -0,0 +1,68 @@
+#include <uibase/filesystemutilities.h>
+
+#include <QRegularExpression>
+#include <QString>
+
+namespace MOBase
+{
+
+bool fixDirectoryName(QString& name)
+{
+ QString temp = name.simplified();
+ while (temp.endsWith('.'))
+ temp.chop(1);
+
+ temp.replace(QRegularExpression(R"([<>:"/\\|?*])"), "");
+ static QString invalidNames[] = {"CON", "PRN", "AUX", "NUL", "COM1", "COM2",
+ "COM3", "COM4", "COM5", "COM6", "COM7", "COM8",
+ "COM9", "LPT1", "LPT2", "LPT3", "LPT4", "LPT5",
+ "LPT6", "LPT7", "LPT8", "LPT9"};
+ for (unsigned int i = 0; i < sizeof(invalidNames) / sizeof(QString); ++i) {
+ if (temp == invalidNames[i]) {
+ temp = "";
+ break;
+ }
+ }
+
+ temp = temp.simplified();
+
+ if (temp.length() >= 1) {
+ name = temp;
+ return true;
+ } else {
+ return false;
+ }
+}
+
+QString sanitizeFileName(const QString& name, const QString& replacement)
+{
+ QString new_name = name;
+
+ // Remove characters not allowed by Windows
+ new_name.replace(QRegularExpression("[\\x{00}-\\x{1f}\\\\/:\\*\\?\"<>|]"),
+ replacement);
+
+ // Don't end with a period or a space
+ // Don't be "." or ".."
+ new_name.remove(QRegularExpression("[\\. ]*$"));
+
+ // Recurse until stuff stops changing
+ if (new_name != name) {
+ return sanitizeFileName(new_name);
+ }
+ return new_name;
+}
+
+bool validFileName(const QString& name)
+{
+ if (name.isEmpty()) {
+ return false;
+ }
+ if (name == "." || name == "..") {
+ return false;
+ }
+
+ return (name == sanitizeFileName(name));
+}
+
+} // namespace MOBase