Skip to content

Commit

Permalink
🐛 修复CSF读写错误
Browse files Browse the repository at this point in the history
Signed-off-by: 舰队的偶像-岛风酱! <frg2089@outlook.com>
  • Loading branch information
frg2089 committed Aug 26, 2023
1 parent 37ffd46 commit 77d4767
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public override void Write(Utf8JsonWriter writer, CsfDocument value, JsonSeriali
{
writer.WriteStartObject();
writer.WriteString("$schema", JsonConstants.SchemaUrls.V1);
writer.WriteNumber("protocol", 1);
writer.WriteProperty<CsfMetadataJsonConverter, CsfMetadata>("head", value.Metadata, options);

writer.WriteStartArray("data");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public override void Write(Utf8JsonWriter writer, IList<CsfValue> value, JsonSer
writer.WriteEndArray();
writer.WriteEndObject();
}
else if (value[0].HasExtra)
else if (value[0].ExtraValue is null)
{
writer.WriteValue<CsfSimpleValueJsonConverter, string>(value[0].Value, options);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public override void Write(Utf8JsonWriter writer, CsfDocument value, JsonSeriali
{
writer.WriteStartObject();
writer.WriteString("$schema", JsonConstants.SchemaUrls.V2);
writer.WriteNumber("protocol", 2);
writer.WriteNumber("version", value.Metadata.Version);
writer.WriteProperty<V1.CsfLanguageJsonConverter, int>("language", value.Metadata.Language, options);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public static CsfDataConverter Instance
}

data.Values = values.ToArray();
data.ReCount();
return data;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public static CsfDocumentConverter Instance
metadata.StringCount = doc.Data.Sum(i => i.StringCount);
doc.Metadata = metadata;
doc.Data = datas.ToArray();
doc.ReCount();
return doc;
}

Expand Down
7 changes: 5 additions & 2 deletions src/Shimakaze.Sdk/IO/Csf/Xml/CsfXmlV1Writer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ namespace Shimakaze.Sdk.IO.Csf.Xml;
/// </summary>
public sealed class CsfXmlV1Writer : AsyncWriter<CsfDocument>, IDisposable, IAsyncDisposable
{
private readonly XmlWriterSettings? _settings;
/// <summary>
/// 构造器
/// </summary>
/// <param name="stream"> 基础流 </param>
/// <param name="settings"></param>
/// <param name="leaveOpen"> 退出时是否保持流打开 </param>
public CsfXmlV1Writer(Stream stream, bool leaveOpen = false) : base(stream, leaveOpen)
public CsfXmlV1Writer(Stream stream, XmlWriterSettings? settings = null, bool leaveOpen = false) : base(stream, leaveOpen)
{
_settings = settings;
}

/// <inheritdoc />
Expand All @@ -25,7 +28,7 @@ public override async Task WriteAsync(CsfDocument value, IProgress<float>? progr
await Task.Yield();

CsfDocumentXmlSerializer serializer = new();
using XmlWriter xmlWriter = XmlWriter.Create(BaseStream);
using XmlWriter xmlWriter = XmlWriter.Create(BaseStream, _settings);
serializer.Serialize(xmlWriter, value);
}
}

0 comments on commit 77d4767

Please sign in to comment.