mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-15 21:57:10 +02:00
Differ file download failure reasons
..and uncomment the code for handling incorrect permissions
This commit is contained in:
parent
7307f0b1a5
commit
173108a9cb
9 changed files with 47 additions and 37 deletions
|
@ -762,7 +762,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
"lng_download_path_dir_radio" = "Custom folder, cleared only manually";
|
||||
"lng_download_path_choose" = "Choose download path";
|
||||
"lng_sure_clear_downloads" = "Do you want to remove all downloaded files from temp folder? It is done automatically on logout or program uninstall.";
|
||||
"lng_download_path_failed" = "File download could not be started.\n\nThis might be because the download location you've selected is invalid. Try changing the \"Download path\" in Settings.";
|
||||
"lng_download_path_failed" = "File download could not be started.\n\nThe default download location will be used now. You can always change it in Settings > Advanced > Download Path.\n\nPlease try once again.";
|
||||
"lng_download_path_settings" = "Settings";
|
||||
"lng_download_finish_failed" = "File download could not be finished.\n\nWould you like to try again?";
|
||||
"lng_download_path_clearing" = "Clearing...";
|
||||
|
|
|
@ -279,11 +279,11 @@ void LoadCloudFile(
|
|||
if (const auto onstack = progress) {
|
||||
onstack();
|
||||
}
|
||||
}, [=, &file](bool started) {
|
||||
}, [=, &file](FileLoader::Error error) {
|
||||
finish(file);
|
||||
file.flags |= CloudFile::Flag::Failed;
|
||||
if (const auto onstack = fail) {
|
||||
onstack(started);
|
||||
onstack(error.started);
|
||||
}
|
||||
}, [=, &file] {
|
||||
finish(file);
|
||||
|
|
|
@ -988,8 +988,9 @@ void DocumentData::handleLoaderUpdates() {
|
|||
_loader->updates(
|
||||
) | rpl::start_with_next_error_done([=] {
|
||||
_owner->documentLoadProgress(this);
|
||||
}, [=](bool started) {
|
||||
if (started && _loader) {
|
||||
}, [=](FileLoader::Error error) {
|
||||
using FailureReason = FileLoader::FailureReason;
|
||||
if (error.started && _loader) {
|
||||
const auto origin = _loader->fileOrigin();
|
||||
const auto failedFileName = _loader->fileName();
|
||||
const auto retry = [=] {
|
||||
|
@ -1000,23 +1001,21 @@ void DocumentData::handleLoaderUpdates() {
|
|||
tr::lng_download_finish_failed(),
|
||||
crl::guard(&session(), retry)
|
||||
}));
|
||||
} else {
|
||||
// Sometimes we have LOCATION_INVALID error in documents / stickers.
|
||||
// Sometimes FILE_REFERENCE_EXPIRED could not be handled.
|
||||
//
|
||||
//const auto openSettings = [=] {
|
||||
// Core::App().settings().etDownloadPathBookmark(QByteArray());
|
||||
// Core::App().settings().setDownloadPath(QString());
|
||||
// Ui::show(Box<DownloadPathBox>());
|
||||
//};
|
||||
//Ui::show(Box<Ui::ConfirmBox>(
|
||||
// tr::lng_download_path_failed(tr::now),
|
||||
// tr::lng_download_path_settings(tr::now),
|
||||
// crl::guard(&session(), openSettings)));
|
||||
} else if (error.failureReason == FailureReason::FileWriteFailure) {
|
||||
if (!Core::App().settings().downloadPath().isEmpty()) {
|
||||
Core::App().settings().setDownloadPathBookmark(QByteArray());
|
||||
Core::App().settings().setDownloadPath(QString());
|
||||
Core::App().saveSettingsDelayed();
|
||||
InvokeQueued(qApp, [] {
|
||||
Ui::show(
|
||||
Ui::MakeInformBox(
|
||||
tr::lng_download_path_failed(tr::now)));
|
||||
});
|
||||
}
|
||||
}
|
||||
finishLoad();
|
||||
status = FileDownloadFailed;
|
||||
_owner->documentLoadFail(this, started);
|
||||
_owner->documentLoadFail(this, error.started);
|
||||
}, [=] {
|
||||
finishLoad();
|
||||
_owner->documentLoadDone(this);
|
||||
|
|
|
@ -1816,7 +1816,7 @@ void FormController::loadFile(File &file) {
|
|||
loader->updates(
|
||||
) | rpl::start_with_next_error_done([=] {
|
||||
fileLoadProgress(key, loader->currentOffset());
|
||||
}, [=](bool started) {
|
||||
}, [=](FileLoader::Error error) {
|
||||
fileLoadFail(key);
|
||||
}, [=] {
|
||||
fileLoadDone(key, loader->bytes());
|
||||
|
|
|
@ -128,12 +128,12 @@ void FileLoader::finishWithBytes(const QByteArray &data) {
|
|||
if (!_filename.isEmpty() && _toCache == LoadToCacheAsWell) {
|
||||
if (!_fileIsOpen) _fileIsOpen = _file.open(QIODevice::WriteOnly);
|
||||
if (!_fileIsOpen) {
|
||||
cancel(true);
|
||||
cancel(FailureReason::FileWriteFailure);
|
||||
return;
|
||||
}
|
||||
_file.seek(0);
|
||||
if (_file.write(_data) != qint64(_data.size())) {
|
||||
cancel(true);
|
||||
cancel(FailureReason::FileWriteFailure);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -258,7 +258,7 @@ bool FileLoader::checkForOpen() {
|
|||
if (_fileIsOpen) {
|
||||
return true;
|
||||
}
|
||||
cancel(true);
|
||||
cancel(FailureReason::FileWriteFailure);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -329,10 +329,10 @@ bool FileLoader::tryLoadLocal() {
|
|||
}
|
||||
|
||||
void FileLoader::cancel() {
|
||||
cancel(false);
|
||||
cancel(FailureReason::NoFailure);
|
||||
}
|
||||
|
||||
void FileLoader::cancel(bool fail) {
|
||||
void FileLoader::cancel(FailureReason fail) {
|
||||
const auto started = (currentOffset() > 0);
|
||||
|
||||
cancelHook();
|
||||
|
@ -347,8 +347,8 @@ void FileLoader::cancel(bool fail) {
|
|||
_data = QByteArray();
|
||||
|
||||
const auto weak = base::make_weak(this);
|
||||
if (fail) {
|
||||
_updates.fire_error_copy(started);
|
||||
if (fail != FailureReason::NoFailure) {
|
||||
_updates.fire_error_copy({ fail, started });
|
||||
} else {
|
||||
_updates.fire_done();
|
||||
}
|
||||
|
@ -377,7 +377,7 @@ bool FileLoader::writeResultPart(int64 offset, bytes::const_span buffer) {
|
|||
}
|
||||
_file.seek(offset);
|
||||
if (_file.write(reinterpret_cast<const char*>(buffer.data()), buffer.size()) != qint64(buffer.size())) {
|
||||
cancel(true);
|
||||
cancel(FailureReason::FileWriteFailure);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -410,7 +410,7 @@ QByteArray FileLoader::readLoadedPartBack(int64 offset, int size) {
|
|||
_file.close();
|
||||
_fileIsOpen = _file.open(QIODevice::ReadWrite);
|
||||
if (!_fileIsOpen) {
|
||||
cancel(true);
|
||||
cancel(FailureReason::FileWriteFailure);
|
||||
return QByteArray();
|
||||
}
|
||||
}
|
||||
|
@ -434,7 +434,7 @@ bool FileLoader::finalizeResult() {
|
|||
}
|
||||
_file.seek(0);
|
||||
if (!_fileIsOpen || _file.write(_data) != qint64(_data.size())) {
|
||||
cancel(true);
|
||||
cancel(FailureReason::FileWriteFailure);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,6 +52,17 @@ struct StorageImageSaved {
|
|||
|
||||
class FileLoader : public base::has_weak_ptr {
|
||||
public:
|
||||
enum class FailureReason {
|
||||
NoFailure,
|
||||
FileWriteFailure,
|
||||
OtherFailure,
|
||||
};
|
||||
|
||||
struct Error {
|
||||
FailureReason failureReason = FailureReason::NoFailure;
|
||||
bool started = false;
|
||||
};
|
||||
|
||||
FileLoader(
|
||||
not_null<Main::Session*> session,
|
||||
const QString &toFile,
|
||||
|
@ -113,7 +124,7 @@ public:
|
|||
const QByteArray &imageFormat,
|
||||
const QImage &imageData);
|
||||
|
||||
[[nodiscard]] rpl::producer<rpl::empty_value, bool> updates() const {
|
||||
[[nodiscard]] rpl::producer<rpl::empty_value, Error> updates() const {
|
||||
return _updates.events();
|
||||
}
|
||||
|
||||
|
@ -142,7 +153,7 @@ protected:
|
|||
startLoading();
|
||||
}
|
||||
|
||||
void cancel(bool failed);
|
||||
void cancel(FailureReason failed);
|
||||
|
||||
void notifyAboutProgress();
|
||||
|
||||
|
@ -177,7 +188,7 @@ protected:
|
|||
mutable QImage _imageData;
|
||||
|
||||
rpl::lifetime _lifetime;
|
||||
rpl::event_stream<rpl::empty_value, bool> _updates;
|
||||
rpl::event_stream<rpl::empty_value, Error> _updates;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -164,7 +164,7 @@ bool mtpFileLoader::feedPart(int64 offset, const QByteArray &bytes) {
|
|||
}
|
||||
|
||||
void mtpFileLoader::cancelOnFail() {
|
||||
cancel(true);
|
||||
cancel(FailureReason::OtherFailure);
|
||||
}
|
||||
|
||||
bool mtpFileLoader::setWebFileSizeHook(int64 size) {
|
||||
|
@ -176,7 +176,7 @@ bool mtpFileLoader::setWebFileSizeHook(int64 size) {
|
|||
"Bad size provided by bot for webDocument: %1, real: %2"
|
||||
).arg(_fullSize
|
||||
).arg(size));
|
||||
cancel(true);
|
||||
cancel(FailureReason::OtherFailure);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -506,7 +506,7 @@ void webFileLoader::loadFinished(const QByteArray &data) {
|
|||
}
|
||||
|
||||
void webFileLoader::loadFailed() {
|
||||
cancel(true);
|
||||
cancel(FailureReason::OtherFailure);
|
||||
}
|
||||
|
||||
Storage::Cache::Key webFileLoader::cacheKey() const {
|
||||
|
|
|
@ -59,7 +59,7 @@ StreamedFileDownloader::StreamedFileDownloader(
|
|||
_reader->partsForDownloader(
|
||||
) | rpl::start_with_next([=](const LoadedPart &part) {
|
||||
if (part.offset == LoadedPart::kFailedOffset) {
|
||||
cancel(true);
|
||||
cancel(FailureReason::OtherFailure);
|
||||
} else {
|
||||
savePart(std::move(part));
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue