From 16a58db75ddd40dae5d59a43b8a52486bb2acb49 Mon Sep 17 00:00:00 2001 From: allexzander Date: Fri, 7 May 2021 20:02:03 +0300 Subject: [PATCH] Temporary! Windows. VFS. Block Virtual Files for partition root sync folders. Signed-off-by: allexzander --- src/common/utility.cpp | 20 +++++++++++++++++++ src/common/utility.h | 5 +++++ src/gui/accountsettings.cpp | 3 +++ src/gui/folderwizard.cpp | 15 ++++++++++++++ src/gui/wizard/owncloudadvancedsetuppage.cpp | 21 ++++++++++++++++++++ src/gui/wizard/owncloudadvancedsetuppage.h | 3 +++ 6 files changed, 67 insertions(+) diff --git a/src/common/utility.cpp b/src/common/utility.cpp index 55ff8647c49a3..c9b0a81fd8c9e 100644 --- a/src/common/utility.cpp +++ b/src/common/utility.cpp @@ -676,6 +676,26 @@ QByteArray Utility::conflictFileBaseNameFromPattern(const QByteArray &conflictNa return conflictName.left(tagStart) + conflictName.mid(tagEnd); } +bool Utility::isPathWindowsDrivePartitionRoot(const QString &path) +{ + Q_UNUSED(path) +#ifdef Q_OS_WIN + // should be 2 or 3 characters length + if (!(path.size() >= 2 && path.size() <= 3)) { + return false; + } + + // must mutch a pattern "[A-Za-z]:" + if (!(path.at(1) == QLatin1Char(':') && path.at(0).isLetter())) { + return false; + } + + // final check - last character should be either slash/backslash, or, it should be missing + return path.size() < 3 || path.at(2) == QLatin1Char('/') || path.at(2) == QLatin1Char('\\'); +#endif + return false; +} + QString Utility::sanitizeForFileName(const QString &name) { const auto invalid = QStringLiteral(R"(/?<>\:*|")"); diff --git a/src/common/utility.h b/src/common/utility.h index 3dc2586b498e3..e02b975019c3a 100644 --- a/src/common/utility.h +++ b/src/common/utility.h @@ -235,6 +235,11 @@ namespace Utility { */ OCSYNC_EXPORT QByteArray conflictFileBaseNameFromPattern(const QByteArray &conflictName); + /** + * @brief Check whether the path is a root of a Windows drive partition ([c:/, d:/, e:/, etc.) + */ + OCSYNC_EXPORT bool isPathWindowsDrivePartitionRoot(const QString &path); + #ifdef Q_OS_WIN OCSYNC_EXPORT bool registryKeyExists(HKEY hRootKey, const QString &subKey); OCSYNC_EXPORT QVariant registryGetKeyValue(HKEY hRootKey, const QString &subKey, const QString &valueName); diff --git a/src/gui/accountsettings.cpp b/src/gui/accountsettings.cpp index a881606f78069..5f5ae3e0fca95 100644 --- a/src/gui/accountsettings.cpp +++ b/src/gui/accountsettings.cpp @@ -571,6 +571,9 @@ void AccountSettings::slotCustomContextMenuRequested(const QPoint &pos) const auto mode = bestAvailableVfsMode(); if (mode == Vfs::WindowsCfApi || ConfigFile().showExperimentalOptions()) { ac = menu->addAction(tr("Enable virtual file support %1 …").arg(mode == Vfs::WindowsCfApi ? QString() : tr("(experimental)"))); + // TODO: remove when UX decision is made + ac->setEnabled(!Utility::isPathWindowsDrivePartitionRoot(folder->path())); + // connect(ac, &QAction::triggered, this, &AccountSettings::slotEnableVfsCurrentFolder); } } diff --git a/src/gui/folderwizard.cpp b/src/gui/folderwizard.cpp index 0b42aab8485e5..e8a3231a010ee 100644 --- a/src/gui/folderwizard.cpp +++ b/src/gui/folderwizard.cpp @@ -536,6 +536,21 @@ void FolderWizardSelectiveSync::initializePage() initialBlacklist = QStringList("/"); } _selectiveSync->setFolderInfo(targetPath, alias, initialBlacklist); + + if (_virtualFilesCheckBox) { + // TODO: remove when UX decision is made + if (Utility::isPathWindowsDrivePartitionRoot(wizard()->field(QStringLiteral("sourceFolder")).toString())) { + _virtualFilesCheckBox->setChecked(false); + _virtualFilesCheckBox->setEnabled(false); + _virtualFilesCheckBox->setText(tr("Virtual files are not supported for Windows partition roots as local folder. Please choose a valid subfolder under drive letter.")); + } else { + _virtualFilesCheckBox->setChecked(bestAvailableVfsMode() == Vfs::WindowsCfApi); + _virtualFilesCheckBox->setEnabled(true); + _virtualFilesCheckBox->setText(tr("Use virtual files instead of downloading content immediately %1").arg(bestAvailableVfsMode() == Vfs::WindowsCfApi ? QString() : tr("(experimental)"))); + } + // + } + QWizardPage::initializePage(); } diff --git a/src/gui/wizard/owncloudadvancedsetuppage.cpp b/src/gui/wizard/owncloudadvancedsetuppage.cpp index 9249ea45a282d..59ebb955cf23f 100644 --- a/src/gui/wizard/owncloudadvancedsetuppage.cpp +++ b/src/gui/wizard/owncloudadvancedsetuppage.cpp @@ -221,6 +221,24 @@ void OwncloudAdvancedSetupPage::fetchUserData() _ui.userNameLabel->setText(userName); } +void OwncloudAdvancedSetupPage::refreshVirtualFilesAvailibility(const QString &path) +{ + // TODO: remove when UX decision is made + if (!_ui.rVirtualFileSync->isVisible()) { + return; + } + + if (Utility::isPathWindowsDrivePartitionRoot(path)) { + _ui.rVirtualFileSync->setText(tr("Virtual files are not supported for Windows partition roots as local folder. Please choose a valid subfolder under drive letter.")); + setRadioChecked(_ui.rSyncEverything); + _ui.rVirtualFileSync->setEnabled(false); + } else { + _ui.rVirtualFileSync->setText(tr("Use &virtual files instead of downloading content immediately %1").arg(bestAvailableVfsMode() == Vfs::WindowsCfApi ? QString() : tr("(experimental)"))); + _ui.rVirtualFileSync->setEnabled(true); + } + // +} + void OwncloudAdvancedSetupPage::setServerAddressLabelUrl(const QUrl &url) { if (!url.isValid()) { @@ -411,6 +429,9 @@ void OwncloudAdvancedSetupPage::slotSelectFolder() { QString dir = QFileDialog::getExistingDirectory(nullptr, tr("Local Sync Folder"), QDir::homePath()); if (!dir.isEmpty()) { + // TODO: remove when UX decision is made + refreshVirtualFilesAvailibility(dir); + setLocalFolderPushButtonPath(dir); wizard()->setProperty("localFolder", dir); updateStatus(); diff --git a/src/gui/wizard/owncloudadvancedsetuppage.h b/src/gui/wizard/owncloudadvancedsetuppage.h index 8af948d9cc474..cb1fa064cfcbb 100644 --- a/src/gui/wizard/owncloudadvancedsetuppage.h +++ b/src/gui/wizard/owncloudadvancedsetuppage.h @@ -84,6 +84,9 @@ private slots: void fetchUserAvatar(); void fetchUserData(); + // TODO: remove when UX decision is made + void refreshVirtualFilesAvailibility(const QString &path); + Ui_OwncloudAdvancedSetupPage _ui; bool _checking = false; bool _created = false;