oops. again

This commit is contained in:
Robert McRackan 2021-09-24 16:44:49 -04:00
parent 30e2caaff5
commit c9c28c7826
12 changed files with 103 additions and 119 deletions

View File

@ -155,7 +155,7 @@ namespace FileLiberator
var dest var dest
= AudibleFileStorage.Audio.IsFileTypeMatch(f) = AudibleFileStorage.Audio.IsFileTypeMatch(f)
? audioFileName ? audioFileName
// non-audio filename: safetitle_limit50char + " [" + productId + "][" + audio_ext +"]." + non_audio_ext // non-audio filename: safetitle_limit50char + " [" + productId + "][" + audio_ext + "]." + non_audio_ext
: FileUtility.GetValidFilename(destinationDir, product.Title, f.Extension, product.AudibleProductId, musicFileExt); : FileUtility.GetValidFilename(destinationDir, product.Title, f.Extension, product.AudibleProductId, musicFileExt);
if (Path.GetExtension(dest).Trim('.').ToLower() == "cue") if (Path.GetExtension(dest).Trim('.').ToLower() == "cue")

View File

@ -11,13 +11,27 @@ using FileManager;
namespace FileLiberator namespace FileLiberator
{ {
public class DownloadPdf : DownloadableBase public class DownloadPdf : IProcessable
{ {
public override bool Validate(LibraryBook libraryBook) public event EventHandler<LibraryBook> Begin;
public event EventHandler<LibraryBook> Completed;
public event EventHandler<string> StreamingBegin;
public event EventHandler<DownloadProgress> StreamingProgressChanged;
public event EventHandler<string> StreamingCompleted;
public event EventHandler<string> StatusUpdate;
public event EventHandler<TimeSpan> StreamingTimeRemaining;
public bool Validate(LibraryBook libraryBook)
=> !string.IsNullOrWhiteSpace(getdownloadUrl(libraryBook)) => !string.IsNullOrWhiteSpace(getdownloadUrl(libraryBook))
&& !libraryBook.Book.PDF_Exists; && !libraryBook.Book.PDF_Exists;
public override async Task<StatusHandler> ProcessItemAsync(LibraryBook libraryBook) public async Task<StatusHandler> ProcessAsync(LibraryBook libraryBook)
{
Begin?.Invoke(this, libraryBook);
try
{ {
var proposedDownloadFilePath = getProposedDownloadFilePath(libraryBook); var proposedDownloadFilePath = getProposedDownloadFilePath(libraryBook);
var actualDownloadedFilePath = await downloadPdfAsync(libraryBook, proposedDownloadFilePath); var actualDownloadedFilePath = await downloadPdfAsync(libraryBook, proposedDownloadFilePath);
@ -27,6 +41,11 @@ namespace FileLiberator
return result; return result;
} }
finally
{
Completed?.Invoke(this, libraryBook);
}
}
private static string getProposedDownloadFilePath(LibraryBook libraryBook) private static string getProposedDownloadFilePath(LibraryBook libraryBook)
{ {
@ -49,17 +68,28 @@ namespace FileLiberator
=> libraryBook?.Book?.Supplements?.FirstOrDefault()?.Url; => libraryBook?.Book?.Supplements?.FirstOrDefault()?.Url;
private async Task<string> downloadPdfAsync(LibraryBook libraryBook, string proposedDownloadFilePath) private async Task<string> downloadPdfAsync(LibraryBook libraryBook, string proposedDownloadFilePath)
{
StreamingBegin?.Invoke(this, proposedDownloadFilePath);
try
{ {
var api = await libraryBook.GetApiAsync(); var api = await libraryBook.GetApiAsync();
var downloadUrl = await api.GetPdfDownloadLinkAsync(libraryBook.Book.AudibleProductId); var downloadUrl = await api.GetPdfDownloadLinkAsync(libraryBook.Book.AudibleProductId);
var client = new HttpClient(); var progress = new Progress<DownloadProgress>();
var actualDownloadedFilePath = await PerformDownloadAsync( progress.ProgressChanged += (_, e) => StreamingProgressChanged?.Invoke(this, e);
proposedDownloadFilePath,
(p) => client.DownloadFileAsync(downloadUrl, proposedDownloadFilePath, p));
var client = new HttpClient();
var actualDownloadedFilePath = await client.DownloadFileAsync(downloadUrl, proposedDownloadFilePath, progress);
StatusUpdate?.Invoke(this, actualDownloadedFilePath);
return actualDownloadedFilePath; return actualDownloadedFilePath;
} }
finally
{
StreamingCompleted?.Invoke(this, proposedDownloadFilePath);
}
}
private static StatusHandler verifyDownload(string actualDownloadedFilePath) private static StatusHandler verifyDownload(string actualDownloadedFilePath)
=> !File.Exists(actualDownloadedFilePath) => !File.Exists(actualDownloadedFilePath)

View File

@ -1,63 +0,0 @@
using System;
using System.Threading.Tasks;
using DataLayer;
using Dinah.Core.ErrorHandling;
using Dinah.Core.Net.Http;
namespace FileLiberator
{
public abstract class DownloadableBase : IProcessable
{
public event EventHandler<LibraryBook> Begin;
public event EventHandler<LibraryBook> Completed;
public event EventHandler<string> StreamingBegin;
public event EventHandler<DownloadProgress> StreamingProgressChanged;
public event EventHandler<string> StreamingCompleted;
public event EventHandler<string> StatusUpdate;
public event EventHandler<TimeSpan> StreamingTimeRemaining;
protected void Invoke_StatusUpdate(string message) => StatusUpdate?.Invoke(this, message);
public abstract bool Validate(LibraryBook libraryBook);
public abstract Task<StatusHandler> ProcessItemAsync(LibraryBook libraryBook);
// do NOT use ConfigureAwait(false) on ProcessAsync()
// often calls events which prints to forms in the UI context
public async Task<StatusHandler> ProcessAsync(LibraryBook libraryBook)
{
Begin?.Invoke(this, libraryBook);
try
{
return await ProcessItemAsync(libraryBook);
}
finally
{
Completed?.Invoke(this, libraryBook);
}
}
protected async Task<string> PerformDownloadAsync(string proposedDownloadFilePath, Func<Progress<DownloadProgress>, Task<string>> func)
{
var progress = new Progress<DownloadProgress>();
progress.ProgressChanged += (_, e) => StreamingProgressChanged?.Invoke(this, e);
StreamingBegin?.Invoke(this, proposedDownloadFilePath);
try
{
var result = await func(progress);
StatusUpdate?.Invoke(this, result);
return result;
}
finally
{
StreamingCompleted?.Invoke(this, proposedDownloadFilePath);
}
}
}
}

View File

@ -10,15 +10,12 @@ namespace FileLiberator
{ {
public static class IProcessableExt public static class IProcessableExt
{ {
//
// DO NOT USE ConfigureAwait(false) WITH ProcessAsync() unless ensuring ProcessAsync() implementation is cross-thread compatible
// ProcessAsync() often does a lot with forms in the UI context
//
// when used in foreach: stateful. deferred execution // when used in foreach: stateful. deferred execution
public static IEnumerable<LibraryBook> GetValidLibraryBooks(this IProcessable processable, IEnumerable<LibraryBook> library) public static IEnumerable<LibraryBook> GetValidLibraryBooks(this IProcessable processable, IEnumerable<LibraryBook> library)
=> library.Where(libraryBook => processable.Validate(libraryBook)); => library.Where(libraryBook =>
processable.Validate(libraryBook)
&& libraryBook.Book.ContentType != ContentType.Episode || FileManager.Configuration.Instance.DownloadEpisodes
);
public static async Task<StatusHandler> ProcessSingleAsync(this IProcessable processable, LibraryBook libraryBook, bool validate) public static async Task<StatusHandler> ProcessSingleAsync(this IProcessable processable, LibraryBook libraryBook, bool validate)
{ {

View File

@ -48,7 +48,7 @@ namespace FileManager
protected AudibleFileStorage(FileType fileType) : base((int)fileType, fileType.ToString()) protected AudibleFileStorage(FileType fileType) : base((int)fileType, fileType.ToString())
{ {
extensions_noDots = Extensions.Select(ext => ext.Trim('.')).ToList(); extensions_noDots = Extensions.Select(ext => ext.ToLower().Trim('.')).ToList();
extAggr = extensions_noDots.Aggregate((a, b) => $"{a}|{b}"); extAggr = extensions_noDots.Aggregate((a, b) => $"{a}|{b}");
BookDirectoryFiles ??= new BackgroundFileSystem(BooksDirectory, "*.*", SearchOption.AllDirectories); BookDirectoryFiles ??= new BackgroundFileSystem(BooksDirectory, "*.*", SearchOption.AllDirectories);
} }
@ -59,7 +59,8 @@ namespace FileManager
if (cachedFile != null) if (cachedFile != null)
return cachedFile; return cachedFile;
string regexPattern = $@"{productId}.*?\.({extAggr})$"; var regex = new Regex($@"{productId}.*?\.({extAggr})$", RegexOptions.IgnoreCase);
string firstOrNull; string firstOrNull;
if (StorageDirectory == BooksDirectory) if (StorageDirectory == BooksDirectory)
@ -76,14 +77,14 @@ namespace FileManager
} }
} }
firstOrNull = BookDirectoryFiles.FindFile(regexPattern, RegexOptions.IgnoreCase); firstOrNull = BookDirectoryFiles.FindFile(regex);
} }
else else
{ {
firstOrNull = firstOrNull =
Directory Directory
.EnumerateFiles(StorageDirectory, "*.*", SearchOption.AllDirectories) .EnumerateFiles(StorageDirectory, "*.*", SearchOption.AllDirectories)
.FirstOrDefault(s => Regex.IsMatch(s, regexPattern, RegexOptions.IgnoreCase)); .FirstOrDefault(s => regex.IsMatch(s));
} }
if (firstOrNull is null) if (firstOrNull is null)

View File

@ -3,8 +3,6 @@ using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace FileManager namespace FileManager
@ -38,10 +36,10 @@ namespace FileManager
Init(); Init();
} }
public string FindFile(string regexPattern, RegexOptions options) public string FindFile(System.Text.RegularExpressions.Regex regex)
{ {
lock (fsCacheLocker) lock (fsCacheLocker)
return fsCache.FirstOrDefault(s => Regex.IsMatch(s, regexPattern, options)); return fsCache.FirstOrDefault(s => regex.IsMatch(s));
} }
public void RefreshFiles() public void RefreshFiles()
@ -61,13 +59,15 @@ namespace FileManager
fsCache.AddRange(Directory.EnumerateFiles(RootDirectory, SearchPattern, SearchOption)); fsCache.AddRange(Directory.EnumerateFiles(RootDirectory, SearchPattern, SearchOption));
directoryChangesEvents = new BlockingCollection<FileSystemEventArgs>(); directoryChangesEvents = new BlockingCollection<FileSystemEventArgs>();
fileSystemWatcher = new FileSystemWatcher(RootDirectory); fileSystemWatcher = new FileSystemWatcher(RootDirectory)
{
IncludeSubdirectories = true,
EnableRaisingEvents = true
};
fileSystemWatcher.Created += FileSystemWatcher_Changed; fileSystemWatcher.Created += FileSystemWatcher_Changed;
fileSystemWatcher.Deleted += FileSystemWatcher_Changed; fileSystemWatcher.Deleted += FileSystemWatcher_Changed;
fileSystemWatcher.Renamed += FileSystemWatcher_Changed; fileSystemWatcher.Renamed += FileSystemWatcher_Changed;
fileSystemWatcher.Error += FileSystemWatcher_Error; fileSystemWatcher.Error += FileSystemWatcher_Error;
fileSystemWatcher.IncludeSubdirectories = true;
fileSystemWatcher.EnableRaisingEvents = true;
backgroundScanner = new Task(BackgroundScanner); backgroundScanner = new Task(BackgroundScanner);
backgroundScanner.Start(); backgroundScanner.Start();

View File

@ -125,6 +125,13 @@ namespace FileManager
set => persistentDictionary.SetString(nameof(BadBook), value.ToString()); set => persistentDictionary.SetString(nameof(BadBook), value.ToString());
} }
[Description("Download episodes? (eg: podcasts)")]
public bool DownloadEpisodes
{
get => persistentDictionary.GetNonString<bool>(nameof(DownloadEpisodes));
set => persistentDictionary.SetNonString(nameof(DownloadEpisodes), value);
}
#endregion #endregion
#region known directories #region known directories

View File

@ -13,7 +13,7 @@ namespace FileManager
// file max length = 255. dir max len = 247 // file max length = 255. dir max len = 247
// sanitize // sanitize
filename = GetAsciiTag(filename); filename = getAsciiTag(filename);
// manage length // manage length
if (filename.Length > 50) if (filename.Length > 50)
filename = filename.Substring(0, 50) + "[...]"; filename = filename.Substring(0, 50) + "[...]";
@ -35,7 +35,7 @@ namespace FileManager
return fullfilename; return fullfilename;
} }
public static string GetAsciiTag(string property) private static string getAsciiTag(string property)
{ {
if (property == null) if (property == null)
return ""; return "";

View File

@ -24,8 +24,8 @@ namespace LibationCli
var config = LibationScaffolding.RunPreConfigMigrations(); var config = LibationScaffolding.RunPreConfigMigrations();
LibationScaffolding.RunPostConfigMigrations(); LibationScaffolding.RunPostConfigMigrations(config);
LibationScaffolding.RunPostMigrationScaffolding(); LibationScaffolding.RunPostMigrationScaffolding(config);
#if !DEBUG #if !DEBUG
checkForUpdate(); checkForUpdate();

View File

@ -48,6 +48,7 @@
this.booksGb = new System.Windows.Forms.GroupBox(); this.booksGb = new System.Windows.Forms.GroupBox();
this.loggingLevelLbl = new System.Windows.Forms.Label(); this.loggingLevelLbl = new System.Windows.Forms.Label();
this.loggingLevelCb = new System.Windows.Forms.ComboBox(); this.loggingLevelCb = new System.Windows.Forms.ComboBox();
this.downloadEpisodesCb = new System.Windows.Forms.CheckBox();
this.advancedSettingsGb.SuspendLayout(); this.advancedSettingsGb.SuspendLayout();
this.badBookGb.SuspendLayout(); this.badBookGb.SuspendLayout();
this.decryptAndConvertGb.SuspendLayout(); this.decryptAndConvertGb.SuspendLayout();
@ -67,7 +68,7 @@
// inProgressDescLbl // inProgressDescLbl
// //
this.inProgressDescLbl.AutoSize = true; this.inProgressDescLbl.AutoSize = true;
this.inProgressDescLbl.Location = new System.Drawing.Point(8, 149); this.inProgressDescLbl.Location = new System.Drawing.Point(8, 174);
this.inProgressDescLbl.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.inProgressDescLbl.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.inProgressDescLbl.Name = "inProgressDescLbl"; this.inProgressDescLbl.Name = "inProgressDescLbl";
this.inProgressDescLbl.Size = new System.Drawing.Size(43, 45); this.inProgressDescLbl.Size = new System.Drawing.Size(43, 45);
@ -77,7 +78,7 @@
// saveBtn // saveBtn
// //
this.saveBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.saveBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.saveBtn.Location = new System.Drawing.Point(714, 445); this.saveBtn.Location = new System.Drawing.Point(714, 470);
this.saveBtn.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.saveBtn.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
this.saveBtn.Name = "saveBtn"; this.saveBtn.Name = "saveBtn";
this.saveBtn.Size = new System.Drawing.Size(88, 27); this.saveBtn.Size = new System.Drawing.Size(88, 27);
@ -90,7 +91,7 @@
// //
this.cancelBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.cancelBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.cancelBtn.DialogResult = System.Windows.Forms.DialogResult.Cancel; this.cancelBtn.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.cancelBtn.Location = new System.Drawing.Point(832, 445); this.cancelBtn.Location = new System.Drawing.Point(832, 470);
this.cancelBtn.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.cancelBtn.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
this.cancelBtn.Name = "cancelBtn"; this.cancelBtn.Name = "cancelBtn";
this.cancelBtn.Size = new System.Drawing.Size(88, 27); this.cancelBtn.Size = new System.Drawing.Size(88, 27);
@ -104,6 +105,7 @@
this.advancedSettingsGb.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) this.advancedSettingsGb.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right))); | System.Windows.Forms.AnchorStyles.Right)));
this.advancedSettingsGb.Controls.Add(this.downloadEpisodesCb);
this.advancedSettingsGb.Controls.Add(this.badBookGb); this.advancedSettingsGb.Controls.Add(this.badBookGb);
this.advancedSettingsGb.Controls.Add(this.decryptAndConvertGb); this.advancedSettingsGb.Controls.Add(this.decryptAndConvertGb);
this.advancedSettingsGb.Controls.Add(this.inProgressSelectControl); this.advancedSettingsGb.Controls.Add(this.inProgressSelectControl);
@ -112,7 +114,7 @@
this.advancedSettingsGb.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.advancedSettingsGb.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
this.advancedSettingsGb.Name = "advancedSettingsGb"; this.advancedSettingsGb.Name = "advancedSettingsGb";
this.advancedSettingsGb.Padding = new System.Windows.Forms.Padding(4, 3, 4, 3); this.advancedSettingsGb.Padding = new System.Windows.Forms.Padding(4, 3, 4, 3);
this.advancedSettingsGb.Size = new System.Drawing.Size(908, 258); this.advancedSettingsGb.Size = new System.Drawing.Size(908, 283);
this.advancedSettingsGb.TabIndex = 6; this.advancedSettingsGb.TabIndex = 6;
this.advancedSettingsGb.TabStop = false; this.advancedSettingsGb.TabStop = false;
this.advancedSettingsGb.Text = "Advanced settings for control freaks"; this.advancedSettingsGb.Text = "Advanced settings for control freaks";
@ -123,7 +125,7 @@
this.badBookGb.Controls.Add(this.badBookRetryRb); this.badBookGb.Controls.Add(this.badBookRetryRb);
this.badBookGb.Controls.Add(this.badBookAbortRb); this.badBookGb.Controls.Add(this.badBookAbortRb);
this.badBookGb.Controls.Add(this.badBookAskRb); this.badBookGb.Controls.Add(this.badBookAskRb);
this.badBookGb.Location = new System.Drawing.Point(372, 22); this.badBookGb.Location = new System.Drawing.Point(372, 47);
this.badBookGb.Name = "badBookGb"; this.badBookGb.Name = "badBookGb";
this.badBookGb.Size = new System.Drawing.Size(529, 124); this.badBookGb.Size = new System.Drawing.Size(529, 124);
this.badBookGb.TabIndex = 11; this.badBookGb.TabIndex = 11;
@ -179,7 +181,7 @@
this.decryptAndConvertGb.Controls.Add(this.allowLibationFixupCbox); this.decryptAndConvertGb.Controls.Add(this.allowLibationFixupCbox);
this.decryptAndConvertGb.Controls.Add(this.convertLossyRb); this.decryptAndConvertGb.Controls.Add(this.convertLossyRb);
this.decryptAndConvertGb.Controls.Add(this.convertLosslessRb); this.decryptAndConvertGb.Controls.Add(this.convertLosslessRb);
this.decryptAndConvertGb.Location = new System.Drawing.Point(7, 22); this.decryptAndConvertGb.Location = new System.Drawing.Point(8, 47);
this.decryptAndConvertGb.Name = "decryptAndConvertGb"; this.decryptAndConvertGb.Name = "decryptAndConvertGb";
this.decryptAndConvertGb.Size = new System.Drawing.Size(359, 124); this.decryptAndConvertGb.Size = new System.Drawing.Size(359, 124);
this.decryptAndConvertGb.TabIndex = 7; this.decryptAndConvertGb.TabIndex = 7;
@ -225,7 +227,7 @@
// //
this.inProgressSelectControl.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) this.inProgressSelectControl.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right))); | System.Windows.Forms.AnchorStyles.Right)));
this.inProgressSelectControl.Location = new System.Drawing.Point(7, 197); this.inProgressSelectControl.Location = new System.Drawing.Point(7, 222);
this.inProgressSelectControl.Name = "inProgressSelectControl"; this.inProgressSelectControl.Name = "inProgressSelectControl";
this.inProgressSelectControl.Size = new System.Drawing.Size(552, 52); this.inProgressSelectControl.Size = new System.Drawing.Size(552, 52);
this.inProgressSelectControl.TabIndex = 16; this.inProgressSelectControl.TabIndex = 16;
@ -280,13 +282,23 @@
this.loggingLevelCb.Size = new System.Drawing.Size(129, 23); this.loggingLevelCb.Size = new System.Drawing.Size(129, 23);
this.loggingLevelCb.TabIndex = 4; this.loggingLevelCb.TabIndex = 4;
// //
// downloadEpisodesCb
//
this.downloadEpisodesCb.AutoSize = true;
this.downloadEpisodesCb.Location = new System.Drawing.Point(8, 22);
this.downloadEpisodesCb.Name = "downloadEpisodesCb";
this.downloadEpisodesCb.Size = new System.Drawing.Size(163, 19);
this.downloadEpisodesCb.TabIndex = 17;
this.downloadEpisodesCb.Text = "[download episodes desc]";
this.downloadEpisodesCb.UseVisualStyleBackColor = true;
//
// SettingsDialog // SettingsDialog
// //
this.AcceptButton = this.saveBtn; this.AcceptButton = this.saveBtn;
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.cancelBtn; this.CancelButton = this.cancelBtn;
this.ClientSize = new System.Drawing.Size(933, 488); this.ClientSize = new System.Drawing.Size(933, 513);
this.Controls.Add(this.logsBtn); this.Controls.Add(this.logsBtn);
this.Controls.Add(this.loggingLevelCb); this.Controls.Add(this.loggingLevelCb);
this.Controls.Add(this.loggingLevelLbl); this.Controls.Add(this.loggingLevelLbl);
@ -334,5 +346,6 @@
private System.Windows.Forms.RadioButton badBookAbortRb; private System.Windows.Forms.RadioButton badBookAbortRb;
private System.Windows.Forms.RadioButton badBookAskRb; private System.Windows.Forms.RadioButton badBookAskRb;
private System.Windows.Forms.RadioButton badBookIgnoreRb; private System.Windows.Forms.RadioButton badBookIgnoreRb;
private System.Windows.Forms.CheckBox downloadEpisodesCb;
} }
} }

View File

@ -26,6 +26,7 @@ namespace LibationWinForms.Dialogs
loggingLevelCb.SelectedItem = config.LogLevel; loggingLevelCb.SelectedItem = config.LogLevel;
} }
this.downloadEpisodesCb.Text = desc(nameof(config.DownloadEpisodes));
this.booksLocationDescLbl.Text = desc(nameof(config.Books)); this.booksLocationDescLbl.Text = desc(nameof(config.Books));
this.inProgressDescLbl.Text = desc(nameof(config.InProgress)); this.inProgressDescLbl.Text = desc(nameof(config.InProgress));
@ -41,6 +42,7 @@ namespace LibationWinForms.Dialogs
"Books"); "Books");
booksSelectControl.SelectDirectory(config.Books); booksSelectControl.SelectDirectory(config.Books);
downloadEpisodesCb.Checked = config.DownloadEpisodes;
allowLibationFixupCbox.Checked = config.AllowLibationFixup; allowLibationFixupCbox.Checked = config.AllowLibationFixup;
convertLosslessRb.Checked = !config.DecryptToLossy; convertLosslessRb.Checked = !config.DecryptToLossy;
convertLossyRb.Checked = config.DecryptToLossy; convertLossyRb.Checked = config.DecryptToLossy;
@ -121,6 +123,7 @@ namespace LibationWinForms.Dialogs
MessageBoxVerboseLoggingWarning.ShowIfTrue(); MessageBoxVerboseLoggingWarning.ShowIfTrue();
} }
config.DownloadEpisodes = downloadEpisodesCb.Checked;
config.AllowLibationFixup = allowLibationFixupCbox.Checked; config.AllowLibationFixup = allowLibationFixupCbox.Checked;
config.DecryptToLossy = convertLossyRb.Checked; config.DecryptToLossy = convertLossyRb.Checked;

View File

@ -42,10 +42,11 @@ namespace LibationWinForms
// Migrations which must occur before configuration is loaded for the first time. Usually ones which alter the Configuration // Migrations which must occur before configuration is loaded for the first time. Usually ones which alter the Configuration
var config = AppScaffolding.LibationScaffolding.RunPreConfigMigrations(); var config = AppScaffolding.LibationScaffolding.RunPreConfigMigrations();
// do this as soon as possible (post-config)
RunInstaller(config); RunInstaller(config);
// most migrations go in here // most migrations go in here
AppScaffolding.LibationScaffolding.RunPostConfigMigrations(); AppScaffolding.LibationScaffolding.RunPostConfigMigrations(config);
// migrations which require Forms or are long-running // migrations which require Forms or are long-running
RunWindowsOnlyMigrations(config); RunWindowsOnlyMigrations(config);
@ -56,6 +57,7 @@ namespace LibationWinForms
checkForUpdate(); checkForUpdate();
#endif #endif
AppScaffolding.LibationScaffolding.RunPostMigrationScaffolding(config);
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -72,8 +74,6 @@ namespace LibationWinForms
return; return;
} }
AppScaffolding.LibationScaffolding.RunPostMigrationScaffolding();
Application.Run(new Form1()); Application.Run(new Form1());
} }
@ -143,8 +143,6 @@ namespace LibationWinForms
// if 'new user' was clicked, or if 'returning user' chose new install: show basic settings dialog // if 'new user' was clicked, or if 'returning user' chose new install: show basic settings dialog
config.Books ??= Path.Combine(defaultLibationFilesDir, "Books"); config.Books ??= Path.Combine(defaultLibationFilesDir, "Books");
config.InProgress ??= Configuration.WinTemp; config.InProgress ??= Configuration.WinTemp;
config.AllowLibationFixup = true;
config.DecryptToLossy = false;
if (new SettingsDialog().ShowDialog() != DialogResult.OK) if (new SettingsDialog().ShowDialog() != DialogResult.OK)
{ {
@ -158,6 +156,7 @@ namespace LibationWinForms
CancelInstallation(); CancelInstallation();
} }
/// <summary>migrations which require Forms or are long-running</summary>
private static void RunWindowsOnlyMigrations(Configuration config) private static void RunWindowsOnlyMigrations(Configuration config)
{ {
// only supported in winforms. don't move to app scaffolding // only supported in winforms. don't move to app scaffolding
@ -170,9 +169,6 @@ namespace LibationWinForms
#region migrate to v5.0.0 re-register device if device info not in settings #region migrate to v5.0.0 re-register device if device info not in settings
private static void migrate_to_v5_0_0(Configuration config) private static void migrate_to_v5_0_0(Configuration config)
{ {
if (!config.Exists(nameof(config.AllowLibationFixup)))
config.AllowLibationFixup = true;
if (!File.Exists(AudibleApiStorage.AccountsSettingsFile)) if (!File.Exists(AudibleApiStorage.AccountsSettingsFile))
return; return;