auto-scan initial code. Feature not yet complete
This commit is contained in:
parent
c99ee56f24
commit
cb8b5d74d7
@ -122,6 +122,9 @@ namespace AppScaffolding
|
|||||||
|
|
||||||
if (!config.Exists(nameof(config.ChapterFileTemplate)))
|
if (!config.Exists(nameof(config.ChapterFileTemplate)))
|
||||||
config.ChapterFileTemplate = Templates.ChapterFile.DefaultTemplate;
|
config.ChapterFileTemplate = Templates.ChapterFile.DefaultTemplate;
|
||||||
|
|
||||||
|
if (!config.Exists(nameof(config.AutoScan)))
|
||||||
|
config.AutoScan = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Initialize logging. Run after migration</summary>
|
/// <summary>Initialize logging. Run after migration</summary>
|
||||||
|
|||||||
@ -7,6 +7,12 @@ namespace AudibleUtilities
|
|||||||
{
|
{
|
||||||
public class AccountsSettingsPersister : JsonFilePersister<AccountsSettings>
|
public class AccountsSettingsPersister : JsonFilePersister<AccountsSettings>
|
||||||
{
|
{
|
||||||
|
public static event EventHandler Saving;
|
||||||
|
public static event EventHandler Saved;
|
||||||
|
|
||||||
|
protected override void OnSaving() => Saving?.Invoke(null, null);
|
||||||
|
protected override void OnSaved() => Saved?.Invoke(null, null);
|
||||||
|
|
||||||
/// <summary>Alias for Target </summary>
|
/// <summary>Alias for Target </summary>
|
||||||
public AccountsSettings AccountsSettings => Target;
|
public AccountsSettings AccountsSettings => Target;
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="AudibleApi" Version="2.7.3.1" />
|
<PackageReference Include="AudibleApi" Version="2.7.5.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Dinah.Core" Version="4.0.6.1" />
|
<PackageReference Include="Dinah.Core" Version="4.1.1.1" />
|
||||||
<PackageReference Include="Polly" Version="7.2.3" />
|
<PackageReference Include="Polly" Version="7.2.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@ -224,6 +224,22 @@ namespace LibationFileManager
|
|||||||
set => persistentDictionary.SetNonString(nameof(DownloadEpisodes), value);
|
set => persistentDictionary.SetNonString(nameof(DownloadEpisodes), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public event EventHandler AutoScanChanged;
|
||||||
|
|
||||||
|
[Description("Automatically run periodic scans in the background?")]
|
||||||
|
public bool AutoScan
|
||||||
|
{
|
||||||
|
get => persistentDictionary.GetNonString<bool>(nameof(AutoScan));
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (AutoScan != value)
|
||||||
|
{
|
||||||
|
persistentDictionary.SetNonString(nameof(AutoScan), value);
|
||||||
|
AutoScanChanged?.Invoke(null, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#region templates: custom file naming
|
#region templates: custom file naming
|
||||||
|
|
||||||
[Description("How to format the folders in which files will be saved")]
|
[Description("How to format the folders in which files will be saved")]
|
||||||
|
|||||||
@ -122,7 +122,6 @@ namespace LibationWinForms.Dialogs
|
|||||||
persist(persister.AccountsSettings);
|
persist(persister.AccountsSettings);
|
||||||
persister.CommitTransation();
|
persister.CommitTransation();
|
||||||
|
|
||||||
_parent.RefreshImportMenu();
|
|
||||||
this.DialogResult = DialogResult.OK;
|
this.DialogResult = DialogResult.OK;
|
||||||
this.Close();
|
this.Close();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,7 +31,6 @@ namespace LibationWinForms
|
|||||||
|
|
||||||
// independent UI updates
|
// independent UI updates
|
||||||
this.Load += (_, _) => this.RestoreSizeAndLocation(Configuration.Instance);
|
this.Load += (_, _) => this.RestoreSizeAndLocation(Configuration.Instance);
|
||||||
this.Load += RefreshImportMenu;
|
|
||||||
this.FormClosing += (_, _) => this.SaveSizeAndLocation(Configuration.Instance);
|
this.FormClosing += (_, _) => this.SaveSizeAndLocation(Configuration.Instance);
|
||||||
LibraryCommands.LibrarySizeChanged += reloadGridAndUpdateBottomNumbers;
|
LibraryCommands.LibrarySizeChanged += reloadGridAndUpdateBottomNumbers;
|
||||||
LibraryCommands.BookUserDefinedItemCommitted += setBackupCounts;
|
LibraryCommands.BookUserDefinedItemCommitted += setBackupCounts;
|
||||||
@ -39,13 +38,53 @@ namespace LibationWinForms
|
|||||||
LibraryCommands.ScanBegin += LibraryCommands_ScanBegin;
|
LibraryCommands.ScanBegin += LibraryCommands_ScanBegin;
|
||||||
LibraryCommands.ScanEnd += LibraryCommands_ScanEnd;
|
LibraryCommands.ScanEnd += LibraryCommands_ScanEnd;
|
||||||
|
|
||||||
|
// accounts updated
|
||||||
|
this.Load += refreshImportMenu;
|
||||||
|
AccountsSettingsPersister.Saved += refreshImportMenu;
|
||||||
|
|
||||||
|
// start autoscanner
|
||||||
|
this.Load += startAutoScan;
|
||||||
|
AccountsSettingsPersister.Saving += accountsPreSave;
|
||||||
|
AccountsSettingsPersister.Saved += accountsPostSave;
|
||||||
|
Configuration.Instance.AutoScanChanged += startAutoScan;
|
||||||
|
|
||||||
|
// init default/placeholder cover art
|
||||||
var format = System.Drawing.Imaging.ImageFormat.Jpeg;
|
var format = System.Drawing.Imaging.ImageFormat.Jpeg;
|
||||||
PictureStorage.SetDefaultImage(PictureSize._80x80, Properties.Resources.default_cover_80x80.ToBytes(format));
|
PictureStorage.SetDefaultImage(PictureSize._80x80, Properties.Resources.default_cover_80x80.ToBytes(format));
|
||||||
PictureStorage.SetDefaultImage(PictureSize._300x300, Properties.Resources.default_cover_300x300.ToBytes(format));
|
PictureStorage.SetDefaultImage(PictureSize._300x300, Properties.Resources.default_cover_300x300.ToBytes(format));
|
||||||
PictureStorage.SetDefaultImage(PictureSize._500x500, Properties.Resources.default_cover_500x500.ToBytes(format));
|
PictureStorage.SetDefaultImage(PictureSize._500x500, Properties.Resources.default_cover_500x500.ToBytes(format));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Form1_Load(object sender, EventArgs e)
|
private List<(string AccountId, string LocaleName)> preSaveDefaultAccounts;
|
||||||
|
private List<(string AccountId, string LocaleName)> getDefaultAccounts()
|
||||||
|
{
|
||||||
|
using var persister = AudibleApiStorage.GetAccountsSettingsPersister();
|
||||||
|
return persister.AccountsSettings
|
||||||
|
.GetAll()
|
||||||
|
.Where(a => a.LibraryScan)
|
||||||
|
.Select(a => (a.AccountId, a.Locale.Name))
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
private void accountsPreSave(object sender = null, EventArgs e = null)
|
||||||
|
=> preSaveDefaultAccounts = getDefaultAccounts();
|
||||||
|
private void accountsPostSave(object sender = null, EventArgs e = null)
|
||||||
|
{
|
||||||
|
var postSaveDefaultAccounts = getDefaultAccounts();
|
||||||
|
var newDefaultAccounts = postSaveDefaultAccounts.Except(preSaveDefaultAccounts).ToList();
|
||||||
|
|
||||||
|
if (newDefaultAccounts.Any())
|
||||||
|
startAutoScan();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startAutoScan(object sender = null, EventArgs e = null)
|
||||||
|
{
|
||||||
|
if (Configuration.Instance.AutoScan)
|
||||||
|
Console.WriteLine("autoScanner.StartScan();");
|
||||||
|
else
|
||||||
|
Console.WriteLine("autoScanner.StopScan();");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Form1_Load(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (this.DesignMode)
|
if (this.DesignMode)
|
||||||
return;
|
return;
|
||||||
@ -237,7 +276,7 @@ namespace LibationWinForms
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Import menu
|
#region Import menu
|
||||||
public void RefreshImportMenu(object _ = null, EventArgs __ = null)
|
private void refreshImportMenu(object _ = null, EventArgs __ = null)
|
||||||
{
|
{
|
||||||
using var persister = AudibleApiStorage.GetAccountsSettingsPersister();
|
using var persister = AudibleApiStorage.GetAccountsSettingsPersister();
|
||||||
var count = persister.AccountsSettings.Accounts.Count;
|
var count = persister.AccountsSettings.Accounts.Count;
|
||||||
@ -489,6 +528,6 @@ namespace LibationWinForms
|
|||||||
|
|
||||||
this.scanningToolStripMenuItem.Visible = false;
|
this.scanningToolStripMenuItem.Visible = false;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,7 +28,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Dinah.Core.WindowsDesktop" Version="4.1.6.1" />
|
<PackageReference Include="Dinah.Core.WindowsDesktop" Version="4.1.8.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user