From bc8336a4b115fd190e068f57159d925683ba3930 Mon Sep 17 00:00:00 2001 From: Rachel Powers <508861+Ryex@users.noreply.github.com> Date: Thu, 9 Feb 2023 16:19:38 -0700 Subject: [PATCH] fix: cleanup UI, detect FAT and turn off links Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com> --- launcher/DesktopServices.cpp | 1 - launcher/FileSystem.cpp | 28 ++++++ launcher/FileSystem.h | 24 ++++- launcher/InstanceCopyPrefs.cpp | 8 +- launcher/InstanceCopyPrefs.h | 6 +- launcher/InstanceCopyTask.cpp | 2 +- launcher/ui/dialogs/CopyInstanceDialog.cpp | 50 +++++++--- launcher/ui/dialogs/CopyInstanceDialog.h | 6 +- launcher/ui/dialogs/CopyInstanceDialog.ui | 111 ++++++++++++++------- 9 files changed, 175 insertions(+), 61 deletions(-) diff --git a/launcher/DesktopServices.cpp b/launcher/DesktopServices.cpp index 69770e99..2984a1b4 100644 --- a/launcher/DesktopServices.cpp +++ b/launcher/DesktopServices.cpp @@ -37,7 +37,6 @@ #include #include #include -//#include "Application.h" /** * This shouldn't exist, but until QTBUG-9328 and other unreported bugs are fixed, it needs to be a thing. diff --git a/launcher/FileSystem.cpp b/launcher/FileSystem.cpp index fd09842f..c363f6ea 100644 --- a/launcher/FileSystem.cpp +++ b/launcher/FileSystem.cpp @@ -1053,4 +1053,32 @@ bool clone_file(const QString& src, const QString& dst, std::error_code& ec) return true; } + +/** + * @brief if the Filesystem is symlink capable + * + */ +bool canLinkOnFS(const QString& path) +{ + FilesystemInfo info = statFS(path); + return canLinkOnFS(info); +} +bool canLinkOnFS(const FilesystemInfo& info) +{ + return canLinkOnFS(info.fsType); +} +bool canLinkOnFS(FilesystemType type) +{ + return !s_non_link_filesystems.contains(type); +} +/** + * @brief if the Filesystem is symlink capable on both ends + * + */ +bool canLink(const QString& src, const QString& dst) +{ + return canLinkOnFS(src) && canLinkOnFS(dst); +} + + } diff --git a/launcher/FileSystem.h b/launcher/FileSystem.h index aa28de93..83ff99a4 100644 --- a/launcher/FileSystem.h +++ b/launcher/FileSystem.h @@ -330,6 +330,7 @@ enum class FilesystemType { HFSPLUS, HFSX, FUSEBLK, + F2FS, UNKNOWN }; @@ -348,6 +349,7 @@ static const QMap s_filesystem_type_names = { {FilesystemType::HFSPLUS, QString("HFSPLUS")}, {FilesystemType::HFSX, QString("HFSX")}, {FilesystemType::FUSEBLK, QString("FUSEBLK")}, + {FilesystemType::F2FS, QString("F2FS")}, {FilesystemType::UNKNOWN, QString("UNKNOWN")} }; @@ -368,6 +370,7 @@ static const QMap s_filesystem_type_names_inverse = { {QString("HFSX"), FilesystemType::HFSX}, {QString("HFS"), FilesystemType::HFS}, {QString("FUSEBLK"), FilesystemType::FUSEBLK}, + {QString("F2FS"), FilesystemType::F2FS}, {QString("UNKNOWN"), FilesystemType::UNKNOWN} }; @@ -405,7 +408,7 @@ bool canCloneOnFS(const FilesystemInfo& info); bool canCloneOnFS(FilesystemType type); /** - * @brief if the Filesystem is reflink/clone capable and both are on the same device + * @brief if the Filesystems are reflink/clone capable and both are on the same device * */ bool canClone(const QString& src, const QString& dst); @@ -457,4 +460,23 @@ class clone : public QObject { */ bool clone_file(const QString& src, const QString& dst, std::error_code& ec); + +static const QList s_non_link_filesystems = { + FilesystemType::FAT, +}; + +/** + * @brief if the Filesystem is symlink capable + * + */ +bool canLinkOnFS(const QString& path); +bool canLinkOnFS(const FilesystemInfo& info); +bool canLinkOnFS(FilesystemType type); + +/** + * @brief if the Filesystem is symlink capable on both ends + * + */ +bool canLink(const QString& src, const QString& dst); + } diff --git a/launcher/InstanceCopyPrefs.cpp b/launcher/InstanceCopyPrefs.cpp index f2aa5e69..c03d0aae 100644 --- a/launcher/InstanceCopyPrefs.cpp +++ b/launcher/InstanceCopyPrefs.cpp @@ -93,9 +93,9 @@ bool InstanceCopyPrefs::isCopyScreenshotsEnabled() const return copyScreenshots; } -bool InstanceCopyPrefs::isLinkFilesEnabled() const +bool InstanceCopyPrefs::isUseSymLinksEnabled() const { - return linkFiles; + return useSymLinks; } bool InstanceCopyPrefs::isUseHardLinksEnabled() const @@ -159,9 +159,9 @@ void InstanceCopyPrefs::enableCopyScreenshots(bool b) copyScreenshots = b; } -void InstanceCopyPrefs::enableLinkFiles(bool b) +void InstanceCopyPrefs::enableUseSymLinks(bool b) { - linkFiles = b; + useSymLinks = b; } void InstanceCopyPrefs::enableLinkRecursively(bool b) diff --git a/launcher/InstanceCopyPrefs.h b/launcher/InstanceCopyPrefs.h index 583fdd4c..14ae9551 100644 --- a/launcher/InstanceCopyPrefs.h +++ b/launcher/InstanceCopyPrefs.h @@ -19,7 +19,7 @@ struct InstanceCopyPrefs { [[nodiscard]] bool isCopyServersEnabled() const; [[nodiscard]] bool isCopyModsEnabled() const; [[nodiscard]] bool isCopyScreenshotsEnabled() const; - [[nodiscard]] bool isLinkFilesEnabled() const; + [[nodiscard]] bool isUseSymLinksEnabled() const; [[nodiscard]] bool isLinkRecursivelyEnabled() const; [[nodiscard]] bool isUseHardLinksEnabled() const; [[nodiscard]] bool isDontLinkSavesEnabled() const; @@ -33,7 +33,7 @@ struct InstanceCopyPrefs { void enableCopyServers(bool b); void enableCopyMods(bool b); void enableCopyScreenshots(bool b); - void enableLinkFiles(bool b); + void enableUseSymLinks(bool b); void enableLinkRecursively(bool b); void enableUseHardLinks(bool b); void enableDontLinkSaves(bool b); @@ -48,7 +48,7 @@ struct InstanceCopyPrefs { bool copyServers = true; bool copyMods = true; bool copyScreenshots = true; - bool linkFiles = false; + bool useSymLinks = false; bool linkRecursively = false; bool useHardLinks = false; bool dontLinkSaves = false; diff --git a/launcher/InstanceCopyTask.cpp b/launcher/InstanceCopyTask.cpp index b3ea54b0..ba0052fa 100644 --- a/launcher/InstanceCopyTask.cpp +++ b/launcher/InstanceCopyTask.cpp @@ -13,7 +13,7 @@ InstanceCopyTask::InstanceCopyTask(InstancePtr origInstance, const InstanceCopyP QString filters = prefs.getSelectedFiltersAsRegex(); - m_useLinks = prefs.isLinkFilesEnabled(); + m_useLinks = prefs.isUseSymLinksEnabled(); m_linkRecursively = prefs.isLinkRecursivelyEnabled(); m_useHardLinks = prefs.isLinkRecursivelyEnabled() && prefs.isUseHardLinksEnabled(); m_copySaves = prefs.isLinkRecursivelyEnabled() && prefs.isDontLinkSavesEnabled() && prefs.isCopySavesEnabled(); diff --git a/launcher/ui/dialogs/CopyInstanceDialog.cpp b/launcher/ui/dialogs/CopyInstanceDialog.cpp index c51bc067..c6cbefcf 100644 --- a/launcher/ui/dialogs/CopyInstanceDialog.cpp +++ b/launcher/ui/dialogs/CopyInstanceDialog.cpp @@ -87,21 +87,26 @@ CopyInstanceDialog::CopyInstanceDialog(InstancePtr original, QWidget *parent) ui->copyModsCheckbox->setChecked(m_selectedOptions.isCopyModsEnabled()); ui->copyScreenshotsCheckbox->setChecked(m_selectedOptions.isCopyScreenshotsEnabled()); - ui->linkFilesGroup->setChecked(m_selectedOptions.isLinkFilesEnabled()); - ui->recursiveLinkCheckbox->setChecked(m_selectedOptions.isLinkRecursivelyEnabled()); + ui->symbolicLinksCheckbox->setChecked(m_selectedOptions.isUseSymLinksEnabled()); ui->hardLinksCheckbox->setChecked(m_selectedOptions.isUseHardLinksEnabled()); + + ui->recursiveLinkCheckbox->setChecked(m_selectedOptions.isLinkRecursivelyEnabled()); ui->dontLinkSavesCheckbox->setChecked(m_selectedOptions.isDontLinkSavesEnabled()); auto detectedOS = FS::statFS(m_original->instanceRoot()).fsType; + m_cloneSupported = FS::canCloneOnFS(detectedOS); + m_linkSupported = FS::canLinkOnFS(detectedOS); if (m_cloneSupported) { - ui->cloneSupportedLabel->setText(tr("Clone / Reflink is supported on (%1)").arg(FS::getFilesystemTypeName(detectedOS))); + ui->cloneSupportedLabel->setText(tr("Reflinks are supported on %1").arg(FS::getFilesystemTypeName(detectedOS))); } else { - ui->cloneSupportedLabel->setText(tr("Clone / Reflink not supported on (%1)").arg(FS::getFilesystemTypeName(detectedOS))); + ui->cloneSupportedLabel->setText(tr("Reflinks aren't supported on %1").arg(FS::getFilesystemTypeName(detectedOS))); } + updateLinkOptions(); updateUseCloneCheckbox(); + } CopyInstanceDialog::~CopyInstanceDialog() @@ -170,6 +175,21 @@ void CopyInstanceDialog::updateUseCloneCheckbox() ui->useCloneCheckbox->setChecked(m_cloneSupported && m_selectedOptions.isUseCloneEnabled()); } +void CopyInstanceDialog::updateLinkOptions() +{ + ui->symbolicLinksCheckbox->setEnabled(m_linkSupported && !ui->hardLinksCheckbox->isChecked()); + ui->hardLinksCheckbox->setEnabled(m_linkSupported && !ui->symbolicLinksCheckbox->isChecked()); + + ui->symbolicLinksCheckbox->setChecked(m_linkSupported && m_selectedOptions.isUseSymLinksEnabled()); + ui->hardLinksCheckbox->setChecked(m_linkSupported && m_selectedOptions.isUseHardLinksEnabled()); + + bool linksInUse = (ui->symbolicLinksCheckbox->isChecked() || ui->hardLinksCheckbox->isChecked()); + ui->recursiveLinkCheckbox->setEnabled(m_linkSupported && linksInUse && !ui->hardLinksCheckbox->isChecked()); + ui->dontLinkSavesCheckbox->setEnabled(m_linkSupported && linksInUse); + ui->recursiveLinkCheckbox->setChecked(m_linkSupported && linksInUse && m_selectedOptions.isLinkRecursivelyEnabled()); + ui->dontLinkSavesCheckbox->setChecked(m_linkSupported && linksInUse && m_selectedOptions.isDontLinkSavesEnabled()); +} + void CopyInstanceDialog::on_iconButton_clicked() { IconPickerDialog dlg(this); @@ -245,10 +265,20 @@ void CopyInstanceDialog::on_copyScreenshotsCheckbox_stateChanged(int state) updateSelectAllCheckbox(); } -void CopyInstanceDialog::on_linkFilesGroup_toggled(bool checked) +void CopyInstanceDialog::on_symbolicLinksCheckbox_stateChanged(int state) { - m_selectedOptions.enableLinkFiles(checked); + m_selectedOptions.enableUseSymLinks(state == Qt::Checked); updateUseCloneCheckbox(); + updateLinkOptions(); +} + +void CopyInstanceDialog::on_hardLinksCheckbox_stateChanged(int state) +{ + m_selectedOptions.enableUseHardLinks(state == Qt::Checked); + if (state == Qt::Checked && !ui->recursiveLinkCheckbox->isChecked()) { + ui->recursiveLinkCheckbox->setChecked(true); + } + updateLinkOptions(); } void CopyInstanceDialog::on_recursiveLinkCheckbox_stateChanged(int state) @@ -261,14 +291,6 @@ void CopyInstanceDialog::on_recursiveLinkCheckbox_stateChanged(int state) } -void CopyInstanceDialog::on_hardLinksCheckbox_stateChanged(int state) -{ - m_selectedOptions.enableUseHardLinks(state == Qt::Checked); - if (state == Qt::Checked && !ui->recursiveLinkCheckbox->isChecked()) { - ui->recursiveLinkCheckbox->setChecked(true); - } -} - void CopyInstanceDialog::on_dontLinkSavesCheckbox_stateChanged(int state) { m_selectedOptions.enableDontLinkSaves(state == Qt::Checked); diff --git a/launcher/ui/dialogs/CopyInstanceDialog.h b/launcher/ui/dialogs/CopyInstanceDialog.h index 859c643c..2dea3795 100644 --- a/launcher/ui/dialogs/CopyInstanceDialog.h +++ b/launcher/ui/dialogs/CopyInstanceDialog.h @@ -56,9 +56,9 @@ slots: void on_copyServersCheckbox_stateChanged(int state); void on_copyModsCheckbox_stateChanged(int state); void on_copyScreenshotsCheckbox_stateChanged(int state); - void on_linkFilesGroup_toggled(bool checked); - void on_recursiveLinkCheckbox_stateChanged(int state); + void on_symbolicLinksCheckbox_stateChanged(int state); void on_hardLinksCheckbox_stateChanged(int state); + void on_recursiveLinkCheckbox_stateChanged(int state); void on_dontLinkSavesCheckbox_stateChanged(int state); void on_useCloneCheckbox_stateChanged(int state); @@ -66,6 +66,7 @@ private: void checkAllCheckboxes(const bool& b); void updateSelectAllCheckbox(); void updateUseCloneCheckbox(); + void updateLinkOptions(); /* data */ Ui::CopyInstanceDialog *ui; @@ -73,4 +74,5 @@ private: InstancePtr m_original; InstanceCopyPrefs m_selectedOptions; bool m_cloneSupported = false; + bool m_linkSupported = false; }; diff --git a/launcher/ui/dialogs/CopyInstanceDialog.ui b/launcher/ui/dialogs/CopyInstanceDialog.ui index ce8657f6..7bf75c2d 100644 --- a/launcher/ui/dialogs/CopyInstanceDialog.ui +++ b/launcher/ui/dialogs/CopyInstanceDialog.ui @@ -9,8 +9,8 @@ 0 0 - 531 - 640 + 527 + 699 @@ -138,7 +138,7 @@ - Instance copy options + Instance Copy Options @@ -224,53 +224,92 @@ - Use symbolic links instead of copying files. + Use symbolic or hard links instead of copying files. - Link files instead of copying them + Symbolic and Hard Link Options false - true + false false - + - Link files recursively + Links are supported on most filesystems except FAT + + + Qt::AlignCenter - - - false + + + 6 - - Use hard links instead of symbolic links + + 6 - - Use hard links + + 6 - - - - - - If "copy saves" is selected world save data will be copied instead of linked and thus not shared between instances. + + 6 - - Don't link saves - - - false - - + + + + true + + + Use hard links instead of symbolic links + + + Use hard links + + + + + + + false + + + Link files recursively + + + + + + + false + + + If "copy saves" is selected world save data will be copied instead of linked and thus not shared between instances. + + + Don't link saves + + + false + + + + + + + Use symbloic links + + + + @@ -278,7 +317,7 @@ - Clone / Reflink (Copy On Write) Options + CoW (Copy-on-Write) Options @@ -287,7 +326,7 @@ false - Use Clone / Reflink + Clone instead of copying @@ -300,7 +339,7 @@ - Clone / Reflink not supported on this filesystem + Your filesystem and/or OS doesn't support reflinks Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter @@ -340,9 +379,11 @@ copyServersCheckbox copyResPacksCheckbox copyModsCheckbox + symbolicLinksCheckbox recursiveLinkCheckbox hardLinksCheckbox dontLinkSavesCheckbox + useCloneCheckbox @@ -353,8 +394,8 @@ accept() - 263 - 571 + 269 + 692 157 @@ -369,8 +410,8 @@ reject() - 331 - 571 + 337 + 692 286