Merge pull request #47 from Mbucari/master

Addressed two issues and some minor fixed.
This commit is contained in:
rmcrackan 2021-07-04 09:27:58 -04:00 committed by GitHub
commit 6f31d97763
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 49 additions and 43 deletions

View File

@ -142,6 +142,9 @@ namespace AaxDecrypter
if (File.Exists(jsonDownloadState)) if (File.Exists(jsonDownloadState))
{ {
nfsPersister = new NetworkFileStreamPersister(jsonDownloadState); nfsPersister = new NetworkFileStreamPersister(jsonDownloadState);
//If More thaan ~1 hour has elapsed since getting the download url, it will expire.
//The new url will be to the same file.
nfsPersister.NetworkFileStream.SetUriForSameFile(new Uri(downloadLicense.DownloadUrl));
} }
else else
{ {

View File

@ -213,8 +213,7 @@ namespace FileLiberator
} }
public bool Validate(LibraryBook libraryBook) public bool Validate(LibraryBook libraryBook)
=> !AudibleFileStorage.Audio.Exists(libraryBook.Book.AudibleProductId) => !AudibleFileStorage.Audio.Exists(libraryBook.Book.AudibleProductId);
&& !AudibleFileStorage.AAX.Exists(libraryBook.Book.AudibleProductId);
public void Cancel() public void Cancel()
{ {

View File

@ -9,7 +9,7 @@ using Dinah.Core.Collections.Generic;
namespace FileManager namespace FileManager
{ {
// could add images here, but for now images are stored in a well-known location // could add images here, but for now images are stored in a well-known location
public enum FileType { Unknown, Audio, AAX, PDF } public enum FileType { Unknown, Audio, AAXC, PDF }
/// <summary> /// <summary>
/// Files are large. File contents are never read by app. /// Files are large. File contents are never read by app.
@ -25,7 +25,7 @@ namespace FileManager
#region static #region static
public static AudioFileStorage Audio { get; } = new AudioFileStorage(); public static AudioFileStorage Audio { get; } = new AudioFileStorage();
public static AudibleFileStorage AAX { get; } = new AaxFileStorage(); public static AudibleFileStorage AAXC { get; } = new AaxcFileStorage();
public static AudibleFileStorage PDF { get; } = new PdfFileStorage(); public static AudibleFileStorage PDF { get; } = new PdfFileStorage();
public static string DownloadsInProgress public static string DownloadsInProgress
@ -77,7 +77,7 @@ namespace FileManager
public FileType FileType => (FileType)Value; public FileType FileType => (FileType)Value;
private IEnumerable<string> extensions_noDots { get; } private IEnumerable<string> extensions_noDots { get; }
private string extAggr { get; } private string extAggr { get; }
protected AudibleFileStorage(FileType fileType) : base((int)fileType, fileType.ToString()) protected AudibleFileStorage(FileType fileType) : base((int)fileType, fileType.ToString())
{ {
@ -153,16 +153,16 @@ namespace FileManager
} }
} }
public class AaxFileStorage : AudibleFileStorage public class AaxcFileStorage : AudibleFileStorage
{ {
public override string[] Extensions { get; } = new[] { "aax" }; public override string[] Extensions { get; } = new[] { "aaxc" };
// 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 "=>"
// - do NOT use assign "=" // - do NOT use assign "="
public override string StorageDirectory => DownloadsFinal; public override string StorageDirectory => DownloadsInProgress;
public AaxFileStorage() : base(FileType.AAX) { } public AaxcFileStorage() : base(FileType.AAXC) { }
} }
public class PdfFileStorage : AudibleFileStorage public class PdfFileStorage : AudibleFileStorage

View File

@ -24,13 +24,18 @@ namespace LibationWinForms.BookLiberation
InitializeComponent(); InitializeComponent();
} }
public void WriteLine(string text) public void WriteLine(string text)
=> logTb.UIThread(() => logTb.AppendText($"{DateTime.Now} {text}{Environment.NewLine}")); {
if (!IsDisposed)
logTb.UIThread(() => logTb.AppendText($"{DateTime.Now} {text}{Environment.NewLine}"));
}
public void FinalizeUI() public void FinalizeUI()
{ {
keepGoingCb.Enabled = false; keepGoingCb.Enabled = false;
logTb.AppendText("");
if (!IsDisposed)
logTb.AppendText("");
} }
private void AutomatedBackupsForm_FormClosing(object sender, FormClosingEventArgs e) => keepGoingCb.Checked = false; private void AutomatedBackupsForm_FormClosing(object sender, FormClosingEventArgs e) => keepGoingCb.Checked = false;

View File

@ -48,12 +48,13 @@ namespace LibationWinForms.BookLiberation
var backupBook = getWiredUpBackupBook(completedAction); var backupBook = getWiredUpBackupBook(completedAction);
(AutomatedBackupsForm automatedBackupsForm, LogMe logMe) = attachToBackupsForm(backupBook); (Action unsibscribeEvents, LogMe logMe) = attachToBackupsForm(backupBook);
automatedBackupsForm.KeepGoingVisible = false;
var libraryBook = IProcessableExt.GetSingleLibraryBook(productId); var libraryBook = IProcessableExt.GetSingleLibraryBook(productId);
// continue even if libraryBook is null. we'll display even that in the processing box // continue even if libraryBook is null. we'll display even that in the processing box
await new BackupSingle(logMe, backupBook, automatedBackupsForm, libraryBook).RunBackupAsync(); await new BackupSingle(logMe, backupBook, libraryBook).RunBackupAsync();
unsibscribeEvents();
} }
public static async Task BackupAllBooksAsync(EventHandler<LibraryBook> completedAction = null) public static async Task BackupAllBooksAsync(EventHandler<LibraryBook> completedAction = null)
@ -61,9 +62,13 @@ namespace LibationWinForms.BookLiberation
Serilog.Log.Logger.Information("Begin " + nameof(BackupAllBooksAsync)); Serilog.Log.Logger.Information("Begin " + nameof(BackupAllBooksAsync));
var backupBook = getWiredUpBackupBook(completedAction); var backupBook = getWiredUpBackupBook(completedAction);
var automatedBackupsForm = new AutomatedBackupsForm();
(Action unsibscribeEvents, LogMe logMe) = attachToBackupsForm(backupBook, automatedBackupsForm);
(AutomatedBackupsForm automatedBackupsForm, LogMe logMe) = attachToBackupsForm(backupBook);
await new BackupLoop(logMe, backupBook, automatedBackupsForm).RunBackupAsync(); await new BackupLoop(logMe, backupBook, automatedBackupsForm).RunBackupAsync();
unsibscribeEvents();
} }
private static BackupBook getWiredUpBackupBook(EventHandler<LibraryBook> completedAction) private static BackupBook getWiredUpBackupBook(EventHandler<LibraryBook> completedAction)
@ -93,11 +98,10 @@ namespace LibationWinForms.BookLiberation
private static void updateIsLiberated(object sender, LibraryBook e) => ApplicationServices.SearchEngineCommands.UpdateIsLiberated(e.Book); private static void updateIsLiberated(object sender, LibraryBook e) => ApplicationServices.SearchEngineCommands.UpdateIsLiberated(e.Book);
private static (AutomatedBackupsForm, LogMe) attachToBackupsForm(BackupBook backupBook) private static (Action unsibscribeEvents, LogMe) attachToBackupsForm(BackupBook backupBook, AutomatedBackupsForm automatedBackupsForm = null)
{ {
#region create form and logger #region create logger
var automatedBackupsForm = new AutomatedBackupsForm(); var logMe = automatedBackupsForm is null? new LogMe() : LogMe.RegisterForm(automatedBackupsForm);
var logMe = LogMe.RegisterForm(automatedBackupsForm);
#endregion #endregion
#region define how model actions will affect form behavior #region define how model actions will affect form behavior
@ -121,7 +125,7 @@ namespace LibationWinForms.BookLiberation
#region when form closes, unsubscribe from model's events #region when form closes, unsubscribe from model's events
// unsubscribe so disposed forms aren't still trying to receive notifications // unsubscribe so disposed forms aren't still trying to receive notifications
automatedBackupsForm.FormClosing += (_, __) => Action unsibscribe = () =>
{ {
backupBook.DecryptBook.Begin -= decryptBookBegin; backupBook.DecryptBook.Begin -= decryptBookBegin;
backupBook.DecryptBook.StatusUpdate -= statusUpdate; backupBook.DecryptBook.StatusUpdate -= statusUpdate;
@ -132,7 +136,7 @@ namespace LibationWinForms.BookLiberation
}; };
#endregion #endregion
return (automatedBackupsForm, logMe); return (unsibscribe, logMe);
} }
public static async Task BackupAllPdfsAsync(EventHandler<LibraryBook> completedAction = null) public static async Task BackupAllPdfsAsync(EventHandler<LibraryBook> completedAction = null)
@ -367,7 +371,7 @@ namespace LibationWinForms.BookLiberation
protected IProcessable Processable { get; } protected IProcessable Processable { get; }
protected AutomatedBackupsForm AutomatedBackupsForm { get; } protected AutomatedBackupsForm AutomatedBackupsForm { get; }
protected BackupRunner(LogMe logMe, IProcessable processable, AutomatedBackupsForm automatedBackupsForm) protected BackupRunner(LogMe logMe, IProcessable processable, AutomatedBackupsForm automatedBackupsForm = null)
{ {
LogMe = logMe; LogMe = logMe;
Processable = processable; Processable = processable;
@ -382,7 +386,7 @@ namespace LibationWinForms.BookLiberation
public async Task RunBackupAsync() public async Task RunBackupAsync()
{ {
AutomatedBackupsForm.Show(); AutomatedBackupsForm?.Show();
try try
{ {
@ -393,7 +397,7 @@ namespace LibationWinForms.BookLiberation
LogMe.Error(ex); LogMe.Error(ex);
} }
AutomatedBackupsForm.FinalizeUI(); AutomatedBackupsForm?.FinalizeUI();
LogMe.Info("DONE"); LogMe.Info("DONE");
} }
@ -454,8 +458,8 @@ An error occurred while trying to process this book. Skip this book permanently?
protected override MessageBoxButtons SkipDialogButtons => MessageBoxButtons.YesNo; protected override MessageBoxButtons SkipDialogButtons => MessageBoxButtons.YesNo;
protected override DialogResult CreateSkipFileResult => DialogResult.Yes; protected override DialogResult CreateSkipFileResult => DialogResult.Yes;
public BackupSingle(LogMe logMe, IProcessable processable, AutomatedBackupsForm automatedBackupsForm, LibraryBook libraryBook) public BackupSingle(LogMe logMe, IProcessable processable, LibraryBook libraryBook)
: base(logMe, processable, automatedBackupsForm) : base(logMe, processable)
{ {
_libraryBook = libraryBook; _libraryBook = libraryBook;
} }
@ -492,6 +496,9 @@ An error occurred while trying to process this book
if (!keepGoing) if (!keepGoing)
return; return;
if (AutomatedBackupsForm.IsDisposed)
break;
if (!AutomatedBackupsForm.KeepGoing) if (!AutomatedBackupsForm.KeepGoing)
{ {
if (AutomatedBackupsForm.KeepGoingVisible && !AutomatedBackupsForm.KeepGoingChecked) if (AutomatedBackupsForm.KeepGoingVisible && !AutomatedBackupsForm.KeepGoingChecked)

View File

@ -117,7 +117,7 @@ namespace LibationWinForms
{ {
if (AudibleFileStorage.Audio.Exists(productId)) if (AudibleFileStorage.Audio.Exists(productId))
return AudioFileState.full; return AudioFileState.full;
if (AudibleFileStorage.AAX.Exists(productId)) if (AudibleFileStorage.AAXC.Exists(productId))
return AudioFileState.aax; return AudioFileState.aax;
return AudioFileState.none; return AudioFileState.none;
} }

View File

@ -26,11 +26,11 @@ namespace LibationWinForms
[Browsable(false)] [Browsable(false)]
public IEnumerable<string> TagsEnumerated => book.UserDefinedItem.TagsEnumerated; public IEnumerable<string> TagsEnumerated => book.UserDefinedItem.TagsEnumerated;
public enum LiberatedState { NotDownloaded, DRM, Liberated } public enum LiberatedState { NotDownloaded, PartialDownload, Liberated }
[Browsable(false)] [Browsable(false)]
public LiberatedState Liberated_Status public LiberatedState Liberated_Status
=> FileManager.AudibleFileStorage.Audio.Exists(book.AudibleProductId) ? LiberatedState.Liberated => FileManager.AudibleFileStorage.Audio.Exists(book.AudibleProductId) ? LiberatedState.Liberated
: FileManager.AudibleFileStorage.AAX.Exists(book.AudibleProductId) ? LiberatedState.DRM : FileManager.AudibleFileStorage.AAXC.Exists(book.AudibleProductId) ? LiberatedState.PartialDownload
: LiberatedState.NotDownloaded; : LiberatedState.NotDownloaded;
public enum PdfState { NoPdf, Downloaded, NotDownloaded } public enum PdfState { NoPdf, Downloaded, NotDownloaded }

View File

@ -126,7 +126,7 @@ namespace LibationWinForms
var libState = liberatedStatus switch var libState = liberatedStatus switch
{ {
GridEntry.LiberatedState.Liberated => "Liberated", GridEntry.LiberatedState.Liberated => "Liberated",
GridEntry.LiberatedState.DRM => "Downloaded but needs DRM removed", GridEntry.LiberatedState.PartialDownload => "File has been at least\r\npartially downloaded",
GridEntry.LiberatedState.NotDownloaded => "Book NOT downloaded", GridEntry.LiberatedState.NotDownloaded => "Book NOT downloaded",
_ => throw new Exception("Unexpected liberation state") _ => throw new Exception("Unexpected liberation state")
}; };
@ -142,7 +142,7 @@ namespace LibationWinForms
var text = libState + pdfState; var text = libState + pdfState;
if (liberatedStatus == GridEntry.LiberatedState.NotDownloaded || if (liberatedStatus == GridEntry.LiberatedState.NotDownloaded ||
liberatedStatus == GridEntry.LiberatedState.DRM || liberatedStatus == GridEntry.LiberatedState.PartialDownload ||
pdfStatus == GridEntry.PdfState.NotDownloaded) pdfStatus == GridEntry.PdfState.NotDownloaded)
text += "\r\nClick to complete"; text += "\r\nClick to complete";
@ -154,7 +154,7 @@ namespace LibationWinForms
{ {
var image_lib var image_lib
= liberatedStatus == GridEntry.LiberatedState.NotDownloaded ? "red" = liberatedStatus == GridEntry.LiberatedState.NotDownloaded ? "red"
: liberatedStatus == GridEntry.LiberatedState.DRM ? "yellow" : liberatedStatus == GridEntry.LiberatedState.PartialDownload ? "yellow"
: liberatedStatus == GridEntry.LiberatedState.Liberated ? "green" : liberatedStatus == GridEntry.LiberatedState.Liberated ? "green"
: throw new Exception("Unexpected liberation state"); : throw new Exception("Unexpected liberation state");
var image_pdf var image_pdf
@ -182,15 +182,7 @@ namespace LibationWinForms
return; return;
} }
// not liberated: liberate await BookLiberation.ProcessorAutomationController.BackupSingleBookAsync(productId, (_, __) => RefreshRow(productId));
var msg
= "Liberate entire library instead?"
+ "\r\n\r\nClick Yes to begin liberating your entire library"
+ "\r\n\r\nClick No to liberate this book only";
if (MessageBox.Show(msg, "Liberate entire library?", MessageBoxButtons.YesNo) == DialogResult.Yes)
await BookLiberation.ProcessorAutomationController.BackupAllBooksAsync((_, libraryBook) => RefreshRow(libraryBook.Book.AudibleProductId));
else
await BookLiberation.ProcessorAutomationController.BackupSingleBookAsync(productId, (_, __) => RefreshRow(productId));
} }
#endregion #endregion