mirror of
https://github.com/rmcrackan/Libation.git
synced 2026-05-18 13:41:27 -04:00
trying again to fix the intermittent cover image issue
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<Version>13.3.5.1</Version>
|
||||
<Version>13.3.5.2</Version>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@@ -107,7 +107,9 @@ public class DownloadDecryptBook : AudioDecodable, IProcessable<DownloadDecryptB
|
||||
|
||||
if (moveFilesTask.IsCompletedSuccessfully && !cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
await Task.Run(() => WindowsDirectory.SetCoverAsFolderIcon(libraryBook.Book.PictureId, finalStorageDir, cancellationToken), cancellationToken);
|
||||
// Same picture key as DownloadCoverArt so we hit the same Amazon asset (and Images cache) the parallel task likely just populated.
|
||||
var folderIconPictureId = libraryBook.Book.PictureLarge ?? libraryBook.Book.PictureId;
|
||||
await Task.Run(() => WindowsDirectory.SetCoverAsFolderIcon(folderIconPictureId, finalStorageDir, cancellationToken), cancellationToken);
|
||||
|
||||
Serilog.Log.Verbose("Updating liberated status for {@Book}", libraryBook.LogFriendly());
|
||||
await libraryBook.UpdateBookStatusAsync(LiberatedStatus.Liberated, Configuration.LibationVersion, audioFormat, audioVersion);
|
||||
|
||||
@@ -37,11 +37,7 @@ public static class WindowsDirectory
|
||||
continue;
|
||||
}
|
||||
|
||||
Serilog.Log.Logger.Warning(
|
||||
"Could not set Explorer folder icon after {MaxAttempts} attempts: the 300x300 cover image never became available (empty or missing). The audiobook download itself is unaffected. Check your network to Amazon images, disk space under Libation's Images folder, or try liberating again. {@DebugInfo}",
|
||||
FolderIconMaxAttempts, new { directory, pictureId });
|
||||
TryDeleteFolderIcon(directory);
|
||||
return;
|
||||
break;
|
||||
}
|
||||
|
||||
InteropFactory.Create().SetFolderIcon(imageJpegBytes: jpegBytes, directory: directory);
|
||||
@@ -56,6 +52,14 @@ public static class WindowsDirectory
|
||||
continue;
|
||||
}
|
||||
|
||||
if (TrySetFolderIconUsingPictureSize(pictureId, directory, PictureSize.Native, cancellationToken))
|
||||
{
|
||||
Serilog.Log.Logger.Information(
|
||||
"Set Explorer folder icon using full-size cover after 300x300 failed (decode, ICO conversion, or writing desktop.ini/Icon.ico). {@DebugInfo}",
|
||||
new { directory, pictureId });
|
||||
return;
|
||||
}
|
||||
|
||||
Serilog.Log.Logger.Error(ex,
|
||||
"Could not set Explorer folder icon after {MaxAttempts} attempts (decode, ICO conversion, or writing desktop.ini/Icon.ico failed). The audiobook download itself should still be fine; try liberating again, or check folder permissions if the library is on removable media. {@DebugInfo}",
|
||||
FolderIconMaxAttempts, new { directory, pictureId });
|
||||
@@ -63,6 +67,38 @@ public static class WindowsDirectory
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 300x300 never returned usable bytes — Native is a separate CDN URL and is often already cached by DownloadCoverArt in the same session.
|
||||
if (TrySetFolderIconUsingPictureSize(pictureId, directory, PictureSize.Native, cancellationToken))
|
||||
{
|
||||
Serilog.Log.Logger.Information(
|
||||
"Set Explorer folder icon using full-size cover after 300x300 was empty or missing. {@DebugInfo}",
|
||||
new { directory, pictureId });
|
||||
return;
|
||||
}
|
||||
|
||||
Serilog.Log.Logger.Warning(
|
||||
"Could not set Explorer folder icon: neither 300x300 nor full-size cover became available. The audiobook download itself is unaffected. Check your network to Amazon images, disk space under Libation's Images folder, or try liberating again. {@DebugInfo}",
|
||||
new { directory, pictureId });
|
||||
TryDeleteFolderIcon(directory);
|
||||
}
|
||||
|
||||
static bool TrySetFolderIconUsingPictureSize(string pictureId, string directory, PictureSize size, CancellationToken cancellationToken)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
try
|
||||
{
|
||||
var jpegBytes = PictureStorage.GetPictureSynchronously(new(pictureId, size), cancellationToken);
|
||||
if (jpegBytes.Length == 0)
|
||||
return false;
|
||||
InteropFactory.Create().SetFolderIcon(imageJpegBytes: jpegBytes, directory: directory);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Serilog.Log.Logger.Debug(ex, "Folder icon: could not set using {PictureSize}. {@DebugInfo}", size, new { directory, pictureId });
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static void DelayBetweenFolderIconRetries(CancellationToken cancellationToken, int attemptAfterFailure)
|
||||
|
||||
Reference in New Issue
Block a user