mirror of
https://github.com/rmcrackan/Libation.git
synced 2026-03-27 19:33:52 -04:00
Add warnings for inaccessable InProgress directory (#1446)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
using FileManager;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
#nullable enable
|
||||
namespace AaxDecrypter
|
||||
{
|
||||
public class UnencryptedAudiobookDownloader : AudiobookDownloadBase
|
||||
|
||||
@@ -243,6 +243,7 @@ namespace AppScaffolding
|
||||
//Log.Logger.Here().Debug("Begin Libation. Debug with line numbers");
|
||||
}
|
||||
|
||||
#nullable enable
|
||||
private static void logStartupState(Configuration config)
|
||||
{
|
||||
#if DEBUG
|
||||
@@ -256,9 +257,11 @@ namespace AppScaffolding
|
||||
// begin logging session with a form feed
|
||||
Log.Logger.Information("\r\n\f");
|
||||
|
||||
static int fileCount(FileManager.LongPath longPath)
|
||||
static int fileCount(FileManager.LongPath? longPath)
|
||||
{
|
||||
try { return FileManager.FileUtility.SaferEnumerateFiles(longPath).Count(); }
|
||||
if (longPath is null)
|
||||
return -1;
|
||||
try { return FileManager.FileUtility.SaferEnumerateFiles(longPath).Count(); }
|
||||
catch { return -1; }
|
||||
}
|
||||
|
||||
@@ -298,8 +301,8 @@ namespace AppScaffolding
|
||||
if (InteropFactory.InteropFunctionsType is null)
|
||||
Serilog.Log.Logger.Warning("WARNING: OSInteropProxy.InteropFunctionsType is null");
|
||||
}
|
||||
|
||||
private static void wireUpSystemEvents(Configuration configuration)
|
||||
#nullable restore
|
||||
private static void wireUpSystemEvents(Configuration configuration)
|
||||
{
|
||||
LibraryCommands.LibrarySizeChanged += (object _, List<DataLayer.LibraryBook> libraryBooks)
|
||||
=> SearchEngineCommands.FullReIndex(libraryBooks);
|
||||
|
||||
@@ -129,20 +129,21 @@ namespace FileLiberator
|
||||
|
||||
private async Task<AudiobookDecryptResult> DownloadAudiobookAsync(AudibleApi.Api api, DownloadOptions dlOptions, CancellationToken cancellationToken)
|
||||
{
|
||||
var outpoutDir = AudibleFileStorage.DecryptInProgressDirectory;
|
||||
var cacheDir = AudibleFileStorage.DownloadsInProgressDirectory;
|
||||
//Directories are validated prior to beginning download/decrypt
|
||||
var outputDir = AudibleFileStorage.DecryptInProgressDirectory!;
|
||||
var cacheDir = AudibleFileStorage.DownloadsInProgressDirectory!;
|
||||
var result = new AudiobookDecryptResult(false, [], []);
|
||||
|
||||
try
|
||||
{
|
||||
if (dlOptions.DrmType is not DrmType.Adrm and not DrmType.Widevine)
|
||||
abDownloader = new UnencryptedAudiobookDownloader(outpoutDir, cacheDir, dlOptions);
|
||||
abDownloader = new UnencryptedAudiobookDownloader(outputDir, cacheDir, dlOptions);
|
||||
else
|
||||
{
|
||||
AaxcDownloadConvertBase converter
|
||||
= dlOptions.Config.SplitFilesByChapter && dlOptions.ChapterInfo.Count > 1 ?
|
||||
new AaxcDownloadMultiConverter(outpoutDir, cacheDir, dlOptions) :
|
||||
new AaxcDownloadSingleConverter(outpoutDir, cacheDir, dlOptions);
|
||||
new AaxcDownloadMultiConverter(outputDir, cacheDir, dlOptions) :
|
||||
new AaxcDownloadSingleConverter(outputDir, cacheDir, dlOptions);
|
||||
|
||||
if (dlOptions.Config.AllowLibationFixup)
|
||||
converter.RetrievedMetadata += Converter_RetrievedMetadata;
|
||||
@@ -176,7 +177,7 @@ namespace FileLiberator
|
||||
|
||||
void AbDownloader_TempFileCreated(object? sender, TempFile e)
|
||||
{
|
||||
if (Path.GetDirectoryName(e.FilePath) == outpoutDir)
|
||||
if (Path.GetDirectoryName(e.FilePath) == outputDir)
|
||||
{
|
||||
result.ResultFiles.Add(e);
|
||||
}
|
||||
|
||||
@@ -19,8 +19,32 @@ namespace LibationFileManager
|
||||
protected abstract List<LongPath> GetFilePathsCustom(string productId);
|
||||
|
||||
#region static
|
||||
public static LongPath DownloadsInProgressDirectory => Directory.CreateDirectory(Path.Combine(Configuration.Instance.InProgress, "DownloadsInProgress")).FullName;
|
||||
public static LongPath DecryptInProgressDirectory => Directory.CreateDirectory(Path.Combine(Configuration.Instance.InProgress, "DecryptInProgress")).FullName;
|
||||
|
||||
/*
|
||||
* Operations like LibraryCommands.GetCounts() hit the file system hard.
|
||||
* Since failing to create a directory and exception handling is expensive,
|
||||
* only retry creating InProgress subdirectories every RetryInProgressInterval.
|
||||
*/
|
||||
private static DateTime lastInProgressFail;
|
||||
private static readonly TimeSpan RetryInProgressInterval = TimeSpan.FromSeconds(2);
|
||||
|
||||
private static DirectoryInfo? CreateInProgressDirectory(string subDirectory)
|
||||
{
|
||||
try
|
||||
{
|
||||
return (DateTime.UtcNow - lastInProgressFail) < RetryInProgressInterval ? null
|
||||
: new DirectoryInfo(Configuration.Instance.InProgress).CreateSubdirectoryEx(subDirectory);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Serilog.Log.Error(ex, "Error creating subdirectory in {@InProgress}", Configuration.Instance.InProgress);
|
||||
lastInProgressFail = DateTime.UtcNow;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static LongPath? DownloadsInProgressDirectory => CreateInProgressDirectory("DownloadsInProgress")?.FullName;
|
||||
public static LongPath? DecryptInProgressDirectory => CreateInProgressDirectory("DecryptInProgress")?.FullName;
|
||||
|
||||
static AudibleFileStorage()
|
||||
{
|
||||
@@ -28,7 +52,9 @@ namespace LibationFileManager
|
||||
//Do not clean DownloadsInProgressDirectory. Those files are resumable.
|
||||
try
|
||||
{
|
||||
foreach (var tempFile in FileUtility.SaferEnumerateFiles(DecryptInProgressDirectory))
|
||||
if (DecryptInProgressDirectory is not LongPath decryptDir)
|
||||
return;
|
||||
foreach (var tempFile in FileUtility.SaferEnumerateFiles(decryptDir))
|
||||
FileUtility.SaferDelete(tempFile);
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -114,9 +140,12 @@ namespace LibationFileManager
|
||||
|
||||
protected override List<LongPath> GetFilePathsCustom(string productId)
|
||||
{
|
||||
if (DownloadsInProgressDirectory is not LongPath dlFolder)
|
||||
return [];
|
||||
|
||||
var regex = GetBookSearchRegex(productId);
|
||||
return FileUtility
|
||||
.SaferEnumerateFiles(DownloadsInProgressDirectory, "*.*", SearchOption.AllDirectories)
|
||||
.SaferEnumerateFiles(dlFolder, "*.*", SearchOption.AllDirectories)
|
||||
.Where(s => regex.IsMatch(s)).ToList();
|
||||
}
|
||||
|
||||
|
||||
@@ -184,6 +184,26 @@ public class ProcessQueueViewModel : ReactiveObject
|
||||
MessageBoxIcon.Error);
|
||||
return false;
|
||||
}
|
||||
else if (AudibleFileStorage.DownloadsInProgressDirectory is null)
|
||||
{
|
||||
Serilog.Log.Logger.Error("Failed to create DownloadsInProgressDirectory in {@InProgress}", Configuration.Instance.InProgress);
|
||||
MessageBoxBase.Show(
|
||||
$"Libation was unable to create the \"Downloads In Progress\" folder in:\n{Configuration.Instance.InProgress}\n\nPlease change the In Progress location in the settings menu.",
|
||||
"Failed to Create Downloads In Progress Directory",
|
||||
MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Error);
|
||||
return false;
|
||||
}
|
||||
else if (AudibleFileStorage.DecryptInProgressDirectory is null)
|
||||
{
|
||||
Serilog.Log.Logger.Error("Failed to create DecryptInProgressDirectory in {@InProgress}", Configuration.Instance.InProgress);
|
||||
MessageBoxBase.Show(
|
||||
$"Libation was unable to create the \"Decrypt In Progress\" folder in:\n{Configuration.Instance.InProgress}\n\nPlease change the In Progress location in the settings menu.",
|
||||
"Failed to Create Decrypt In Progress Directory",
|
||||
MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user