From 2765e3f9b379f0dc2a5732c1ca9ba23dbe2a7f15 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 13 Apr 2022 22:06:07 -0400 Subject: enable nullable annotations in bundled mods (#837) --- src/SMAPI.Mods.SaveBackup/ModEntry.cs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src/SMAPI.Mods.SaveBackup') diff --git a/src/SMAPI.Mods.SaveBackup/ModEntry.cs b/src/SMAPI.Mods.SaveBackup/ModEntry.cs index b2b41ca6..a79c092f 100644 --- a/src/SMAPI.Mods.SaveBackup/ModEntry.cs +++ b/src/SMAPI.Mods.SaveBackup/ModEntry.cs @@ -1,7 +1,6 @@ -#nullable disable - using System; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.IO; using System.IO.Compression; using System.Linq; @@ -82,7 +81,7 @@ namespace StardewModdingAPI.Mods.SaveBackup } // compress backup if possible - if (!this.TryCompress(fallbackDir.FullName, targetFile, out Exception compressError)) + if (!this.TryCompress(fallbackDir.FullName, targetFile, out Exception? compressError)) { this.Monitor.Log(Constants.TargetPlatform != GamePlatform.Android ? $"Backed up to {fallbackDir.FullName}." // expected to fail on Android @@ -142,7 +141,7 @@ namespace StardewModdingAPI.Mods.SaveBackup /// The destination file to create. /// The error which occurred trying to compress, if applicable. This is if compression isn't supported on this platform. /// Returns whether compression succeeded. - private bool TryCompress(string sourcePath, FileInfo destination, out Exception error) + private bool TryCompress(string sourcePath, FileInfo destination, [NotNullWhen(false)] out Exception? error) { try { @@ -210,7 +209,7 @@ namespace StardewModdingAPI.Mods.SaveBackup /// A filter which matches the files or directories to copy, or null to copy everything. /// Derived from the SMAPI installer code. /// Returns whether any files were copied. - private bool RecursiveCopy(FileSystemInfo source, DirectoryInfo targetFolder, Func filter, bool copyRoot = true) + private bool RecursiveCopy(FileSystemInfo source, DirectoryInfo targetFolder, Func? filter, bool copyRoot = true) { if (!source.Exists || filter?.Invoke(source) == false) return false; @@ -244,7 +243,7 @@ namespace StardewModdingAPI.Mods.SaveBackup private bool MatchSaveFolders(DirectoryInfo savesFolder, FileSystemInfo entry) { // only need to filter top-level entries - string parentPath = (entry as FileInfo)?.DirectoryName ?? (entry as DirectoryInfo)?.Parent?.FullName; + string? parentPath = (entry as FileInfo)?.DirectoryName ?? (entry as DirectoryInfo)?.Parent?.FullName; if (parentPath != savesFolder.FullName) return true; -- cgit