diff --git a/Source/LibationUiBase/GridView/GridContextMenu.cs b/Source/LibationUiBase/GridView/GridContextMenu.cs index 2be8ce03..fece7465 100644 --- a/Source/LibationUiBase/GridView/GridContextMenu.cs +++ b/Source/LibationUiBase/GridView/GridContextMenu.cs @@ -12,7 +12,7 @@ using System.Threading.Tasks; namespace LibationUiBase.GridView; -public delegate void LiberateClickedHandler(object sender, System.Collections.Generic.IList libraryBooks, Configuration config); +public delegate void LiberateClickedHandler(object? sender, System.Collections.Generic.IList libraryBooks, Configuration config); public class GridContextMenu { public string CopyCellText => $"{Accelerator}Copy Cell Contents"; diff --git a/Source/LibationWinForms/Form1.BackupCounts.cs b/Source/LibationWinForms/Form1.BackupCounts.cs index 8c8ee876..877e3214 100644 --- a/Source/LibationWinForms/Form1.BackupCounts.cs +++ b/Source/LibationWinForms/Form1.BackupCounts.cs @@ -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 libraryBooks) + private void setBackupCounts(object? _, List? 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; }); } } diff --git a/Source/LibationWinForms/Form1.Export.cs b/Source/LibationWinForms/Form1.Export.cs index 4451a7c6..7a1350d4 100644 --- a/Source/LibationWinForms/Form1.Export.cs +++ b/Source/LibationWinForms/Form1.Export.cs @@ -2,6 +2,7 @@ using System.Windows.Forms; using ApplicationServices; +#nullable enable namespace LibationWinForms { public partial class Form1 diff --git a/Source/LibationWinForms/Form1.Filter.cs b/Source/LibationWinForms/Form1.Filter.cs index a3186a2f..ca705225 100644 --- a/Source/LibationWinForms/Form1.Filter.cs +++ b/Source/LibationWinForms/Form1.Filter.cs @@ -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; diff --git a/Source/LibationWinForms/Form1.Liberate.cs b/Source/LibationWinForms/Form1.Liberate.cs index a7a8efeb..7f63d123 100644 --- a/Source/LibationWinForms/Form1.Liberate.cs +++ b/Source/LibationWinForms/Form1.Liberate.cs @@ -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); diff --git a/Source/LibationWinForms/Form1.ProcessQueue.cs b/Source/LibationWinForms/Form1.ProcessQueue.cs index 01625fd5..14c1569f 100644 --- a/Source/LibationWinForms/Form1.ProcessQueue.cs +++ b/Source/LibationWinForms/Form1.ProcessQueue.cs @@ -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) { diff --git a/Source/LibationWinForms/Form1.QuickFilters.cs b/Source/LibationWinForms/Form1.QuickFilters.cs index 68e78a25..ac415871 100644 --- a/Source/LibationWinForms/Form1.QuickFilters.cs +++ b/Source/LibationWinForms/Form1.QuickFilters.cs @@ -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) diff --git a/Source/LibationWinForms/Form1.RemoveBooks.cs b/Source/LibationWinForms/Form1.RemoveBooks.cs index 51b710fb..8de5f238 100644 --- a/Source/LibationWinForms/Form1.RemoveBooks.cs +++ b/Source/LibationWinForms/Form1.RemoveBooks.cs @@ -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 diff --git a/Source/LibationWinForms/Form1.ScanAuto.cs b/Source/LibationWinForms/Form1.ScanAuto.cs index cd283f99..21901e3f 100644 --- a/Source/LibationWinForms/Form1.ScanAuto.cs +++ b/Source/LibationWinForms/Form1.ScanAuto.cs @@ -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; } } diff --git a/Source/LibationWinForms/Form1.ScanManual.cs b/Source/LibationWinForms/Form1.ScanManual.cs index 48333ae0..7b0d49ec 100644 --- a/Source/LibationWinForms/Form1.ScanManual.cs +++ b/Source/LibationWinForms/Form1.ScanManual.cs @@ -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) diff --git a/Source/LibationWinForms/Form1.ScanNotification.cs b/Source/LibationWinForms/Form1.ScanNotification.cs index e7c82255..a19b4c06 100644 --- a/Source/LibationWinForms/Form1.ScanNotification.cs +++ b/Source/LibationWinForms/Form1.ScanNotification.cs @@ -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; diff --git a/Source/LibationWinForms/Form1.Settings.cs b/Source/LibationWinForms/Form1.Settings.cs index 235c0897..b1b79eef 100644 --- a/Source/LibationWinForms/Form1.Settings.cs +++ b/Source/LibationWinForms/Form1.Settings.cs @@ -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) { diff --git a/Source/LibationWinForms/Form1.Upgrade.cs b/Source/LibationWinForms/Form1.Upgrade.cs index ec43b38e..4a9a6db9 100644 --- a/Source/LibationWinForms/Form1.Upgrade.cs +++ b/Source/LibationWinForms/Form1.Upgrade.cs @@ -3,6 +3,7 @@ using LibationWinForms.Dialogs; using System.Threading.Tasks; using System.Windows.Forms; +#nullable enable namespace LibationWinForms { public partial class Form1 diff --git a/Source/LibationWinForms/Form1.VisibleBooks.cs b/Source/LibationWinForms/Form1.VisibleBooks.cs index 7c1f99ee..8c6ed5a9 100644 --- a/Source/LibationWinForms/Form1.VisibleBooks.cs +++ b/Source/LibationWinForms/Form1.VisibleBooks.cs @@ -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; diff --git a/Source/LibationWinForms/Form1._NonUI.cs b/Source/LibationWinForms/Form1._NonUI.cs index 783a18ce..72466898 100644 --- a/Source/LibationWinForms/Form1._NonUI.cs +++ b/Source/LibationWinForms/Form1._NonUI.cs @@ -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 { diff --git a/Source/LibationWinForms/GridView/ProductsDisplay.cs b/Source/LibationWinForms/GridView/ProductsDisplay.cs index 05e31ef7..d1970a30 100644 --- a/Source/LibationWinForms/GridView/ProductsDisplay.cs +++ b/Source/LibationWinForms/GridView/ProductsDisplay.cs @@ -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 { /// Number of visible rows has changed - public event EventHandler VisibleCountChanged; - public event EventHandler RemovableCountChanged; - public event LiberateClickedHandler LiberateClicked; - public event EventHandler LiberateSeriesClicked; - public event EventHandler ConvertToMp3Clicked; - public event EventHandler InitialLoaded; + public event EventHandler? VisibleCountChanged; + public event EventHandler? RemovableCountChanged; + public event LiberateClickedHandler? LiberateClicked; + public event EventHandler? LiberateSeriesClicked; + public event EventHandler? 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 libraryBooks = null) + public async Task DisplayAsync(List? 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); }