Moved string literals for messages into new Strings.resx file
This commit is contained in:
parent
1431a301d2
commit
e0d1fe9438
|
@ -148,7 +148,7 @@ namespace SharpNBT
|
|||
case CompressionType.GZip: return new GZipStream(stream, level, false);
|
||||
case CompressionType.ZLib: return new ZLibStream(stream, level);
|
||||
case CompressionType.AutoDetect:
|
||||
throw new ArgumentOutOfRangeException(nameof(type), "Auto-detect is not a valid compression type for writing files.");
|
||||
throw new ArgumentOutOfRangeException(nameof(type), Strings.AutoDetectNotValid);
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(type), type, null);
|
||||
}
|
||||
|
@ -168,7 +168,7 @@ namespace SharpNBT
|
|||
0x1F => CompressionType.GZip,
|
||||
0x08 => CompressionType.None, // ListTag (valid in Bedrock)
|
||||
0x0A => CompressionType.None, // CompoundTag
|
||||
_ => throw new FormatException("Unable to detect compression type.")
|
||||
_ => throw new FormatException(Strings.CannotDetectCompression)
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -20,4 +20,19 @@
|
|||
<ItemGroup>
|
||||
<None Include="icon.png" Pack="true" Visible="true" PackagePath="" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Update="Strings.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Strings.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="Strings.Designer.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Strings.resx</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
|
@ -0,0 +1,81 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>1.3</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="UnknownTagType" xml:space="preserve">
|
||||
<value>Unknown tag type.</value>
|
||||
</data>
|
||||
<data name="AutoDetectNotValid" xml:space="preserve">
|
||||
<value>Auto-detect is not a valid compression type when writing.</value>
|
||||
</data>
|
||||
<data name="CannotDetectCompression" xml:space="preserve">
|
||||
<value>Unable to detect compression type.</value>
|
||||
</data>
|
||||
<data name="CannotReadStream" xml:space="preserve">
|
||||
<value>Stream is not opened for reading.</value>
|
||||
</data>
|
||||
<data name="CannotWriteStream" xml:space="preserve">
|
||||
<value>Stream is not opened for writing.</value>
|
||||
</data>
|
||||
<data name="InvalidEndTagChild" xml:space="preserve">
|
||||
<value>An EndTag is not a valid child type for a non-empty ListTag.</value>
|
||||
</data>
|
||||
<data name="VarIntTooMuchData" xml:space="preserve">
|
||||
<value>Value too large to be stored in a {0} integer.</value>
|
||||
</data>
|
||||
<data name="VarIntCannotDecode" xml:space="preserve">
|
||||
<value>Cannot decode value from bytes.</value>
|
||||
</data>
|
||||
<data name="ZLibValueGreater15" xml:space="preserve">
|
||||
<value>Value cannot be greater than 15.</value>
|
||||
</data>
|
||||
<data name="ZLibValueGreater31" xml:space="preserve">
|
||||
<value>Value cannot be greater than 31.</value>
|
||||
</data>
|
||||
<data name="CRCFail" xml:space="preserve">
|
||||
<value>CRC validation failed.</value>
|
||||
</data>
|
||||
<data name="ZlibUnsupported" xml:space="preserve">
|
||||
<value>Unsupported stream.</value>
|
||||
</data>
|
||||
<data name="WordElement" xml:space="preserve">
|
||||
<value>element</value>
|
||||
</data>
|
||||
<data name="WordElements" xml:space="preserve">
|
||||
<value>elements</value>
|
||||
</data>
|
||||
<data name="WordEntry" xml:space="preserve">
|
||||
<value>entry</value>
|
||||
</data>
|
||||
<data name="WordEntries" xml:space="preserve">
|
||||
<value>entries</value>
|
||||
</data>
|
||||
<data name="ChildCannotBeNull" xml:space="preserve">
|
||||
<value>Child tag in collection cannot be null.</value>
|
||||
</data>
|
||||
<data name="ChildrenMustBeNamed" xml:space="preserve">
|
||||
<value>Children of this collection type must be named.</value>
|
||||
</data>
|
||||
<data name="ChildrenMustNotBeNamed" xml:space="preserve">
|
||||
<value>Children of this collection type cannot be named.</value>
|
||||
</data>
|
||||
<data name="ChildWrongType" xml:space="preserve">
|
||||
<value>Incorrect tag type added to this collection.</value>
|
||||
</data>
|
||||
</root>
|
|
@ -36,7 +36,7 @@ namespace SharpNBT
|
|||
public TagReader([NotNull] Stream stream, FormatOptions options, bool leaveOpen = false) : base(stream, options)
|
||||
{
|
||||
if (!stream.CanRead)
|
||||
throw new IOException("Stream is not opened for reading.");
|
||||
throw new IOException(Strings.CannotReadStream);
|
||||
this.leaveOpen = leaveOpen;
|
||||
}
|
||||
|
||||
|
@ -260,7 +260,7 @@ namespace SharpNBT
|
|||
var count = ReadCount();
|
||||
|
||||
if (childType == TagType.End && count > 0)
|
||||
throw new FormatException("An EndTag is not a valid child type for a non-empty ListTag.");
|
||||
throw new FormatException(Strings.InvalidEndTagChild);
|
||||
|
||||
var list = new ListTag(name, childType);
|
||||
while (count-- > 0)
|
||||
|
|
|
@ -28,7 +28,7 @@ namespace SharpNBT
|
|||
public TagWriter([NotNull] Stream stream, FormatOptions options, bool leaveOpen = false) : base(stream, options)
|
||||
{
|
||||
if (!stream.CanWrite)
|
||||
throw new IOException("Stream is not opened for writing.");
|
||||
throw new IOException(Strings.CannotWriteStream);
|
||||
this.leaveOpen = leaveOpen;
|
||||
}
|
||||
|
||||
|
@ -269,7 +269,7 @@ namespace SharpNBT
|
|||
WriteLongArray((LongArrayTag)tag);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(tag.Type), "Unknown tag type.");
|
||||
throw new ArgumentOutOfRangeException(nameof(tag.Type), Strings.UnknownTagType);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ namespace SharpNBT
|
|||
/// <inheritdoc cref="object.ToString"/>
|
||||
public override string ToString()
|
||||
{
|
||||
var word = Count == 1 ? "element" : "elements";
|
||||
var word = Count == 1 ? Strings.WordElement : Strings.WordElements;
|
||||
return $"TAG_Byte_Array({PrettyName}): [{Count} {word}]";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ namespace SharpNBT
|
|||
/// <footer><a href="https://docs.microsoft.com/en-us/dotnet/api/System.Object.ToString?view=netcore-5.0">`Object.ToString` on docs.microsoft.com</a></footer>
|
||||
public override string ToString()
|
||||
{
|
||||
var word = Count == 1 ? "entry" : "entries";
|
||||
var word = Count == 1 ? Strings.WordEntry : Strings.WordEntries;
|
||||
return $"TAG_Compound({PrettyName}): [{Count} {word}]";
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,6 @@ namespace SharpNBT
|
|||
{
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc cref="object.ToString"/>
|
||||
public override string ToString() => $"TAG_Float({PrettyName}): {Value}";
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ namespace SharpNBT
|
|||
/// <inheritdoc cref="object.ToString"/>
|
||||
public override string ToString()
|
||||
{
|
||||
var word = Count == 1 ? "element" : "elements";
|
||||
var word = Count == 1 ? Strings.WordElement : Strings.WordElements;
|
||||
return $"TAG_Int_Array({PrettyName}): [{Count} {word}]";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ namespace SharpNBT
|
|||
/// <inheritdoc cref="object.ToString"/>
|
||||
public override string ToString()
|
||||
{
|
||||
var word = Count == 1 ? "entry" : "entries";
|
||||
var word = Count == 1 ? Strings.WordEntry : Strings.WordEntries;
|
||||
return $"TAG_List({PrettyName}): [{Count} {word}]";
|
||||
}
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ namespace SharpNBT
|
|||
/// <inheritdoc cref="object.ToString"/>
|
||||
public override string ToString()
|
||||
{
|
||||
var word = Count == 1 ? "element" : "elements";
|
||||
var word = Count == 1 ? Strings.WordElement : Strings.WordElements;
|
||||
return $"TAG_Long_Array({PrettyName}): [{Count} {word}]";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -148,15 +148,18 @@ namespace SharpNBT
|
|||
protected Tag AssertConventions([CanBeNull] Tag tag)
|
||||
{
|
||||
if (tag is null)
|
||||
throw new ArgumentNullException(nameof(tag), "Child tag in collection cannot be null");
|
||||
throw new ArgumentNullException(nameof(tag), Strings.ChildCannotBeNull);
|
||||
|
||||
if (NamedChildren && tag.Name is null)
|
||||
throw new FormatException("Children of this collection type must be named.");
|
||||
if (!NamedChildren && tag.Name != null)
|
||||
throw new FormatException("Children of this collection type cannot be named.");
|
||||
switch (NamedChildren)
|
||||
{
|
||||
case true when tag.Name is null:
|
||||
throw new FormatException(Strings.ChildrenMustBeNamed);
|
||||
case false when tag.Name != null:
|
||||
throw new FormatException(Strings.ChildrenMustNotBeNamed);
|
||||
}
|
||||
|
||||
if (RequiredType.HasValue && RequiredType.Value != tag.Type)
|
||||
throw new ArrayTypeMismatchException("Incorrect tag type added to this collection.");
|
||||
throw new ArrayTypeMismatchException(Strings.ChildWrongType);
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
|
|
@ -70,14 +70,14 @@ namespace SharpNBT
|
|||
ulong tmp = byteValue & 0x7f;
|
||||
result |= tmp << shift;
|
||||
if (shift > bits)
|
||||
throw new OverflowException($"Value too large to be stored in a {bits} integer.");
|
||||
throw new OverflowException(string.Format(Strings.VarIntTooMuchData, bits));
|
||||
size++;
|
||||
if ((byteValue & 0x80) != 0x80)
|
||||
return result;
|
||||
|
||||
shift += 7;
|
||||
}
|
||||
throw new FormatException("Cannot decode value from bytes.");
|
||||
throw new FormatException(Strings.VarIntCannotDecode);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
|
@ -95,7 +95,7 @@ namespace SharpNBT
|
|||
ulong tmp = byteValue & 0x7f;
|
||||
result |= tmp << shift;
|
||||
if (shift > bits)
|
||||
throw new OverflowException($"Value too large to be stored in a {bits}-bit integer.");
|
||||
throw new OverflowException(string.Format(Strings.VarIntTooMuchData, bits));
|
||||
if ((byteValue & 0x80) != 0x80)
|
||||
return result;
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ namespace SharpNBT.ZLib
|
|||
|
||||
fCheck = Convert.ToByte(31 - Convert.ToByte((CMF * 256 + flg) % 31));
|
||||
if (fCheck > 31)
|
||||
throw new ArgumentOutOfRangeException(nameof(fCheck), "Value cannot be greater than 31.");
|
||||
throw new ArgumentOutOfRangeException(nameof(fCheck), Strings.ZLibValueGreater31);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -97,11 +97,11 @@ namespace SharpNBT.ZLib
|
|||
|
||||
result.compressionInfo = Convert.ToByte((cmf & 0xF0) >> 4);
|
||||
if (result.compressionInfo > 15)
|
||||
throw new ArgumentOutOfRangeException(nameof(result.compressionInfo), "Value cannot be greater than 15");
|
||||
throw new ArgumentOutOfRangeException(nameof(result.compressionInfo), Strings.ZLibValueGreater15);
|
||||
|
||||
result.compressionMethod = Convert.ToByte(cmf & 0x0F);
|
||||
if (result.compressionInfo > 15)
|
||||
throw new ArgumentOutOfRangeException(nameof(result.compressionMethod), "Value cannot be greater than 15");
|
||||
throw new ArgumentOutOfRangeException(nameof(result.compressionMethod), Strings.ZLibValueGreater15);
|
||||
|
||||
result.fCheck = Convert.ToByte(flg & 0x1F);
|
||||
result.fDict = Convert.ToByte((flg & 0x20) >> 5);
|
||||
|
|
|
@ -361,7 +361,7 @@ namespace SharpNBT.ZLib
|
|||
var crcStream = BitConverter.ToInt32(checksum, 0);
|
||||
|
||||
if (crcStream != crcAdler)
|
||||
throw new InvalidDataException("CRC validation failed.");
|
||||
throw new InvalidDataException(Strings.CRCFail);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -379,7 +379,7 @@ namespace SharpNBT.ZLib
|
|||
case CompressionMode.Decompress:
|
||||
{
|
||||
if (!IsSupported(BaseStream))
|
||||
throw new InvalidDataException();
|
||||
throw new InvalidDataException(Strings.ZlibUnsupported);
|
||||
|
||||
return new DeflateStream(BaseStream, CompressionMode.Decompress, true);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue