mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
[CP/M filesystem] Move definitions to json.
This commit is contained in:
@@ -71,7 +71,7 @@
|
||||
<EmbeddedResource Include="..\LICENSE.LGPL">
|
||||
<Link>LICENSE.LGPL</Link>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="CPM\cpmdefs.xml"/>
|
||||
<EmbeddedResource Include="CPM\cpmdefs.json" />
|
||||
<EmbeddedResource Update="Localization\Localization.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Localization.Designer.cs</LastGenOutput>
|
||||
|
||||
@@ -35,26 +35,23 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Xml;
|
||||
using System.Xml.Serialization;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Aaru.Filesystems;
|
||||
|
||||
public sealed partial class CPM
|
||||
{
|
||||
/// <summary>Loads all the known CP/M disk definitions from an XML stored as an embedded resource.</summary>
|
||||
/// <summary>Loads all the known CP/M disk definitions from an JSON stored as an embedded resource.</summary>
|
||||
/// <returns>The definitions.</returns>
|
||||
bool LoadDefinitions()
|
||||
{
|
||||
try
|
||||
{
|
||||
var defsReader =
|
||||
XmlReader.Create(Assembly.GetExecutingAssembly().
|
||||
GetManifestResourceStream("Aaru.Filesystems.CPM.cpmdefs.xml") ??
|
||||
new MemoryStream());
|
||||
|
||||
var defsSerializer = new XmlSerializer(typeof(CpmDefinitions));
|
||||
_definitions = (CpmDefinitions)defsSerializer.Deserialize(defsReader);
|
||||
_definitions =
|
||||
JsonSerializer.
|
||||
Deserialize(Assembly.GetExecutingAssembly().GetManifestResourceStream("Aaru.Filesystems.CPM.cpmdefs.json") ?? new MemoryStream(),
|
||||
typeof(CpmDefinitions), CpmDefinitionsContext.Default) as CpmDefinitions;
|
||||
|
||||
if(_definitions is null)
|
||||
return false;
|
||||
@@ -99,6 +96,11 @@ public sealed partial class CPM
|
||||
}
|
||||
}
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
|
||||
IncludeFields = true)]
|
||||
[JsonSerializable(typeof(CpmDefinitions))]
|
||||
public class CpmDefinitionsContext : JsonSerializerContext {}
|
||||
|
||||
/// <summary>CP/M disk definitions</summary>
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
public sealed class CpmDefinitions
|
||||
|
||||
21847
Aaru.Filesystems/CPM/cpmdefs.json
Normal file
21847
Aaru.Filesystems/CPM/cpmdefs.json
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user