Omit '.libhack' skip/error files

This commit is contained in:
Robert McRackan 2021-08-20 22:16:46 -04:00
parent c9727f84ab
commit 2be5fd5af3
5 changed files with 28 additions and 28 deletions

View File

@ -57,7 +57,6 @@ namespace DataLayer
get get
{ {
var status = UserDefinedItem?.BookStatus; var status = UserDefinedItem?.BookStatus;
// true since Error == libhack
return status.HasValue && status.Value != LiberatedStatus.NotLiberated; return status.HasValue && status.Value != LiberatedStatus.NotLiberated;
} }
} }

View File

@ -96,9 +96,7 @@ namespace FileManager
public class AudioFileStorage : AudibleFileStorage public class AudioFileStorage : AudibleFileStorage
{ {
public const string SKIP_FILE_EXT = "libhack"; protected override string[] Extensions { get; } = new[] { "m4b", "mp3", "aac", "mp4", "m4a", "ogg", "flac" };
protected override string[] Extensions { get; } = new[] { "m4b", "mp3", "aac", "mp4", "m4a", "ogg", "flac", SKIP_FILE_EXT };
// we always want to use the latest config value, therefore // we always want to use the latest config value, therefore
// - DO use 'get' arrow "=>" // - DO use 'get' arrow "=>"
@ -109,17 +107,6 @@ namespace FileManager
public void Refresh() => BookDirectoryFiles.RefreshFiles(); public void Refresh() => BookDirectoryFiles.RefreshFiles();
public string CreateSkipFile(string title, string asin, string contents = null)
{
var destinationDir = GetDestDir(title, asin);
Directory.CreateDirectory(destinationDir);
var path = FileUtility.GetValidFilename(destinationDir, title, SKIP_FILE_EXT, asin);
File.WriteAllText(path, contents ?? string.Empty);
return path;
}
public string GetDestDir(string title, string asin) public string GetDestDir(string title, string asin)
{ {
// to prevent the paths from getting too long, we don't need after the 1st ":" for the folder // to prevent the paths from getting too long, we don't need after the 1st ":" for the folder

View File

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

View File

@ -5,13 +5,14 @@ using System.Linq;
using System.Windows.Forms; using System.Windows.Forms;
using AudibleApi.Authorization; using AudibleApi.Authorization;
using DataLayer; using DataLayer;
using Microsoft.EntityFrameworkCore; using Dinah.Core;
using Dinah.Core.IO; using Dinah.Core.IO;
using Dinah.Core.Logging; using Dinah.Core.Logging;
using FileManager; using FileManager;
using InternalUtilities; using InternalUtilities;
using LibationWinForms; using LibationWinForms;
using LibationWinForms.Dialogs; using LibationWinForms.Dialogs;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using Serilog; using Serilog;
@ -244,6 +245,11 @@ namespace LibationLauncher
if (!File.Exists(filePaths)) if (!File.Exists(filePaths))
return; return;
// files to be deleted at the end
var libhackFilesToDelete = new List<string>();
// .libhack files => errors
var libhackFiles = Directory.EnumerateDirectories(config.Books, "*.libhack", SearchOption.AllDirectories);
using var context = ApplicationServices.DbContexts.GetContext(); using var context = ApplicationServices.DbContexts.GetContext();
context.Books.Load(); context.Books.Load();
@ -274,11 +280,24 @@ namespace LibationLauncher
book.UserDefinedItem.PdfStatus = LiberatedStatus.Liberated; book.UserDefinedItem.PdfStatus = LiberatedStatus.Liberated;
if (fileType == FileType.Audio) if (fileType == FileType.Audio)
book.UserDefinedItem.BookStatus = LiberatedStatus.Liberated; {
var lhack = libhackFiles.FirstOrDefault(f => f.ContainsInsensitive(asin));
if (lhack is null)
book.UserDefinedItem.BookStatus = LiberatedStatus.Liberated;
else
{
book.UserDefinedItem.BookStatus = LiberatedStatus.Error;
libhackFilesToDelete.Add(lhack);
}
}
} }
context.SaveChanges(); context.SaveChanges();
// only do this after save changes
foreach (var libhackFile in libhackFilesToDelete)
File.Delete(libhackFile);
File.Delete(filePaths); File.Delete(filePaths);
} }
catch (Exception ex) catch (Exception ex)

View File

@ -176,7 +176,7 @@ namespace LibationWinForms.BookLiberation
protected abstract string SkipDialogText { get; } protected abstract string SkipDialogText { get; }
protected abstract MessageBoxButtons SkipDialogButtons { get; } protected abstract MessageBoxButtons SkipDialogButtons { get; }
protected abstract MessageBoxDefaultButton SkipDialogDefaultButton { get; } protected abstract MessageBoxDefaultButton SkipDialogDefaultButton { get; }
protected abstract DialogResult CreateSkipFileResult { get; } protected abstract DialogResult SkipResult { get; }
public async Task RunBackupAsync() public async Task RunBackupAsync()
{ {
@ -244,15 +244,10 @@ $@" Title: {libraryBook.Book.Title}
if (dialogResult == DialogResult.Abort) if (dialogResult == DialogResult.Abort)
return false; return false;
if (dialogResult == CreateSkipFileResult) if (dialogResult == SkipResult)
{ {
ApplicationServices.LibraryCommands.UpdateBook(libraryBook, LiberatedStatus.Error); ApplicationServices.LibraryCommands.UpdateBook(libraryBook, LiberatedStatus.Error);
var path = FileManager.AudibleFileStorage.Audio.CreateSkipFile(libraryBook.Book.Title, libraryBook.Book.AudibleProductId, logMessage); LogMe.Info($"Error. Skip: [{libraryBook.Book.AudibleProductId}] {libraryBook.Book.Title}");
LogMe.Info($@"
Created new 'skip' file
[{libraryBook.Book.AudibleProductId}] {libraryBook.Book.Title}
{path}
".Trim());
} }
return true; return true;
@ -273,7 +268,7 @@ An error occurred while trying to process this book. Skip this book permanently?
".Trim(); ".Trim();
protected override MessageBoxButtons SkipDialogButtons => MessageBoxButtons.YesNo; protected override MessageBoxButtons SkipDialogButtons => MessageBoxButtons.YesNo;
protected override MessageBoxDefaultButton SkipDialogDefaultButton => MessageBoxDefaultButton.Button2; protected override MessageBoxDefaultButton SkipDialogDefaultButton => MessageBoxDefaultButton.Button2;
protected override DialogResult CreateSkipFileResult => DialogResult.Yes; protected override DialogResult SkipResult => DialogResult.Yes;
public BackupSingle(LogMe logMe, IProcessable processable, LibraryBook libraryBook) public BackupSingle(LogMe logMe, IProcessable processable, LibraryBook libraryBook)
: base(logMe, processable) : base(logMe, processable)
@ -302,7 +297,7 @@ An error occurred while trying to process this book.
".Trim(); ".Trim();
protected override MessageBoxButtons SkipDialogButtons => MessageBoxButtons.AbortRetryIgnore; protected override MessageBoxButtons SkipDialogButtons => MessageBoxButtons.AbortRetryIgnore;
protected override MessageBoxDefaultButton SkipDialogDefaultButton => MessageBoxDefaultButton.Button1; protected override MessageBoxDefaultButton SkipDialogDefaultButton => MessageBoxDefaultButton.Button1;
protected override DialogResult CreateSkipFileResult => DialogResult.Ignore; protected override DialogResult SkipResult => DialogResult.Ignore;
public BackupLoop(LogMe logMe, IProcessable processable, AutomatedBackupsForm automatedBackupsForm) public BackupLoop(LogMe logMe, IProcessable processable, AutomatedBackupsForm automatedBackupsForm)
: base(logMe, processable, automatedBackupsForm) { } : base(logMe, processable, automatedBackupsForm) { }