Bug fix: after successful pdf download, this state wasn't being saved

This commit is contained in:
Robert McRackan 2021-08-26 15:53:33 -04:00
parent 3eda498a5e
commit 9a4903f0dd
4 changed files with 13 additions and 11 deletions

View File

@ -175,7 +175,6 @@ namespace FileLiberator
File.Move(f.FullName, dest);
movedAudioFile |= AudibleFileStorage.Audio.IsFileTypeMatch(f);
}
AudibleFileStorage.Audio.Refresh();

View File

@ -20,8 +20,8 @@ namespace FileLiberator
public override async Task<StatusHandler> ProcessItemAsync(LibraryBook libraryBook)
{
var proposedDownloadFilePath = getProposedDownloadFilePath(libraryBook);
await downloadPdfAsync(libraryBook, proposedDownloadFilePath);
var result = verifyDownload(libraryBook);
var actualDownloadedFilePath = await downloadPdfAsync(libraryBook, proposedDownloadFilePath);
var result = verifyDownload(actualDownloadedFilePath);
libraryBook.Book.UserDefinedItem.PdfStatus = result.IsSuccess ? LiberatedStatus.Liberated : LiberatedStatus.NotLiberated;
@ -48,7 +48,7 @@ namespace FileLiberator
private static string getdownloadUrl(LibraryBook libraryBook)
=> libraryBook?.Book?.Supplements?.FirstOrDefault()?.Url;
private async Task downloadPdfAsync(LibraryBook libraryBook, string proposedDownloadFilePath)
private async Task<string> downloadPdfAsync(LibraryBook libraryBook, string proposedDownloadFilePath)
{
var api = await GetApiAsync(libraryBook);
var downloadUrl = await api.GetPdfDownloadLinkAsync(libraryBook.Book.AudibleProductId);
@ -57,10 +57,12 @@ namespace FileLiberator
var actualDownloadedFilePath = await PerformDownloadAsync(
proposedDownloadFilePath,
(p) => client.DownloadFileAsync(downloadUrl, proposedDownloadFilePath, p));
return actualDownloadedFilePath;
}
private static StatusHandler verifyDownload(LibraryBook libraryBook)
=> !libraryBook.Book.PDF_Exists
private static StatusHandler verifyDownload(string actualDownloadedFilePath)
=> !File.Exists(actualDownloadedFilePath)
? new StatusHandler { "Downloaded PDF cannot be found" }
: new StatusHandler();
}

View File

@ -13,7 +13,7 @@
<!-- <PublishSingleFile>true</PublishSingleFile> -->
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<Version>5.5.7.2</Version>
<Version>5.5.7.4</Version>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">

View File

@ -132,14 +132,15 @@ namespace LibationWinForms
private void Commit()
{
//We don't want LiberatedStatus.PartialDownload to be a persistent status.
var bookStatus = Book.UserDefinedItem.BookStatus;
var saveStatus = bookStatus == LiberatedStatus.PartialDownload ? LiberatedStatus.NotLiberated : bookStatus;
// We don't want LiberatedStatus.PartialDownload to be a persistent status.
// If display/icon status is PartialDownload then save NotLiberated to db then restore PartialDownload for display
var displayStatus = Book.UserDefinedItem.BookStatus;
var saveStatus = displayStatus == LiberatedStatus.PartialDownload ? LiberatedStatus.NotLiberated : displayStatus;
Book.UserDefinedItem.BookStatus = saveStatus;
LibraryCommands.UpdateUserDefinedItem(Book);
Book.UserDefinedItem.BookStatus = bookStatus;
Book.UserDefinedItem.BookStatus = displayStatus;
Refilter?.Invoke();
}