diff --git a/Directory.Build.props b/Directory.Build.props
index 4e5f50ca..412fff75 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -3,47 +3,37 @@
$([MSBuild]::NormalizeDirectory('$(MSBuildThisFileDirectory)'))
- $([MSBuild]::NormalizeDirectory('$(ShimakazeSdk_RootFolder)', 'app'))
- $([MSBuild]::NormalizeDirectory('$(ShimakazeSdk_RootFolder)', 'lib'))
+ $([MSBuild]::NormalizeDirectory('$(ShimakazeSdk_RootFolder)', 'src'))
$([MSBuild]::NormalizeDirectory('$(ShimakazeSdk_RootFolder)', 'test'))
- Application
- Library
- UnitTest
+ False
+ False
- 0.0.1-preview.12-patch.1
+ True
+ True
-
-
- net8.0
+
+
+ netstandard2.0;netstandard2.1;net6.0;net8.0
+ latest
enable
enable
True
- False
+ True
True
snupkg
True
True
true
-
-
-
-
- all
- runtime; build; native; contentfiles; analyzers
-
-
+ $(MSBuildProjectName.Replace('.Abstractions', ''))
-
-
-
+ True
+ latest-recommended
-
- $(MSBuildProjectDirectory)\Assets\logo.png
- $(ShimakazeSdk_RootFolder)assets\logo.png
- $(MSBuildProjectDirectory)\ReadMe.md
- $(ShimakazeSdk_RootFolder)ReadMe.md
+
+ 1701;1702;8601;8604;8767
+ annotations
Shimakaze Project
Copyright © 2020 - $([System.DateTime]::Now.ToString("yyyy")) $(Authors)
@@ -55,67 +45,65 @@
MIT
True
$(ShimakazeSdk_RootFolder)nupkg
+
+ $(MSBuildProjectDirectory)\Assets\logo.png
+ $(ShimakazeSdk_RootFolder)assets\logo.png
+ $(MSBuildProjectDirectory)\ReadMe.md
+ $(ShimakazeSdk_RootFolder)ReadMe.md
-
-
-
+
+
+
-
-
- Exe
- true
-
+
+
+ all
+ runtime; build; native; contentfiles; analyzers
+
+
-
-
+
+
+
-
-
- $(MSBuildProjectName.Replace('.Tests', ''))
+
+
+ net8.0
+ false
+ true
+
False
False
- False
False
True
lcov
Obsolete,GeneratedCodeAttribute,ExcludeFromCodeCoverageAttribute
-
-
-
-
-
- all
- runtime; build; native; contentfiles; analyzers
-
-
+
+
+
+
+
+
all
runtime; build; native; contentfiles; analyzers
-
+
-
-
+
+
-
+
-
+
diff --git a/Directory.Build.targets b/Directory.Build.targets
index dc803871..f347dfba 100644
--- a/Directory.Build.targets
+++ b/Directory.Build.targets
@@ -1,10 +1,11 @@
-
-
-
+
@@ -23,15 +24,22 @@
-
+
+
+
+
+
-
-
-
-
-
-
-
diff --git a/app/Shimakaze.Sdk.Vpl.Editor/Shimakaze.Sdk.Vpl.Editor.csproj b/app/Shimakaze.Sdk.Vpl.Editor/Shimakaze.Sdk.Vpl.Editor.csproj
deleted file mode 100644
index 31f5ae1a..00000000
--- a/app/Shimakaze.Sdk.Vpl.Editor/Shimakaze.Sdk.Vpl.Editor.csproj
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
-
-
-
diff --git a/lib/ReadMe.md b/lib/ReadMe.md
deleted file mode 100644
index 4533aa79..00000000
--- a/lib/ReadMe.md
+++ /dev/null
@@ -1,4 +0,0 @@
-# Sources Code
-
-这里包含项目的源代码。
-The source code of the project is included here.
diff --git a/lib/Shimakaze.Sdk.Build/Sdk/tasks.props b/lib/Shimakaze.Sdk.Build/Sdk/tasks.props
deleted file mode 100644
index 8cd85284..00000000
--- a/lib/Shimakaze.Sdk.Build/Sdk/tasks.props
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/lib/Shimakaze.Sdk.Build/Shimakaze.Sdk.Build.csproj b/lib/Shimakaze.Sdk.Build/Shimakaze.Sdk.Build.csproj
deleted file mode 100644
index 719b6a7d..00000000
--- a/lib/Shimakaze.Sdk.Build/Shimakaze.Sdk.Build.csproj
+++ /dev/null
@@ -1,39 +0,0 @@
-
-
-
- Shimakaze.Sdk.RA2
- Build your RA2 Module Project by MSBuild
- MSBuild MSBuildSdk RA2Mod ShimakazeProject
- MSBuildSdk
- $(NoWarn);NU5128;
- True
- PackAllDependencies
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/lib/Shimakaze.Sdk.JsonRPC.Server/JsonRPCHostedService.cs b/lib/Shimakaze.Sdk.JsonRPC.Server/JsonRPCHostedService.cs
deleted file mode 100644
index e092a660..00000000
--- a/lib/Shimakaze.Sdk.JsonRPC.Server/JsonRPCHostedService.cs
+++ /dev/null
@@ -1,53 +0,0 @@
-using System.Collections.Immutable;
-
-using Microsoft.Extensions.Hosting;
-using Microsoft.Extensions.Logging;
-
-using StreamJsonRpc;
-
-namespace Shimakaze.Sdk.JsonRPC.Server;
-
-///
-/// JsonRPCHostedService
-///
-public sealed class JsonRPCHostedService : IHostedService
-{
- private readonly JsonRpc _jsonRpc;
- private readonly ImmutableArray _methods;
- private readonly IServiceProvider _provider;
- private readonly ILogger? _logger;
-
- ///
- ///
- ///
- ///
- ///
- ///
- public JsonRPCHostedService(JsonRPCHostedServiceOptions options, IServiceProvider serviceProvider, ILogger? logger = null)
- {
- _jsonRpc = options.JsonRpc;
- _methods = options.Targets;
- _provider = serviceProvider;
- _logger = logger;
- }
-
- ///
- public Task StartAsync(CancellationToken cancellationToken)
- {
- foreach (var method in _methods)
- {
- var isEvent = method.Method.ReturnType == typeof(void);
- _logger?.LogDebug("Find {type}: {path}", isEvent ? "Event" : "Method", method.Route);
- _jsonRpc.AddLocalRpcMethod(method.Route, method.Method, _provider.GetService(method.Type));
- }
-
- return Task.Run(_jsonRpc.StartListening, cancellationToken);
- }
-
- ///
- public Task StopAsync(CancellationToken cancellationToken)
- {
- _logger?.LogInformation("See you next time!");
- return Task.CompletedTask;
- }
-}
diff --git a/lib/Shimakaze.Sdk.Preprocessor/Commands/ConditionCommand.cs b/lib/Shimakaze.Sdk.Preprocessor/Commands/ConditionCommand.cs
deleted file mode 100644
index fccc0e7c..00000000
--- a/lib/Shimakaze.Sdk.Preprocessor/Commands/ConditionCommand.cs
+++ /dev/null
@@ -1,159 +0,0 @@
-using Microsoft.Extensions.Logging;
-
-using Shimakaze.Sdk.Preprocessor.Kernel;
-
-namespace Shimakaze.Sdk.Preprocessor.Commands;
-
-///
-/// Condition Commands if elif else endif
-///
-public sealed class ConditionalCommand
-{
- private readonly Engine _engine;
- private readonly Logger? _logger;
-
- ///
- ///
- ///
- ///
- ///
- public ConditionalCommand(Engine engine, Logger? logger = null)
- {
- _engine = engine;
- _logger = logger;
- }
-
- ///
- /// #if condition
- ///
- ///
- [Command]
- public void If([Param(@".*")] string condition)
- {
- if (string.IsNullOrWhiteSpace(condition))
- throw new ArgumentNullException(nameof(condition));
-
- var conditionStack = _engine.GetOrNew("ConditionStack", () => new Stack());
- var conditionParser = _engine.GetOrNew("ConditionParser", () => new ConditionParser(_engine));
-
- _engine.CanWritable = conditionParser.Parse(condition);
- _logger?.LogDebug("If Condition: \"{condition}\" and computed value is: \"{value}\" ", condition, _engine.CanWritable);
-
- conditionStack.Push(new ConditionStatus(_engine.CanWritable, condition, "if"));
- _logger?.LogDebug("Push Stack: If");
- }
-
- ///
- /// #elif condition
- ///
- ///
- [Command]
- public void Elif([Param(@".*")] string condition)
- {
- if (string.IsNullOrWhiteSpace(condition))
- throw new ArgumentNullException(nameof(condition));
-
- var conditionStack = _engine.GetOrNew("ConditionStack", () => new Stack());
- var conditionParser = _engine.GetOrNew("ConditionParser", () => new ConditionParser(_engine));
-
- var lastStatus = conditionStack.Pop();
- _logger?.LogDebug("Pop Stack: {tag}", lastStatus.Tag);
-
- _engine.CanWritable = false;
- if (lastStatus.IsMatched)
- {
- _logger?.LogDebug("ElIf is NOT Actived.");
- }
- else
- {
- _engine.CanWritable = conditionParser.Parse(condition);
- _logger?.LogDebug("ElIf Condition: \"{condition}\" and computed value is: \"{value}\" ", condition, _engine.CanWritable);
- }
-
- conditionStack.Push(new(_engine.CanWritable, condition, "elif"));
- _logger?.LogDebug("Push Stack: Elif");
- }
-
- ///
- /// #else
- ///
- [Command]
- public void Else()
- {
- var conditionStack = _engine.GetOrNew("ConditionStack", () => new Stack());
-
- var lastStatus = conditionStack.Pop();
- _logger?.LogDebug("Pop Stack: {tag}", lastStatus.Tag);
-
- _engine.CanWritable = false;
-
- if (lastStatus.IsMatched)
- {
- _logger?.LogDebug("Else is NOT Actived.");
- }
- else
- {
- _engine.CanWritable = true;
- _logger?.LogDebug("Else computed value is: \"{value}\" ", _engine.CanWritable);
- }
-
- conditionStack.Push(new(_engine.CanWritable, string.Empty, "else"));
- _logger?.LogDebug("Push Stack: Else");
- }
-
- ///
- /// #endif
- ///
- [Command]
- public void Endif()
- {
- var conditionStack = _engine.GetOrNew("ConditionStack", () => new Stack());
-
- var lastStatus = conditionStack.Pop();
- _logger?.LogDebug("Pop Stack: {tag}", lastStatus.Tag);
-
- _engine.CanWritable = true;
- _logger?.LogDebug("EndIf Actived!");
- }
-}
-
-file sealed class ConditionParser
-{
- private readonly Engine _engine;
-
- public ConditionParser(Engine engine) => _engine = engine;
-
- public bool Parse(string condition)
- {
- condition = condition.Trim();
- switch (condition.ToLowerInvariant())
- {
- case "true": return true;
- case "false": return false;
- default: break;
- }
-
- var defines = _engine.GetOrNew("Defines", () => new HashSet());
-
- return defines.Any(i => i.Equals(condition, StringComparison.OrdinalIgnoreCase))
- || (condition.Contains("||")
- ? OR(condition)
- : condition.Contains("&&")
- ? AND(condition)
- : condition.TrimStart().StartsWith('!') && NOT(condition));
- }
-
- private bool AND(string condition) => condition.Trim().Split("&&").All(Parse);
-
- private bool NOT(string condition)
- {
- condition = condition.Trim();
- return condition.StartsWith('!')
- ? !Parse(condition[1..])
- : Parse(condition);
- }
-
- private bool OR(string condition) => condition.Trim().Split("||").Any(Parse);
-}
-
-file sealed record ConditionStatus(bool IsMatched, string Condition, string Tag);
\ No newline at end of file
diff --git a/lib/Shimakaze.Sdk.Preprocessor/Commands/DefineCommand.cs b/lib/Shimakaze.Sdk.Preprocessor/Commands/DefineCommand.cs
deleted file mode 100644
index 30b972ee..00000000
--- a/lib/Shimakaze.Sdk.Preprocessor/Commands/DefineCommand.cs
+++ /dev/null
@@ -1,48 +0,0 @@
-using Microsoft.Extensions.Logging;
-
-using Shimakaze.Sdk.Preprocessor.Kernel;
-
-namespace Shimakaze.Sdk.Preprocessor.Commands;
-///
-/// Define Commands: define undef
-///
-public sealed class DefineCommand
-{
- private readonly Engine _engine;
- private readonly Logger? _logger;
-
- ///
- ///
- ///
- ///
- ///
- public DefineCommand(Engine engine, Logger? logger = null)
- {
- _engine = engine;
- _logger = logger;
- }
-
- ///
- /// #define identifier
- ///
- ///
- [Command]
- public void Define(string identifier)
- {
- var defines = _engine.GetOrNew("Defines", () => new HashSet());
- defines.Add(identifier);
- _logger?.LogDebug("Define {identifier}", identifier);
- }
-
- ///
- /// #undef identifier
- ///
- ///
- [Command]
- public void Undef(string identifier)
- {
- var defines = _engine.GetOrNew("Defines", () => new HashSet());
- defines.Remove(identifier);
- _logger?.LogDebug("Undefine {identifier}", identifier);
- }
-}
\ No newline at end of file
diff --git a/lib/Shimakaze.Sdk.Preprocessor/Commands/RegionCommand.cs b/lib/Shimakaze.Sdk.Preprocessor/Commands/RegionCommand.cs
deleted file mode 100644
index 0a9aa7b8..00000000
--- a/lib/Shimakaze.Sdk.Preprocessor/Commands/RegionCommand.cs
+++ /dev/null
@@ -1,34 +0,0 @@
-using System.Diagnostics.CodeAnalysis;
-
-using Microsoft.Extensions.Logging;
-
-using Shimakaze.Sdk.Preprocessor.Kernel;
-
-namespace Shimakaze.Sdk.Preprocessor.Commands;
-
-///
-/// Region Commands: region endregion
-///
-[ExcludeFromCodeCoverage]
-public sealed class RegionCommand
-{
- private readonly Logger? _logger;
-
- ///
- ///
- ///
- ///
- public RegionCommand(Logger? logger = null) => _logger = logger;
-
- ///
- /// #region
- ///
- [Command]
- public void Region() => _logger?.LogDebug("Region");
-
- ///
- /// #endregion
- ///
- [Command]
- public void Endregion() => _logger?.LogDebug("Endregion");
-}
\ No newline at end of file
diff --git a/lib/Shimakaze.Sdk.Preprocessor/Commands/TypeCommand.cs b/lib/Shimakaze.Sdk.Preprocessor/Commands/TypeCommand.cs
deleted file mode 100644
index 8bc8ee4f..00000000
--- a/lib/Shimakaze.Sdk.Preprocessor/Commands/TypeCommand.cs
+++ /dev/null
@@ -1,74 +0,0 @@
-using System.Diagnostics.CodeAnalysis;
-
-using Microsoft.Extensions.Logging;
-
-using Shimakaze.Sdk.Preprocessor.Kernel;
-
-namespace Shimakaze.Sdk.Preprocessor.Commands;
-
-///
-/// Region Commands: region endregion
-///
-public sealed class TypeCommand
-{
- private readonly Engine _engine;
- private readonly Logger? _logger;
-
- ///
- ///
- ///
- ///
- ///
- public TypeCommand(Engine engine, Logger? logger = null)
- {
- _engine = engine;
- _logger = logger;
- }
-
- ///
- /// #type
- ///
- /// 类型
- /// 键
- /// 单位名
- [Command]
- public void Type(string type, string key, string unit)
- {
- _logger?.LogDebug("Adding {unit} as {key} in {type}", unit, key, type);
- string reg = $"""
- [{type}]
- {key}={unit}
- """;
- _engine.Writer.WriteLine(reg);
- }
-
- ///
- [Command]
- public void Type(string type, string key)
- {
- if (string.IsNullOrEmpty(_engine.FilePath))
- {
- _logger?.LogError("Cannot found current file's name");
- throw new NotSupportedException("Cannot found current file's name");
- }
-
- string unit = Path.GetFileName(_engine.FilePath).Split('.').First();
- Type(type, key, unit);
- }
-
- ///
- [Command]
- public void Type(string type)
- {
- var typeCounter = _engine.GetOrNew("TypeCounter", () => new TypeCounter());
- var key = typeCounter.Counter.ToString();
- Type(type, key);
- }
-
-}
-
-file sealed class TypeCounter
-{
- private int _counter = 0;
- public int Counter => _counter++;
-}
\ No newline at end of file
diff --git a/lib/Shimakaze.Sdk.Preprocessor/Shimakaze.Sdk.Preprocessor.csproj b/lib/Shimakaze.Sdk.Preprocessor/Shimakaze.Sdk.Preprocessor.csproj
deleted file mode 100644
index 0dad13cd..00000000
--- a/lib/Shimakaze.Sdk.Preprocessor/Shimakaze.Sdk.Preprocessor.csproj
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/lib/Shimakaze.Sdk/IO/Csf/Xml/CsfXmlV1Reader.cs b/lib/Shimakaze.Sdk/IO/Csf/Xml/CsfXmlV1Reader.cs
deleted file mode 100644
index 0ec5e0c1..00000000
--- a/lib/Shimakaze.Sdk/IO/Csf/Xml/CsfXmlV1Reader.cs
+++ /dev/null
@@ -1,31 +0,0 @@
-using System.Xml;
-
-using Shimakaze.Sdk.Csf;
-using Shimakaze.Sdk.Csf.Xml.Converter.V1;
-
-namespace Shimakaze.Sdk.IO.Csf.Xml;
-
-///
-/// CsfXmlV1Reader.
-///
-public sealed class CsfXmlV1Reader : AsyncReader, IDisposable, IAsyncDisposable
-{
- ///
- /// 构造器
- ///
- /// 基础流
- /// 退出时是否保持流打开
- public CsfXmlV1Reader(Stream stream, bool leaveOpen = false) : base(stream, leaveOpen)
- {
- }
-
- ///
- public override async Task ReadAsync(IProgress? progress = default, CancellationToken cancellationToken = default)
- {
- await Task.Yield();
-
- CsfDocumentXmlSerializer serializer = new();
- using XmlReader xmlReader = XmlReader.Create(BaseStream);
- return serializer.Deserialize(xmlReader);
- }
-}
\ No newline at end of file
diff --git a/lib/Shimakaze.Sdk/IO/Csf/Xml/CsfXmlV1Writer.cs b/lib/Shimakaze.Sdk/IO/Csf/Xml/CsfXmlV1Writer.cs
deleted file mode 100644
index bc7dbd94..00000000
--- a/lib/Shimakaze.Sdk/IO/Csf/Xml/CsfXmlV1Writer.cs
+++ /dev/null
@@ -1,34 +0,0 @@
-using System.Xml;
-
-using Shimakaze.Sdk.Csf;
-using Shimakaze.Sdk.Csf.Xml.Converter.V1;
-
-namespace Shimakaze.Sdk.IO.Csf.Xml;
-
-///
-/// CsfXmlV1Writer.
-///
-public sealed class CsfXmlV1Writer : AsyncWriter, IDisposable, IAsyncDisposable
-{
- private readonly XmlWriterSettings? _settings;
- ///
- ///
- ///
- ///
- ///
- /// ˳ʱǷ
- public CsfXmlV1Writer(Stream stream, XmlWriterSettings? settings = null, bool leaveOpen = false) : base(stream, leaveOpen)
- {
- _settings = settings;
- }
-
- ///
- public override async Task WriteAsync(CsfDocument value, IProgress? progress = default, CancellationToken cancellationToken = default)
- {
- await Task.Yield();
-
- CsfDocumentXmlSerializer serializer = new();
- using XmlWriter xmlWriter = XmlWriter.Create(BaseStream, _settings);
- serializer.Serialize(xmlWriter, value);
- }
-}
\ No newline at end of file
diff --git a/lib/Shimakaze.Sdk/IO/Csf/Yaml/CsfYamlV1Reader.cs b/lib/Shimakaze.Sdk/IO/Csf/Yaml/CsfYamlV1Reader.cs
deleted file mode 100644
index f197e26f..00000000
--- a/lib/Shimakaze.Sdk/IO/Csf/Yaml/CsfYamlV1Reader.cs
+++ /dev/null
@@ -1,35 +0,0 @@
-using Shimakaze.Sdk.Csf;
-using Shimakaze.Sdk.Csf.Yaml.Converter.V1;
-
-using YamlDotNet.Serialization;
-
-namespace Shimakaze.Sdk.IO.Csf.Yaml;
-
-///
-/// CSF YAML Deserializer.
-///
-public sealed class CsfYamlV1Reader : AsyncReader, IDisposable, IAsyncDisposable
-{
- ///
- /// 构造器
- ///
- /// 基础流
- /// 退出时是否保持流打开
- public CsfYamlV1Reader(Stream stream, bool leaveOpen = false) : base(stream, leaveOpen)
- {
- }
-
- ///
- public override async Task ReadAsync(IProgress? progress = default, CancellationToken cancellationToken = default)
- {
- await Task.Yield();
-
- using StreamReader reader = new(BaseStream, leaveOpen: true);
- return new DeserializerBuilder()
- .WithTypeConverter(CsfValueConverter.Instance)
- .WithTypeConverter(CsfDataConverter.Instance)
- .WithTypeConverter(CsfDocumentConverter.Instance)
- .Build()
- .Deserialize(reader);
- }
-}
\ No newline at end of file
diff --git a/lib/Shimakaze.Sdk/IO/Ini/IniMerger.cs b/lib/Shimakaze.Sdk/IO/Ini/IniMerger.cs
deleted file mode 100644
index f1490637..00000000
--- a/lib/Shimakaze.Sdk/IO/Ini/IniMerger.cs
+++ /dev/null
@@ -1,156 +0,0 @@
-using System.Collections;
-using System.Diagnostics.CodeAnalysis;
-
-using Shimakaze.Sdk.Ini;
-
-namespace Shimakaze.Sdk.IO.Ini;
-
-///
-/// Ini 合并器
-///
-public class IniMerger : ISet
-{
- ///
- /// 内部的词典
- ///
- protected readonly Dictionary _cache = [];
-
- ///
- public virtual int Count => _cache.Count;
-
- ///
- public virtual bool IsReadOnly { get; } = false;
-
- ///
- public virtual bool Add(IniSection item)
- {
- if (!_cache.TryGetValue(item.Name, out var section))
- _cache.Add(item.Name, section = new() { Name = item.Name });
-
- foreach (var kvp in item)
- section[kvp.Key] = kvp.Value;
-
- return true;
- }
-
- ///
- [ExcludeFromCodeCoverage]
- void ICollection.Add(IniSection item) => Add(item);
-
- ///
- /// 生成Ini
- ///
- /// Ini文档对象
- public virtual IniDocument Build()
- {
- return new(_cache.Values);
- }
-
- ///
- /// 直接写入Ini文件到流
- ///
- /// 流
- ///
- ///
- public virtual async Task BuildAndWriteToAsync(Stream stream, IProgress? progress = default, CancellationToken cancellationToken = default)
- {
- await using IniWriter serializer = new(stream, true);
- await serializer.WriteAsync(Build(), progress, cancellationToken);
- }
-
- ///
- public virtual void Clear() => _cache.Clear();
-
- ///
- public virtual bool Contains(IniSection item) => _cache.TryGetValue(item.Name, out _);
-
- ///
- public virtual void CopyTo(IniSection[] array, int arrayIndex) => _cache.Values.CopyTo(array, arrayIndex);
-
- ///
- public virtual void ExceptWith(IEnumerable other)
- {
- foreach (var item in other)
- _cache.Remove(item.Name);
- }
-
- ///
- public virtual IEnumerator GetEnumerator() => _cache.Values.GetEnumerator();
-
- ///
- [ExcludeFromCodeCoverage]
- IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
-
- ///
- public virtual void IntersectWith(IEnumerable other)
- {
- Clear();
- foreach (var item in other)
- Add(item);
- }
-
- ///
- public virtual bool IsProperSubsetOf(IEnumerable other)
- {
- if (other.Count() <= Count)
- return false;
-
- var tmp = other.Select(item => item.Name);
- return !_cache.Keys.Any(i => !tmp.Contains(i));
- }
-
- ///
- public virtual bool IsProperSupersetOf(IEnumerable other) => other.Count() < Count && !other.Any(i => !_cache.TryGetValue(i.Name, out _));
-
- ///
- public virtual bool IsSubsetOf(IEnumerable other)
- {
- if (other.Count() < Count)
- return false;
-
- var tmp = other.Select(item => item.Name);
- return !_cache.Keys.Any(i => !tmp.Contains(i));
- }
-
- ///
- public virtual bool IsSupersetOf(IEnumerable other) => other.Count() <= Count && !other.Any(i => !_cache.TryGetValue(i.Name, out _));
-
- ///
- public virtual bool Overlaps(IEnumerable other)
- {
- var tmp = other.Select(item => item.Name);
- return _cache.Keys.Any(i => tmp.Contains(i));
- }
-
- ///
- public virtual bool Remove(IniSection item) => _cache.Remove(item.Name);
-
- ///
- public virtual bool SetEquals(IEnumerable other)
- {
- if (other.Count() != Count)
- return false;
-
- var tmp = other.Select(item => item.Name);
- return !_cache.Keys.Any(i => !tmp.Contains(i));
- }
-
- ///
- public virtual void SymmetricExceptWith(IEnumerable other)
- {
- foreach (var item in other)
- {
- if (_cache.TryGetValue(item.Name, out var value))
- Remove(value);
- else
- Add(item);
- }
- }
-
- ///
- public virtual void UnionWith(IEnumerable other)
- {
- foreach (var item in other)
- Add(item);
- }
-}
\ No newline at end of file
diff --git a/lib/Shimakaze.Sdk/IO/Ini/IniReader.cs b/lib/Shimakaze.Sdk/IO/Ini/IniReader.cs
deleted file mode 100644
index 14bfbd13..00000000
--- a/lib/Shimakaze.Sdk/IO/Ini/IniReader.cs
+++ /dev/null
@@ -1,69 +0,0 @@
-using Shimakaze.Sdk.Ini;
-using Shimakaze.Sdk.Ini.Binder;
-using Shimakaze.Sdk.Ini.Parser;
-
-namespace Shimakaze.Sdk.IO.Ini;
-
-///
-/// Ini反序列化器
-///
-public sealed class IniReader : AsyncReader
-{
- ///
- /// 基础读取器
- ///
- private TextReader BaseReader { get; }
- private readonly IniTokenReader _tokenReader;
- private readonly IniDocumentBinder _binder;
-
- ///
- /// 构造 Ini反序列化器
- ///
- /// 基础流
- /// 退出时是否保持流打开
- public IniReader(Stream stream, bool leaveOpen = false) : base(stream, leaveOpen)
- {
- BaseReader = new StreamReader(stream, leaveOpen: leaveOpen);
- _tokenReader = new(BaseReader, leaveOpen: leaveOpen);
- _binder = new(_tokenReader, leaveOpen: leaveOpen);
- }
-
- ///
- /// 读取一个 INI 文档
- ///
- ///
- public IniDocument Read() => _binder.Bind();
-
- ///
- public override Task ReadAsync(IProgress? progress = default, CancellationToken cancellationToken = default)
- => Task.Run(Read, cancellationToken);
-
- ///
- protected override void Dispose(bool disposing)
- {
- if (disposing)
- {
- if (!_leaveOpen)
- _binder.Dispose();
- if (!_leaveOpen)
- _tokenReader.Dispose();
- if (!_leaveOpen)
- BaseReader.Dispose();
- }
-
- base.Dispose(disposing);
- }
-
- ///
- protected override ValueTask DisposeAsyncCore()
- {
- if (!_leaveOpen)
- _binder.Dispose();
- if (!_leaveOpen)
- _tokenReader.Dispose();
- if (!_leaveOpen)
- BaseReader.Dispose();
-
- return base.DisposeAsyncCore();
- }
-}
\ No newline at end of file
diff --git a/lib/Shimakaze.Sdk/IO/Ini/IniWriter.cs b/lib/Shimakaze.Sdk/IO/Ini/IniWriter.cs
deleted file mode 100644
index a3f53f3d..00000000
--- a/lib/Shimakaze.Sdk/IO/Ini/IniWriter.cs
+++ /dev/null
@@ -1,88 +0,0 @@
-using Shimakaze.Sdk.Ini;
-using Shimakaze.Sdk.Ini.Parser;
-
-namespace Shimakaze.Sdk.IO.Ini;
-
-///
-/// Ini序列化器
-///
-public sealed class IniWriter : AsyncWriter
-{
- ///
- /// 基础写入器
- ///
- public TextWriter BaseWriter { get; }
- private readonly IniTokenWriter _iniTokenWriter;
-
- ///
- /// 构造 INI 序列化器
- ///
- /// 基础流
- /// 退出时是否保持流打开
- public IniWriter(Stream baseStream, bool leaveOpen = false) : base(baseStream, leaveOpen)
- {
- BaseWriter = new StreamWriter(baseStream, leaveOpen: leaveOpen);
- _iniTokenWriter = new(BaseWriter, leaveOpen: leaveOpen);
- }
-
- ///
- /// 写入
- ///
- ///
- public void Write(in IniDocument ini)
- {
- WriteSectionBody(ini.Default);
- foreach (var section in ini)
- {
- _iniTokenWriter.Write(new(IniTokenType.Section, section.Name));
- _iniTokenWriter.WriteLine();
- WriteSectionBody(section);
- }
- }
-
- ///
- public override Task WriteAsync(IniDocument ini, IProgress? progress = default, CancellationToken cancellationToken = default)
- => Task.Run(() => Write(ini), cancellationToken);
-
- ///
- /// 释放资源
- ///
- ///
- protected override void Dispose(bool disposing)
- {
- if (disposing)
- {
- if (!_leaveOpen)
- _iniTokenWriter.Dispose();
- if (!_leaveOpen)
- BaseWriter.Dispose();
- }
-
- base.Dispose(disposing);
- }
-
- ///
- protected override ValueTask DisposeAsyncCore()
- {
- if (!_leaveOpen)
- _iniTokenWriter.Dispose();
- if (!_leaveOpen)
- BaseWriter.Dispose();
-
- return base.DisposeAsyncCore();
- }
-
- ///
- /// 写入Section块 不包含Section头
- ///
- /// Section
- private void WriteSectionBody(in IniSection section)
- {
- foreach (var item in section)
- {
- _iniTokenWriter.Write(new(IniTokenType.Key, item.Key));
- _iniTokenWriter.Write(new(IniTokenType.Value, item.Value));
- _iniTokenWriter.WriteLine();
- }
- }
-}
\ No newline at end of file
diff --git a/lib/Shimakaze.Sdk/IO/Mix/IdCalculaters.cs b/lib/Shimakaze.Sdk/IO/Mix/IdCalculaters.cs
deleted file mode 100644
index 4995ab19..00000000
--- a/lib/Shimakaze.Sdk/IO/Mix/IdCalculaters.cs
+++ /dev/null
@@ -1,42 +0,0 @@
-using System.IO.Hashing;
-using System.Text;
-
-namespace Shimakaze.Sdk.IO.Mix;
-
-///
-/// File Id Calculater
-///
-public delegate uint IdCalculater(string name);
-
-///
-/// File Id Calculaters
-///
-public static class IdCalculaters
-{
- ///
- /// Tiberian Sun Id Calc
- ///
- /// File Name
- /// Id
- public static uint TSIdCalculater(string name)
- {
- name = name.ToUpper();
- int l = name.Length;
- int a = l >> 2;
- if ((l & 3) is not 0)
- {
- name += (char)(byte)(l - (a << 2));
- int i = 3 - (l & 3);
- while (i-- is not 0)
- name += name[a << 2];
- }
- return BitConverter.ToUInt32(Crc32.Hash(Encoding.ASCII.GetBytes(name)), 0);
- }
-
- // /// /// Id Calc for RA/TD /// /// /// This method are used by
- // RedAlert and Tiberian Down. /// /// File Name ///
- // Id [Obsolete("It's NOT pass the test!")] public static uint
- // OldIdCalculater(string name) { name = name.ToUpper(); int i = 0; uint id = 0; int l =
- // name.Length; while (i < l) { uint a = 0; for (int j = 0; j < 4; j++) { a >>= 8; if (i < l) a
- // += ((uint)name[i]) << 24; i++; } id = (id << 1 | id >> 31) + a; } return id; }
-}
\ No newline at end of file
diff --git a/lib/Shimakaze.Sdk/Ini/Ares/AresIniDocument.cs b/lib/Shimakaze.Sdk/Ini/Ares/AresIniDocument.cs
deleted file mode 100644
index ff1e1590..00000000
--- a/lib/Shimakaze.Sdk/Ini/Ares/AresIniDocument.cs
+++ /dev/null
@@ -1,26 +0,0 @@
-namespace Shimakaze.Sdk.Ini.Ares;
-
-///
-public sealed class AresIniDocument : IniDocument
-{
- ///
- public AresIniDocument()
- {
- Default = new(";Default;", default, new(_defaultSectionKeyComparer));
- }
-
- ///
- public AresIniDocument(IEnumerable sections) : base(sections)
- {
- Default = new(";Default;", default, new(_defaultSectionKeyComparer));
- }
-
- ///
- public AresIniDocument(IEqualityComparer sectionNameComparer, IEqualityComparer? keyComparer = default) : base(sectionNameComparer, keyComparer)
- {
- Default = new(";Default;", default, new(_defaultSectionKeyComparer));
- }
-
- ///
- public override AresIniSection Default { get; }
-}
\ No newline at end of file
diff --git a/lib/Shimakaze.Sdk/Ini/Binder/Ares/AresIniDocumentBinder.cs b/lib/Shimakaze.Sdk/Ini/Binder/Ares/AresIniDocumentBinder.cs
deleted file mode 100644
index 45f00d74..00000000
--- a/lib/Shimakaze.Sdk/Ini/Binder/Ares/AresIniDocumentBinder.cs
+++ /dev/null
@@ -1,92 +0,0 @@
-using Shimakaze.Sdk.Ini.Ares;
-using Shimakaze.Sdk.Ini.Parser;
-using Shimakaze.Sdk.Ini.Parser.Ares;
-
-namespace Shimakaze.Sdk.Ini.Binder.Ares;
-
-///
-/// AresIniDocument 绑定器
-///
-///
-///
-///
-public sealed class AresIniDocumentBinder(AresIniTokenReader tokenReader, bool leaveOpen = false, EqualityComparer? keyComparer = default) : IDisposable
-{
- private readonly bool _leaveOpen = leaveOpen;
- private readonly AresIniTokenReader _tokenReader = tokenReader;
-
- ///
- /// 绑定
- ///
- ///
- public AresIniDocument Bind(AresIniDocument? ini = default)
- {
- ini ??= [];
- AresIniSection current = ini.Default;
- string? key = default;
- bool isBase = false;
- foreach (var token in _tokenReader)
- {
- switch (token.Type)
- {
- // 继承节符号
- case AresIniTokenType.BASE_SECTION:
- isBase = true;
- break;
- // 继承节
- case IniTokenType.Section when isBase:
- current.BaseName = token.Value;
- isBase = false;
- break;
- // 节
- case IniTokenType.Section when !isBase && !string.IsNullOrEmpty(token.Value):
- if (!ini.TryGetSection(token.Value, out var section))
- section = ini[token.Value] = keyComparer is not null
- ? new(token.Value, default, new(keyComparer))
- : new(token.Value);
-
- current = section;
- break;
- // 随机键名
- case AresIniTokenType.PLUS:
- if (key is not null)
- current[key] = string.Empty;
- key = Guid.NewGuid().ToString();
- break;
- // 键
- case IniTokenType.Key:
- if (key is not null)
- current[key] = string.Empty;
- key = token.Value;
- break;
- // 值
- case IniTokenType.Value when !string.IsNullOrEmpty(token.Value):
- if (key is null)
- {
- current[token.Value] = string.Empty;
- }
- else
- {
- current[key] = token.Value;
- key = default;
- }
- break;
- }
- }
-
- // 组织继承节
- foreach (var section in ini)
- {
- if (!string.IsNullOrEmpty(section.BaseName) && ini.TryGetSection(section.BaseName, out var baseSection))
- section.Base = baseSection;
- }
- return ini;
- }
-
- ///
- public void Dispose()
- {
- if (!_leaveOpen)
- _tokenReader.Dispose();
- }
-}
\ No newline at end of file
diff --git a/lib/Shimakaze.Sdk/Ini/Binder/IniDocumentBinder.cs b/lib/Shimakaze.Sdk/Ini/Binder/IniDocumentBinder.cs
deleted file mode 100644
index 8c5f9209..00000000
--- a/lib/Shimakaze.Sdk/Ini/Binder/IniDocumentBinder.cs
+++ /dev/null
@@ -1,67 +0,0 @@
-using Shimakaze.Sdk.Ini.Parser;
-
-namespace Shimakaze.Sdk.Ini.Binder;
-
-///
-/// IniDocument 绑定器
-///
-///
-///
-///
-public sealed class IniDocumentBinder(IniTokenReader tokenReader, bool leaveOpen = false, EqualityComparer? keyComparer = default) : IDisposable
-{
- private readonly bool _leaveOpen = leaveOpen;
- private readonly IniTokenReader _tokenReader = tokenReader;
-
- ///
- /// 绑定
- ///
- ///
- public IniDocument Bind(IniDocument? ini = default)
- {
- ini ??= [];
- IniSection current = ini.Default;
- string? key = default;
- foreach (var token in _tokenReader)
- {
- if (token.Value is null)
- continue;
-
- switch (token.Type)
- {
- case IniTokenType.Section:
- if (!ini.TryGetSection(token.Value, out var section))
- section = ini[token.Value] = keyComparer is not null
- ? new(token.Value, new(keyComparer))
- : new(token.Value);
-
- current = section;
- break;
- case IniTokenType.Key:
- if (key is not null)
- current[key] = string.Empty;
- key = token.Value;
- break;
- case IniTokenType.Value:
- if (key is null)
- {
- current[token.Value] = string.Empty;
- }
- else
- {
- current[key] = token.Value;
- key = default;
- }
- break;
- }
- }
- return ini;
- }
-
- ///
- public void Dispose()
- {
- if (!_leaveOpen)
- _tokenReader.Dispose();
- }
-}
\ No newline at end of file
diff --git a/lib/Shimakaze.Sdk/Ini/IniDocument.cs b/lib/Shimakaze.Sdk/Ini/IniDocument.cs
deleted file mode 100644
index dbd31481..00000000
--- a/lib/Shimakaze.Sdk/Ini/IniDocument.cs
+++ /dev/null
@@ -1,26 +0,0 @@
-namespace Shimakaze.Sdk.Ini;
-
-///
-public sealed class IniDocument : IniDocument
-{
- ///
- public IniDocument()
- {
- Default = new(";Default;", new(_defaultSectionKeyComparer));
- }
-
- ///
- public IniDocument(IEnumerable sections) : base(sections)
- {
- Default = new(";Default;", new(_defaultSectionKeyComparer));
- }
-
- ///
- public IniDocument(IEqualityComparer sectionNameComparer, IEqualityComparer? keyComparer = default) : base(sectionNameComparer, keyComparer)
- {
- Default = new(";Default;", new(_defaultSectionKeyComparer));
- }
-
- ///
- public override IniSection Default { get; }
-}
\ No newline at end of file
diff --git a/lib/Shimakaze.Sdk/Ini/Parser/Ares/AresIniTokenReader.cs b/lib/Shimakaze.Sdk/Ini/Parser/Ares/AresIniTokenReader.cs
deleted file mode 100644
index 28c41fe3..00000000
--- a/lib/Shimakaze.Sdk/Ini/Parser/Ares/AresIniTokenReader.cs
+++ /dev/null
@@ -1,38 +0,0 @@
-using System.Diagnostics.CodeAnalysis;
-
-namespace Shimakaze.Sdk.Ini.Parser.Ares;
-
-///
-/// Ares INI 方言语法分析器
-///
-///
-///
-///
-public class AresIniTokenReader(TextReader textReader, IniTokenIgnoreLevel ignore = IniTokenIgnoreLevel.NonValue, bool leaveOpen = false) : IniTokenReader(textReader, ignore, leaveOpen)
-{
- ///
- protected override bool FlushBuffer([NotNullWhen(true)] out IniToken? result, int type = IniTokenType.Unknown)
- {
- result = default;
- if (Buffer.Length is not 0)
- {
- switch ((type, Buffer[0]))
- {
- case (IniTokenType.Unknown, ':'):
- // 继承节
- result = new(AresIniTokenType.BASE_SECTION);
- Buffer.Clear();
- break;
- case (IniTokenType.Key, '+'):
- // += 注册表
- result = new(AresIniTokenType.PLUS);
- Buffer.Clear();
- break;
- default:
- break;
- }
- }
-
- return result is not null || base.FlushBuffer(out result, type);
- }
-}
diff --git a/lib/Shimakaze.Sdk/Ini/Parser/Ares/AresIniTokenType.cs b/lib/Shimakaze.Sdk/Ini/Parser/Ares/AresIniTokenType.cs
deleted file mode 100644
index b38d5407..00000000
--- a/lib/Shimakaze.Sdk/Ini/Parser/Ares/AresIniTokenType.cs
+++ /dev/null
@@ -1,22 +0,0 @@
-namespace Shimakaze.Sdk.Ini.Parser.Ares;
-
-///
-/// Ares INI Token Type
-///
-public static class AresIniTokenType
-{
- ///
- /// Ares INI 特有的 继承 Section
- ///
- ///
- /// [Section] : [Base]
- ///
- public const int BASE_SECTION = ':';
- ///
- /// PLUS
- ///
- ///
- /// += Value
- ///
- public const int PLUS = '+';
-}
\ No newline at end of file
diff --git a/lib/Shimakaze.Sdk/Ini/Parser/Ares/AresIniTokenWriter.cs b/lib/Shimakaze.Sdk/Ini/Parser/Ares/AresIniTokenWriter.cs
deleted file mode 100644
index 292ffd0c..00000000
--- a/lib/Shimakaze.Sdk/Ini/Parser/Ares/AresIniTokenWriter.cs
+++ /dev/null
@@ -1,26 +0,0 @@
-namespace Shimakaze.Sdk.Ini.Parser.Ares;
-
-///
-/// Ares INI 方言语法流写入器
-///
-///
-///
-public class AresIniTokenWriter(TextWriter textWriter, bool leaveOpen = false) : IniTokenWriter(textWriter, leaveOpen)
-{
- ///
- public override void Write(in IniToken token)
- {
- switch (token.Type)
- {
- case AresIniTokenType.BASE_SECTION:
- case AresIniTokenType.PLUS:
- {
- BaseWriter.Write((char)token.Type);
- break;
- }
- default:
- base.Write(token);
- break;
- }
- }
-}
\ No newline at end of file
diff --git a/lib/Shimakaze.Sdk/Ini/Parser/BucketStack.cs b/lib/Shimakaze.Sdk/Ini/Parser/BucketStack.cs
deleted file mode 100644
index 365d223d..00000000
--- a/lib/Shimakaze.Sdk/Ini/Parser/BucketStack.cs
+++ /dev/null
@@ -1,56 +0,0 @@
-using System.Diagnostics.CodeAnalysis;
-using System.Text;
-
-namespace Shimakaze.Sdk.Ini.Parser;
-
-///
-/// 成对符号栈
-///
-public sealed class BucketStack
-{
- private readonly Stack<(char Start, StringBuilder Buffer)> _depths = new();
- private readonly Stack _bufferCaches = new();
-
- ///
- /// 暂存区
- ///
- public StringBuilder Buffer { get; private set; } = new();
-
- ///
- /// 当前符号
- ///
- public char Current => _depths.TryPeek(out var result) ? result.Start : char.MinValue;
-
- ///
- /// 是否是空的
- ///
- public bool Empty => _depths.Count is 0;
-
- ///
- /// 压栈
- ///
- ///
- public void Push(char start)
- {
- _depths.Push((start, Buffer));
- if (!_bufferCaches.TryPop(out var buffer))
- buffer = new();
- Buffer = buffer.Clear();
- }
-
- ///
- /// 弹栈
- ///
- ///
- ///
- public bool Pop([NotNullWhen(true)] out string? result)
- {
- result = default;
- (_, StringBuilder lastBuffer) = _depths.Pop();
- if (Buffer is not { Length: 0 })
- result = Buffer.ToString();
- _bufferCaches.Push(Buffer);
- Buffer = lastBuffer;
- return result is not null;
- }
-}
\ No newline at end of file
diff --git a/lib/Shimakaze.Sdk/Ini/Parser/IniReaderIgnoreLevel.cs b/lib/Shimakaze.Sdk/Ini/Parser/IniReaderIgnoreLevel.cs
deleted file mode 100644
index 19a922d0..00000000
--- a/lib/Shimakaze.Sdk/Ini/Parser/IniReaderIgnoreLevel.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-namespace Shimakaze.Sdk.Ini.Parser;
-
-///
-/// Token忽略等级
-///
-public enum IniTokenIgnoreLevel
-{
- ///
- /// 不忽略
- ///
- None,
- ///
- /// 忽略空白
- ///
- White,
- ///
- /// 忽略不包含值的Token
- ///
- NonValue,
-}
\ No newline at end of file
diff --git a/lib/Shimakaze.Sdk/Ini/Parser/IniToken.cs b/lib/Shimakaze.Sdk/Ini/Parser/IniToken.cs
deleted file mode 100644
index b9fe30be..00000000
--- a/lib/Shimakaze.Sdk/Ini/Parser/IniToken.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-namespace Shimakaze.Sdk.Ini.Parser;
-
-///
-/// Ini Token
-///
-///
-///
-public record struct IniToken(int Type, string? Value = default)
-{
- ///
- ///
- ///
- ///
- public IniToken(int type, string? value, bool trim)
- : this(type, value)
- {
- if (trim)
- Value = value?.Trim();
- }
-}
\ No newline at end of file
diff --git a/lib/Shimakaze.Sdk/Ini/Parser/IniTokenReader.cs b/lib/Shimakaze.Sdk/Ini/Parser/IniTokenReader.cs
deleted file mode 100644
index 866f4d98..00000000
--- a/lib/Shimakaze.Sdk/Ini/Parser/IniTokenReader.cs
+++ /dev/null
@@ -1,207 +0,0 @@
-using System.Collections;
-using System.Diagnostics.CodeAnalysis;
-using System.Text;
-
-namespace Shimakaze.Sdk.Ini.Parser;
-
-///
-/// 语法树抽象
-///
-///
-///
-///
-public class IniTokenReader(TextReader textReader, IniTokenIgnoreLevel ignore = IniTokenIgnoreLevel.NonValue, bool leaveOpen = false) : IEnumerable, IDisposable
-{
- ///
- /// leave Open
- ///
- protected bool _leaveOpen = leaveOpen;
-
- ///
- /// 基础流
- ///
- public TextReader BaseReader { get; } = textReader;
- ///
- /// 忽略等级
- ///
- public IniTokenIgnoreLevel IgnoreLevel { get; } = ignore;
-
- ///
- /// 括号栈
- ///
- protected readonly BucketStack _depths = new();
-
- ///
- /// 字符暂存区
- ///
- protected StringBuilder Buffer => _depths.Buffer;
- private bool _disposedValue;
-
- ///
- /// 将 内容输出为
- ///
- ///
- ///
- ///
- protected virtual bool FlushBuffer([NotNullWhen(true)] out IniToken? result, int type = IniTokenType.Unknown)
- {
- result = default;
-
- switch (_depths.Current)
- {
- // Flush Value
- case '[' when _depths.Pop(out var value):
- result = new IniToken(IniTokenType.Section, value, IgnoreLevel is >= IniTokenIgnoreLevel.White);
- break;
- case '=' when _depths.Pop(out var value):
- result = new IniToken(IniTokenType.Value, value, IgnoreLevel is >= IniTokenIgnoreLevel.White);
- break;
- default:
- if (Buffer is not { Length: 0 })
- {
- // 不知道是什么东西
- result = new IniToken(type, Buffer.ToString(), IgnoreLevel is >= IniTokenIgnoreLevel.White);
- Buffer.Clear();
- }
- break;
- }
-
- return result is not null;
- }
-
- private IEnumerable ReadAllInternal()
- {
- IniToken? token;
- while (BaseReader.Peek() is not -1)
- {
- char ch = (char)BaseReader.Read();
-
- // 字符匹配
- switch (ch)
- {
- // 行尾匹配
- case '\r':
- {
- // Flush
- if (FlushBuffer(out token))
- yield return token.Value;
- if (IgnoreLevel < IniTokenIgnoreLevel.White)
- yield return new(IniTokenType.CR);
- break;
- }
- case '\n':
- {
- // Flush
- if (FlushBuffer(out token))
- yield return token.Value;
- if (IgnoreLevel < IniTokenIgnoreLevel.White)
- yield return new(IniTokenType.LF);
- break;
- }
- // 空格
- case ' ':
- {
- if (_depths.Empty && IgnoreLevel < IniTokenIgnoreLevel.White)
- yield return new(IniTokenType.SPACE);
- break;
- }
- // 横向制表符
- case '\t':
- {
- if (_depths.Empty && IgnoreLevel < IniTokenIgnoreLevel.White)
- yield return new(IniTokenType.TAB);
- break;
- }
- // 行内注释
- case ';':
- {
- // Flush
- if (FlushBuffer(out token))
- yield return token.Value;
- if (IgnoreLevel < IniTokenIgnoreLevel.NonValue)
- yield return new(IniTokenType.SEMI);
-
- yield return new IniToken(IniTokenType.Comment, BaseReader.ReadLine() ?? string.Empty, IgnoreLevel is >= IniTokenIgnoreLevel.White);
- break;
- }
- // 匹配尾中括号
- case ']':
- {
- // Flush
- if (FlushBuffer(out token))
- yield return token.Value;
- if (IgnoreLevel < IniTokenIgnoreLevel.NonValue)
- yield return new(IniTokenType.END_BRACKET);
- break;
- }
- // 匹配首中括号
- case '[':
- {
- // Flush
- if (FlushBuffer(out token))
- yield return token.Value;
- if (IgnoreLevel < IniTokenIgnoreLevel.NonValue)
- yield return new(IniTokenType.START_BRACKET);
-
- _depths.Push(ch);
- break;
- }
- case '=':
- {
- // Flush
- if (FlushBuffer(out token, IniTokenType.Key))
- yield return token.Value;
- if (IgnoreLevel < IniTokenIgnoreLevel.NonValue)
- yield return new(IniTokenType.EQ);
-
- _depths.Push(ch);
- break;
- }
- default:
- {
- Buffer.Append(ch);
- break;
- }
- }
- }
- if (FlushBuffer(out token))
- yield return token.Value;
- if (IgnoreLevel < IniTokenIgnoreLevel.White)
- yield return new(IniTokenType.EOF);
- }
-
- ///
- public IEnumerator GetEnumerator() => ReadAllInternal().GetEnumerator();
-
- IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
-
- ///
- ///
- ///
- ///
- protected virtual void Dispose(bool disposing)
- {
- if (_disposedValue)
- return;
-
- _disposedValue = true;
- if (disposing)
- {
- if (!_leaveOpen)
- BaseReader.Dispose();
- }
-
- }
-
- // ~IniTokenReader()
- // {
- // Dispose(disposing: false);
- // }
-
- ///
- public void Dispose()
- {
- Dispose(disposing: true);
- GC.SuppressFinalize(this);
- }
-}
\ No newline at end of file
diff --git a/lib/Shimakaze.Sdk/Ini/Parser/IniTokenType.cs b/lib/Shimakaze.Sdk/Ini/Parser/IniTokenType.cs
deleted file mode 100644
index 0d59b4e9..00000000
--- a/lib/Shimakaze.Sdk/Ini/Parser/IniTokenType.cs
+++ /dev/null
@@ -1,65 +0,0 @@
-namespace Shimakaze.Sdk.Ini.Parser;
-
-///
-/// INI Token Type
-///
-public static class IniTokenType
-{
- ///
- /// Unknown
- ///
- public const int Unknown = 0;
- ///
- /// End of File
- ///
- public const int EOF = -1;
- ///
- /// CR
- ///
- public const int CR = '\r';
- ///
- /// LF
- ///
- public const int LF = '\n';
- ///
- /// Space
- ///
- public const int SPACE = ' ';
- ///
- /// Tab
- ///
- public const int TAB = '\t';
- ///
- /// ;
- ///
- public const int SEMI = ';';
- ///
- /// =
- ///
- public const int EQ = '=';
- ///
- /// [
- ///
- public const int START_BRACKET = '[';
- ///
- /// ]
- ///
- public const int END_BRACKET = ']';
- // =====================================
- ///
- /// ; Comment
- ///
- public const int Comment = 1;
- ///
- /// [Section]
- ///
- public const int Section = 2;
- ///
- /// Key=
- ///
- public const int Key = 3;
- ///
- /// =Value
- ///
- public const int Value = 4;
-}
\ No newline at end of file
diff --git a/lib/Shimakaze.Sdk/Ini/Parser/IniTokenWriter.cs b/lib/Shimakaze.Sdk/Ini/Parser/IniTokenWriter.cs
deleted file mode 100644
index bf1182f3..00000000
--- a/lib/Shimakaze.Sdk/Ini/Parser/IniTokenWriter.cs
+++ /dev/null
@@ -1,110 +0,0 @@
-namespace Shimakaze.Sdk.Ini.Parser;
-
-///
-/// INI Token 流写入器
-///
-///
-///
-public class IniTokenWriter(TextWriter textWriter, bool leaveOpen = false) : IDisposable
-{
- private bool _disposedValue;
- ///
- /// leave Open
- ///
- protected bool _leaveOpen = leaveOpen;
-
- ///
- /// 基础流
- ///
- public TextWriter BaseWriter { get; } = textWriter;
-
- ///
- /// 写入Token
- ///
- ///
- public virtual void Write(in IniToken token)
- {
- switch (token.Type)
- {
- case IniTokenType.Comment:
- {
- BaseWriter.Write(';');
- BaseWriter.Write(token.Value);
- break;
- }
- case IniTokenType.Section:
- {
- BaseWriter.Write('[');
- BaseWriter.Write(token.Value);
- BaseWriter.Write(']');
- break;
- }
- case IniTokenType.Key:
- {
- BaseWriter.Write(token.Value);
- break;
- }
- case IniTokenType.Value:
- {
- BaseWriter.Write('=');
- BaseWriter.Write(token.Value);
- break;
- }
- case IniTokenType.CR:
- case IniTokenType.LF:
- case IniTokenType.SPACE:
- case IniTokenType.TAB:
- {
- BaseWriter.Write((char)token.Type);
- break;
- }
- default:
- throw new NotSupportedException();
- }
- }
-
- ///
- /// 写入Token 后写入换行符
- ///
- ///
- public void WriteLine(in IniToken token)
- {
- Write(token);
- WriteLine();
- }
-
- ///
- /// 写入换行符
- ///
- public void WriteLine() => BaseWriter.WriteLine();
-
- ///
- ///
- ///
- ///
- protected virtual void Dispose(bool disposing)
- {
- if (_disposedValue)
- return;
-
- _disposedValue = true;
- if (disposing)
- {
- if (!_leaveOpen)
- BaseWriter.Dispose();
- }
-
- }
-
- // ~IniTokenReader()
- // {
- // Dispose(disposing: false);
- // }
-
- ///
- public void Dispose()
- {
- Dispose(disposing: true);
- GC.SuppressFinalize(this);
- }
-}
\ No newline at end of file
diff --git a/lib/Shimakaze.Sdk/Shimakaze.Sdk.csproj b/lib/Shimakaze.Sdk/Shimakaze.Sdk.csproj
deleted file mode 100644
index a222528d..00000000
--- a/lib/Shimakaze.Sdk/Shimakaze.Sdk.csproj
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/lib/Shimakaze.Sdk/Vxl/VXLFile.cs b/lib/Shimakaze.Sdk/Vxl/VXLFile.cs
deleted file mode 100644
index ebc8dfa5..00000000
--- a/lib/Shimakaze.Sdk/Vxl/VXLFile.cs
+++ /dev/null
@@ -1,27 +0,0 @@
-using Shimakaze.Sdk.Pal;
-
-namespace Shimakaze.Sdk.Vxl;
-
-///
-/// VXL 文件
-///
-public record struct VXLFile
-{
- ///
- /// 文件头
- ///
- public VXLHeader Header;
- ///
- /// 文件色板
- ///
- public Palette Palette;
- ///
- ///
- public SectionHeader[] SectionHeaders;
- ///
- ///
- public SectionData[] SectionData;
- ///
- ///
- public SectionTailer[] SectionTailers;
-}
\ No newline at end of file
diff --git a/lib/Shimakaze.Sdk.Build/CommonUtil.cs b/src/Shimakaze.Sdk.Build/CommonUtil.cs
similarity index 97%
rename from lib/Shimakaze.Sdk.Build/CommonUtil.cs
rename to src/Shimakaze.Sdk.Build/CommonUtil.cs
index 130b9d64..e5f47c68 100644
--- a/lib/Shimakaze.Sdk.Build/CommonUtil.cs
+++ b/src/Shimakaze.Sdk.Build/CommonUtil.cs
@@ -4,7 +4,6 @@
namespace Shimakaze.Sdk.Build;
-[ExcludeFromCodeCoverage]
internal static class CommonUtil
{
///
diff --git a/lib/Shimakaze.Sdk.Build/ReadMe.md b/src/Shimakaze.Sdk.Build/ReadMe.md
similarity index 100%
rename from lib/Shimakaze.Sdk.Build/ReadMe.md
rename to src/Shimakaze.Sdk.Build/ReadMe.md
diff --git a/lib/Shimakaze.Sdk.Build/Sdk/Sdk.props b/src/Shimakaze.Sdk.Build/Sdk/Sdk.props
similarity index 100%
rename from lib/Shimakaze.Sdk.Build/Sdk/Sdk.props
rename to src/Shimakaze.Sdk.Build/Sdk/Sdk.props
diff --git a/lib/Shimakaze.Sdk.Build/Sdk/Sdk.targets b/src/Shimakaze.Sdk.Build/Sdk/Sdk.targets
similarity index 100%
rename from lib/Shimakaze.Sdk.Build/Sdk/Sdk.targets
rename to src/Shimakaze.Sdk.Build/Sdk/Sdk.targets
diff --git a/src/Shimakaze.Sdk.Build/Sdk/tasks.props b/src/Shimakaze.Sdk.Build/Sdk/tasks.props
new file mode 100644
index 00000000..942505c1
--- /dev/null
+++ b/src/Shimakaze.Sdk.Build/Sdk/tasks.props
@@ -0,0 +1,15 @@
+
+
+
+
+ netstandard2.0
+ net8.0
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Shimakaze.Sdk.Build/Shimakaze.Sdk.Build.csproj b/src/Shimakaze.Sdk.Build/Shimakaze.Sdk.Build.csproj
new file mode 100644
index 00000000..d896f2a1
--- /dev/null
+++ b/src/Shimakaze.Sdk.Build/Shimakaze.Sdk.Build.csproj
@@ -0,0 +1,43 @@
+
+
+
+ Shimakaze.Sdk.RA2
+ Build your RA2 Module Project by MSBuild
+ MSBuild MSBuildSdk RA2Mod ShimakazeProject
+ MSBuildSdk
+ $(NoWarn);NU5128;
+ True
+ PackAllDependencies
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/lib/Shimakaze.Sdk.Build/TaskCsfGenerator.cs b/src/Shimakaze.Sdk.Build/TaskCsfGenerator.cs
similarity index 76%
rename from lib/Shimakaze.Sdk.Build/TaskCsfGenerator.cs
rename to src/Shimakaze.Sdk.Build/TaskCsfGenerator.cs
index 5cfa04f9..3abf7ad1 100644
--- a/lib/Shimakaze.Sdk.Build/TaskCsfGenerator.cs
+++ b/src/Shimakaze.Sdk.Build/TaskCsfGenerator.cs
@@ -3,10 +3,9 @@
using Microsoft.Extensions.DependencyInjection;
using Shimakaze.Sdk.Csf;
-using Shimakaze.Sdk.IO.Csf;
-using Shimakaze.Sdk.IO.Csf.Json;
-using Shimakaze.Sdk.IO.Csf.Xml;
-using Shimakaze.Sdk.IO.Csf.Yaml;
+using Shimakaze.Sdk.Csf.Json;
+using Shimakaze.Sdk.Csf.Xml;
+using Shimakaze.Sdk.Csf.Yaml;
using MSTask = Microsoft.Build.Utilities.Task;
@@ -20,18 +19,18 @@ public sealed class TaskCsfGenerator : MSTask
///
/// 生成的中间文件的路径
///
- public const string Metadata_Intermediate = "Intermediate";
+ public const string MetadataIntermediate = "Intermediate";
///
/// Type
///
- public const string Metadata_Type = "Type";
+ public const string MetadataType = "Type";
///
/// 生成的目标文件
///
[Output]
- public ITaskItem[] OutputFiles { get; set; } = Array.Empty();
+ public ITaskItem[] OutputFiles { get; set; } = [];
///
/// 将要被处理的文件
@@ -48,15 +47,15 @@ public override bool Execute()
List items = new(SourceFiles.Length);
foreach (var file in SourceFiles)
{
- var dest = file.GetMetadata(Metadata_Intermediate);
- var tag = file.GetMetadata(Metadata_Type);
+ var dest = file.GetMetadata(MetadataIntermediate);
+ var tag = file.GetMetadata(MetadataType);
if (!dest.CreateParentDirectory(Log))
return false;
services.Clear();
using Stream stream = File.OpenRead(file.ItemSpec);
using Stream output = File.Create(dest);
- services.AddSingleton>(new CsfWriter(output));
+ services.AddSingleton(new CsfWriter(output));
switch (tag.ToLowerInvariant())
{
@@ -71,24 +70,24 @@ public override bool Execute()
0,
0,
"You shouldn't use the \"CSF Json version 1\". Please port your file to \"version 2\" or use \"Csf Yaml version 1\" to replace that.");
- services.AddSingleton>(new CsfJsonV1Reader(stream));
+ services.AddSingleton(new CsfJsonV1Reader(stream));
break;
case "json":
case "jsonv2":
- services.AddSingleton>(new CsfJsonV2Reader(stream));
+ services.AddSingleton(new CsfJsonV2Reader(stream));
break;
case "xml":
case "xmlv1":
- services.AddSingleton>(new CsfXmlV1Reader(stream));
+ services.AddSingleton(new CsfXmlV1Reader(new StreamReader(stream)));
break;
case "yml":
case "yaml":
case "ymlv1":
case "yamlv1":
- services.AddSingleton>(new CsfYamlV1Reader(stream));
+ services.AddSingleton(new CsfYamlV1Reader(new StreamReader(stream)));
break;
case "csf":
@@ -122,7 +121,7 @@ public override bool Execute()
CsfDocument csf;
try
{
- csf = provider.GetRequiredService>().ReadAsync().Result;
+ csf = provider.GetRequiredService().ReadAsync().Result;
}
catch (Exception e)
{
@@ -144,14 +143,14 @@ public override bool Execute()
}
return false;
}
- provider.GetRequiredService>().WriteAsync(csf).Wait();
+ provider.GetRequiredService().WriteAsync(csf).Wait();
TaskItem item = new(dest);
file.CopyMetadataTo(item);
- item.RemoveMetadata(Metadata_Intermediate);
- item.SetMetadata(Metadata_Type, "Csf");
+ item.RemoveMetadata(MetadataIntermediate);
+ item.SetMetadata(MetadataType, "Csf");
items.Add(item);
}
- OutputFiles = items.ToArray();
+ OutputFiles = [.. items];
return !Log.HasLoggedErrors;
}
diff --git a/lib/Shimakaze.Sdk.Build/TaskCsfMerger.cs b/src/Shimakaze.Sdk.Build/TaskCsfMerger.cs
similarity index 88%
rename from lib/Shimakaze.Sdk.Build/TaskCsfMerger.cs
rename to src/Shimakaze.Sdk.Build/TaskCsfMerger.cs
index 845c558f..3455b161 100644
--- a/lib/Shimakaze.Sdk.Build/TaskCsfMerger.cs
+++ b/src/Shimakaze.Sdk.Build/TaskCsfMerger.cs
@@ -1,7 +1,7 @@
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
-using Shimakaze.Sdk.IO.Csf;
+using Shimakaze.Sdk.Csf;
using MSTask = Microsoft.Build.Utilities.Task;
@@ -15,7 +15,7 @@ public sealed class TaskCsfMerger : MSTask
///
/// Pack
///
- public const string Metadata_Pack = "Pack";
+ public const string MetadataPack = "Pack";
///
/// 生成的文件
@@ -42,7 +42,7 @@ public override bool Execute()
if (!DestinationFile.CreateParentDirectory(Log))
return false;
- CsfMerger merger = new();
+ CsfSet merger = [];
OutputFile = new TaskItem(DestinationFile);
foreach (var file in SourceFiles)
{
@@ -52,7 +52,7 @@ public override bool Execute()
file.CopyMetadataTo(OutputFile);
}
- OutputFile.SetMetadata(Metadata_Pack, true.ToString());
+ OutputFile.SetMetadata(MetadataPack, true.ToString());
using Stream output = File.Create(DestinationFile);
merger.BuildAndWriteToAsync(output).Wait();
output.Flush();
diff --git a/lib/Shimakaze.Sdk.Build/TaskIniMerger.cs b/src/Shimakaze.Sdk.Build/TaskIniMerger.cs
similarity index 78%
rename from lib/Shimakaze.Sdk.Build/TaskIniMerger.cs
rename to src/Shimakaze.Sdk.Build/TaskIniMerger.cs
index 70c9a43e..f2104078 100644
--- a/lib/Shimakaze.Sdk.Build/TaskIniMerger.cs
+++ b/src/Shimakaze.Sdk.Build/TaskIniMerger.cs
@@ -2,9 +2,6 @@
using Microsoft.Build.Utilities;
using Shimakaze.Sdk.Ini;
-using Shimakaze.Sdk.Ini.Binder;
-using Shimakaze.Sdk.Ini.Parser;
-using Shimakaze.Sdk.IO.Ini;
using MSTask = Microsoft.Build.Utilities.Task;
@@ -18,7 +15,13 @@ public sealed class TaskIniMerger : MSTask
///
/// Pack
///
- public const string Metadata_Pack = "Pack";
+ public const string MetadataPack = "Pack";
+
+ // TODO: Support Ares INI
+ /////
+ ///// SpecialType
+ /////
+ //public const string MetadataSpecialType = "SpecialType";
///
/// 生成的文件
@@ -56,9 +59,9 @@ public override bool Execute()
file.CopyMetadataTo(OutputFile);
}
- OutputFile.SetMetadata(Metadata_Pack, true.ToString());
- using Stream output = File.Create(DestinationFile);
- using IniWriter writer = new(output);
+ OutputFile.SetMetadata(MetadataPack, true.ToString());
+ using var output = File.CreateText(DestinationFile);
+ using IniTokenWriter writer = new(output);
writer.Write(ini);
output.Flush();
diff --git a/lib/Shimakaze.Sdk.Build/TaskIniPreprocessor.cs b/src/Shimakaze.Sdk.Build/TaskIniPreprocessor.cs
similarity index 88%
rename from lib/Shimakaze.Sdk.Build/TaskIniPreprocessor.cs
rename to src/Shimakaze.Sdk.Build/TaskIniPreprocessor.cs
index a02f38be..6618ddc2 100644
--- a/lib/Shimakaze.Sdk.Build/TaskIniPreprocessor.cs
+++ b/src/Shimakaze.Sdk.Build/TaskIniPreprocessor.cs
@@ -20,7 +20,7 @@ public sealed class TaskIniPreprocessor : MSTask
///
/// 生成的中间文件的路径
///
- public const string Metadata_Intermediate = "Intermediate";
+ public const string MetadataIntermediate = "Intermediate";
///
/// 符号
@@ -32,7 +32,7 @@ public sealed class TaskIniPreprocessor : MSTask
/// 输出的文件
///
[Output]
- public ITaskItem[] OutputFiles { get; set; } = Array.Empty();
+ public ITaskItem[] OutputFiles { get; set; } = [];
///
/// 将要被预处理的文件列表
@@ -64,7 +64,7 @@ public override bool Execute()
{
try
{
- var dest = file.GetMetadata(Metadata_Intermediate);
+ var dest = file.GetMetadata(MetadataIntermediate);
if (!dest.CreateParentDirectory(Log))
return false;
@@ -75,7 +75,7 @@ public override bool Execute()
TaskItem item = new(dest);
file.CopyMetadataTo(item);
- item.RemoveMetadata(Metadata_Intermediate);
+ item.RemoveMetadata(MetadataIntermediate);
outputs.Add(item);
}
catch (Exception ex)
@@ -84,7 +84,7 @@ public override bool Execute()
}
}
- OutputFiles = outputs.ToArray();
+ OutputFiles = [.. outputs];
return !Log.HasLoggedErrors;
}
diff --git a/lib/Shimakaze.Sdk.Build/TaskMixGenerator.cs b/src/Shimakaze.Sdk.Build/TaskMixGenerator.cs
similarity index 98%
rename from lib/Shimakaze.Sdk.Build/TaskMixGenerator.cs
rename to src/Shimakaze.Sdk.Build/TaskMixGenerator.cs
index 5ad89707..17ec85df 100644
--- a/lib/Shimakaze.Sdk.Build/TaskMixGenerator.cs
+++ b/src/Shimakaze.Sdk.Build/TaskMixGenerator.cs
@@ -1,7 +1,7 @@
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
-using Shimakaze.Sdk.IO.Mix;
+using Shimakaze.Sdk.Mix;
using MSTask = Microsoft.Build.Utilities.Task;
diff --git a/lib/Shimakaze.Sdk.Build/targets/Csf.targets b/src/Shimakaze.Sdk.Build/targets/Csf.targets
similarity index 100%
rename from lib/Shimakaze.Sdk.Build/targets/Csf.targets
rename to src/Shimakaze.Sdk.Build/targets/Csf.targets
diff --git a/lib/Shimakaze.Sdk.Build/targets/Csf/CsfGenerator.targets b/src/Shimakaze.Sdk.Build/targets/Csf/CsfGenerator.targets
similarity index 100%
rename from lib/Shimakaze.Sdk.Build/targets/Csf/CsfGenerator.targets
rename to src/Shimakaze.Sdk.Build/targets/Csf/CsfGenerator.targets
diff --git a/lib/Shimakaze.Sdk.Build/targets/Csf/CsfMerger.targets b/src/Shimakaze.Sdk.Build/targets/Csf/CsfMerger.targets
similarity index 100%
rename from lib/Shimakaze.Sdk.Build/targets/Csf/CsfMerger.targets
rename to src/Shimakaze.Sdk.Build/targets/Csf/CsfMerger.targets
diff --git a/lib/Shimakaze.Sdk.Build/targets/Ini.targets b/src/Shimakaze.Sdk.Build/targets/Ini.targets
similarity index 100%
rename from lib/Shimakaze.Sdk.Build/targets/Ini.targets
rename to src/Shimakaze.Sdk.Build/targets/Ini.targets
diff --git a/lib/Shimakaze.Sdk.Build/targets/Ini/IniMerger.targets b/src/Shimakaze.Sdk.Build/targets/Ini/IniMerger.targets
similarity index 100%
rename from lib/Shimakaze.Sdk.Build/targets/Ini/IniMerger.targets
rename to src/Shimakaze.Sdk.Build/targets/Ini/IniMerger.targets
diff --git a/lib/Shimakaze.Sdk.Build/targets/Ini/IniPreprocessor.targets b/src/Shimakaze.Sdk.Build/targets/Ini/IniPreprocessor.targets
similarity index 100%
rename from lib/Shimakaze.Sdk.Build/targets/Ini/IniPreprocessor.targets
rename to src/Shimakaze.Sdk.Build/targets/Ini/IniPreprocessor.targets
diff --git a/lib/Shimakaze.Sdk.Build/targets/Mix.targets b/src/Shimakaze.Sdk.Build/targets/Mix.targets
similarity index 100%
rename from lib/Shimakaze.Sdk.Build/targets/Mix.targets
rename to src/Shimakaze.Sdk.Build/targets/Mix.targets
diff --git a/lib/Shimakaze.Sdk.Build/targets/Mix/MixGenerator.targets b/src/Shimakaze.Sdk.Build/targets/Mix/MixGenerator.targets
similarity index 100%
rename from lib/Shimakaze.Sdk.Build/targets/Mix/MixGenerator.targets
rename to src/Shimakaze.Sdk.Build/targets/Mix/MixGenerator.targets
diff --git a/lib/Shimakaze.Sdk/Common/AsyncReader.cs b/src/Shimakaze.Sdk.Common/AsyncReader.cs
similarity index 94%
rename from lib/Shimakaze.Sdk/Common/AsyncReader.cs
rename to src/Shimakaze.Sdk.Common/AsyncReader.cs
index 3a3b6802..4e53c85d 100644
--- a/lib/Shimakaze.Sdk/Common/AsyncReader.cs
+++ b/src/Shimakaze.Sdk.Common/AsyncReader.cs
@@ -1,18 +1,15 @@
-using System.Diagnostics.CodeAnalysis;
-
-namespace Shimakaze.Sdk.Common;
+namespace Shimakaze.Sdk;
///
/// 异步读取器
///
///
-[ExcludeFromCodeCoverage]
public abstract class AsyncReader : IDisposable, IAsyncDisposable
{
///
/// Leave Open
///
- protected readonly bool _leaveOpen;
+ private readonly bool _leaveOpen;
private bool _disposedValue;
@@ -99,4 +96,4 @@ protected virtual async ValueTask DisposeAsyncCore()
{
Dispose(disposing: false);
}
-}
\ No newline at end of file
+}
diff --git a/src/Shimakaze.Sdk.Common/AsyncTextReader.cs b/src/Shimakaze.Sdk.Common/AsyncTextReader.cs
new file mode 100644
index 00000000..c6eb950f
--- /dev/null
+++ b/src/Shimakaze.Sdk.Common/AsyncTextReader.cs
@@ -0,0 +1,102 @@
+namespace Shimakaze.Sdk;
+
+///
+/// 异步读取器
+///
+///
+public abstract class AsyncTextReader : IDisposable, IAsyncDisposable
+{
+ ///
+ /// Leave Open
+ ///
+ private readonly bool _leaveOpen;
+
+ private bool _disposedValue;
+
+ ///
+ /// 基础流
+ ///
+ public TextReader BaseReader { get; }
+
+ ///
+ /// 构造 Csf 读取器
+ ///
+ /// 基础流
+ /// 退出时是否保持流打开
+ protected AsyncTextReader(TextReader baseReader, bool leaveOpen = false)
+ {
+ BaseReader = baseReader;
+ _leaveOpen = leaveOpen;
+ }
+
+ ///
+ public void Dispose()
+ {
+ Dispose(disposing: true);
+ GC.SuppressFinalize(this);
+ }
+
+ ///
+ public async ValueTask DisposeAsync()
+ {
+ await DisposeAsyncCore().ConfigureAwait(false);
+
+ Dispose(disposing: false);
+ GC.SuppressFinalize(this);
+ }
+
+ ///
+ public virtual Task ReadAsync() => ReadAsync(default, default);
+
+ ///
+ public virtual Task ReadAsync(CancellationToken cancellationToken) => ReadAsync(default, default);
+
+ ///
+ public virtual Task ReadAsync(IProgress? progress) => ReadAsync(default, default);
+
+ ///
+ /// 读取
+ ///
+ /// 进度
+ /// 取消
+ ///
+ public abstract Task ReadAsync(IProgress? progress = default, CancellationToken cancellationToken = default);
+
+ ///
+ /// 释放模式
+ ///
+ ///
+ protected virtual void Dispose(bool disposing)
+ {
+ if (_disposedValue)
+ return;
+
+ if (disposing)
+ {
+ if (!_leaveOpen)
+ BaseReader.Dispose();
+ }
+
+ _disposedValue = true;
+ }
+
+ ///
+ /// 释放模式
+ ///
+ protected virtual async ValueTask DisposeAsyncCore()
+ {
+ await Task.Run(() =>
+ {
+ if (!_leaveOpen)
+ BaseReader.Dispose();
+ });
+ }
+
+ ///
+ /// 终结器
+ ///
+ ~AsyncTextReader()
+ {
+ Dispose(disposing: false);
+ }
+}
diff --git a/src/Shimakaze.Sdk.Common/AsyncTextWriter.cs b/src/Shimakaze.Sdk.Common/AsyncTextWriter.cs
new file mode 100644
index 00000000..79014583
--- /dev/null
+++ b/src/Shimakaze.Sdk.Common/AsyncTextWriter.cs
@@ -0,0 +1,100 @@
+namespace Shimakaze.Sdk;
+
+///
+/// 异步写入器
+///
+///
+public abstract class AsyncTextWriter : IDisposable, IAsyncDisposable
+{
+ ///
+ /// Leave Open
+ ///
+ private readonly bool _leaveOpen;
+
+ private bool _disposedValue;
+
+ ///
+ /// 基础流
+ ///
+ public TextWriter BaseWriter { get; }
+
+ ///
+ /// 构造 Csf 读取器
+ ///
+ /// 基础流
+ /// 退出时是否保持流打开
+ protected AsyncTextWriter(TextWriter baseWriter, bool leaveOpen = false)
+ {
+ BaseWriter = baseWriter;
+ _leaveOpen = leaveOpen;
+ }
+
+ ///
+ public void Dispose()
+ {
+ Dispose(disposing: true);
+ GC.SuppressFinalize(this);
+ }
+
+ ///
+ public async ValueTask DisposeAsync()
+ {
+ await DisposeAsyncCore().ConfigureAwait(false);
+
+ Dispose(disposing: false);
+ GC.SuppressFinalize(this);
+ }
+
+ ///
+ public virtual Task WriteAsync(T value) => WriteAsync(value, default, default);
+
+ ///
+ public virtual Task WriteAsync(T value, CancellationToken cancellationToken) => WriteAsync(value, default, default);
+
+ ///
+ public virtual Task WriteAsync(T value, IProgress? progress) => WriteAsync(value, default, default);
+
+ ///
+ /// 写入
+ ///
+ /// 值
+ /// 进度
+ /// 取消
+ ///
+ public abstract Task WriteAsync(T value, IProgress? progress = default, CancellationToken cancellationToken = default);
+
+ ///
+ /// 释放模式
+ ///
+ ///
+ protected virtual void Dispose(bool disposing)
+ {
+ if (_disposedValue)
+ return;
+
+ if (disposing)
+ {
+ if (!_leaveOpen)
+ BaseWriter.Dispose();
+ }
+
+ _disposedValue = true;
+ }
+
+ ///
+ /// 释放模式
+ ///
+ protected virtual async ValueTask DisposeAsyncCore()
+ {
+ if (!_leaveOpen)
+ await BaseWriter.DisposeAsync().ConfigureAwait(false);
+ }
+
+ ///
+ /// 终结器
+ ///
+ ~AsyncTextWriter()
+ {
+ Dispose(disposing: false);
+ }
+}
diff --git a/lib/Shimakaze.Sdk/Common/AsyncWriter.cs b/src/Shimakaze.Sdk.Common/AsyncWriter.cs
similarity index 94%
rename from lib/Shimakaze.Sdk/Common/AsyncWriter.cs
rename to src/Shimakaze.Sdk.Common/AsyncWriter.cs
index 7238ab14..76c96474 100644
--- a/lib/Shimakaze.Sdk/Common/AsyncWriter.cs
+++ b/src/Shimakaze.Sdk.Common/AsyncWriter.cs
@@ -1,18 +1,15 @@
-using System.Diagnostics.CodeAnalysis;
-
-namespace Shimakaze.Sdk.Common;
+namespace Shimakaze.Sdk;
///
/// 异步写入器
///
///
-[ExcludeFromCodeCoverage]
public abstract class AsyncWriter : IDisposable, IAsyncDisposable
{
///
/// Leave Open
///
- protected readonly bool _leaveOpen;
+ private readonly bool _leaveOpen;
private bool _disposedValue;
diff --git a/src/Shimakaze.Sdk.Common/GroupCollectionShim.cs b/src/Shimakaze.Sdk.Common/GroupCollectionShim.cs
new file mode 100644
index 00000000..f1a29f67
--- /dev/null
+++ b/src/Shimakaze.Sdk.Common/GroupCollectionShim.cs
@@ -0,0 +1,23 @@
+using System.Text.RegularExpressions;
+
+namespace Shimakaze.Sdk;
+
+///
+/// 垫片
+///
+public static class GroupCollectionShim
+{
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static IEnumerable GetValues(this GroupCollection group)
+ {
+#if NETSTANDARD
+ return group.Cast();
+#else
+ return group.Values;
+#endif
+ }
+}
diff --git a/src/Shimakaze.Sdk.Common/Shimakaze.Sdk.Common.csproj b/src/Shimakaze.Sdk.Common/Shimakaze.Sdk.Common.csproj
new file mode 100644
index 00000000..ca63f0e6
--- /dev/null
+++ b/src/Shimakaze.Sdk.Common/Shimakaze.Sdk.Common.csproj
@@ -0,0 +1,11 @@
+
+
+
+ Shimakaze.Sdk
+
+
+
+
+
+
+
diff --git a/lib/Shimakaze.Sdk/Common/StreamExtensions.cs b/src/Shimakaze.Sdk.Common/StreamExtensions.cs
similarity index 97%
rename from lib/Shimakaze.Sdk/Common/StreamExtensions.cs
rename to src/Shimakaze.Sdk.Common/StreamExtensions.cs
index fb324472..d9447af4 100644
--- a/lib/Shimakaze.Sdk/Common/StreamExtensions.cs
+++ b/src/Shimakaze.Sdk.Common/StreamExtensions.cs
@@ -1,13 +1,11 @@
-using System.Diagnostics.CodeAnalysis;
-
-namespace Shimakaze.Sdk.Common;
+namespace Shimakaze.Sdk;
///
/// 流实用工具
///
-[ExcludeFromCodeCoverage]
public static unsafe class StreamExtensions
{
+
///
/// 读取结构体
///
diff --git a/src/Shimakaze.Sdk.Common/StringShim.cs b/src/Shimakaze.Sdk.Common/StringShim.cs
new file mode 100644
index 00000000..70180c1b
--- /dev/null
+++ b/src/Shimakaze.Sdk.Common/StringShim.cs
@@ -0,0 +1,22 @@
+namespace Shimakaze.Sdk;
+
+///
+/// 垫片
+///
+public static class StringShim
+{
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static string Join(this IEnumerable strings, char ch)
+ {
+#if NETSTANDARD2_0
+ return string.Join(new(ch, 1), strings);
+#else
+ return string.Join(ch, strings);
+#endif
+ }
+}
\ No newline at end of file
diff --git a/app/Shimakaze.Sdk.Csf.Converter/Program.cs b/src/Shimakaze.Sdk.Csf.Converter/Program.cs
similarity index 78%
rename from app/Shimakaze.Sdk.Csf.Converter/Program.cs
rename to src/Shimakaze.Sdk.Csf.Converter/Program.cs
index c3b76d34..7de2aa99 100644
--- a/app/Shimakaze.Sdk.Csf.Converter/Program.cs
+++ b/src/Shimakaze.Sdk.Csf.Converter/Program.cs
@@ -6,32 +6,30 @@
using Sharprompt;
-using Shimakaze.Sdk.Common;
using Shimakaze.Sdk.Csf;
-using Shimakaze.Sdk.IO.Csf;
-using Shimakaze.Sdk.IO.Csf.Json;
-using Shimakaze.Sdk.IO.Csf.Xml;
-using Shimakaze.Sdk.IO.Csf.Yaml;
+using Shimakaze.Sdk.Csf.Json;
+using Shimakaze.Sdk.Csf.Xml;
+using Shimakaze.Sdk.Csf.Yaml;
if (args is { Length: < 1 })
throw new ArgumentException("参数太少");
string input = args[0];
-await using var ifs = File.OpenRead(input);
+using Stream ifs = File.OpenRead(input);
ServiceCollection services = new();
string current;
string defaultValue;
-string[] supportFormats = new[] {
+string[] supportFormats = [
"Yaml",
"JsonV2",
"JsonV1",
"Xml",
"Csf"
-};
+];
Func supportFormatNames = value => value switch
{
"Yaml" => "Shimakaze.Sdk 定义的 Yaml 格式",
@@ -45,13 +43,13 @@
switch (Path.GetExtension(input).ToLowerInvariant())
{
case ".csf":
- services.AddSingleton>(new CsfReader(ifs));
+ services.AddSingleton(new CsfReader(ifs));
current = "Csf";
defaultValue = "Yaml";
break;
case ".yml":
case ".yaml":
- services.AddSingleton>(new CsfYamlV1Reader(ifs));
+ services.AddSingleton(new CsfYamlV1Reader(new StreamReader(ifs)));
current = "Yaml";
defaultValue = "Csf";
break;
@@ -78,11 +76,11 @@
switch (protocol)
{
case 2:
- services.AddSingleton>(new CsfJsonV2Reader(ifs, options));
+ services.AddSingleton(new CsfJsonV2Reader(ifs, options));
current = "JsonV2";
break;
case 1:
- services.AddSingleton>(new CsfJsonV1Reader(ifs, options));
+ services.AddSingleton(new CsfJsonV1Reader(ifs, options));
current = "JsonV1";
break;
default:
@@ -93,7 +91,7 @@
break;
case ".xml":
case ".xaml":
- services.AddSingleton>(new CsfXmlV1Reader(ifs));
+ services.AddSingleton(new CsfXmlV1Reader(new StreamReader(ifs)));
current = "Xml";
defaultValue = "Csf";
break;
@@ -133,16 +131,16 @@
_ => throw new NotSupportedException()
});
-await using var ofs = File.Create(output);
-services.AddSingleton>(selected switch
+using Stream ofs = File.Create(output);
+services.AddSingleton(selected switch
{
- "Yaml" => new CsfYamlV1Writer(ofs),
+ "Yaml" => new CsfYamlV1Writer(new StreamWriter(ofs)),
"JsonV2" => new CsfJsonV2Writer(ofs, new() { WriteIndented = true, Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping }),
"JsonV1" => new CsfJsonV1Writer(ofs, new() { WriteIndented = true, Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping }),
- "Xml" => new CsfXmlV1Writer(ofs, new() { Indent = true }),
+ "Xml" => new CsfXmlV1Writer(new StreamWriter(ofs), new() { Indent = true }),
"Csf" => new CsfWriter(ofs),
_ => throw new NotSupportedException()
});
await using var provider = services.BuildServiceProvider();
-var csf = await provider.GetRequiredService>().ReadAsync();
-await provider.GetRequiredService>().WriteAsync(csf);
\ No newline at end of file
+var csf = await provider.GetRequiredService().ReadAsync();
+await provider.GetRequiredService().WriteAsync(csf);
\ No newline at end of file
diff --git a/src/Shimakaze.Sdk.Csf.Converter/Shimakaze.Sdk.Csf.Converter.csproj b/src/Shimakaze.Sdk.Csf.Converter/Shimakaze.Sdk.Csf.Converter.csproj
new file mode 100644
index 00000000..6c5c3213
--- /dev/null
+++ b/src/Shimakaze.Sdk.Csf.Converter/Shimakaze.Sdk.Csf.Converter.csproj
@@ -0,0 +1,21 @@
+
+
+
+ Exe
+ net8.0
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/lib/Shimakaze.Sdk/Csf/Json/Converter/V1/CsfAdvancedValueJsonConverter.cs b/src/Shimakaze.Sdk.Csf.Json/Converter/V1/CsfAdvancedValueJsonConverter.cs
similarity index 100%
rename from lib/Shimakaze.Sdk/Csf/Json/Converter/V1/CsfAdvancedValueJsonConverter.cs
rename to src/Shimakaze.Sdk.Csf.Json/Converter/V1/CsfAdvancedValueJsonConverter.cs
diff --git a/lib/Shimakaze.Sdk/Csf/Json/Converter/V1/CsfDataJsonConverter.cs b/src/Shimakaze.Sdk.Csf.Json/Converter/V1/CsfDataJsonConverter.cs
similarity index 98%
rename from lib/Shimakaze.Sdk/Csf/Json/Converter/V1/CsfDataJsonConverter.cs
rename to src/Shimakaze.Sdk.Csf.Json/Converter/V1/CsfDataJsonConverter.cs
index 5e33f444..f395a217 100644
--- a/lib/Shimakaze.Sdk/Csf/Json/Converter/V1/CsfDataJsonConverter.cs
+++ b/src/Shimakaze.Sdk.Csf.Json/Converter/V1/CsfDataJsonConverter.cs
@@ -52,7 +52,7 @@ public override CsfData Read(ref Utf8JsonReader reader, Type typeToConvert, Json
{
return new(label)
{
- Values = values.ToArray()
+ Values = [.. values]
};
}
else
@@ -117,7 +117,7 @@ internal static List ReadValues(ref Utf8JsonReader reader, JsonSeriali
{
reader.Read().ThrowWhenFalse();
reader.TokenType.ThrowWhenNotToken(JsonTokenType.StartArray);
- List values = new();
+ List values = [];
while (reader.Read().ThrowWhenNull())
{
if (reader.TokenType is JsonTokenType.EndArray)
diff --git a/lib/Shimakaze.Sdk/Csf/Json/Converter/V1/CsfFileJsonConverter.cs b/src/Shimakaze.Sdk.Csf.Json/Converter/V1/CsfFileJsonConverter.cs
similarity index 98%
rename from lib/Shimakaze.Sdk/Csf/Json/Converter/V1/CsfFileJsonConverter.cs
rename to src/Shimakaze.Sdk.Csf.Json/Converter/V1/CsfFileJsonConverter.cs
index 7f246a4d..d1e92fae 100644
--- a/lib/Shimakaze.Sdk/Csf/Json/Converter/V1/CsfFileJsonConverter.cs
+++ b/src/Shimakaze.Sdk.Csf.Json/Converter/V1/CsfFileJsonConverter.cs
@@ -65,7 +65,7 @@ private static List ReadDataList(ref Utf8JsonReader reader, JsonSeriali
{
reader.Read().ThrowWhenNull();
reader.TokenType.ThrowWhenNotToken(JsonTokenType.StartArray);
- List data = new();
+ List data = [];
while (reader.Read().ThrowWhenNull())
{
if (reader.TokenType is JsonTokenType.EndArray)
diff --git a/lib/Shimakaze.Sdk/Csf/Json/Converter/V1/CsfJsonSerializerOptions.cs b/src/Shimakaze.Sdk.Csf.Json/Converter/V1/CsfJsonSerializerOptions.cs
similarity index 100%
rename from lib/Shimakaze.Sdk/Csf/Json/Converter/V1/CsfJsonSerializerOptions.cs
rename to src/Shimakaze.Sdk.Csf.Json/Converter/V1/CsfJsonSerializerOptions.cs
diff --git a/lib/Shimakaze.Sdk/Csf/Json/Converter/V1/CsfLanguageJsonConverter.cs b/src/Shimakaze.Sdk.Csf.Json/Converter/V1/CsfLanguageJsonConverter.cs
similarity index 100%
rename from lib/Shimakaze.Sdk/Csf/Json/Converter/V1/CsfLanguageJsonConverter.cs
rename to src/Shimakaze.Sdk.Csf.Json/Converter/V1/CsfLanguageJsonConverter.cs
diff --git a/lib/Shimakaze.Sdk/Csf/Json/Converter/V1/CsfMetadataJsonConverter.cs b/src/Shimakaze.Sdk.Csf.Json/Converter/V1/CsfMetadataJsonConverter.cs
similarity index 100%
rename from lib/Shimakaze.Sdk/Csf/Json/Converter/V1/CsfMetadataJsonConverter.cs
rename to src/Shimakaze.Sdk.Csf.Json/Converter/V1/CsfMetadataJsonConverter.cs
diff --git a/lib/Shimakaze.Sdk/Csf/Json/Converter/V1/CsfSimpleValueJsonConverter.cs b/src/Shimakaze.Sdk.Csf.Json/Converter/V1/CsfSimpleValueJsonConverter.cs
similarity index 100%
rename from lib/Shimakaze.Sdk/Csf/Json/Converter/V1/CsfSimpleValueJsonConverter.cs
rename to src/Shimakaze.Sdk.Csf.Json/Converter/V1/CsfSimpleValueJsonConverter.cs
diff --git a/lib/Shimakaze.Sdk/Csf/Json/Converter/V1/CsfValueJsonConverter.cs b/src/Shimakaze.Sdk.Csf.Json/Converter/V1/CsfValueJsonConverter.cs
similarity index 100%
rename from lib/Shimakaze.Sdk/Csf/Json/Converter/V1/CsfValueJsonConverter.cs
rename to src/Shimakaze.Sdk.Csf.Json/Converter/V1/CsfValueJsonConverter.cs
diff --git a/lib/Shimakaze.Sdk/Csf/Json/Converter/V2/CsfDataValueJsonConverter.cs b/src/Shimakaze.Sdk.Csf.Json/Converter/V2/CsfDataValueJsonConverter.cs
similarity index 97%
rename from lib/Shimakaze.Sdk/Csf/Json/Converter/V2/CsfDataValueJsonConverter.cs
rename to src/Shimakaze.Sdk.Csf.Json/Converter/V2/CsfDataValueJsonConverter.cs
index 54bc9c40..916efc11 100644
--- a/lib/Shimakaze.Sdk/Csf/Json/Converter/V2/CsfDataValueJsonConverter.cs
+++ b/src/Shimakaze.Sdk.Csf.Json/Converter/V2/CsfDataValueJsonConverter.cs
@@ -15,15 +15,15 @@ public sealed class CsfDataValueJsonConverter : JsonConverter>
{
return reader.TokenType switch
{
- JsonTokenType.String or JsonTokenType.StartArray => new(){
+ JsonTokenType.String or JsonTokenType.StartArray => [
new CsfValue(
reader
.Get(options)
.ThrowWhenNull()
)
- },
+ ],
JsonTokenType.StartObject => ReadAdvancedValue(ref reader, options),
- JsonTokenType.Null => new(),
+ JsonTokenType.Null => [],
_ => reader.TokenType.ThrowNotSupportToken>(),
};
}
@@ -97,13 +97,13 @@ private static List ReadAdvancedValue(ref Utf8JsonReader reader, JsonS
value.ThrowWhenNull();
- return new()
- {
+ return
+ [
string.IsNullOrEmpty(extra) switch
{
true => value.Value,
false => new CsfValue(value.Value.Value, extra)
}
- };
+ ];
}
}
\ No newline at end of file
diff --git a/lib/Shimakaze.Sdk/Csf/Json/Converter/V2/CsfFileJsonConverter.cs b/src/Shimakaze.Sdk.Csf.Json/Converter/V2/CsfFileJsonConverter.cs
similarity index 94%
rename from lib/Shimakaze.Sdk/Csf/Json/Converter/V2/CsfFileJsonConverter.cs
rename to src/Shimakaze.Sdk.Csf.Json/Converter/V2/CsfFileJsonConverter.cs
index 04736212..63801026 100644
--- a/lib/Shimakaze.Sdk/Csf/Json/Converter/V2/CsfFileJsonConverter.cs
+++ b/src/Shimakaze.Sdk.Csf.Json/Converter/V2/CsfFileJsonConverter.cs
@@ -69,7 +69,7 @@ private static List ReadDataList(ref Utf8JsonReader reader, JsonSeriali
{
reader.Read().ThrowWhenNull();
reader.TokenType.ThrowWhenNotToken(JsonTokenType.StartObject);
- List list = new();
+ List list = [];
while (reader.Read().ThrowWhenNull())
{
@@ -77,7 +77,7 @@ private static List ReadDataList(ref Utf8JsonReader reader, JsonSeriali
break;
list.Add(new(reader.GetString().ThrowWhenNull())
{
- Values = reader.Read>(options).ThrowWhenNull().ToArray()
+ Values = [.. reader.Read>(options).ThrowWhenNull()]
});
}
diff --git a/lib/Shimakaze.Sdk/Csf/Json/Converter/V2/CsfJsonSerializerOptions.cs b/src/Shimakaze.Sdk.Csf.Json/Converter/V2/CsfJsonSerializerOptions.cs
similarity index 100%
rename from lib/Shimakaze.Sdk/Csf/Json/Converter/V2/CsfJsonSerializerOptions.cs
rename to src/Shimakaze.Sdk.Csf.Json/Converter/V2/CsfJsonSerializerOptions.cs
diff --git a/lib/Shimakaze.Sdk/IO/Csf/Json/CsfJsonV1Reader.cs b/src/Shimakaze.Sdk.Csf.Json/CsfJsonV1Reader.cs
similarity index 84%
rename from lib/Shimakaze.Sdk/IO/Csf/Json/CsfJsonV1Reader.cs
rename to src/Shimakaze.Sdk.Csf.Json/CsfJsonV1Reader.cs
index 22552a51..c9d610bc 100644
--- a/lib/Shimakaze.Sdk/IO/Csf/Json/CsfJsonV1Reader.cs
+++ b/src/Shimakaze.Sdk.Csf.Json/CsfJsonV1Reader.cs
@@ -1,14 +1,13 @@
using System.Text.Json;
-using Shimakaze.Sdk.Csf;
using Shimakaze.Sdk.Csf.Json.Converter.V1;
-namespace Shimakaze.Sdk.IO.Csf.Json;
+namespace Shimakaze.Sdk.Csf.Json;
///
/// CsfJsonV1Reader.
///
-public sealed class CsfJsonV1Reader : AsyncReader, IDisposable, IAsyncDisposable
+public sealed class CsfJsonV1Reader : AsyncReader, ICsfReader
{
private readonly JsonSerializerOptions _options;
@@ -30,6 +29,8 @@ public CsfJsonV1Reader(Stream stream, JsonSerializerOptions? options = null, boo
///
public override async Task ReadAsync(IProgress? progress = default, CancellationToken cancellationToken = default)
{
- return await JsonSerializer.DeserializeAsync(BaseStream, _options, cancellationToken);
+ return await JsonSerializer.DeserializeAsync(BaseStream, _options, cancellationToken) is not CsfDocument csf
+ ? throw ThrowHelper.CastCsfDocumentException
+ : csf;
}
}
\ No newline at end of file
diff --git a/lib/Shimakaze.Sdk/IO/Csf/Json/CsfJsonV1Writer.cs b/src/Shimakaze.Sdk.Csf.Json/CsfJsonV1Writer.cs
similarity index 91%
rename from lib/Shimakaze.Sdk/IO/Csf/Json/CsfJsonV1Writer.cs
rename to src/Shimakaze.Sdk.Csf.Json/CsfJsonV1Writer.cs
index d9102bed..1da0dfbb 100644
--- a/lib/Shimakaze.Sdk/IO/Csf/Json/CsfJsonV1Writer.cs
+++ b/src/Shimakaze.Sdk.Csf.Json/CsfJsonV1Writer.cs
@@ -1,14 +1,13 @@
using System.Text.Json;
-using Shimakaze.Sdk.Csf;
using Shimakaze.Sdk.Csf.Json.Converter.V1;
-namespace Shimakaze.Sdk.IO.Csf.Json;
+namespace Shimakaze.Sdk.Csf.Json;
///
/// CsfJsonV1Writer.
///
-public sealed class CsfJsonV1Writer : AsyncWriter, IDisposable, IAsyncDisposable
+public sealed class CsfJsonV1Writer : AsyncWriter, ICsfWriter
{
private readonly JsonSerializerOptions _options;
diff --git a/lib/Shimakaze.Sdk/IO/Csf/Json/CsfJsonV2Reader.cs b/src/Shimakaze.Sdk.Csf.Json/CsfJsonV2Reader.cs
similarity index 79%
rename from lib/Shimakaze.Sdk/IO/Csf/Json/CsfJsonV2Reader.cs
rename to src/Shimakaze.Sdk.Csf.Json/CsfJsonV2Reader.cs
index f08b3269..ff621498 100644
--- a/lib/Shimakaze.Sdk/IO/Csf/Json/CsfJsonV2Reader.cs
+++ b/src/Shimakaze.Sdk.Csf.Json/CsfJsonV2Reader.cs
@@ -1,14 +1,13 @@
using System.Text.Json;
-using Shimakaze.Sdk.Csf;
using Shimakaze.Sdk.Csf.Json.Converter.V2;
-namespace Shimakaze.Sdk.IO.Csf.Json;
+namespace Shimakaze.Sdk.Csf.Json;
///
/// CsfJsonV2Reader.
///
-public sealed class CsfJsonV2Reader : AsyncReader, IDisposable, IAsyncDisposable
+public sealed class CsfJsonV2Reader : AsyncReader, ICsfReader
{
private readonly JsonSerializerOptions _options;
@@ -30,12 +29,16 @@ public CsfJsonV2Reader(Stream stream, JsonSerializerOptions? options = null, boo
///
public CsfDocument Deserialize()
{
- return JsonSerializer.Deserialize(BaseStream, _options);
+ return JsonSerializer.Deserialize(BaseStream, _options) is not CsfDocument csf
+ ? throw ThrowHelper.CastCsfDocumentException
+ : csf;
}
///
public override async Task ReadAsync(IProgress? progress = default, CancellationToken cancellationToken = default)
{
- return await JsonSerializer.DeserializeAsync(BaseStream, _options, cancellationToken);
+ return await JsonSerializer.DeserializeAsync(BaseStream, _options, cancellationToken) is not CsfDocument csf
+ ? throw ThrowHelper.CastCsfDocumentException
+ : csf;
}
}
\ No newline at end of file
diff --git a/lib/Shimakaze.Sdk/IO/Csf/Json/CsfJsonV2Writer.cs b/src/Shimakaze.Sdk.Csf.Json/CsfJsonV2Writer.cs
similarity index 91%
rename from lib/Shimakaze.Sdk/IO/Csf/Json/CsfJsonV2Writer.cs
rename to src/Shimakaze.Sdk.Csf.Json/CsfJsonV2Writer.cs
index 6a2201da..b521e9e3 100644
--- a/lib/Shimakaze.Sdk/IO/Csf/Json/CsfJsonV2Writer.cs
+++ b/src/Shimakaze.Sdk.Csf.Json/CsfJsonV2Writer.cs
@@ -1,14 +1,13 @@
using System.Text.Json;
-using Shimakaze.Sdk.Csf;
using Shimakaze.Sdk.Csf.Json.Converter.V2;
-namespace Shimakaze.Sdk.IO.Csf.Json;
+namespace Shimakaze.Sdk.Csf.Json;
///
/// CsfJsonV2Writer.
///
-public sealed class CsfJsonV2Writer : AsyncWriter, IDisposable, IAsyncDisposable
+public sealed class CsfJsonV2Writer : AsyncWriter, ICsfWriter
{
private readonly JsonSerializerOptions _options;
diff --git a/lib/Shimakaze.Sdk/Csf/Json/JsonConstants.cs b/src/Shimakaze.Sdk.Csf.Json/JsonConstants.cs
similarity index 90%
rename from lib/Shimakaze.Sdk/Csf/Json/JsonConstants.cs
rename to src/Shimakaze.Sdk.Csf.Json/JsonConstants.cs
index 4f0cdebd..d25b923c 100644
--- a/lib/Shimakaze.Sdk/Csf/Json/JsonConstants.cs
+++ b/src/Shimakaze.Sdk.Csf.Json/JsonConstants.cs
@@ -1,11 +1,8 @@
-using System.Diagnostics.CodeAnalysis;
-
namespace Shimakaze.Sdk.Csf.Json;
///
/// JsonConstants.
///
-[ExcludeFromCodeCoverage]
internal class JsonConstants
{
///
diff --git a/lib/Shimakaze.Sdk/Csf/Json/JsonConverterExtensions.cs b/src/Shimakaze.Sdk.Csf.Json/JsonConverterExtensions.cs
similarity index 87%
rename from lib/Shimakaze.Sdk/Csf/Json/JsonConverterExtensions.cs
rename to src/Shimakaze.Sdk.Csf.Json/JsonConverterExtensions.cs
index 40dc1cbc..5d675602 100644
--- a/lib/Shimakaze.Sdk/Csf/Json/JsonConverterExtensions.cs
+++ b/src/Shimakaze.Sdk.Csf.Json/JsonConverterExtensions.cs
@@ -1,10 +1,8 @@
-using System.Diagnostics.CodeAnalysis;
-using System.Text.Json;
+using System.Text.Json;
using System.Text.Json.Serialization;
namespace Shimakaze.Sdk.Csf.Json;
-[ExcludeFromCodeCoverage]
internal static class JsonConverterExtensions
{
public static TJsonConverter Get(this JsonSerializerOptions options)
diff --git a/src/Shimakaze.Sdk.Csf.Json/Shimakaze.Sdk.Csf.Json.csproj b/src/Shimakaze.Sdk.Csf.Json/Shimakaze.Sdk.Csf.Json.csproj
new file mode 100644
index 00000000..5d8b9a6a
--- /dev/null
+++ b/src/Shimakaze.Sdk.Csf.Json/Shimakaze.Sdk.Csf.Json.csproj
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
diff --git a/lib/Shimakaze.Sdk/Csf/Json/ThrowHelper.cs b/src/Shimakaze.Sdk.Csf.Json/ThrowHelper.cs
similarity index 71%
rename from lib/Shimakaze.Sdk/Csf/Json/ThrowHelper.cs
rename to src/Shimakaze.Sdk.Csf.Json/ThrowHelper.cs
index 639938c4..731d4f61 100644
--- a/lib/Shimakaze.Sdk/Csf/Json/ThrowHelper.cs
+++ b/src/Shimakaze.Sdk.Csf.Json/ThrowHelper.cs
@@ -1,23 +1,26 @@
+using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Text.Json;
namespace Shimakaze.Sdk.Csf.Json;
-[ExcludeFromCodeCoverage]
+[StackTraceHidden]
internal static class ThrowHelper
{
[DoesNotReturn]
public static T ThrowNotSupportToken(this JsonTokenType value)
{
- throw new JsonException($"Not Support Token \"{value}\"");
+ throw new NotSupportedException("Not Support", new JsonException($"Unsupported Token \"{value}\""));
}
[DoesNotReturn]
public static TResult ThrowNotSupportValue(this TValue value)
{
- throw new JsonException($"Not Support Value \"{value}\"");
+ throw new NotSupportedException("Not Support", new JsonException($"Unsupported Value \"{value}\""));
}
+ public static InvalidCastException CastCsfDocumentException => new($"Cannot Convert as CsfDocument");
+
public static void ThrowWhenFalse(this bool value, string message)
{
if (!value)
diff --git a/lib/Shimakaze.Sdk/Csf/Json/Utf8JsonReaderExtensions.cs b/src/Shimakaze.Sdk.Csf.Json/Utf8JsonReaderExtensions.cs
similarity index 92%
rename from lib/Shimakaze.Sdk/Csf/Json/Utf8JsonReaderExtensions.cs
rename to src/Shimakaze.Sdk.Csf.Json/Utf8JsonReaderExtensions.cs
index 48355319..240edc24 100644
--- a/lib/Shimakaze.Sdk/Csf/Json/Utf8JsonReaderExtensions.cs
+++ b/src/Shimakaze.Sdk.Csf.Json/Utf8JsonReaderExtensions.cs
@@ -1,10 +1,8 @@
-using System.Diagnostics.CodeAnalysis;
-using System.Text.Json;
+using System.Text.Json;
using System.Text.Json.Serialization;
namespace Shimakaze.Sdk.Csf.Json;
-[ExcludeFromCodeCoverage]
internal static class Utf8JsonReaderExtensions
{
public static T? Get(this ref Utf8JsonReader reader, JsonSerializerOptions options)
diff --git a/lib/Shimakaze.Sdk/Csf/Json/Utf8JsonWriterExtensions.cs b/src/Shimakaze.Sdk.Csf.Json/Utf8JsonWriterExtensions.cs
similarity index 91%
rename from lib/Shimakaze.Sdk/Csf/Json/Utf8JsonWriterExtensions.cs
rename to src/Shimakaze.Sdk.Csf.Json/Utf8JsonWriterExtensions.cs
index dd1da4a4..e5ad47bf 100644
--- a/lib/Shimakaze.Sdk/Csf/Json/Utf8JsonWriterExtensions.cs
+++ b/src/Shimakaze.Sdk.Csf.Json/Utf8JsonWriterExtensions.cs
@@ -1,10 +1,8 @@
-using System.Diagnostics.CodeAnalysis;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Shimakaze.Sdk.Csf.Json;
-[ExcludeFromCodeCoverage]
internal static class Utf8JsonWriterExtensions
{
public static void WriteProperty(this Utf8JsonWriter writer, string propertyName, T value, JsonSerializerOptions options)
diff --git a/lib/Shimakaze.Sdk/Csf/Xml/Converter/IXmlSerializer.cs b/src/Shimakaze.Sdk.Csf.Xml/Converter/IXmlSerializer.cs
similarity index 100%
rename from lib/Shimakaze.Sdk/Csf/Xml/Converter/IXmlSerializer.cs
rename to src/Shimakaze.Sdk.Csf.Xml/Converter/IXmlSerializer.cs
diff --git a/lib/Shimakaze.Sdk/Csf/Xml/Converter/V1/CsfDataListXmlSerializer.cs b/src/Shimakaze.Sdk.Csf.Xml/Converter/V1/CsfDataListXmlSerializer.cs
similarity index 96%
rename from lib/Shimakaze.Sdk/Csf/Xml/Converter/V1/CsfDataListXmlSerializer.cs
rename to src/Shimakaze.Sdk.Csf.Xml/Converter/V1/CsfDataListXmlSerializer.cs
index dd74229c..fd3cc4f1 100644
--- a/lib/Shimakaze.Sdk/Csf/Xml/Converter/V1/CsfDataListXmlSerializer.cs
+++ b/src/Shimakaze.Sdk.Csf.Xml/Converter/V1/CsfDataListXmlSerializer.cs
@@ -12,7 +12,7 @@ public class CsfDataListXmlSerializer : IXmlSerializer>
///
public IList Deserialize(XmlReader reader)
{
- List data = new();
+ List data = [];
while (reader.Read())
{
switch (reader.NodeType)
diff --git a/lib/Shimakaze.Sdk/Csf/Xml/Converter/V1/CsfDataXmlSerializer.cs b/src/Shimakaze.Sdk.Csf.Xml/Converter/V1/CsfDataXmlSerializer.cs
similarity index 94%
rename from lib/Shimakaze.Sdk/Csf/Xml/Converter/V1/CsfDataXmlSerializer.cs
rename to src/Shimakaze.Sdk.Csf.Xml/Converter/V1/CsfDataXmlSerializer.cs
index e635cf11..06d2efee 100644
--- a/lib/Shimakaze.Sdk/Csf/Xml/Converter/V1/CsfDataXmlSerializer.cs
+++ b/src/Shimakaze.Sdk.Csf.Xml/Converter/V1/CsfDataXmlSerializer.cs
@@ -23,7 +23,7 @@ public CsfData Deserialize(XmlReader reader)
label.Values = reader.GetAttribute("extra") switch
{
not null => new[] { _csfValueXmlSerializer.Deserialize(reader) },
- _ => _csfValueListXmlSerializer.Deserialize(reader).ToArray(),
+ _ => [.. _csfValueListXmlSerializer.Deserialize(reader)],
};
}
return label;
diff --git a/lib/Shimakaze.Sdk/Csf/Xml/Converter/V1/CsfDocumentXmlSerializer.cs b/src/Shimakaze.Sdk.Csf.Xml/Converter/V1/CsfDocumentXmlSerializer.cs
similarity index 89%
rename from lib/Shimakaze.Sdk/Csf/Xml/Converter/V1/CsfDocumentXmlSerializer.cs
rename to src/Shimakaze.Sdk.Csf.Xml/Converter/V1/CsfDocumentXmlSerializer.cs
index 1e938825..c377bb77 100644
--- a/lib/Shimakaze.Sdk/Csf/Xml/Converter/V1/CsfDocumentXmlSerializer.cs
+++ b/src/Shimakaze.Sdk.Csf.Xml/Converter/V1/CsfDocumentXmlSerializer.cs
@@ -1,3 +1,4 @@
+using System.Globalization;
using System.Xml;
namespace Shimakaze.Sdk.Csf.Xml.Converter.V1;
@@ -31,7 +32,7 @@ public CsfDocument Deserialize(XmlReader reader)
return new()
{
Metadata = head,
- Data = _csfDataListXmlSerializer.Deserialize(reader).ToArray()
+ Data = [.. _csfDataListXmlSerializer.Deserialize(reader)]
};
}
@@ -44,8 +45,8 @@ public void Serialize(XmlWriter writer, CsfDocument value)
//
writer.WriteStartElement("Resources");
writer.WriteAttributeString("protocol", "1");
- writer.WriteAttributeString("version", value.Metadata.Version.ToString());
- writer.WriteAttributeString("language", value.Metadata.Language.ToString());
+ writer.WriteAttributeString("version", value.Metadata.Version.ToString(CultureInfo.InvariantCulture));
+ writer.WriteAttributeString("language", value.Metadata.Language.ToString(CultureInfo.InvariantCulture));
_csfDataListXmlSerializer.Serialize(writer, value.Data);
diff --git a/lib/Shimakaze.Sdk/Csf/Xml/Converter/V1/CsfValueListXmlSerializer.cs b/src/Shimakaze.Sdk.Csf.Xml/Converter/V1/CsfValueListXmlSerializer.cs
similarity index 98%
rename from lib/Shimakaze.Sdk/Csf/Xml/Converter/V1/CsfValueListXmlSerializer.cs
rename to src/Shimakaze.Sdk.Csf.Xml/Converter/V1/CsfValueListXmlSerializer.cs
index 9809cacd..b5c0823b 100644
--- a/lib/Shimakaze.Sdk/Csf/Xml/Converter/V1/CsfValueListXmlSerializer.cs
+++ b/src/Shimakaze.Sdk.Csf.Xml/Converter/V1/CsfValueListXmlSerializer.cs
@@ -12,7 +12,7 @@ public class CsfValueListXmlSerializer : IXmlSerializer>
///
public IList Deserialize(XmlReader reader)
{
- List values = new();
+ List values = [];
while (reader.Read())
{
switch (reader.NodeType)
diff --git a/lib/Shimakaze.Sdk/Csf/Xml/Converter/V1/CsfValueXmlSerializer.cs b/src/Shimakaze.Sdk.Csf.Xml/Converter/V1/CsfValueXmlSerializer.cs
similarity index 100%
rename from lib/Shimakaze.Sdk/Csf/Xml/Converter/V1/CsfValueXmlSerializer.cs
rename to src/Shimakaze.Sdk.Csf.Xml/Converter/V1/CsfValueXmlSerializer.cs
diff --git a/src/Shimakaze.Sdk.Csf.Xml/CsfXmlV1Reader.cs b/src/Shimakaze.Sdk.Csf.Xml/CsfXmlV1Reader.cs
new file mode 100644
index 00000000..09d281a2
--- /dev/null
+++ b/src/Shimakaze.Sdk.Csf.Xml/CsfXmlV1Reader.cs
@@ -0,0 +1,27 @@
+using System.Xml;
+
+using Shimakaze.Sdk.Csf.Xml.Converter.V1;
+
+namespace Shimakaze.Sdk.Csf.Xml;
+
+///
+/// CsfXmlV1Reader.
+///
+///
+/// 构造器
+///
+/// 基础流
+/// 退出时是否保持流打开
+public sealed class CsfXmlV1Reader(TextReader stream, bool leaveOpen = false) : AsyncTextReader(stream, leaveOpen), ICsfReader
+{
+
+ ///
+ public override async Task ReadAsync(IProgress? progress = default, CancellationToken cancellationToken = default)
+ {
+ await Task.Yield();
+
+ CsfDocumentXmlSerializer serializer = new();
+ using XmlReader xmlReader = XmlReader.Create(BaseReader);
+ return serializer.Deserialize(xmlReader);
+ }
+}
\ No newline at end of file
diff --git a/src/Shimakaze.Sdk.Csf.Xml/CsfXmlV1Writer.cs b/src/Shimakaze.Sdk.Csf.Xml/CsfXmlV1Writer.cs
new file mode 100644
index 00000000..ff598cfc
--- /dev/null
+++ b/src/Shimakaze.Sdk.Csf.Xml/CsfXmlV1Writer.cs
@@ -0,0 +1,28 @@
+using System.Xml;
+
+using Shimakaze.Sdk.Csf.Xml.Converter.V1;
+
+namespace Shimakaze.Sdk.Csf.Xml;
+
+///
+/// CsfXmlV1Writer.
+///
+///
+///
+///
+///
+///
+/// ˳ʱǷ
+public sealed class CsfXmlV1Writer(TextWriter stream, XmlWriterSettings? settings = null, bool leaveOpen = false) : AsyncTextWriter(stream, leaveOpen), ICsfWriter
+{
+
+ ///
+ public override async Task WriteAsync(CsfDocument value, IProgress? progress = default, CancellationToken cancellationToken = default)
+ {
+ await Task.Yield();
+
+ CsfDocumentXmlSerializer serializer = new();
+ using XmlWriter xmlWriter = XmlWriter.Create(BaseWriter, settings);
+ serializer.Serialize(xmlWriter, value);
+ }
+}
\ No newline at end of file
diff --git a/src/Shimakaze.Sdk.Csf.Xml/Shimakaze.Sdk.Csf.Xml.csproj b/src/Shimakaze.Sdk.Csf.Xml/Shimakaze.Sdk.Csf.Xml.csproj
new file mode 100644
index 00000000..e51e71ce
--- /dev/null
+++ b/src/Shimakaze.Sdk.Csf.Xml/Shimakaze.Sdk.Csf.Xml.csproj
@@ -0,0 +1,5 @@
+
+
+
+
+
diff --git a/lib/Shimakaze.Sdk/Csf/Xml/XmlConstants.cs b/src/Shimakaze.Sdk.Csf.Xml/XmlConstants.cs
similarity index 79%
rename from lib/Shimakaze.Sdk/Csf/Xml/XmlConstants.cs
rename to src/Shimakaze.Sdk.Csf.Xml/XmlConstants.cs
index 844a7308..84cd0825 100644
--- a/lib/Shimakaze.Sdk/Csf/Xml/XmlConstants.cs
+++ b/src/Shimakaze.Sdk.Csf.Xml/XmlConstants.cs
@@ -1,8 +1,5 @@
-using System.Diagnostics.CodeAnalysis;
-
namespace Shimakaze.Sdk.Csf.Xml;
-[ExcludeFromCodeCoverage]
internal class XmlConstants
{
public static class SchemaUrls
diff --git a/lib/Shimakaze.Sdk/Csf/Yaml/Converter/V1/CsfDataConverter.cs b/src/Shimakaze.Sdk.Csf.Yaml/Converter/V1/CsfDataConverter.cs
similarity index 94%
rename from lib/Shimakaze.Sdk/Csf/Yaml/Converter/V1/CsfDataConverter.cs
rename to src/Shimakaze.Sdk.Csf.Yaml/Converter/V1/CsfDataConverter.cs
index a8793042..c306dedb 100644
--- a/lib/Shimakaze.Sdk/Csf/Yaml/Converter/V1/CsfDataConverter.cs
+++ b/src/Shimakaze.Sdk.Csf.Yaml/Converter/V1/CsfDataConverter.cs
@@ -36,7 +36,7 @@ public static CsfDataConverter Instance
if (parser.Accept(out var label))
{
CsfData data = new(label.Value);
- List values = new();
+ List values = [];
if (parser.TryConsume(out _))
{
ParseValue(parser, values);
@@ -49,7 +49,7 @@ public static CsfDataConverter Instance
}
}
- data.Values = values.ToArray();
+ data.Values = [.. values];
data.ReCount();
return data;
}
@@ -91,7 +91,7 @@ public void WriteYaml(IEmitter emitter, object? value, Type type)
}
}
- private static void ParseValue(IParser parser, IList data)
+ private static void ParseValue(IParser parser, List data)
{
if (CsfValueConverter.Instance.ReadYaml(parser, typeof(CsfValue)) is CsfValue value)
{
diff --git a/lib/Shimakaze.Sdk/Csf/Yaml/Converter/V1/CsfDocumentConverter.cs b/src/Shimakaze.Sdk.Csf.Yaml/Converter/V1/CsfDocumentConverter.cs
similarity index 93%
rename from lib/Shimakaze.Sdk/Csf/Yaml/Converter/V1/CsfDocumentConverter.cs
rename to src/Shimakaze.Sdk.Csf.Yaml/Converter/V1/CsfDocumentConverter.cs
index 9da9eec7..391d0c0e 100644
--- a/lib/Shimakaze.Sdk/Csf/Yaml/Converter/V1/CsfDocumentConverter.cs
+++ b/src/Shimakaze.Sdk.Csf.Yaml/Converter/V1/CsfDocumentConverter.cs
@@ -1,4 +1,6 @@
-using YamlDotNet.Core;
+using System.Globalization;
+
+using YamlDotNet.Core;
using YamlDotNet.Core.Events;
using YamlDotNet.Serialization;
@@ -47,7 +49,7 @@ public static CsfDocumentConverter Instance
CsfDocument doc = new();
CsfMetadata metadata = doc.Metadata;
- List datas = new();
+ List datas = [];
parser.Consume();
while (!parser.TryConsume(out _))
@@ -72,7 +74,7 @@ public static CsfDocumentConverter Instance
case "version":
if (parser.TryConsume(out var scalar2))
{
- metadata.Version = int.Parse(scalar2.Value);
+ metadata.Version = int.Parse(scalar2.Value, CultureInfo.InvariantCulture);
}
break;
@@ -96,7 +98,7 @@ public static CsfDocumentConverter Instance
metadata.LabelCount = doc.Data.Length;
metadata.StringCount = doc.Data.Sum(i => i.StringCount);
doc.Metadata = metadata;
- doc.Data = datas.ToArray();
+ doc.Data = [.. datas];
doc.ReCount();
return doc;
}
@@ -118,11 +120,11 @@ public void WriteYaml(IEmitter emitter, object? value, Type type)
}
else
{
- emitter.Emit(new Scalar(doc.Metadata.Language.ToString()));
+ emitter.Emit(new Scalar(doc.Metadata.Language.ToString(CultureInfo.InvariantCulture)));
}
emitter.Emit(new Scalar("version"));
- emitter.Emit(new Scalar(doc.Metadata.Version.ToString()));
+ emitter.Emit(new Scalar(doc.Metadata.Version.ToString(CultureInfo.InvariantCulture)));
emitter.Emit(new MappingEnd());
emitter.Emit(new DocumentEnd(true));
emitter.Emit(new DocumentStart());
diff --git a/lib/Shimakaze.Sdk/Csf/Yaml/Converter/V1/CsfValueConverter.cs b/src/Shimakaze.Sdk.Csf.Yaml/Converter/V1/CsfValueConverter.cs
similarity index 98%
rename from lib/Shimakaze.Sdk/Csf/Yaml/Converter/V1/CsfValueConverter.cs
rename to src/Shimakaze.Sdk.Csf.Yaml/Converter/V1/CsfValueConverter.cs
index e6917a65..4fd38f06 100644
--- a/lib/Shimakaze.Sdk/Csf/Yaml/Converter/V1/CsfValueConverter.cs
+++ b/src/Shimakaze.Sdk.Csf.Yaml/Converter/V1/CsfValueConverter.cs
@@ -39,7 +39,7 @@ public static CsfValueConverter Instance
}
else if (parser.TryConsume(out _))
{
- Dictionary map = new();
+ Dictionary map = [];
string? key = null;
while (!parser.TryConsume(out _))
{
diff --git a/src/Shimakaze.Sdk.Csf.Yaml/CsfYamlV1Reader.cs b/src/Shimakaze.Sdk.Csf.Yaml/CsfYamlV1Reader.cs
new file mode 100644
index 00000000..2084eecc
--- /dev/null
+++ b/src/Shimakaze.Sdk.Csf.Yaml/CsfYamlV1Reader.cs
@@ -0,0 +1,29 @@
+using Shimakaze.Sdk.Csf.Yaml.Converter.V1;
+
+using YamlDotNet.Serialization;
+
+namespace Shimakaze.Sdk.Csf.Yaml;
+
+///
+/// CSF YAML Deserializer.
+///
+///
+/// 构造器
+///
+/// 基础流
+/// 退出时是否保持流打开
+public sealed class CsfYamlV1Reader(TextReader reader, bool leaveOpen = false) : AsyncTextReader(reader, leaveOpen), ICsfReader
+{
+ ///
+ public override async Task ReadAsync(IProgress? progress = default, CancellationToken cancellationToken = default)
+ {
+ await Task.Yield();
+
+ return new DeserializerBuilder()
+ .WithTypeConverter(CsfValueConverter.Instance)
+ .WithTypeConverter(CsfDataConverter.Instance)
+ .WithTypeConverter(CsfDocumentConverter.Instance)
+ .Build()
+ .Deserialize(BaseReader);
+ }
+}
\ No newline at end of file
diff --git a/lib/Shimakaze.Sdk/IO/Csf/Yaml/CsfYamlV1Writer.cs b/src/Shimakaze.Sdk.Csf.Yaml/CsfYamlV1Writer.cs
similarity index 52%
rename from lib/Shimakaze.Sdk/IO/Csf/Yaml/CsfYamlV1Writer.cs
rename to src/Shimakaze.Sdk.Csf.Yaml/CsfYamlV1Writer.cs
index 6061ce09..512ab34c 100644
--- a/lib/Shimakaze.Sdk/IO/Csf/Yaml/CsfYamlV1Writer.cs
+++ b/src/Shimakaze.Sdk.Csf.Yaml/CsfYamlV1Writer.cs
@@ -1,35 +1,30 @@
-using Shimakaze.Sdk.Csf;
using Shimakaze.Sdk.Csf.Yaml.Converter.V1;
using YamlDotNet.Serialization;
-namespace Shimakaze.Sdk.IO.Csf.Yaml;
+namespace Shimakaze.Sdk.Csf.Yaml;
///
/// CSF YAML Serializer.
///
-public sealed class CsfYamlV1Writer : AsyncWriter, IDisposable, IAsyncDisposable
+///
+///
+///
+///
+/// ˳ʱǷ
+public sealed class CsfYamlV1Writer(TextWriter stream, bool leaveOpen = false) : AsyncTextWriter(stream, leaveOpen), ICsfWriter
{
- ///
- ///
- ///
- ///
- /// ˳ʱǷ
- public CsfYamlV1Writer(Stream stream, bool leaveOpen = false) : base(stream, leaveOpen)
- {
- }
///
public override async Task WriteAsync(CsfDocument value, IProgress? progress = default, CancellationToken cancellationToken = default)
{
await Task.Yield();
- using StreamWriter writer = new(BaseStream, leaveOpen: true);
new SerializerBuilder()
.WithTypeConverter(CsfValueConverter.Instance)
.WithTypeConverter(CsfDataConverter.Instance)
.WithTypeConverter(CsfDocumentConverter.Instance)
.Build()
- .Serialize(writer, value);
+ .Serialize(BaseWriter, value);
}
}
\ No newline at end of file
diff --git a/src/Shimakaze.Sdk.Csf.Yaml/Shimakaze.Sdk.Csf.Yaml.csproj b/src/Shimakaze.Sdk.Csf.Yaml/Shimakaze.Sdk.Csf.Yaml.csproj
new file mode 100644
index 00000000..2df29bdc
--- /dev/null
+++ b/src/Shimakaze.Sdk.Csf.Yaml/Shimakaze.Sdk.Csf.Yaml.csproj
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
diff --git a/lib/Shimakaze.Sdk/Csf/Yaml/YamlConstants.cs b/src/Shimakaze.Sdk.Csf.Yaml/YamlConstants.cs
similarity index 85%
rename from lib/Shimakaze.Sdk/Csf/Yaml/YamlConstants.cs
rename to src/Shimakaze.Sdk.Csf.Yaml/YamlConstants.cs
index 400255f2..0e0f911b 100644
--- a/lib/Shimakaze.Sdk/Csf/Yaml/YamlConstants.cs
+++ b/src/Shimakaze.Sdk.Csf.Yaml/YamlConstants.cs
@@ -1,18 +1,15 @@
-using System.Diagnostics.CodeAnalysis;
-
namespace Shimakaze.Sdk.Csf.Yaml;
///
/// YamlConstants.
///
-[ExcludeFromCodeCoverage]
internal class YamlConstants
{
///
/// LanguageList.
///
- public static readonly List LanguageList = new()
- {
+ public static readonly List LanguageList =
+ [
"en_US",
"en_UK",
"de",
@@ -23,7 +20,7 @@ internal class YamlConstants
"Jabberwockie",
"kr",
"zh",
- };
+ ];
///
/// SchemaUrls.
diff --git a/lib/Shimakaze.Sdk/Csf/CsfConstants.cs b/src/Shimakaze.Sdk.Csf/CsfConstants.cs
similarity index 94%
rename from lib/Shimakaze.Sdk/Csf/CsfConstants.cs
rename to src/Shimakaze.Sdk.Csf/CsfConstants.cs
index f0177481..a86c5af6 100644
--- a/lib/Shimakaze.Sdk/Csf/CsfConstants.cs
+++ b/src/Shimakaze.Sdk.Csf/CsfConstants.cs
@@ -1,11 +1,8 @@
-using System.Diagnostics.CodeAnalysis;
-
-namespace Shimakaze.Sdk.Csf;
+namespace Shimakaze.Sdk.Csf;
///
/// CsfConstants.
///
-[ExcludeFromCodeCoverage]
public static class CsfConstants
{
///
diff --git a/lib/Shimakaze.Sdk/Csf/CsfData.cs b/src/Shimakaze.Sdk.Csf/CsfData.cs
similarity index 68%
rename from lib/Shimakaze.Sdk/Csf/CsfData.cs
rename to src/Shimakaze.Sdk.Csf/CsfData.cs
index b8594408..dda27073 100644
--- a/lib/Shimakaze.Sdk/Csf/CsfData.cs
+++ b/src/Shimakaze.Sdk.Csf/CsfData.cs
@@ -3,8 +3,13 @@
///
/// Csf Data.
///
-public record struct CsfData
+public record class CsfData
{
+ internal int InternalIdentifier = CsfConstants.LblFlagRaw;
+ internal int InternalStringCount;
+ internal int InternalLabelNameLength;
+ internal string InternalLabelName;
+
///
/// Initializes a new instance of the class.
///
@@ -43,37 +48,52 @@ public CsfData(string labelName, IEnumerable values)
/// values.
public CsfData(int identifier, int stringCount, int labelNameLength, string labelName, IEnumerable values)
{
- Identifier = identifier;
- StringCount = stringCount;
- LabelNameLength = labelNameLength;
- LabelName = labelName;
+ InternalIdentifier = identifier;
+ InternalStringCount = stringCount;
+ InternalLabelNameLength = labelNameLength;
+ InternalLabelName = labelName;
Values = values.ToArray();
}
///
/// Gets or sets identifier.
///
- public int Identifier = CsfConstants.LblFlagRaw;
-
+ public int Identifier
+ {
+ get => InternalIdentifier;
+ set => InternalIdentifier = value;
+ }
///
/// Gets or sets stringCount.
///
- public int StringCount;
+ public int StringCount
+ {
+ get => InternalStringCount;
+ set => InternalStringCount = value;
+ }
///
/// Gets or sets labelNameLength.
///
- public int LabelNameLength;
+ public int LabelNameLength
+ {
+ get => InternalLabelNameLength;
+ set => InternalLabelNameLength = value;
+ }
///
/// Gets or sets labelName.
///
- public string LabelName;
+ public string LabelName
+ {
+ get => InternalLabelName;
+ set => InternalLabelName = value;
+ }
///
/// Gets or sets values.
///
- public CsfValue[] Values;
+ public CsfValue[] Values { get; set; }
///
/// Re Count.
diff --git a/lib/Shimakaze.Sdk/Csf/CsfDocument.cs b/src/Shimakaze.Sdk.Csf/CsfDocument.cs
similarity index 76%
rename from lib/Shimakaze.Sdk/Csf/CsfDocument.cs
rename to src/Shimakaze.Sdk.Csf/CsfDocument.cs
index f4f42a76..0bf921f8 100644
--- a/lib/Shimakaze.Sdk/Csf/CsfDocument.cs
+++ b/src/Shimakaze.Sdk.Csf/CsfDocument.cs
@@ -3,8 +3,10 @@
///
/// Csf Document.
///
-public record struct CsfDocument
+public record class CsfDocument
{
+ internal CsfMetadata InternalMetadata;
+
///
/// Initializes a new instance of the class.
///
@@ -36,12 +38,16 @@ public CsfDocument(CsfMetadata metadata, IEnumerable data)
///
/// Gets or sets metadata.
///
- public CsfMetadata Metadata;
+ public CsfMetadata Metadata
+ {
+ get => InternalMetadata;
+ set => InternalMetadata = value;
+ }
///
/// Gets or sets datas.
///
- public CsfData[] Data = Array.Empty();
+ public CsfData[] Data { get; set; } = [];
///
/// ReCount.
@@ -51,7 +57,7 @@ public void ReCount()
foreach (CsfData item in Data)
item.ReCount();
- Metadata.LabelCount = Data.Length;
- Metadata.StringCount = Data.Select(x => x.StringCount).Sum();
+ InternalMetadata.LabelCount = Data.Length;
+ InternalMetadata.StringCount = Data.Select(x => x.StringCount).Sum();
}
}
\ No newline at end of file
diff --git a/lib/Shimakaze.Sdk/Csf/CsfMetadata.cs b/src/Shimakaze.Sdk.Csf/CsfMetadata.cs
similarity index 82%
rename from lib/Shimakaze.Sdk/Csf/CsfMetadata.cs
rename to src/Shimakaze.Sdk.Csf/CsfMetadata.cs
index 8a2b7fc4..82eefbf8 100644
--- a/lib/Shimakaze.Sdk/Csf/CsfMetadata.cs
+++ b/src/Shimakaze.Sdk.Csf/CsfMetadata.cs
@@ -4,7 +4,7 @@ namespace Shimakaze.Sdk.Csf;
///
/// CsfMetadata.
///
-[StructLayout(LayoutKind.Explicit)]
+[StructLayout(LayoutKind.Sequential)]
public record struct CsfMetadata
{
///
@@ -32,36 +32,30 @@ public CsfMetadata(int version, int language)
///
/// Identifier.
///
- [FieldOffset(sizeof(int) * 0)]
public int Identifier;
///
/// Version.
///
- [FieldOffset(sizeof(int) * 1)]
public int Version;
///
/// LabelCount.
///
- [FieldOffset(sizeof(int) * 2)]
public int LabelCount;
///
/// StringCount.
///
- [FieldOffset(sizeof(int) * 3)]
public int StringCount;
///
/// Unknown.
///
- [FieldOffset(sizeof(int) * 4)]
public int Unknown;
///
/// Language.
///
- [FieldOffset(sizeof(int) * 5)]
public int Language;
};
\ No newline at end of file
diff --git a/lib/Shimakaze.Sdk/IO/Csf/CsfReader.cs b/src/Shimakaze.Sdk.Csf/CsfReader.cs
similarity index 60%
rename from lib/Shimakaze.Sdk/IO/Csf/CsfReader.cs
rename to src/Shimakaze.Sdk.Csf/CsfReader.cs
index c0908112..b24b4459 100644
--- a/lib/Shimakaze.Sdk/IO/Csf/CsfReader.cs
+++ b/src/Shimakaze.Sdk.Csf/CsfReader.cs
@@ -1,26 +1,20 @@
-using Shimakaze.Sdk.Csf;
-
-namespace Shimakaze.Sdk.IO.Csf;
+namespace Shimakaze.Sdk.Csf;
///
/// Csf ȡ
///
-public sealed class CsfReader : AsyncReader, IDisposable, IAsyncDisposable
+///
+/// Csf ȡ
+///
+///
+/// ˳ʱǷ
+public sealed class CsfReader(Stream stream, bool leaveOpen = false) : AsyncReader(stream, leaveOpen), ICsfReader
{
- ///
- /// Csf ȡ
- ///
- ///
- /// ˳ʱǷ
- public CsfReader(Stream stream, bool leaveOpen = false) : base(stream, leaveOpen)
- {
- }
-
///
public override async Task ReadAsync(IProgress? progress = default, CancellationToken cancellationToken = default)
{
CsfDocument csf = new();
- BaseStream.Read(out csf.Metadata);
+ BaseStream.Read(out csf.InternalMetadata);
CsfThrowHelper.IsCsfFile(csf.Metadata.Identifier);
csf.Data = new CsfData[csf.Metadata.LabelCount];
@@ -29,24 +23,25 @@ public override async Task ReadAsync(IProgress? progress = d
for (int i = 0; i < csf.Metadata.LabelCount; i++)
{
cancellationToken.ThrowIfCancellationRequested();
+ csf.Data[i] ??= new();
progress?.Report((float)i / csf.Data.Length);
- BaseStream.Read(out csf.Data[i].Identifier);
+ BaseStream.Read(out csf.Data[i].InternalIdentifier);
CsfThrowHelper.IsLabel(csf.Data[i].Identifier, () => new object[] { i, BaseStream.Position });
- BaseStream.Read(out csf.Data[i].StringCount);
- BaseStream.Read(out csf.Data[i].LabelNameLength);
- BaseStream.Read(out csf.Data[i].LabelName, csf.Data[i].LabelNameLength);
+ BaseStream.Read(out csf.Data[i].InternalStringCount);
+ BaseStream.Read(out csf.Data[i].InternalLabelNameLength);
+ BaseStream.Read(out csf.Data[i].InternalLabelName, csf.Data[i].LabelNameLength);
csf.Data[i].Values = new CsfValue[csf.Data[i].StringCount];
for (int j = 0; j < csf.Data[i].StringCount; j++)
{
cancellationToken.ThrowIfCancellationRequested();
- BaseStream.Read(out csf.Data[i].Values[j].Identifier);
+ BaseStream.Read(out csf.Data[i].Values[j].InternalIdentifier);
CsfThrowHelper.IsStringOrExtraString(csf.Data[i].Values[j].Identifier, () => new object[] { i, j, BaseStream.Position });
- BaseStream.Read(out csf.Data[i].Values[j].ValueLength);
- BaseStream.Read(out csf.Data[i].Values[j].Value, csf.Data[i].Values[j].ValueLength, true);
+ BaseStream.Read(out csf.Data[i].Values[j].InternalValueLength);
+ BaseStream.Read(out csf.Data[i].Values[j].InternalValue, csf.Data[i].Values[j].ValueLength, true);
unsafe
{
fixed (char* ptr = csf.Data[i].Values[j].Value)
@@ -57,7 +52,7 @@ public override async Task ReadAsync(IProgress? progress = d
{
BaseStream.Read(out int length);
csf.Data[i].Values[j].ExtraValueLength = length;
- BaseStream.Read(out csf.Data[i].Values[j].ExtraValue, length);
+ BaseStream.Read(out csf.Data[i].Values[j].InternalExtraValue, length);
}
}
}
diff --git a/lib/Shimakaze.Sdk/IO/Csf/CsfMerger.cs b/src/Shimakaze.Sdk.Csf/CsfSet.cs
similarity index 67%
rename from lib/Shimakaze.Sdk/IO/Csf/CsfMerger.cs
rename to src/Shimakaze.Sdk.Csf/CsfSet.cs
index 154bd1c6..695e3490 100644
--- a/lib/Shimakaze.Sdk/IO/Csf/CsfMerger.cs
+++ b/src/Shimakaze.Sdk.Csf/CsfSet.cs
@@ -1,31 +1,28 @@
using System.Collections;
-using System.Diagnostics.CodeAnalysis;
-using Shimakaze.Sdk.Csf;
-
-namespace Shimakaze.Sdk.IO.Csf;
+namespace Shimakaze.Sdk.Csf;
///
/// Csf合并器
///
-public class CsfMerger : ISet
+public class CsfSet
+ : ISet
{
///
/// 内部的词典
///
- protected readonly Dictionary _cache = new();
+ protected Dictionary Cache { get; } = [];
///
- public virtual int Count => _cache.Count;
+ public virtual int Count => Cache.Count;
///
- public virtual bool IsReadOnly { get; } = false;
+ public virtual bool IsReadOnly { get; }
///
- public virtual bool Add(CsfData item) => _cache.TryAdd(item.LabelName, item);
+ public virtual bool Add(CsfData item) => Cache.TryAdd(item.LabelName, item);
///
- [ExcludeFromCodeCoverage]
void ICollection.Add(CsfData item) => Add(item);
///
@@ -40,7 +37,7 @@ public virtual CsfDocument Build(int language = 0, int version = 3, int unknown
return new(new(version, language)
{
Unknown = unknown
- }, _cache.Values);
+ }, Cache.Values);
}
///
@@ -59,27 +56,25 @@ public virtual async Task BuildAndWriteToAsync(Stream stream, int language = 0,
}
///
- public virtual void Clear() => _cache.Clear();
+ public virtual void Clear() => Cache.Clear();
///
- public virtual bool Contains(CsfData item) => _cache.TryGetValue(item.LabelName, out _);
+ public virtual bool Contains(CsfData item) => Cache.TryGetValue(item.LabelName, out _);
///
- public virtual void CopyTo(CsfData[] array, int arrayIndex) => _cache.Values.CopyTo(array, arrayIndex);
+ public virtual void CopyTo(CsfData[] array, int arrayIndex) => Cache.Values.CopyTo(array, arrayIndex);
///
public virtual void ExceptWith(IEnumerable other)
{
foreach (var item in other)
- _cache.Remove(item.LabelName);
+ Cache.Remove(item.LabelName);
}
///
- [ExcludeFromCodeCoverage]
- public virtual IEnumerator GetEnumerator() => _cache.Values.GetEnumerator();
+ public virtual IEnumerator GetEnumerator() => Cache.Values.GetEnumerator();
///
- [ExcludeFromCodeCoverage]
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
///
@@ -91,32 +86,32 @@ public virtual void IntersectWith(IEnumerable other)
}
///
- public virtual bool IsProperSubsetOf(IEnumerable other) => other.Count() > Count && !_cache.Values.Any(i => !other.Contains(i));
+ public virtual bool IsProperSubsetOf(IEnumerable other) => other.Count() > Count && !Cache.Values.Any(i => !other.Contains(i));
///
- public virtual bool IsProperSupersetOf(IEnumerable other) => other.Count() < Count && !other.Any(i => !_cache.TryGetValue(i.LabelName, out _));
+ public virtual bool IsProperSupersetOf(IEnumerable other) => other.Count() < Count && !other.Any(i => !Cache.TryGetValue(i.LabelName, out _));
///
- public virtual bool IsSubsetOf(IEnumerable other) => other.Count() >= Count && !_cache.Values.Any(i => !other.Contains(i));
+ public virtual bool IsSubsetOf(IEnumerable other) => other.Count() >= Count && !Cache.Values.Any(i => !other.Contains(i));
///
- public virtual bool IsSupersetOf(IEnumerable other) => other.Count() <= Count && !other.Any(i => !_cache.TryGetValue(i.LabelName, out _));
+ public virtual bool IsSupersetOf(IEnumerable other) => other.Count() <= Count && !other.Any(i => !Cache.TryGetValue(i.LabelName, out _));
///
- public virtual bool Overlaps(IEnumerable other) => _cache.Values.Any(i => other.Contains(i));
+ public virtual bool Overlaps(IEnumerable other) => Cache.Values.Any(i => other.Contains(i));
///
- public virtual bool Remove(CsfData item) => _cache.Remove(item.LabelName);
+ public virtual bool Remove(CsfData item) => Cache.Remove(item.LabelName);
///
- public virtual bool SetEquals(IEnumerable other) => other.Count() == Count && !_cache.Values.Any(i => !other.Contains(i));
+ public virtual bool SetEquals(IEnumerable other) => other.Count() == Count && !Cache.Values.Any(i => !other.Contains(i));
///
public virtual void SymmetricExceptWith(IEnumerable other)
{
foreach (var item in other)
{
- if (_cache.TryGetValue(item.LabelName, out var value))
+ if (Cache.TryGetValue(item.LabelName, out var value))
Remove(value);
else
Add(item);
@@ -127,6 +122,6 @@ public virtual void SymmetricExceptWith(IEnumerable other)
public virtual void UnionWith(IEnumerable other)
{
foreach (var item in other)
- _cache[item.LabelName] = item;
+ Cache[item.LabelName] = item;
}
}
\ No newline at end of file
diff --git a/lib/Shimakaze.Sdk/Csf/CsfThrowHelper.cs b/src/Shimakaze.Sdk.Csf/CsfThrowHelper.cs
similarity index 78%
rename from lib/Shimakaze.Sdk/Csf/CsfThrowHelper.cs
rename to src/Shimakaze.Sdk.Csf/CsfThrowHelper.cs
index 4ed67bee..8833c91a 100644
--- a/lib/Shimakaze.Sdk/Csf/CsfThrowHelper.cs
+++ b/src/Shimakaze.Sdk.Csf/CsfThrowHelper.cs
@@ -1,4 +1,6 @@
-namespace Shimakaze.Sdk.Csf;
+using System.Globalization;
+
+namespace Shimakaze.Sdk.Csf;
///
/// CsfThrowHelper.
@@ -26,7 +28,7 @@ public static int IsCsfFile(int flag)
public static int IsLabel(int flag, Func