Skip to content

Commit

Permalink
Add quotes to strings in array to avoid csv serialization problem
Browse files Browse the repository at this point in the history
  • Loading branch information
aianlinb committed Dec 11, 2022
1 parent b010ce3 commit 0d9b296
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
2 changes: 1 addition & 1 deletion LibDat2/LibDat2.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Nullable>enable</Nullable>
<Authors>aianlinb</Authors>
<Copyright>Copyright © 2020-2022 aianlinb</Copyright>
<Version>0.15.2</Version>
<Version>0.15.3</Version>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DebugType>embedded</DebugType>
</PropertyGroup>
Expand Down
34 changes: 21 additions & 13 deletions LibDat2/Types/ArrayData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public override ArrayData<TypeOfValueInArray> FromString(string value) {
newValue = new TypeOfValueInArray[sarray.Length];
if (TypeOfValue.EndsWith("string"))
for (var n = 0; n < sarray.Length; ++n)
newValue[n] = (TypeOfValueInArray)IFieldData.FromString(sarray[n], TypeOfValue, Dat);
newValue[n] = (TypeOfValueInArray)IFieldData.FromString(sarray[n].Trim('"', ' '), TypeOfValue, Dat);
else
for (var n = 0; n < sarray.Length; ++n)
newValue[n] = (TypeOfValueInArray)IFieldData.FromString(sarray[n], TypeOfValue, Dat).Value;
Expand All @@ -272,18 +272,26 @@ public override string ToString() {
if (Value == null)
return "{null}";
var s = new StringBuilder("[");
foreach (var f in Value) {
s.Append(f?.ToString() ?? "{null}");
if (Value is uint or ulong)
s.Append('U');
if (Value is long or ulong)
s.Append('L');
else if (Value is float)
s.Append('F');
else if (Value is double)
s.Append('D');
s.Append(", ");
}

if (TypeOfValue.EndsWith("string"))
foreach (var f in Value) {
s.Append(f == null ? "{null}" : $"\"{f}\"");
s.Append(", ");
}
else
foreach (var f in Value) {
s.Append(f?.ToString() ?? "{null}");
if (Value is uint or ulong)
s.Append('U');
if (Value is long or ulong)
s.Append('L');
else if (Value is float)
s.Append('F');
else if (Value is double)
s.Append('D');
s.Append(", ");
}

if (s.Length > 2)
s.Remove(s.Length - 2, 2);
s.Append(']');
Expand Down
2 changes: 1 addition & 1 deletion LibDat2/Types/IFieldData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static int SizeOfType(string type, bool x64) {
"i64" => 8,
"u64" => 8,
"f64" => 8,
"valuestring" => -1,
"valuestring" => -1, // Shouldn't be used
_ => throw new ArgumentException("Unknown Type: " + type, nameof(type))
};
}
Expand Down
2 changes: 1 addition & 1 deletion VisualGGPK2/VisualGGPK2.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>net6.0-windows</TargetFramework>
<Authors>aianlinb</Authors>
<Copyright>Copyright © 2020-2022 aianlinb</Copyright>
<Version>0.15.2</Version>
<Version>0.15.3</Version>
<OutputType>WinExe</OutputType>
<UseWPF>true</UseWPF>
<UseWindowsForms>true</UseWindowsForms>
Expand Down

0 comments on commit 0d9b296

Please sign in to comment.