mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Better check for download path availability in sandbox
This commit is contained in:
parent
04a8a9b7ee
commit
54a0f443b4
3 changed files with 39 additions and 6 deletions
|
@ -91,6 +91,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "boxes/premium_limits_box.h"
|
#include "boxes/premium_limits_box.h"
|
||||||
#include "ui/boxes/confirm_box.h"
|
#include "ui/boxes/confirm_box.h"
|
||||||
|
|
||||||
|
#include <QtCore/QStandardPaths>
|
||||||
#include <QtCore/QMimeDatabase>
|
#include <QtCore/QMimeDatabase>
|
||||||
#include <QtGui/QGuiApplication>
|
#include <QtGui/QGuiApplication>
|
||||||
#include <QtGui/QScreen>
|
#include <QtGui/QScreen>
|
||||||
|
@ -251,6 +252,15 @@ void Application::run() {
|
||||||
return;
|
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>();
|
_translator = std::make_unique<Lang::Translator>();
|
||||||
QCoreApplication::instance()->installTranslator(_translator.get());
|
QCoreApplication::instance()->installTranslator(_translator.get());
|
||||||
|
|
||||||
|
@ -589,9 +599,15 @@ void Application::saveSettings() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Application::canSaveFileWithoutAskingForPath() const {
|
bool Application::canSaveFileWithoutAskingForPath() const {
|
||||||
return !Core::App().settings().askDownloadPath()
|
if (Core::App().settings().askDownloadPath()) {
|
||||||
&& (!KSandbox::isInside()
|
return false;
|
||||||
|| !Core::App().settings().downloadPath().isEmpty());
|
} 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 {
|
MTP::Config &Application::fallbackProductionConfig() const {
|
||||||
|
|
|
@ -173,12 +173,15 @@ QString DefaultDownloadPathFolder(not_null<Main::Session*> session) {
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DefaultDownloadPath(not_null<Main::Session*> session) {
|
QString DefaultDownloadPath(not_null<Main::Session*> session) {
|
||||||
const auto realDefaultPath = QStandardPaths::writableLocation(
|
const auto standardLocation = QStandardPaths::writableLocation(
|
||||||
QStandardPaths::DownloadLocation)
|
QStandardPaths::DownloadLocation);
|
||||||
|
const auto realDefaultPath = standardLocation
|
||||||
+ '/'
|
+ '/'
|
||||||
+ DefaultDownloadPathFolder(session)
|
+ DefaultDownloadPathFolder(session)
|
||||||
+ '/';
|
+ '/';
|
||||||
if (KSandbox::isInside() && Core::App().settings().downloadPath().isEmpty()) {
|
if (KSandbox::isInside()
|
||||||
|
&& Core::App().settings().downloadPath().isEmpty()
|
||||||
|
&& !base::CanReadDirectory(standardLocation)) {
|
||||||
QStringList files;
|
QStringList files;
|
||||||
QByteArray remoteContent;
|
QByteArray remoteContent;
|
||||||
const auto success = Platform::FileDialog::Get(
|
const auto success = Platform::FileDialog::Get(
|
||||||
|
|
|
@ -21,6 +21,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include <QtNetwork/QNetworkProxy>
|
#include <QtNetwork/QNetworkProxy>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
#include <filesystem>
|
||||||
|
|
||||||
#if __has_include(<kurlmimedata.h>)
|
#if __has_include(<kurlmimedata.h>)
|
||||||
#include <kurlmimedata.h>
|
#include <kurlmimedata.h>
|
||||||
|
@ -60,6 +61,19 @@ inline QString IconName() {
|
||||||
}
|
}
|
||||||
#endif
|
#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
|
} // namespace base
|
||||||
|
|
||||||
static const int32 ScrollMax = INT_MAX;
|
static const int32 ScrollMax = INT_MAX;
|
||||||
|
|
Loading…
Add table
Reference in a new issue