diff --git a/Telegram/SourceFiles/core/application.cpp b/Telegram/SourceFiles/core/application.cpp index 6e9f5a6e0..06652a540 100644 --- a/Telegram/SourceFiles/core/application.cpp +++ b/Telegram/SourceFiles/core/application.cpp @@ -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 #include #include #include @@ -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(); 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 { diff --git a/Telegram/SourceFiles/core/file_utilities.cpp b/Telegram/SourceFiles/core/file_utilities.cpp index 9c9fbb308..f90b7ed28 100644 --- a/Telegram/SourceFiles/core/file_utilities.cpp +++ b/Telegram/SourceFiles/core/file_utilities.cpp @@ -173,12 +173,15 @@ QString DefaultDownloadPathFolder(not_null session) { } QString DefaultDownloadPath(not_null 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( diff --git a/Telegram/SourceFiles/core/utils.h b/Telegram/SourceFiles/core/utils.h index 02ba16b1e..f0f097b3b 100644 --- a/Telegram/SourceFiles/core/utils.h +++ b/Telegram/SourceFiles/core/utils.h @@ -21,6 +21,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include #include #include +#include #if __has_include() #include @@ -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;