Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
<Project>
<PropertyGroup>
<DefineConstants>$(DefineConstants)</DefineConstants>
<EnableWindowsTargeting>true</EnableWindowsTargeting>
<LangVersion>13.0</LangVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DefineConstants>$(DefineConstants);DEBUG;TRACE</DefineConstants>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Meziantou.Polyfill" Version="1.0.52" PrivateAssets="all" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion Diz.Core.Interfaces/Diz.Core.Interfaces.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<TargetFrameworks>netstandard2.0;net9.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GenerateAssemblyInfo>true</GenerateAssemblyInfo>
Expand Down
6 changes: 4 additions & 2 deletions Diz.Core/Diz.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<TargetFrameworks>netstandard2.0;net9.0</TargetFrameworks>
<UseWindowsForms>false</UseWindowsForms>
<GenerateAssemblyInfo>true</GenerateAssemblyInfo>
<RootNamespace>Diz.Core</RootNamespace>
Expand All @@ -16,16 +16,18 @@
<PackageReference Include="JetBrains.Annotations">
<Version>2023.3.0</Version>
</PackageReference>
<PackageReference Include="JetBrains.Profiler.SelfApi" Version="2.5.0" />
<PackageReference Include="JetBrains.Profiler.SelfApi" Version="2.5.0" NoWarn="NU1701" />
<PackageReference Include="LightInject">
<Version>6.6.4</Version>
</PackageReference>
<PackageReference Include="SharpZipLib">
<Version>1.4.2</Version>
</PackageReference>
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
<PackageReference Include="System.Diagnostics.Tracing">
<Version>4.3.0</Version>
</PackageReference>
<PackageReference Include="System.Reflection.Emit" Version="4.7.0" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="8.0.0" />
<PackageReference Include="FluentValidation">
<Version>11.9.0</Version>
Expand Down
41 changes: 41 additions & 0 deletions Diz.Core/Polyfills.cs
Original file line number Diff line number Diff line change
@@ -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<TKey, TValue>(
this System.Collections.Generic.IDictionary<TKey, TValue> 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
}
}
2 changes: 1 addition & 1 deletion Diz.Core/export/LogWriterSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Diz.Core/model/Annotation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
2 changes: 1 addition & 1 deletion Diz.Core/model/snes/Data.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public SortedDictionary<int, string> Comments
// deserializer that handles this instead
public Dictionary<int, IAnnotationLabel> LabelsSerialization
{
get => new(Labels.Labels);
get => Labels.Labels.ToDictionary();
set => Labels.SetAll(value);
}

Expand Down
2 changes: 1 addition & 1 deletion Diz.Core/serialization/ProjectFileManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Diz.Core/util/LabelSearchTerms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions Diz.Core/util/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -450,7 +450,7 @@ public static class NotifyPropertyChangedExtensions
/// Set a field, and if changed, dispatch any events associated with it
/// </summary>
/// <returns>true if we set property to a new value and dispatched events</returns>
public static bool SetField<T>(this INotifyPropertyChanged sender, [CanBeNull] PropertyChangedEventHandler handler, ref T field, T value, bool compareRefOnly = false, [CallerMemberName] string propertyName = null)
public static bool SetField<T>(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;
Expand All @@ -465,7 +465,7 @@ public static bool SetField<T>(this INotifyPropertyChanged sender, [CanBeNull] P
/// Set a field, and if changed, dispatch any events associated with it
/// </summary>
/// <returns>true if we set property to a new value and dispatched events</returns>
public static bool SetField<T>(this INotifyPropertyChangedExt sender, ref T field, T value, bool compareRefOnly = false, [CallerMemberName] string propertyName = null)
public static bool SetField<T>(this INotifyPropertyChangedExt sender, ref T field, T value, bool compareRefOnly = false, [CallerMemberName] string propertyName = null!)
{
if (FieldIsEqual(field, value, compareRefOnly))
return false;
Expand Down
2 changes: 1 addition & 1 deletion Diz.Cpu.65816/Diz.Cpu.65816.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<TargetFrameworks>netstandard2.0;net9.0</TargetFrameworks>
<GenerateAssemblyInfo>true</GenerateAssemblyInfo>
<RootNamespace>Diz.Cpu._65816</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
Expand Down
4 changes: 2 additions & 2 deletions Diz.Cpu.65816/src/CPU65C816.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()!;
}
}
}
Expand Down Expand Up @@ -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..
Expand Down
2 changes: 1 addition & 1 deletion Diz.Cpu.65816/src/CpuUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Diz.Cpu.65816/src/SampleRomData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions Diz.Cpu.65816/src/SnesData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions Diz.Cpu.65816/src/import/ImportUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
7 changes: 6 additions & 1 deletion Diz.Cpu.65816/src/import/MigrationNoOp.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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) {}
}
2 changes: 2 additions & 0 deletions Diz.Import/src/bsnes/tracelog/BSNESImportStreamProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ public IEnumerable<WorkItemDecompressSnesTraces> 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
Expand Down
4 changes: 2 additions & 2 deletions Diz.Ui.Eto/DizEtoAppSettingsProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
4 changes: 2 additions & 2 deletions Diz.Ui.Eto/ui/EtoMainGridForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private void CreateMenu()
};
}

private GridView gridView;
private GridView gridView = null!;

private void CreateGui()
{
Expand Down Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion Diz.Ui.Eto/ui/EtoProgressForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
Loading