diff --git a/Directory.Build.targets b/Directory.Build.targets index 5bedf7d1..2be9e4c8 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -1,8 +1,13 @@ $(DefineConstants) + true + 13.0 $(DefineConstants);DEBUG;TRACE + + + \ No newline at end of file diff --git a/Diz.Core.Interfaces/Diz.Core.Interfaces.csproj b/Diz.Core.Interfaces/Diz.Core.Interfaces.csproj index 6f30dda0..ec54a93b 100644 --- a/Diz.Core.Interfaces/Diz.Core.Interfaces.csproj +++ b/Diz.Core.Interfaces/Diz.Core.Interfaces.csproj @@ -1,7 +1,7 @@ - net9.0 + netstandard2.0;net9.0 enable enable true diff --git a/Diz.Core/Diz.Core.csproj b/Diz.Core/Diz.Core.csproj index f8439c49..fc5039dc 100644 --- a/Diz.Core/Diz.Core.csproj +++ b/Diz.Core/Diz.Core.csproj @@ -1,7 +1,7 @@  - net9.0 + netstandard2.0;net9.0 false true Diz.Core @@ -16,16 +16,18 @@ 2023.3.0 - + 6.6.4 1.4.2 + 4.3.0 + 11.9.0 diff --git a/Diz.Core/Polyfills.cs b/Diz.Core/Polyfills.cs new file mode 100644 index 00000000..3172bc00 --- /dev/null +++ b/Diz.Core/Polyfills.cs @@ -0,0 +1,41 @@ +#nullable enable + +namespace Diz.Core +{ + internal static class CollectionExtensions + { +#if !(NETSTANDARD2_1_OR_GREATER || NETCOREAPP2_0_OR_GREATER) + public static bool TryAdd( + this System.Collections.Generic.IDictionary dictionary, + TKey key, + TValue value) + { + if (dictionary is null) throw new System.ArgumentNullException(paramName: nameof(dictionary)); + if (dictionary.ContainsKey(key)) return false; + dictionary.Add(key, value); + return true; + } +#endif + } + + internal static class PathPolyfill + { + public static bool IsPathFullyQualified(string path) +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP2_1_OR_GREATER + => System.IO.Path.IsPathFullyQualified(path); +#else // copied from https://github.com/TASEmulators/BizHawk/commit/d9069ea2cc6d36fef16cd533389fd66482aae471 + { + if (/*OSTailoredCode.IsUnixHost*/!System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows)) + { + return /*path.StartsWith(Path.DirectorySeparatorChar)*/path is [ '/', .. ]; + } + /* Windows: + var root = System.IO.Path.GetPathRoot(path); + return root.StartsWith($"{Path.DirectorySeparatorChar}{Path.DirectorySeparatorChar}") + || (root.Length >= 2 && root.EndsWith(Path.DirectorySeparatorChar)); + */ + return System.IO.Path.GetPathRoot(path) is [ '\\', '\\', .. ] or [ .., _, '\\' ]; + } +#endif + } +} \ No newline at end of file diff --git a/Diz.Core/export/LogWriterSettings.cs b/Diz.Core/export/LogWriterSettings.cs index b0429d27..257bc794 100644 --- a/Diz.Core/export/LogWriterSettings.cs +++ b/Diz.Core/export/LogWriterSettings.cs @@ -91,7 +91,7 @@ public string BuildFullOutputPath() path += "\\"; // force it to treat it as a path. // if it's absolute path, use that first, ignore base path - if (Path.IsPathFullyQualified(path)) + if (PathPolyfill.IsPathFullyQualified(path)) return path; // if it's not an absolute path, combine BaseOutputPath and FileOrFolderPath to get the final diff --git a/Diz.Core/model/Annotation.cs b/Diz.Core/model/Annotation.cs index b6e6da94..adcce82d 100644 --- a/Diz.Core/model/Annotation.cs +++ b/Diz.Core/model/Annotation.cs @@ -285,9 +285,9 @@ public string NameOverride set { nameOverride = value; OnPropertyChanged(); } } - public event PropertyChangedEventHandler? PropertyChanged; + public event PropertyChangedEventHandler/*?*/ PropertyChanged; - protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null) + protected virtual void OnPropertyChanged([CallerMemberName] string/*?*/ propertyName = null) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } diff --git a/Diz.Core/model/snes/Data.cs b/Diz.Core/model/snes/Data.cs index 35adb892..74af46ea 100644 --- a/Diz.Core/model/snes/Data.cs +++ b/Diz.Core/model/snes/Data.cs @@ -56,7 +56,7 @@ public SortedDictionary Comments // deserializer that handles this instead public Dictionary LabelsSerialization { - get => new(Labels.Labels); + get => Labels.Labels.ToDictionary(); set => Labels.SetAll(value); } diff --git a/Diz.Core/serialization/ProjectFileManager.cs b/Diz.Core/serialization/ProjectFileManager.cs index c7f728ea..93042581 100644 --- a/Diz.Core/serialization/ProjectFileManager.cs +++ b/Diz.Core/serialization/ProjectFileManager.cs @@ -153,7 +153,7 @@ private void OnPostProjectDeserialized(string filename, ProjectXmlSerializer.Roo var romAddCmd = addRomDataCommandCreate(); Debug.Assert(romAddCmd != null); - romAddCmd.Root = xmlProjectSerializedRoot; + romAddCmd!.Root = xmlProjectSerializedRoot; romAddCmd.GetNextRomFileToTry = RomPromptFn; romAddCmd.MigrationRunner = serializer.MigrationRunner; diff --git a/Diz.Core/serialization/xml_serializer/PostSerializeMigrations.cs b/Diz.Core/serialization/xml_serializer/PostSerializeMigrations.cs index 990467e2..7b927000 100644 --- a/Diz.Core/serialization/xml_serializer/PostSerializeMigrations.cs +++ b/Diz.Core/serialization/xml_serializer/PostSerializeMigrations.cs @@ -7,8 +7,8 @@ public interface IMigrationEvents // add migrations to hook in various places in the code as needed. // example: something to pre-process incoming XML text, or modify the XML deserializer before it's used - void OnLoadingBeforeAddLinkedRom(IAddRomDataCommand romAddCmd) { } - void OnLoadingAfterAddLinkedRom(IAddRomDataCommand romAddCmd) { } + void OnLoadingBeforeAddLinkedRom(IAddRomDataCommand romAddCmd); + void OnLoadingAfterAddLinkedRom(IAddRomDataCommand romAddCmd); } public interface IMigration : IMigrationEvents diff --git a/Diz.Core/util/LabelSearchTerms.cs b/Diz.Core/util/LabelSearchTerms.cs index f881191d..f75e47d9 100644 --- a/Diz.Core/util/LabelSearchTerms.cs +++ b/Diz.Core/util/LabelSearchTerms.cs @@ -66,7 +66,7 @@ private bool TryParseSpecialTerm(string term) return false; } - private AddressComparison? TryParseAddressComparison(string term) + private AddressComparison/*?*/ TryParseAddressComparison(string term) { if (term.Length < 2) return null; diff --git a/Diz.Core/util/Util.cs b/Diz.Core/util/Util.cs index 51690b49..13e2f86f 100644 --- a/Diz.Core/util/Util.cs +++ b/Diz.Core/util/Util.cs @@ -41,7 +41,7 @@ public static string GetRelativePath(string fileSpec, string? folder) { var pathUri = new Uri(fileSpec); // Folders must end in a slash - if (!string.IsNullOrEmpty(folder) && !folder.EndsWith(Path.DirectorySeparatorChar.ToString())) + if (!string.IsNullOrEmpty(folder) && !folder!.EndsWith(Path.DirectorySeparatorChar.ToString())) { folder += Path.DirectorySeparatorChar; } @@ -450,7 +450,7 @@ public static class NotifyPropertyChangedExtensions /// Set a field, and if changed, dispatch any events associated with it /// /// true if we set property to a new value and dispatched events - public static bool SetField(this INotifyPropertyChanged sender, [CanBeNull] PropertyChangedEventHandler handler, ref T field, T value, bool compareRefOnly = false, [CallerMemberName] string propertyName = null) + public static bool SetField(this INotifyPropertyChanged sender, [CanBeNull] PropertyChangedEventHandler? handler, ref T field, T value, bool compareRefOnly = false, [CallerMemberName] string propertyName = null!) { if (FieldIsEqual(field, value, compareRefOnly)) return false; @@ -465,7 +465,7 @@ public static bool SetField(this INotifyPropertyChanged sender, [CanBeNull] P /// Set a field, and if changed, dispatch any events associated with it /// /// true if we set property to a new value and dispatched events - public static bool SetField(this INotifyPropertyChangedExt sender, ref T field, T value, bool compareRefOnly = false, [CallerMemberName] string propertyName = null) + public static bool SetField(this INotifyPropertyChangedExt sender, ref T field, T value, bool compareRefOnly = false, [CallerMemberName] string propertyName = null!) { if (FieldIsEqual(field, value, compareRefOnly)) return false; diff --git a/Diz.Cpu.65816/Diz.Cpu.65816.csproj b/Diz.Cpu.65816/Diz.Cpu.65816.csproj index 408ff4ac..2258bf3a 100644 --- a/Diz.Cpu.65816/Diz.Cpu.65816.csproj +++ b/Diz.Cpu.65816/Diz.Cpu.65816.csproj @@ -1,7 +1,7 @@ - net9.0 + netstandard2.0;net9.0 true Diz.Cpu._65816 enable diff --git a/Diz.Cpu.65816/src/CPU65C816.cs b/Diz.Cpu.65816/src/CPU65C816.cs index 61a049f0..cd303bbe 100644 --- a/Diz.Cpu.65816/src/CPU65C816.cs +++ b/Diz.Cpu.65816/src/CPU65C816.cs @@ -309,7 +309,7 @@ public override CpuInstructionDataFormatted GetInstructionData(TByteSource data, } else if (specialDirective.ConstantFormatOverride == CpuUtils.OperandOverride.FormatOverride.AsDecimal && operandValue1!=null) { - operandFinalStr1 = operandValue1.ToString(); + operandFinalStr1 = operandValue1.ToString()!; } } } @@ -727,7 +727,7 @@ private static string GenerateDisplacementString(int amountToDisplace) // some special cases related to +/- local labels: // is this a local label? like "+". "-", "++", "--", etc? - if (!RomUtil.IsValidPlusMinusLabel(candidateLabel.Name)) + if (!RomUtil.IsValidPlusMinusLabel(candidateLabel!.Name)) return candidateLabel; // not local label, so we're good // this IS a local +/- label, so let's do some additional validation.. diff --git a/Diz.Cpu.65816/src/CpuUtils.cs b/Diz.Cpu.65816/src/CpuUtils.cs index c18824b6..2408a563 100644 --- a/Diz.Cpu.65816/src/CpuUtils.cs +++ b/Diz.Cpu.65816/src/CpuUtils.cs @@ -40,7 +40,7 @@ public enum FormatOverride { // TODO: allow multiple directives in a line separated by delimiter - if (string.IsNullOrEmpty(inputText) || !inputText.StartsWith("!!")) + if (string.IsNullOrEmpty(inputText) || !inputText!.StartsWith("!!")) return null; // filter anything after a semicolon, which we'll treat like a comment and ignore. trim leftover whitespace diff --git a/Diz.Cpu.65816/src/SampleRomData.cs b/Diz.Cpu.65816/src/SampleRomData.cs index 6f34311f..13cf5e15 100644 --- a/Diz.Cpu.65816/src/SampleRomData.cs +++ b/Diz.Cpu.65816/src/SampleRomData.cs @@ -278,10 +278,10 @@ private static void PostProcess(Data data) // inject the game name into the bytes // This is a UTF8 string that needs to be converted to ShiftJIS (Ascii w/some japanese chars) encoding. - snesApi.SetCartridgeTitle(GetSampleUtf8CartridgeTitle()); + snesApi!.SetCartridgeTitle(GetSampleUtf8CartridgeTitle()); // initialize some SNES header stuff (this is not complete, feel free to add things that are useful) - Debug.Assert(snesApi.RomMapMode == RomMapMode.LoRom); + Debug.Assert(snesApi!.RomMapMode == RomMapMode.LoRom); Debug.Assert(snesApi.RomSpeed == RomSpeed.FastRom); var romSettingsOffset = RomUtil.GetRomSettingOffset(RomMapMode.LoRom); const int loromAndFastRom = 0x30; diff --git a/Diz.Cpu.65816/src/SnesData.cs b/Diz.Cpu.65816/src/SnesData.cs index ad6615f9..76b556bc 100644 --- a/Diz.Cpu.65816/src/SnesData.cs +++ b/Diz.Cpu.65816/src/SnesData.cs @@ -627,10 +627,10 @@ public IProject Create() var project = createNewProject.Create() as Project; // TODO: don't cast, refactor to use IProject instead Debug.Assert(project?.Data != null); - var snesData = project.Data.GetSnesApi(); + var snesData = project!.Data.GetSnesApi(); Debug.Assert(snesData != null); - snesData.CacheVerificationInfoFor(project); + snesData!.CacheVerificationInfoFor(project); return project; } diff --git a/Diz.Cpu.65816/src/import/ImportUtils.cs b/Diz.Cpu.65816/src/import/ImportUtils.cs index 1a2c2861..c73573c3 100644 --- a/Diz.Cpu.65816/src/import/ImportUtils.cs +++ b/Diz.Cpu.65816/src/import/ImportUtils.cs @@ -25,7 +25,7 @@ public Project Read() Debug.Assert(project?.Data != null); - project.AttachedRomFilename = importSettings.RomFilename; + project!.AttachedRomFilename = importSettings.RomFilename; project.Session = new ProjectSession(project, "") { UnsavedChanges = true @@ -39,7 +39,7 @@ public Project Read() project.Data.PopulateFrom(importSettings.RomBytes, importSettings.RomMapMode, importSettings.RomSpeed); #else // old way - snesApi.RomMapMode = importSettings.RomMapMode; + snesApi!.RomMapMode = importSettings.RomMapMode; snesApi.RomSpeed = importSettings.RomSpeed; project.Data.RomBytes.CreateRomBytesFromRom(importSettings.RomBytes); #endif diff --git a/Diz.Cpu.65816/src/import/MigrationNoOp.cs b/Diz.Cpu.65816/src/import/MigrationNoOp.cs index 99341fe7..63828a13 100644 --- a/Diz.Cpu.65816/src/import/MigrationNoOp.cs +++ b/Diz.Cpu.65816/src/import/MigrationNoOp.cs @@ -1,4 +1,5 @@ -using Diz.Core.serialization.xml_serializer; +using Diz.Core.serialization; +using Diz.Core.serialization.xml_serializer; using JetBrains.Annotations; namespace Diz.Cpu._65816.import; @@ -13,4 +14,8 @@ public sealed class MigrationNoOp : IMigration { // you MUST set this when instantiating though public int AppliesToSaveVersion { get; init; } = -1; + + public void OnLoadingBeforeAddLinkedRom(IAddRomDataCommand romAddCmd) {} + + public void OnLoadingAfterAddLinkedRom(IAddRomDataCommand romAddCmd) {} } \ No newline at end of file diff --git a/Diz.Import/src/bsnes/tracelog/BSNESImportStreamProcessor.cs b/Diz.Import/src/bsnes/tracelog/BSNESImportStreamProcessor.cs index 673fb2f6..2511d0ae 100644 --- a/Diz.Import/src/bsnes/tracelog/BSNESImportStreamProcessor.cs +++ b/Diz.Import/src/bsnes/tracelog/BSNESImportStreamProcessor.cs @@ -135,6 +135,8 @@ public IEnumerable GetCompressedWorkItems(Stream? private WorkItemDecompressSnesTraces? ReadPacketFromStream(Stream? stream) { + if (stream is null) throw new ArgumentNullException(paramName: nameof(stream)); + #if PROFILING var mainSpan = Markers.EnterSpan("BSNES socket read"); #endif diff --git a/Diz.Ui.Eto/DizEtoAppSettingsProvider.cs b/Diz.Ui.Eto/DizEtoAppSettingsProvider.cs index e161839c..8dd1d90e 100644 --- a/Diz.Ui.Eto/DizEtoAppSettingsProvider.cs +++ b/Diz.Ui.Eto/DizEtoAppSettingsProvider.cs @@ -10,7 +10,7 @@ namespace Diz.Ui.Eto; public class DizEtoAppSettingsProvider : IDizAppSettings { public event PropertyChangedEventHandler? PropertyChanged; - public string LastProjectFilename { get; set; } + public string? LastProjectFilename { get; set; } public bool OpenLastFileAutomatically { get; set; } - public string LastOpenedFile { get; set; } + public string? LastOpenedFile { get; set; } } \ No newline at end of file diff --git a/Diz.Ui.Eto/ui/EtoMainGridForm.cs b/Diz.Ui.Eto/ui/EtoMainGridForm.cs index f8f0be5e..93b117dd 100644 --- a/Diz.Ui.Eto/ui/EtoMainGridForm.cs +++ b/Diz.Ui.Eto/ui/EtoMainGridForm.cs @@ -95,7 +95,7 @@ private void CreateMenu() }; } - private GridView gridView; + private GridView gridView = null!; private void CreateGui() { @@ -277,7 +277,7 @@ public void SelectOffsetWithOvershoot(int pcOffset, int overshootAmount = 0) public int SelectedOffset => -1; // temp, fixme. - public Project Project { get; set; } + public Project? Project { get; set; } public void OnProjectOpenFail(string errorMsg) { diff --git a/Diz.Ui.Eto/ui/EtoProgressForm.cs b/Diz.Ui.Eto/ui/EtoProgressForm.cs index 60224b85..56c9289f 100644 --- a/Diz.Ui.Eto/ui/EtoProgressForm.cs +++ b/Diz.Ui.Eto/ui/EtoProgressForm.cs @@ -7,7 +7,7 @@ namespace Diz.Ui.Eto.ui; public class EtoProgressForm : Dialog, IProgressView { public event EventHandler? OnFormClosed; - private Label mainText; + private Label mainText = null!; public EtoProgressForm() {