Skip to content

Commit

Permalink
♻️ update
Browse files Browse the repository at this point in the history
Signed-off-by: 舰队的偶像-岛风酱! <[email protected]>
  • Loading branch information
frg2089 committed Jul 10, 2023
1 parent f7d88c2 commit 0f7cb9e
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 75 deletions.
2 changes: 1 addition & 1 deletion src/Shimakaze.Sdk.Build/CsfBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public override bool Execute()
Log.LogWarning(
"Shimakaze.Sdk.Csf",
"CSF0001",
"No Json V1",
"No CSF",
file.ItemSpec,
0,
0,
Expand Down
25 changes: 4 additions & 21 deletions src/Shimakaze.Sdk.Build/CsfMerger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,10 @@ public override bool Execute()
OutputFile = new TaskItem(DestinationFile);
foreach (var file in SourceFiles)
{
try
{
using Stream stream = File.OpenRead(file.ItemSpec);
using CsfReader reader = new(stream);
merger.UnionWith(reader.ReadAsync().Result.Data);
file.CopyMetadataTo(OutputFile);
}
catch (Exception ex)
{
Log.LogError(
"Shimakaze.Sdk.Csf",
"CSF0004",
"Merge Failed",
file.ItemSpec,
0,
0,
0,
0,
"Cannot Merge file into CSF.");
Log.LogErrorFromException(ex);
}
using Stream stream = File.OpenRead(file.ItemSpec);
using CsfReader reader = new(stream);
merger.UnionWith(reader.ReadAsync().Result.Data);
file.CopyMetadataTo(OutputFile);
}

OutputFile.SetMetadata(Metadata_Pack, true.ToString());
Expand Down
44 changes: 6 additions & 38 deletions src/Shimakaze.Sdk.Ini/IO/IniReader.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Diagnostics.CodeAnalysis;

using Shimakaze.Sdk.Ini;

namespace Shimakaze.Sdk.IO.Ini;
Expand All @@ -22,42 +24,6 @@ public IniReader(Stream stream, bool leaveOpen = false) : base(stream, leaveOpen
BaseReader = new StreamReader(stream, leaveOpen);
}

/// <summary>
/// 反序列化INI
/// </summary>
/// <returns> </returns>
public virtual IniDocument Read()
{
IniDocument doc = new();
IniSection current = doc.Default;
string? line;
while ((line = BaseReader.ReadLine()) is not null)
{
line = line.Split(';', '#').First().Trim();

if (string.IsNullOrEmpty(line))
continue;

if (line.StartsWith('[') && line.EndsWith(']'))
{
current = new()
{
Name = line.Substring(1, line.Length - 2)
};
doc.Add(current);

continue;
}

var index = line.IndexOf('=');
if (index is -1)
current.Add(line, string.Empty);
else
current.Add(line.Substring(0, index).TrimEnd(), line.Substring(index + 1).TrimStart());
}
return doc;
}

/// <inheritdoc />
public override async Task<IniDocument> ReadAsync(IProgress<float>? progress = default, CancellationToken cancellationToken = default)
{
Expand All @@ -77,7 +43,7 @@ public override async Task<IniDocument> ReadAsync(IProgress<float>? progress = d
{
current = new()
{
Name = line.Substring(1, line.Length - 2)
Name = line[1..^1]
};
doc.Add(current);

Expand All @@ -89,12 +55,13 @@ public override async Task<IniDocument> ReadAsync(IProgress<float>? progress = d
if (index is -1)
current.Add(line, string.Empty);
else
current.Add(line.Substring(0, index).TrimEnd(), line.Substring(index + 1).TrimStart());
current.Add(line[..index].TrimEnd(), line[(index + 1)..].TrimStart());
}
return doc;
}

/// <inheritdoc />
[ExcludeFromCodeCoverage]
protected override void Dispose(bool disposing)
{
if (disposing)
Expand All @@ -107,6 +74,7 @@ protected override void Dispose(bool disposing)
}

/// <inheritdoc />
[ExcludeFromCodeCoverage]
protected override ValueTask DisposeAsyncCore()
{
if (!_leaveOpen)
Expand Down
18 changes: 4 additions & 14 deletions src/Shimakaze.Sdk.Ini/IO/IniWriter.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Diagnostics.CodeAnalysis;

using Shimakaze.Sdk.Ini;

namespace Shimakaze.Sdk.IO.Ini;
Expand Down Expand Up @@ -37,24 +39,11 @@ public override async Task WriteAsync(IniDocument value, IProgress<float>? progr
}
}

/// <summary>
/// 序列化Ini文档
/// </summary>
/// <param name="value"> value </param>
public virtual void Writer(in IniDocument value)
{
WriteSectionBody(value.Default);
foreach (var item in value)
{
BaseWriter.WriteLine($"[{item.Name}]");
WriteSectionBody(item);
}
}

/// <summary>
/// 释放资源
/// </summary>
/// <param name="disposing"> </param>
[ExcludeFromCodeCoverage]
protected override void Dispose(bool disposing)
{
if (disposing)
Expand All @@ -67,6 +56,7 @@ protected override void Dispose(bool disposing)
}

/// <inheritdoc />
[ExcludeFromCodeCoverage]
protected override ValueTask DisposeAsyncCore()
{
if (!_leaveOpen)
Expand Down
3 changes: 2 additions & 1 deletion src/Shimakaze.Sdk.JsonRPC.Server/JsonRPCHostedService.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using System.Reflection;

using Microsoft.Extensions.DependencyInjection;
Expand Down Expand Up @@ -26,7 +27,7 @@ public JsonRPCHostedService(
_options = serviceProvider.GetRequiredService<JsonRPCHostedServiceOptions>();
_jsonRpc = new(_options.JsonRpcMessageHandler);
}

[ExcludeFromCodeCoverage]
public void Dispose()
{
_jsonRpc.Dispose();
Expand Down

0 comments on commit 0f7cb9e

Please sign in to comment.