Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn about unlistenable folders #1483

Merged
merged 4 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/ui/create-repo-dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
#include "ui/create-repo-dialog.h"
#include "ui/repos-tab.h"

#ifdef Q_OS_WIN32
#include "utils/utils-win.h"
#endif

CreateRepoDialog::CreateRepoDialog(const Account& account,
const QString& worktree,
ReposTab *repos_tab,
Expand Down Expand Up @@ -88,6 +92,17 @@ void CreateRepoDialog::createAction()
if (!validateInputs()) {
return;
}
#ifdef Q_OS_WIN32
if (utils::win::isNetworkDevice(path_)) {
bool ok = seafApplet->yesOrCancelBox(
tr("File changes on network drives may not be synced automatically. You can set sync intervals to enable periodic sync. Do you want to sync with this folder?"),
this, true);
if (!ok) {
return;
}
}
#endif // Q_OS_WIN32

mStatusText->setText(tr("Creating..."));

setAllInputsEnabled(false);
Expand Down
17 changes: 17 additions & 0 deletions src/ui/download-repo-dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
#include "repo-service.h"
#include "download-repo-dialog.h"

#ifdef Q_OS_WIN32
#include "utils/utils-win.h"
#endif

namespace {
const int kAlternativeTryTimes = 20;
bool inline isPathInWorktree(const QString& worktree, const QString &path)
Expand Down Expand Up @@ -230,6 +234,19 @@ void DownloadRepoDialog::onOkBtnClicked()
if (!validateInputs()) {
return;
}
#ifdef Q_OS_WIN32
QString worktree = alternative_path_.isEmpty() ?
QDir(mDirectory->text()).absoluteFilePath(repo_.name) :
alternative_path_;
if (utils::win::isNetworkDevice(worktree)) {
bool ok = seafApplet->yesOrCancelBox(
tr("File changes on network drives may not be synced automatically. You can set sync intervals to enable periodic sync. Do you want to sync with this folder?"),
this, true);
if (!ok) {
return;
}
}
#endif // Q_OS_WIN32

setAllInputsEnabled(false);

Expand Down
20 changes: 20 additions & 0 deletions src/utils/utils-win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <QLibrary>
#include <QPair>
#include <QString>
#include <QDir>

#include "utils/utils-win.h"

Expand Down Expand Up @@ -348,6 +349,25 @@ DWORD runShellAsAdministrator(LPCSTR cmd, LPCSTR arg, int n_show)
return exit_code;
}

bool isNetworkDevice(QString path)
{
// Shared folders are supposed to be network device.
if (path.startsWith("//")) {
return true;
}

QString root = path;
while (!QDir(root).isRoot()) {
root = QDir::cleanPath(root + "/..");
}
if (!root.endsWith("/")) {
root += "/";
}
root = QDir::toNativeSeparators(root);

LPCWSTR lpRootPathName = reinterpret_cast<LPCWSTR>(root.utf16());
return GetDriveTypeW(lpRootPathName) == DRIVE_REMOTE;
}

} // namespace win

Expand Down
2 changes: 2 additions & 0 deletions src/utils/utils-win.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ bool isWindows10OrHigher();
bool fixQtHDPINonIntegerScaling();
std::string getLocalPipeName(const char *pipeName);
DWORD runShellAsAdministrator(LPCSTR cmd, LPCSTR arg, int n_show);
bool isNetworkDevice(QString path);

} // namespace win
} // namespace utils
#endif
Expand Down