Better check for download path availability in sandbox
This commit is contained in:
parent
04a8a9b7ee
commit
54a0f443b4
|
@ -91,6 +91,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "boxes/premium_limits_box.h"
|
||||
#include "ui/boxes/confirm_box.h"
|
||||
|
||||
#include <QtCore/QStandardPaths>
|
||||
#include <QtCore/QMimeDatabase>
|
||||
#include <QtGui/QGuiApplication>
|
||||
#include <QtGui/QScreen>
|
||||
|
@ -251,6 +252,15 @@ void Application::run() {
|
|||
return;
|
||||
}
|
||||
|
||||
if (KSandbox::isInside()) {
|
||||
const auto path = settings().downloadPath();
|
||||
if (!path.isEmpty()
|
||||
&& path != qstr("tmp")
|
||||
&& !base::CanReadDirectory(path)) {
|
||||
settings().setDownloadPath(QString());
|
||||
}
|
||||
}
|
||||
|
||||
_translator = std::make_unique<Lang::Translator>();
|
||||
QCoreApplication::instance()->installTranslator(_translator.get());
|
||||
|
||||
|
@ -589,9 +599,15 @@ void Application::saveSettings() {
|
|||
}
|
||||
|
||||
bool Application::canSaveFileWithoutAskingForPath() const {
|
||||
return !Core::App().settings().askDownloadPath()
|
||||
&& (!KSandbox::isInside()
|
||||
|| !Core::App().settings().downloadPath().isEmpty());
|
||||
if (Core::App().settings().askDownloadPath()) {
|
||||
return false;
|
||||
} else if (KSandbox::isInside()
|
||||
&& Core::App().settings().downloadPath().isEmpty()) {
|
||||
const auto path = QStandardPaths::writableLocation(
|
||||
QStandardPaths::DownloadLocation);
|
||||
return base::CanReadDirectory(path);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
MTP::Config &Application::fallbackProductionConfig() const {
|
||||
|
|
|
@ -173,12 +173,15 @@ QString DefaultDownloadPathFolder(not_null<Main::Session*> session) {
|
|||
}
|
||||
|
||||
QString DefaultDownloadPath(not_null<Main::Session*> session) {
|
||||
const auto realDefaultPath = QStandardPaths::writableLocation(
|
||||
QStandardPaths::DownloadLocation)
|
||||
const auto standardLocation = QStandardPaths::writableLocation(
|
||||
QStandardPaths::DownloadLocation);
|
||||
const auto realDefaultPath = standardLocation
|
||||
+ '/'
|
||||
+ DefaultDownloadPathFolder(session)
|
||||
+ '/';
|
||||
if (KSandbox::isInside() && Core::App().settings().downloadPath().isEmpty()) {
|
||||
if (KSandbox::isInside()
|
||||
&& Core::App().settings().downloadPath().isEmpty()
|
||||
&& !base::CanReadDirectory(standardLocation)) {
|
||||
QStringList files;
|
||||
QByteArray remoteContent;
|
||||
const auto success = Platform::FileDialog::Get(
|
||||
|
|
|
@ -21,6 +21,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include <QtNetwork/QNetworkProxy>
|
||||
#include <cmath>
|
||||
#include <set>
|
||||
#include <filesystem>
|
||||
|
||||
#if __has_include(<kurlmimedata.h>)
|
||||
#include <kurlmimedata.h>
|
||||
|
@ -60,6 +61,19 @@ inline QString IconName() {
|
|||
}
|
||||
#endif
|
||||
|
||||
inline bool CanReadDirectory(const QString &path) {
|
||||
#ifndef Q_OS_MAC // directory_iterator since 10.15
|
||||
try {
|
||||
std::filesystem::directory_iterator(path.toStdString());
|
||||
return true;
|
||||
} catch (...) {
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
Unexpected("Not implemented.");
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace base
|
||||
|
||||
static const int32 ScrollMax = INT_MAX;
|
||||
|
|
Loading…
Reference in New Issue