Enable NTRs on main form and fix resulting warnings.

This commit is contained in:
Michael Bucari-Tovo
2026-01-27 12:41:28 -07:00
parent 807bb56c49
commit cb159336a6
16 changed files with 69 additions and 60 deletions

View File

@@ -12,7 +12,7 @@ using System.Threading.Tasks;
namespace LibationUiBase.GridView;
public delegate void LiberateClickedHandler(object sender, System.Collections.Generic.IList<LibraryBook> libraryBooks, Configuration config);
public delegate void LiberateClickedHandler(object? sender, System.Collections.Generic.IList<LibraryBook> libraryBooks, Configuration config);
public class GridContextMenu
{
public string CopyCellText => $"{Accelerator}Copy Cell Contents";

View File

@@ -4,6 +4,7 @@ using Dinah.Core;
using Dinah.Core.Threading;
using System.Collections.Generic;
#nullable enable
namespace LibationWinForms
{
public partial class Form1
@@ -30,7 +31,7 @@ namespace LibationWinForms
private bool runBackupCountsAgain;
private void setBackupCounts(object _, List<LibraryBook> libraryBooks)
private void setBackupCounts(object? _, List<LibraryBook>? libraryBooks)
{
runBackupCountsAgain = true;
@@ -38,7 +39,7 @@ namespace LibationWinForms
updateCountsBw.RunWorkerAsync(libraryBooks);
}
private void UpdateCountsBw_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
private void UpdateCountsBw_DoWork(object? sender, System.ComponentModel.DoWorkEventArgs e)
{
while (runBackupCountsAgain)
{
@@ -47,47 +48,47 @@ namespace LibationWinForms
}
}
private void exportMenuEnable(object _, System.ComponentModel.RunWorkerCompletedEventArgs e)
private void exportMenuEnable(object? _, System.ComponentModel.RunWorkerCompletedEventArgs e)
{
var libraryStats = e.Result as LibraryCommands.LibraryStats;
Invoke(() => exportLibraryToolStripMenuItem.Enabled = libraryStats.HasBookResults);
Invoke(() => exportLibraryToolStripMenuItem.Enabled = libraryStats?.HasBookResults is true);
}
private void updateBottomStats(object _, System.ComponentModel.RunWorkerCompletedEventArgs e)
private void updateBottomStats(object? _, System.ComponentModel.RunWorkerCompletedEventArgs e)
{
var libraryStats = e.Result as LibraryCommands.LibraryStats;
statusStrip1.UIThreadAsync(() => backupsCountsLbl.Text = libraryStats.StatusString);
statusStrip1.UIThreadAsync(() => backupsCountsLbl.Text = libraryStats?.StatusString ?? "ERROR GETTING STATUS");
}
// update 'begin book and pdf backups' menu item
private void update_BeginBookBackups_menuItem(object _, System.ComponentModel.RunWorkerCompletedEventArgs e)
private void update_BeginBookBackups_menuItem(object? _, System.ComponentModel.RunWorkerCompletedEventArgs e)
{
var libraryStats = e.Result as LibraryCommands.LibraryStats;
var menuItemText
= libraryStats.HasPendingBooks
= libraryStats?.HasPendingBooks is true
? $"{libraryStats.PendingBooks} remaining"
: "All books have been liberated";
menuStrip1.UIThreadAsync(() =>
{
beginBookBackupsToolStripMenuItem.Format(menuItemText);
beginBookBackupsToolStripMenuItem.Enabled = libraryStats.HasPendingBooks;
beginBookBackupsToolStripMenuItem.Enabled = libraryStats?.HasPendingBooks is true;
});
}
// update 'begin pdf only backups' menu item
private void udpate_BeginPdfOnlyBackups_menuItem(object _, System.ComponentModel.RunWorkerCompletedEventArgs e)
private void udpate_BeginPdfOnlyBackups_menuItem(object? _, System.ComponentModel.RunWorkerCompletedEventArgs e)
{
var libraryStats = e.Result as LibraryCommands.LibraryStats;
var menuItemText
= libraryStats.pdfsNotDownloaded > 0
= libraryStats?.pdfsNotDownloaded > 0
? $"{libraryStats.pdfsNotDownloaded} remaining"
: "All PDFs have been downloaded";
menuStrip1.UIThreadAsync(() =>
{
beginPdfBackupsToolStripMenuItem.Format(menuItemText);
beginPdfBackupsToolStripMenuItem.Enabled = libraryStats.pdfsNotDownloaded > 0;
beginPdfBackupsToolStripMenuItem.Enabled = libraryStats?.pdfsNotDownloaded > 0;
});
}
}

View File

@@ -2,6 +2,7 @@
using System.Windows.Forms;
using ApplicationServices;
#nullable enable
namespace LibationWinForms
{
public partial class Form1

View File

@@ -2,6 +2,7 @@
using System.Windows.Forms;
using LibationWinForms.Dialogs;
#nullable enable
namespace LibationWinForms
{
public partial class Form1
@@ -27,8 +28,8 @@ namespace LibationWinForms
private void filterBtn_Click(object sender, EventArgs e) => performFilter(this.filterSearchTb.Text);
private string lastGoodFilter = "";
private void performFilter(string filterString)
private string? lastGoodFilter = null;
private void performFilter(string? filterString)
{
this.filterSearchTb.Text = filterString;
@@ -55,12 +56,12 @@ namespace LibationWinForms
dialog.Show(this);
return dialog;
void Dialog_Closed(object sender, FormClosedEventArgs e)
void Dialog_Closed(object? sender, FormClosedEventArgs e)
{
dialog.TagDoubleClicked -= Dialog_TagDoubleClicked;
filterHelpBtn.Enabled = true;
}
void Dialog_TagDoubleClicked(object sender, string tag)
void Dialog_TagDoubleClicked(object? sender, string tag)
{
if (string.IsNullOrEmpty(tag)) return;

View File

@@ -6,6 +6,7 @@ using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
#nullable enable
namespace LibationWinForms
{
public partial class Form1
@@ -13,7 +14,7 @@ namespace LibationWinForms
private void Configure_Liberate() { }
//GetLibrary_Flat_NoTracking() may take a long time on a hugh library. so run in new thread
private async void beginBookBackupsToolStripMenuItem_Click(object _ = null, EventArgs __ = null)
private async void beginBookBackupsToolStripMenuItem_Click(object? _ = null, EventArgs? __ = null)
{
var library = await Task.Run(DbContexts.GetUnliberated_Flat_NoTracking);
BackupAllBooks(library);

View File

@@ -1,14 +1,13 @@
using DataLayer;
using Dinah.Core;
using LibationFileManager;
using LibationUiBase;
using LibationUiBase.Forms;
using LibationUiBase.GridView;
using LibationWinForms.ProcessQueue;
using System;
using System.Linq;
using System.Windows.Forms;
#nullable enable
namespace LibationWinForms
{
public partial class Form1
@@ -106,7 +105,7 @@ namespace LibationWinForms
SetQueueCollapseState(!splitContainer1.Panel2Collapsed);
}
private void ProcessBookQueue1_PopOut(object sender, EventArgs e)
private void ProcessBookQueue1_PopOut(object? sender, EventArgs e)
{
ProcessBookForm dockForm = new();
dockForm.WidthChange = splitContainer1.Panel2.Width + splitContainer1.SplitterWidth;
@@ -124,7 +123,7 @@ namespace LibationWinForms
filterSearchTb.Location = new System.Drawing.Point(filterSearchTb.Location.X + deltax, filterSearchTb.Location.Y);
}
private void DockForm_FormClosing(object sender, FormClosingEventArgs e)
private void DockForm_FormClosing(object? sender, FormClosingEventArgs e)
{
if (sender is ProcessBookForm dockForm)
{

View File

@@ -4,6 +4,7 @@ using System.Windows.Forms;
using LibationFileManager;
using LibationWinForms.Dialogs;
#nullable enable
namespace LibationWinForms
{
public partial class Form1
@@ -17,7 +18,7 @@ namespace LibationWinForms
}
private object quickFilterTag { get; } = new();
private void updateFiltersMenu(object _ = null, object __ = null)
private void updateFiltersMenu(object? _ = null, object? __ = null)
{
// remove old
var removeUs = quickFiltersToolStripMenuItem.DropDownItems
@@ -41,7 +42,7 @@ namespace LibationWinForms
}
}
private void updateFirstFilterIsDefaultToolStripMenuItem(object sender, EventArgs e)
private void updateFirstFilterIsDefaultToolStripMenuItem(object? sender, EventArgs e)
=> firstFilterIsDefaultToolStripMenuItem.Checked = QuickFilters.UseDefault;
private void firstFilterIsDefaultToolStripMenuItem_Click(object sender, EventArgs e)

View File

@@ -1,12 +1,10 @@
using AudibleUtilities;
using LibationWinForms.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
#nullable enable
namespace LibationWinForms
{
public partial class Form1

View File

@@ -7,6 +7,7 @@ using AudibleUtilities;
using Dinah.Core;
using LibationFileManager;
#nullable enable
namespace LibationWinForms
{
// This is for the auto-scanner. It is unrelated to manual scanning/import
@@ -58,7 +59,7 @@ namespace LibationWinForms
[PropertyChangeFilter(nameof(Configuration.AutoScan))]
private void Configuration_PropertyChanged(object sender, PropertyChangedEventArgsEx e)
private void Configuration_PropertyChanged(object? sender, PropertyChangedEventArgsEx e)
{
// when autoscan setting is changed, update menu checkbox and run autoscan
updateAutoScanLibraryToolStripMenuItem(sender, e);
@@ -75,9 +76,9 @@ namespace LibationWinForms
.Select(a => (a.AccountId, a.Locale.Name))
.ToList();
}
private void accountsPreSave(object sender = null, EventArgs e = null)
private void accountsPreSave(object? sender = null, EventArgs? e = null)
=> preSaveDefaultAccounts = getDefaultAccounts();
private void accountsPostSave(object sender = null, EventArgs e = null)
private void accountsPostSave(object? sender = null, EventArgs? e = null)
{
var postSaveDefaultAccounts = getDefaultAccounts();
var newDefaultAccounts = postSaveDefaultAccounts.Except(preSaveDefaultAccounts).ToList();
@@ -86,7 +87,7 @@ namespace LibationWinForms
startAutoScan();
}
private void startAutoScan(object sender = null, EventArgs e = null)
private void startAutoScan(object? sender = null, EventArgs? e = null)
{
if (Configuration.Instance.AutoScan)
autoScanTimer.PerformNow();
@@ -94,8 +95,8 @@ namespace LibationWinForms
autoScanTimer.Stop();
}
private void updateAutoScanLibraryToolStripMenuItem(object sender, EventArgs e) => autoScanLibraryToolStripMenuItem.Checked = Configuration.Instance.AutoScan;
private void updateAutoScanLibraryToolStripMenuItem(object? sender, EventArgs e) => autoScanLibraryToolStripMenuItem.Checked = Configuration.Instance.AutoScan;
private void autoScanLibraryToolStripMenuItem_Click(object sender, EventArgs e) => Configuration.Instance.AutoScan = !autoScanLibraryToolStripMenuItem.Checked;
private void autoScanLibraryToolStripMenuItem_Click(object? sender, EventArgs e) => Configuration.Instance.AutoScan = !autoScanLibraryToolStripMenuItem.Checked;
}
}

View File

@@ -8,6 +8,7 @@ using AudibleUtilities;
using LibationFileManager;
using LibationWinForms.Dialogs;
#nullable enable
namespace LibationWinForms
{
// this is for manual scan/import. Unrelated to auto-scan
@@ -20,7 +21,7 @@ namespace LibationWinForms
locateAudiobooksToolStripMenuItem.ToolTipText = Configuration.GetHelpText("LocateAudiobooks");
}
private void refreshImportMenu(object _, EventArgs __)
private void refreshImportMenu(object? _, EventArgs? __)
{
using var persister = AudibleApiStorage.GetAccountsSettingsPersister();
var count = persister.AccountsSettings.Accounts.Count;
@@ -46,8 +47,8 @@ namespace LibationWinForms
private async void scanLibraryToolStripMenuItem_Click(object sender, EventArgs e)
{
using var persister = AudibleApiStorage.GetAccountsSettingsPersister();
var firstAccount = persister.AccountsSettings.GetAll().FirstOrDefault();
await scanLibrariesAsync(firstAccount);
if (persister.AccountsSettings.GetAll().FirstOrDefault() is { } firstAccount)
await scanLibrariesAsync(firstAccount);
}
private async void scanLibraryOfAllAccountsToolStripMenuItem_Click(object sender, EventArgs e)

View File

@@ -1,6 +1,7 @@
using System;
using ApplicationServices;
#nullable enable
namespace LibationWinForms
{
// This is for the Scanning notification in the upper right. This shown for manual scanning and auto-scan
@@ -12,7 +13,7 @@ namespace LibationWinForms
LibraryCommands.ScanEnd += LibraryCommands_ScanEnd;
}
private void LibraryCommands_ScanBegin(object sender, int accountsLength)
private void LibraryCommands_ScanBegin(object? sender, int accountsLength)
{
removeLibraryBooksToolStripMenuItem.Enabled = false;
removeAllAccountsToolStripMenuItem.Enabled = false;
@@ -29,7 +30,7 @@ namespace LibationWinForms
: $"Scanning {accountsLength} accounts...";
}
private void LibraryCommands_ScanEnd(object sender, int newCount)
private void LibraryCommands_ScanEnd(object? sender, int newCount)
{
removeLibraryBooksToolStripMenuItem.Enabled = true;
removeAllAccountsToolStripMenuItem.Enabled = true;

View File

@@ -2,6 +2,7 @@
using System.Windows.Forms;
using LibationWinForms.Dialogs;
#nullable enable
namespace LibationWinForms
{
public partial class Form1
@@ -11,7 +12,7 @@ namespace LibationWinForms
Shown += FormShown_Settings;
}
private void FormShown_Settings(object sender, EventArgs e)
private void FormShown_Settings(object? sender, EventArgs e)
{
if (LibationFileManager.AudibleFileStorage.BooksDirectory is null)
{

View File

@@ -3,6 +3,7 @@ using LibationWinForms.Dialogs;
using System.Threading.Tasks;
using System.Windows.Forms;
#nullable enable
namespace LibationWinForms
{
public partial class Form1

View File

@@ -8,6 +8,7 @@ using Dinah.Core.Threading;
using LibationUiBase;
using LibationWinForms.Dialogs;
#nullable enable
namespace LibationWinForms
{
public partial class Form1
@@ -24,7 +25,7 @@ namespace LibationWinForms
LibraryCommands.BookUserDefinedItemCommitted += setLiberatedVisibleMenuItemAsync;
}
private async void setLiberatedVisibleMenuItemAsync(object _, object __)
private async void setLiberatedVisibleMenuItemAsync(object? _, object __)
=> await Task.Run(setLiberatedVisibleMenuItem);
private static DateTime lastVisibleCountUpdated;

View File

@@ -6,6 +6,7 @@ using FileManager;
using LibationFileManager;
using LibationUiBase;
#nullable enable
namespace LibationWinForms
{
public partial class Form1
@@ -26,7 +27,7 @@ namespace LibationWinForms
// wire-up event to automatically download after scan.
// winforms only. this should NOT be allowed in cli
updateCountsBw.RunWorkerCompleted += (object sender, System.ComponentModel.RunWorkerCompletedEventArgs e) =>
updateCountsBw.RunWorkerCompleted += (object? sender, System.ComponentModel.RunWorkerCompletedEventArgs e) =>
{
if (!Configuration.Instance.AutoDownloadEpisodes || e.Result is not LibraryCommands.LibraryStats libraryStats)
return;
@@ -36,14 +37,14 @@ namespace LibationWinForms
};
}
private static object LoadResourceImage(string resourceName)
private static object? LoadResourceImage(string resourceName)
{
if (Application.IsDarkModeEnabled)
resourceName += "_dark";
return Properties.Resources.ResourceManager.GetObject(resourceName);
}
private void AudibleApiStorage_LoadError(object sender, AccountSettingsLoadErrorEventArgs e)
private void AudibleApiStorage_LoadError(object? sender, AccountSettingsLoadErrorEventArgs e)
{
try
{

View File

@@ -14,18 +14,18 @@ using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
#nullable enable
namespace LibationWinForms.GridView
{
public partial class ProductsDisplay : UserControl
{
/// <summary>Number of visible rows has changed</summary>
public event EventHandler<int> VisibleCountChanged;
public event EventHandler<int> RemovableCountChanged;
public event LiberateClickedHandler LiberateClicked;
public event EventHandler<SeriesEntry> LiberateSeriesClicked;
public event EventHandler<LibraryBook[]> ConvertToMp3Clicked;
public event EventHandler InitialLoaded;
public event EventHandler<int>? VisibleCountChanged;
public event EventHandler<int>? RemovableCountChanged;
public event LiberateClickedHandler? LiberateClicked;
public event EventHandler<SeriesEntry>? LiberateSeriesClicked;
public event EventHandler<LibraryBook[]>? ConvertToMp3Clicked;
public event EventHandler? InitialLoaded;
private bool hasBeenDisplayed;
@@ -37,15 +37,15 @@ namespace LibationWinForms.GridView
#region Button controls
private ImageDisplay imageDisplay;
private ImageDisplay? imageDisplay;
private void productsGrid_CoverClicked(GridEntry liveGridEntry)
{
var picDef = new PictureDefinition(liveGridEntry.LibraryBook.Book.PictureLarge ?? liveGridEntry.LibraryBook.Book.PictureId, PictureSize.Native);
void PictureCached(object sender, PictureCachedEventArgs e)
void PictureCached(object? sender, PictureCachedEventArgs e)
{
if (e.Definition.PictureId == picDef.PictureId)
imageDisplay.SetCoverArt(e.Picture);
imageDisplay?.SetCoverArt(e.Picture);
PictureStorage.PictureCached -= PictureCached;
}
@@ -82,7 +82,7 @@ namespace LibationWinForms.GridView
BorderThickness = 2,
};
void CloseWindow(object o, EventArgs e)
void CloseWindow(object? o, EventArgs e)
{
displayWindow.Close();
}
@@ -92,7 +92,7 @@ namespace LibationWinForms.GridView
displayWindow.Show(this);
}
private BookDetailsDialog bookDetailsForm;
private BookDetailsDialog? bookDetailsForm;
private void productsGrid_DetailsClicked(LibraryBookEntry liveGridEntry)
{
if (bookDetailsForm is null || bookDetailsForm.IsDisposed || !bookDetailsForm.Visible)
@@ -106,7 +106,7 @@ namespace LibationWinForms.GridView
if (!bookDetailsForm.Visible)
bookDetailsForm.Show(this);
async void bookDetailsForm_FormClosed(object sender, FormClosedEventArgs e)
async void bookDetailsForm_FormClosed(object? sender, FormClosedEventArgs e)
{
bookDetailsForm.FormClosed -= bookDetailsForm_FormClosed;
bookDetailsForm.SaveSizeAndLocation(Configuration.Instance);
@@ -381,7 +381,7 @@ namespace LibationWinForms.GridView
foreach (var r in removable)
r.Remove = true;
productsGrid_RemovableCountChanged(this, null);
productsGrid_RemovableCountChanged(this, EventArgs.Empty);
}
catch (OperationCanceledException)
{
@@ -401,7 +401,7 @@ namespace LibationWinForms.GridView
#region UI display functions
public async Task DisplayAsync(List<LibraryBook> libraryBooks = null)
public async Task DisplayAsync(List<LibraryBook>? libraryBooks = null)
{
try
{
@@ -428,7 +428,7 @@ namespace LibationWinForms.GridView
#region Filter
public void Filter(string searchString)
public void Filter(string? searchString)
=> productsGrid.Filter(searchString);
#endregion
@@ -443,7 +443,7 @@ namespace LibationWinForms.GridView
private void productsGrid_LiberateClicked(LibraryBookEntry liveGridEntry)
{
if (liveGridEntry.LibraryBook.Book.UserDefinedItem.BookStatus is not LiberatedStatus.Error
&& !liveGridEntry.Liberate.IsUnavailable)
&& liveGridEntry.Liberate?.IsUnavailable is false)
LiberateClicked?.Invoke(this, [liveGridEntry.LibraryBook], Configuration.Instance);
}