diff --git a/Scripts/Bundle_MacOS.sh b/Scripts/Bundle_MacOS.sh
index 57bc60e1..b0fb88be 100644
--- a/Scripts/Bundle_MacOS.sh
+++ b/Scripts/Bundle_MacOS.sh
@@ -65,6 +65,9 @@ if [ $? -ne 0 ]
exit
fi
+echo "Make fileicon executable..."
+chmod +x $BUNDLE_MACOS/fileicon
+
echo "Moving icon..."
mv $BUNDLE_MACOS/libation.icns $BUNDLE_RESOURCES/libation.icns
diff --git a/Source/AppScaffolding/LibationScaffolding.cs b/Source/AppScaffolding/LibationScaffolding.cs
index 1756da77..fbe45a4e 100644
--- a/Source/AppScaffolding/LibationScaffolding.cs
+++ b/Source/AppScaffolding/LibationScaffolding.cs
@@ -75,13 +75,15 @@ namespace AppScaffolding
??= new[] { ExecutingAssembly.GetName(), EntryAssembly.GetName() }
.Max(a => a.Version);
- /// Run migrations before loading Configuration for the first time. Then load and return Configuration
- public static Configuration RunPreConfigMigrations()
+ /// Run migrations before loading Configuration for the first time. Then load and return Configuration
+ public static Configuration RunPreConfigMigrations()
{
// must occur before access to Configuration instance
// // outdated. kept here as an example of what belongs in this area
// // Migrations.migrate_to_v5_2_0__pre_config();
+ Configuration.SetLibationVersion(BuildVersion);
+
//***********************************************//
// //
// do not use Configuration before this line //
diff --git a/Source/ApplicationServices/LibraryCommands.cs b/Source/ApplicationServices/LibraryCommands.cs
index a051fa84..d166a158 100644
--- a/Source/ApplicationServices/LibraryCommands.cs
+++ b/Source/ApplicationServices/LibraryCommands.cs
@@ -242,18 +242,16 @@ namespace ApplicationServices
#endregion
#region remove/restore books
- public static Task RemoveBooksAsync(List idsToRemove) => Task.Run(() => removeBooks(idsToRemove));
- public static int RemoveBook(string idToRemove) => removeBooks(new() { idToRemove });
- private static int removeBooks(List idsToRemove)
+ public static Task RemoveBooksAsync(this IEnumerable idsToRemove) => Task.Run(() => removeBooks(idsToRemove));
+ public static int RemoveBook(this LibraryBook idToRemove) => removeBooks(new[] { idToRemove });
+ private static int removeBooks(IEnumerable removeLibraryBooks)
{
try
{
- if (idsToRemove is null || !idsToRemove.Any())
+ if (removeLibraryBooks is null || !removeLibraryBooks.Any())
return 0;
using var context = DbContexts.GetContext();
- var libBooks = context.GetLibrary_Flat_NoTracking();
- var removeLibraryBooks = libBooks.Where(lb => idsToRemove.Contains(lb.Book.AudibleProductId)).ToList();
// Attach() NoTracking entities before SaveChanges()
foreach (var lb in removeLibraryBooks)
@@ -275,7 +273,7 @@ namespace ApplicationServices
}
}
- public static int RestoreBooks(this List libraryBooks)
+ public static int RestoreBooks(this IEnumerable libraryBooks)
{
try
{
@@ -303,6 +301,31 @@ namespace ApplicationServices
throw;
}
}
+
+ public static int PermanentlyDeleteBooks(this IEnumerable libraryBooks)
+ {
+ try
+ {
+ if (libraryBooks is null || !libraryBooks.Any())
+ return 0;
+
+ using var context = DbContexts.GetContext();
+
+ context.LibraryBooks.RemoveRange(libraryBooks);
+ context.Books.RemoveRange(libraryBooks.Select(lb => lb.Book));
+
+ var qtyChanges = context.SaveChanges();
+ if (qtyChanges > 0)
+ finalizeLibrarySizeChange();
+
+ return qtyChanges;
+ }
+ catch (Exception ex)
+ {
+ Log.Logger.Error(ex, "Error restoring books");
+ throw;
+ }
+ }
#endregion
// call this whenever books are added or removed from library
@@ -346,8 +369,10 @@ namespace ApplicationServices
if (rating is not null)
udi.UpdateRating(rating.OverallRating, rating.PerformanceRating, rating.StoryRating);
- });
+ });
+ public static int UpdateBookStatus(this Book book, LiberatedStatus bookStatus, Version libationVersion)
+ => book.UpdateUserDefinedItem(udi => { udi.BookStatus = bookStatus; udi.SetLastDownloaded(libationVersion); });
public static int UpdateBookStatus(this Book book, LiberatedStatus bookStatus)
=> book.UpdateUserDefinedItem(udi => udi.BookStatus = bookStatus);
public static int UpdateBookStatus(this IEnumerable books, LiberatedStatus bookStatus)
diff --git a/Source/DataLayer/Configurations/BookConfig.cs b/Source/DataLayer/Configurations/BookConfig.cs
index 17054ea7..55c13038 100644
--- a/Source/DataLayer/Configurations/BookConfig.cs
+++ b/Source/DataLayer/Configurations/BookConfig.cs
@@ -1,5 +1,6 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
+using System;
namespace DataLayer.Configurations
{
@@ -19,40 +20,45 @@ namespace DataLayer.Configurations
entity.Ignore(nameof(Book.Authors));
entity.Ignore(nameof(Book.Narrators));
entity.Ignore(nameof(Book.AudioFormat));
- //// these don't seem to matter
- //entity.Ignore(nameof(Book.AuthorNames));
- //entity.Ignore(nameof(Book.NarratorNames));
- //entity.Ignore(nameof(Book.HasPdfs));
+ //// these don't seem to matter
+ //entity.Ignore(nameof(Book.AuthorNames));
+ //entity.Ignore(nameof(Book.NarratorNames));
+ //entity.Ignore(nameof(Book.HasPdfs));
- // OwnsMany: "Can only ever appear on navigation properties of other entity types.
- // Are automatically loaded, and can only be tracked by a DbContext alongside their owner."
- entity
- .OwnsMany(b => b.Supplements, b_s =>
- {
- b_s.WithOwner(s => s.Book)
- .HasForeignKey(s => s.BookId);
- b_s.HasKey(s => s.SupplementId);
- });
+ // OwnsMany: "Can only ever appear on navigation properties of other entity types.
+ // Are automatically loaded, and can only be tracked by a DbContext alongside their owner."
+ entity
+ .OwnsMany(b => b.Supplements, b_s =>
+ {
+ b_s.WithOwner(s => s.Book)
+ .HasForeignKey(s => s.BookId);
+ b_s.HasKey(s => s.SupplementId);
+ });
// even though it's owned, we need to map its backing field
entity
.Metadata
.FindNavigation(nameof(Book.Supplements))
.SetPropertyAccessMode(PropertyAccessMode.Field);
- // owns it 1:1, store in separate table
- entity
- .OwnsOne(b => b.UserDefinedItem, b_udi =>
- {
- b_udi.WithOwner(udi => udi.Book)
- .HasForeignKey(udi => udi.BookId);
- b_udi.Property(udi => udi.BookId).ValueGeneratedNever();
- b_udi.ToTable(nameof(Book.UserDefinedItem));
+ // owns it 1:1, store in separate table
+ entity
+ .OwnsOne(b => b.UserDefinedItem, b_udi =>
+ {
+ b_udi.WithOwner(udi => udi.Book)
+ .HasForeignKey(udi => udi.BookId);
+ b_udi.Property(udi => udi.BookId).ValueGeneratedNever();
+ b_udi.ToTable(nameof(Book.UserDefinedItem));
- // owns it 1:1, store in same table
- b_udi.OwnsOne(udi => udi.Rating);
- });
+ b_udi.Property(udi => udi.LastDownloaded);
+ b_udi
+ .Property(udi => udi.LastDownloadedVersion)
+ .HasConversion(ver => ver.ToString(), str => Version.Parse(str));
- entity
+ // owns it 1:1, store in same table
+ b_udi.OwnsOne(udi => udi.Rating);
+ });
+
+ entity
.Metadata
.FindNavigation(nameof(Book.ContributorsLink))
// PropertyAccessMode.Field : Contributions is a get-only property, not a field, so use its backing field
@@ -68,6 +74,6 @@ namespace DataLayer.Configurations
.HasOne(b => b.Category)
.WithMany()
.HasForeignKey(b => b.CategoryId);
- }
+ }
}
}
\ No newline at end of file
diff --git a/Source/DataLayer/EfClasses/UserDefinedItem.cs b/Source/DataLayer/EfClasses/UserDefinedItem.cs
index d34c45e7..86c87fcf 100644
--- a/Source/DataLayer/EfClasses/UserDefinedItem.cs
+++ b/Source/DataLayer/EfClasses/UserDefinedItem.cs
@@ -24,8 +24,27 @@ namespace DataLayer
{
internal int BookId { get; private set; }
public Book Book { get; private set; }
+ public DateTime? LastDownloaded { get; private set; }
+ public Version LastDownloadedVersion { get; private set; }
- private UserDefinedItem() { }
+ public void SetLastDownloaded(Version version)
+ {
+ if (LastDownloadedVersion != version)
+ {
+ LastDownloadedVersion = version;
+ OnItemChanged(nameof(LastDownloadedVersion));
+ }
+
+ if (version is null)
+ LastDownloaded = null;
+ else
+ {
+ LastDownloaded = DateTime.Now;
+ OnItemChanged(nameof(LastDownloaded));
+ }
+ }
+
+ private UserDefinedItem() { }
internal UserDefinedItem(Book book)
{
ArgumentValidator.EnsureNotNull(book, nameof(book));
diff --git a/Source/DataLayer/Migrations/20230302220539_AddLastDownloadedInfo.Designer.cs b/Source/DataLayer/Migrations/20230302220539_AddLastDownloadedInfo.Designer.cs
new file mode 100644
index 00000000..ffcec6cc
--- /dev/null
+++ b/Source/DataLayer/Migrations/20230302220539_AddLastDownloadedInfo.Designer.cs
@@ -0,0 +1,410 @@
+//
+using System;
+using DataLayer;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+
+#nullable disable
+
+namespace DataLayer.Migrations
+{
+ [DbContext(typeof(LibationContext))]
+ [Migration("20230302220539_AddLastDownloadedInfo")]
+ partial class AddLastDownloadedInfo
+ {
+ ///
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder.HasAnnotation("ProductVersion", "7.0.3");
+
+ modelBuilder.Entity("DataLayer.Book", b =>
+ {
+ b.Property("BookId")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER");
+
+ b.Property("AudibleProductId")
+ .HasColumnType("TEXT");
+
+ b.Property("CategoryId")
+ .HasColumnType("INTEGER");
+
+ b.Property("ContentType")
+ .HasColumnType("INTEGER");
+
+ b.Property("DatePublished")
+ .HasColumnType("TEXT");
+
+ b.Property("Description")
+ .HasColumnType("TEXT");
+
+ b.Property("IsAbridged")
+ .HasColumnType("INTEGER");
+
+ b.Property("Language")
+ .HasColumnType("TEXT");
+
+ b.Property("LengthInMinutes")
+ .HasColumnType("INTEGER");
+
+ b.Property("Locale")
+ .HasColumnType("TEXT");
+
+ b.Property("PictureId")
+ .HasColumnType("TEXT");
+
+ b.Property("PictureLarge")
+ .HasColumnType("TEXT");
+
+ b.Property("Title")
+ .HasColumnType("TEXT");
+
+ b.Property("_audioFormat")
+ .HasColumnType("INTEGER");
+
+ b.HasKey("BookId");
+
+ b.HasIndex("AudibleProductId");
+
+ b.HasIndex("CategoryId");
+
+ b.ToTable("Books");
+ });
+
+ modelBuilder.Entity("DataLayer.BookContributor", b =>
+ {
+ b.Property("BookId")
+ .HasColumnType("INTEGER");
+
+ b.Property("ContributorId")
+ .HasColumnType("INTEGER");
+
+ b.Property("Role")
+ .HasColumnType("INTEGER");
+
+ b.Property("Order")
+ .HasColumnType("INTEGER");
+
+ b.HasKey("BookId", "ContributorId", "Role");
+
+ b.HasIndex("BookId");
+
+ b.HasIndex("ContributorId");
+
+ b.ToTable("BookContributor");
+ });
+
+ modelBuilder.Entity("DataLayer.Category", b =>
+ {
+ b.Property("CategoryId")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER");
+
+ b.Property("AudibleCategoryId")
+ .HasColumnType("TEXT");
+
+ b.Property("Name")
+ .HasColumnType("TEXT");
+
+ b.Property("ParentCategoryCategoryId")
+ .HasColumnType("INTEGER");
+
+ b.HasKey("CategoryId");
+
+ b.HasIndex("AudibleCategoryId");
+
+ b.HasIndex("ParentCategoryCategoryId");
+
+ b.ToTable("Categories");
+
+ b.HasData(
+ new
+ {
+ CategoryId = -1,
+ AudibleCategoryId = "",
+ Name = ""
+ });
+ });
+
+ modelBuilder.Entity("DataLayer.Contributor", b =>
+ {
+ b.Property("ContributorId")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER");
+
+ b.Property("AudibleContributorId")
+ .HasColumnType("TEXT");
+
+ b.Property("Name")
+ .HasColumnType("TEXT");
+
+ b.HasKey("ContributorId");
+
+ b.HasIndex("Name");
+
+ b.ToTable("Contributors");
+
+ b.HasData(
+ new
+ {
+ ContributorId = -1,
+ Name = ""
+ });
+ });
+
+ modelBuilder.Entity("DataLayer.LibraryBook", b =>
+ {
+ b.Property("BookId")
+ .HasColumnType("INTEGER");
+
+ b.Property("Account")
+ .HasColumnType("TEXT");
+
+ b.Property("DateAdded")
+ .HasColumnType("TEXT");
+
+ b.Property("IsDeleted")
+ .HasColumnType("INTEGER");
+
+ b.HasKey("BookId");
+
+ b.ToTable("LibraryBooks");
+ });
+
+ modelBuilder.Entity("DataLayer.Series", b =>
+ {
+ b.Property("SeriesId")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER");
+
+ b.Property("AudibleSeriesId")
+ .HasColumnType("TEXT");
+
+ b.Property("Name")
+ .HasColumnType("TEXT");
+
+ b.HasKey("SeriesId");
+
+ b.HasIndex("AudibleSeriesId");
+
+ b.ToTable("Series");
+ });
+
+ modelBuilder.Entity("DataLayer.SeriesBook", b =>
+ {
+ b.Property("SeriesId")
+ .HasColumnType("INTEGER");
+
+ b.Property("BookId")
+ .HasColumnType("INTEGER");
+
+ b.Property("Order")
+ .HasColumnType("TEXT");
+
+ b.HasKey("SeriesId", "BookId");
+
+ b.HasIndex("BookId");
+
+ b.HasIndex("SeriesId");
+
+ b.ToTable("SeriesBook");
+ });
+
+ modelBuilder.Entity("DataLayer.Book", b =>
+ {
+ b.HasOne("DataLayer.Category", "Category")
+ .WithMany()
+ .HasForeignKey("CategoryId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.OwnsOne("DataLayer.Rating", "Rating", b1 =>
+ {
+ b1.Property("BookId")
+ .HasColumnType("INTEGER");
+
+ b1.Property("OverallRating")
+ .HasColumnType("REAL");
+
+ b1.Property("PerformanceRating")
+ .HasColumnType("REAL");
+
+ b1.Property("StoryRating")
+ .HasColumnType("REAL");
+
+ b1.HasKey("BookId");
+
+ b1.ToTable("Books");
+
+ b1.WithOwner()
+ .HasForeignKey("BookId");
+ });
+
+ b.OwnsMany("DataLayer.Supplement", "Supplements", b1 =>
+ {
+ b1.Property("SupplementId")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER");
+
+ b1.Property("BookId")
+ .HasColumnType("INTEGER");
+
+ b1.Property("Url")
+ .HasColumnType("TEXT");
+
+ b1.HasKey("SupplementId");
+
+ b1.HasIndex("BookId");
+
+ b1.ToTable("Supplement");
+
+ b1.WithOwner("Book")
+ .HasForeignKey("BookId");
+
+ b1.Navigation("Book");
+ });
+
+ b.OwnsOne("DataLayer.UserDefinedItem", "UserDefinedItem", b1 =>
+ {
+ b1.Property("BookId")
+ .HasColumnType("INTEGER");
+
+ b1.Property("BookStatus")
+ .HasColumnType("INTEGER");
+
+ b1.Property("LastDownloaded")
+ .HasColumnType("TEXT");
+
+ b1.Property("LastDownloadedVersion")
+ .HasColumnType("TEXT");
+
+ b1.Property("PdfStatus")
+ .HasColumnType("INTEGER");
+
+ b1.Property("Tags")
+ .HasColumnType("TEXT");
+
+ b1.HasKey("BookId");
+
+ b1.ToTable("UserDefinedItem", (string)null);
+
+ b1.WithOwner("Book")
+ .HasForeignKey("BookId");
+
+ b1.OwnsOne("DataLayer.Rating", "Rating", b2 =>
+ {
+ b2.Property("UserDefinedItemBookId")
+ .HasColumnType("INTEGER");
+
+ b2.Property("OverallRating")
+ .HasColumnType("REAL");
+
+ b2.Property("PerformanceRating")
+ .HasColumnType("REAL");
+
+ b2.Property("StoryRating")
+ .HasColumnType("REAL");
+
+ b2.HasKey("UserDefinedItemBookId");
+
+ b2.ToTable("UserDefinedItem");
+
+ b2.WithOwner()
+ .HasForeignKey("UserDefinedItemBookId");
+ });
+
+ b1.Navigation("Book");
+
+ b1.Navigation("Rating");
+ });
+
+ b.Navigation("Category");
+
+ b.Navigation("Rating");
+
+ b.Navigation("Supplements");
+
+ b.Navigation("UserDefinedItem");
+ });
+
+ modelBuilder.Entity("DataLayer.BookContributor", b =>
+ {
+ b.HasOne("DataLayer.Book", "Book")
+ .WithMany("ContributorsLink")
+ .HasForeignKey("BookId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("DataLayer.Contributor", "Contributor")
+ .WithMany("BooksLink")
+ .HasForeignKey("ContributorId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Book");
+
+ b.Navigation("Contributor");
+ });
+
+ modelBuilder.Entity("DataLayer.Category", b =>
+ {
+ b.HasOne("DataLayer.Category", "ParentCategory")
+ .WithMany()
+ .HasForeignKey("ParentCategoryCategoryId");
+
+ b.Navigation("ParentCategory");
+ });
+
+ modelBuilder.Entity("DataLayer.LibraryBook", b =>
+ {
+ b.HasOne("DataLayer.Book", "Book")
+ .WithOne()
+ .HasForeignKey("DataLayer.LibraryBook", "BookId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Book");
+ });
+
+ modelBuilder.Entity("DataLayer.SeriesBook", b =>
+ {
+ b.HasOne("DataLayer.Book", "Book")
+ .WithMany("SeriesLink")
+ .HasForeignKey("BookId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("DataLayer.Series", "Series")
+ .WithMany("BooksLink")
+ .HasForeignKey("SeriesId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Book");
+
+ b.Navigation("Series");
+ });
+
+ modelBuilder.Entity("DataLayer.Book", b =>
+ {
+ b.Navigation("ContributorsLink");
+
+ b.Navigation("SeriesLink");
+ });
+
+ modelBuilder.Entity("DataLayer.Contributor", b =>
+ {
+ b.Navigation("BooksLink");
+ });
+
+ modelBuilder.Entity("DataLayer.Series", b =>
+ {
+ b.Navigation("BooksLink");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/Source/DataLayer/Migrations/20230302220539_AddLastDownloadedInfo.cs b/Source/DataLayer/Migrations/20230302220539_AddLastDownloadedInfo.cs
new file mode 100644
index 00000000..db823779
--- /dev/null
+++ b/Source/DataLayer/Migrations/20230302220539_AddLastDownloadedInfo.cs
@@ -0,0 +1,39 @@
+using System;
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+namespace DataLayer.Migrations
+{
+ ///
+ public partial class AddLastDownloadedInfo : Migration
+ {
+ ///
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.AddColumn(
+ name: "LastDownloaded",
+ table: "UserDefinedItem",
+ type: "TEXT",
+ nullable: true);
+
+ migrationBuilder.AddColumn(
+ name: "LastDownloadedVersion",
+ table: "UserDefinedItem",
+ type: "TEXT",
+ nullable: true);
+ }
+
+ ///
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropColumn(
+ name: "LastDownloaded",
+ table: "UserDefinedItem");
+
+ migrationBuilder.DropColumn(
+ name: "LastDownloadedVersion",
+ table: "UserDefinedItem");
+ }
+ }
+}
diff --git a/Source/DataLayer/Migrations/LibationContextModelSnapshot.cs b/Source/DataLayer/Migrations/LibationContextModelSnapshot.cs
index 080d7beb..747513d6 100644
--- a/Source/DataLayer/Migrations/LibationContextModelSnapshot.cs
+++ b/Source/DataLayer/Migrations/LibationContextModelSnapshot.cs
@@ -15,7 +15,7 @@ namespace DataLayer.Migrations
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
- modelBuilder.HasAnnotation("ProductVersion", "7.0.2");
+ modelBuilder.HasAnnotation("ProductVersion", "7.0.3");
modelBuilder.Entity("DataLayer.Book", b =>
{
@@ -272,6 +272,12 @@ namespace DataLayer.Migrations
b1.Property("BookStatus")
.HasColumnType("INTEGER");
+ b1.Property("LastDownloaded")
+ .HasColumnType("TEXT");
+
+ b1.Property("LastDownloadedVersion")
+ .HasColumnType("TEXT");
+
b1.Property("PdfStatus")
.HasColumnType("INTEGER");
diff --git a/Source/FileLiberator/DownloadDecryptBook.cs b/Source/FileLiberator/DownloadDecryptBook.cs
index c6ea7e4b..3d43c8b6 100644
--- a/Source/FileLiberator/DownloadDecryptBook.cs
+++ b/Source/FileLiberator/DownloadDecryptBook.cs
@@ -41,7 +41,7 @@ namespace FileLiberator
OnBegin(libraryBook);
- try
+ try
{
if (libraryBook.Book.Audio_Exists())
return new StatusHandler { "Cannot find decrypt. Final audio file already exists" };
@@ -61,31 +61,30 @@ namespace FileLiberator
}
// decrypt failed
- if (!success)
+ if (!success || getFirstAudioFile(entries) == default)
{
- foreach (var tmpFile in entries.Where(f => f.FileType != FileType.AAXC))
- FileUtility.SaferDelete(tmpFile.Path);
+ await Task.WhenAll(
+ entries
+ .Where(f => f.FileType != FileType.AAXC)
+ .Select(f => Task.Run(() => FileUtility.SaferDelete(f.Path))));
- return abDownloader?.IsCanceled == true ?
- new StatusHandler { "Cancelled" } :
- new StatusHandler { "Decrypt failed" };
+ return
+ abDownloader?.IsCanceled is true
+ ? new StatusHandler { "Cancelled" }
+ : new StatusHandler { "Decrypt failed" };
}
- // moves new files from temp dir to final dest.
- // This could take a few seconds if moving hundreds of files.
- var finalStorageDir = await Task.Run(() => moveFilesToBooksDir(libraryBook, entries));
+ var finalStorageDir = getDestinationDirectory(libraryBook);
- // decrypt failed
- if (finalStorageDir is null)
- return new StatusHandler { "Cannot find final audio file after decryption" };
+ Task[] finalTasks = new[]
+ {
+ Task.Run(() => downloadCoverArt(libraryBook)),
+ Task.Run(() => moveFilesToBooksDir(libraryBook, entries)),
+ Task.Run(() => libraryBook.Book.UpdateBookStatus(LiberatedStatus.Liberated, Configuration.LibationVersion)),
+ Task.Run(() => WindowsDirectory.SetCoverAsFolderIcon(libraryBook.Book.PictureId, finalStorageDir))
+ };
- if (Configuration.Instance.DownloadCoverArt)
- downloadCoverArt(libraryBook);
-
- // contains logic to check for config setting and OS
- WindowsDirectory.SetCoverAsFolderIcon(pictureId: libraryBook.Book.PictureId, directory: finalStorageDir);
-
- libraryBook.Book.UpdateBookStatus(LiberatedStatus.Liberated);
+ await Task.WhenAll(finalTasks);
return new StatusHandler();
}
@@ -131,8 +130,8 @@ namespace FileLiberator
abDownloader.RetrievedCoverArt += AaxcDownloader_RetrievedCoverArt;
abDownloader.FileCreated += (_, path) => OnFileCreated(libraryBook, path);
- // REAL WORK DONE HERE
- return await abDownloader.RunAsync();
+ // REAL WORK DONE HERE
+ return await abDownloader.RunAsync();
}
private DownloadOptions BuildDownloadOptions(LibraryBook libraryBook, Configuration config, AudibleApi.Common.ContentLicense contentLic)
@@ -335,18 +334,12 @@ namespace FileLiberator
/// Move new files to 'Books' directory
/// Return directory if audiobook file(s) were successfully created and can be located on disk. Else null.
- private static string moveFilesToBooksDir(LibraryBook libraryBook, List entries)
+ private static void moveFilesToBooksDir(LibraryBook libraryBook, List entries)
{
// create final directory. move each file into it
- var destinationDir = AudibleFileStorage.Audio.GetDestinationDirectory(libraryBook);
- Directory.CreateDirectory(destinationDir);
+ var destinationDir = getDestinationDirectory(libraryBook);
- FilePathCache.CacheEntry getFirstAudio() => entries.FirstOrDefault(f => f.FileType == FileType.Audio);
-
- if (getFirstAudio() == default)
- return null;
-
- for (var i = 0; i < entries.Count; i++)
+ for (var i = 0; i < entries.Count; i++)
{
var entry = entries[i];
@@ -357,22 +350,33 @@ namespace FileLiberator
entries[i] = entry with { Path = realDest };
}
- var cue = entries.FirstOrDefault(f => f.FileType == FileType.Cue);
+ var cue = entries.FirstOrDefault(f => f.FileType == FileType.Cue);
if (cue != default)
- Cue.UpdateFileName(cue.Path, getFirstAudio().Path);
+ Cue.UpdateFileName(cue.Path, getFirstAudioFile(entries).Path);
AudibleFileStorage.Audio.Refresh();
-
- return destinationDir;
}
- private static void downloadCoverArt(LibraryBook libraryBook)
+ private static string getDestinationDirectory(LibraryBook libraryBook)
{
+ var destinationDir = AudibleFileStorage.Audio.GetDestinationDirectory(libraryBook);
+ if (!Directory.Exists(destinationDir))
+ Directory.CreateDirectory(destinationDir);
+ return destinationDir;
+ }
+
+ private static FilePathCache.CacheEntry getFirstAudioFile(IEnumerable entries)
+ => entries.FirstOrDefault(f => f.FileType == FileType.Audio);
+
+ private static void downloadCoverArt(LibraryBook libraryBook)
+ {
+ if (!Configuration.Instance.DownloadCoverArt) return;
+
var coverPath = "[null]";
try
{
- var destinationDir = AudibleFileStorage.Audio.GetDestinationDirectory(libraryBook);
+ var destinationDir = getDestinationDirectory(libraryBook);
coverPath = AudibleFileStorage.Audio.GetBooksDirectoryFilename(libraryBook, ".jpg");
coverPath = Path.Combine(destinationDir, Path.GetFileName(coverPath));
diff --git a/Source/LibationAvalonia/Assets/Arrows_left.png b/Source/LibationAvalonia/Assets/Arrows_left.png
new file mode 100644
index 00000000..a1a73311
Binary files /dev/null and b/Source/LibationAvalonia/Assets/Arrows_left.png differ
diff --git a/Source/LibationAvalonia/Assets/Arrows_right.png b/Source/LibationAvalonia/Assets/Arrows_right.png
new file mode 100644
index 00000000..126dfa40
Binary files /dev/null and b/Source/LibationAvalonia/Assets/Arrows_right.png differ
diff --git a/Source/LibationAvalonia/Controls/CheckedListBox.axaml b/Source/LibationAvalonia/Controls/CheckedListBox.axaml
new file mode 100644
index 00000000..cf70be9a
--- /dev/null
+++ b/Source/LibationAvalonia/Controls/CheckedListBox.axaml
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Source/LibationAvalonia/Controls/CheckedListBox.axaml.cs b/Source/LibationAvalonia/Controls/CheckedListBox.axaml.cs
new file mode 100644
index 00000000..f0ab1e61
--- /dev/null
+++ b/Source/LibationAvalonia/Controls/CheckedListBox.axaml.cs
@@ -0,0 +1,46 @@
+using Avalonia;
+using Avalonia.Collections;
+using Avalonia.Controls;
+using LibationAvalonia.ViewModels;
+using ReactiveUI;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+
+namespace LibationAvalonia.Controls
+{
+ public partial class CheckedListBox : UserControl
+ {
+ public static readonly StyledProperty> ItemsProperty =
+ AvaloniaProperty.Register>(nameof(Items));
+
+ public AvaloniaList Items { get => GetValue(ItemsProperty); set => SetValue(ItemsProperty, value); }
+ private CheckedListBoxViewModel _viewModel = new();
+
+ public CheckedListBox()
+ {
+ InitializeComponent();
+ scroller.DataContext = _viewModel;
+ }
+ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
+ {
+ if (change.Property.Name == nameof(Items) && Items != null)
+ _viewModel.CheckboxItems = Items;
+ base.OnPropertyChanged(change);
+ }
+
+ private class CheckedListBoxViewModel : ViewModelBase
+ {
+ private AvaloniaList _checkboxItems;
+ public AvaloniaList CheckboxItems { get => _checkboxItems; set => this.RaiseAndSetIfChanged(ref _checkboxItems, value); }
+ }
+ }
+
+ public class CheckBoxViewModel : ViewModelBase
+ {
+ private bool _isChecked;
+ public bool IsChecked { get => _isChecked; set => this.RaiseAndSetIfChanged(ref _isChecked, value); }
+ private object _bookText;
+ public object Item { get => _bookText; set => this.RaiseAndSetIfChanged(ref _bookText, value); }
+ }
+}
diff --git a/Source/LibationAvalonia/Dialogs/SettingsDialog.axaml b/Source/LibationAvalonia/Dialogs/SettingsDialog.axaml
index ffaa7fc9..6c7c0419 100644
--- a/Source/LibationAvalonia/Dialogs/SettingsDialog.axaml
+++ b/Source/LibationAvalonia/Dialogs/SettingsDialog.axaml
@@ -2,7 +2,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
- mc:Ignorable="d" d:DesignWidth="900" d:DesignHeight="700"
+ mc:Ignorable="d" d:DesignWidth="900" d:DesignHeight="750"
MinWidth="900" MinHeight="700"
x:Class="LibationAvalonia.Dialogs.SettingsDialog"
xmlns:controls="clr-namespace:LibationAvalonia.Controls"
@@ -376,7 +376,7 @@
Grid.Row="3"
Margin="5"
VerticalAlignment="Top"
- IsVisible="{Binding IsWindows}"
+ IsVisible="{Binding !IsLinux}"
IsChecked="{Binding DownloadDecryptSettings.UseCoverAsFolderIcon, Mode=TwoWay}">
AppScaffolding.LibationScaffolding.ReleaseIdentifier is AppScaffolding.ReleaseIdentifier.WindowsAvalonia;
+ public bool IsLinux => Configuration.IsLinux;
+ public bool IsWindows => Configuration.IsWindows;
public ImportantSettings ImportantSettings { get; private set; }
public ImportSettings ImportSettings { get; private set; }
public DownloadDecryptSettings DownloadDecryptSettings { get; private set; }
diff --git a/Source/LibationAvalonia/Dialogs/TrashBinDialog.axaml b/Source/LibationAvalonia/Dialogs/TrashBinDialog.axaml
new file mode 100644
index 00000000..1738a67e
--- /dev/null
+++ b/Source/LibationAvalonia/Dialogs/TrashBinDialog.axaml
@@ -0,0 +1,66 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Source/LibationAvalonia/Dialogs/TrashBinDialog.axaml.cs b/Source/LibationAvalonia/Dialogs/TrashBinDialog.axaml.cs
new file mode 100644
index 00000000..073a0845
--- /dev/null
+++ b/Source/LibationAvalonia/Dialogs/TrashBinDialog.axaml.cs
@@ -0,0 +1,145 @@
+using ApplicationServices;
+using Avalonia.Collections;
+using Avalonia.Controls;
+using Avalonia.Threading;
+using DataLayer;
+using LibationAvalonia.Controls;
+using LibationAvalonia.ViewModels;
+using LibationFileManager;
+using ReactiveUI;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace LibationAvalonia.Dialogs
+{
+ public partial class TrashBinDialog : Window
+ {
+ TrashBinViewModel _viewModel;
+
+ public TrashBinDialog()
+ {
+ InitializeComponent();
+ this.RestoreSizeAndLocation(Configuration.Instance);
+ DataContext = _viewModel = new();
+
+ this.Closing += (_,_) => this.SaveSizeAndLocation(Configuration.Instance);
+ }
+
+ public async void EmptyTrash_Click(object sender, Avalonia.Interactivity.RoutedEventArgs e)
+ => await _viewModel.PermanentlyDeleteCheckedAsync();
+ public async void Restore_Click(object sender, Avalonia.Interactivity.RoutedEventArgs e)
+ => await _viewModel.RestoreCheckedAsync();
+ }
+
+ public class TrashBinViewModel : ViewModelBase, IDisposable
+ {
+ public AvaloniaList DeletedBooks { get; }
+ public string CheckedCountText => $"Checked : {_checkedBooksCount} of {_totalBooksCount}";
+
+ private bool _controlsEnabled = true;
+ public bool ControlsEnabled { get => _controlsEnabled; set=> this.RaiseAndSetIfChanged(ref _controlsEnabled, value); }
+
+ private bool? everythingChecked = false;
+ public bool? EverythingChecked
+ {
+ get => everythingChecked;
+ set
+ {
+ everythingChecked = value ?? false;
+
+ if (everythingChecked is true)
+ CheckAll();
+ else if (everythingChecked is false)
+ UncheckAll();
+ }
+ }
+
+ private int _totalBooksCount = 0;
+ private int _checkedBooksCount = -1;
+ public int CheckedBooksCount
+ {
+ get => _checkedBooksCount;
+ set
+ {
+ if (_checkedBooksCount != value)
+ {
+ _checkedBooksCount = value;
+ this.RaisePropertyChanged(nameof(CheckedCountText));
+ }
+
+ everythingChecked
+ = _checkedBooksCount == 0 || _totalBooksCount == 0 ? false
+ : _checkedBooksCount == _totalBooksCount ? true
+ : null;
+
+ this.RaisePropertyChanged(nameof(EverythingChecked));
+ }
+ }
+
+ public IEnumerable CheckedBooks => DeletedBooks.Where(i => i.IsChecked).Select(i => i.Item).Cast();
+
+ public TrashBinViewModel()
+ {
+ DeletedBooks = new()
+ {
+ ResetBehavior = ResetBehavior.Remove
+ };
+
+ tracker = DeletedBooks.TrackItemPropertyChanged(CheckboxPropertyChanged);
+ Reload();
+ }
+
+ public void CheckAll()
+ {
+ foreach (var item in DeletedBooks)
+ item.IsChecked = true;
+ }
+
+ public void UncheckAll()
+ {
+ foreach (var item in DeletedBooks)
+ item.IsChecked = false;
+ }
+
+ public async Task RestoreCheckedAsync()
+ {
+ ControlsEnabled = false;
+ var qtyChanges = await Task.Run(CheckedBooks.RestoreBooks);
+ if (qtyChanges > 0)
+ Reload();
+ ControlsEnabled = true;
+ }
+
+ public async Task PermanentlyDeleteCheckedAsync()
+ {
+ ControlsEnabled = false;
+ var qtyChanges = await Task.Run(CheckedBooks.PermanentlyDeleteBooks);
+ if (qtyChanges > 0)
+ Reload();
+ ControlsEnabled = true;
+ }
+
+ private void Reload()
+ {
+ var deletedBooks = DbContexts.GetContext().GetDeletedLibraryBooks();
+
+ DeletedBooks.Clear();
+ DeletedBooks.AddRange(deletedBooks.Select(lb => new CheckBoxViewModel { Item = lb }));
+
+ _totalBooksCount = DeletedBooks.Count;
+ CheckedBooksCount = 0;
+ }
+
+ private IDisposable tracker;
+ private void CheckboxPropertyChanged(Tuple