Skip to content

Commit

Permalink
Update source code
Browse files Browse the repository at this point in the history
  • Loading branch information
Max-RM committed May 5, 2023
1 parent 7e029f9 commit 644e490
Show file tree
Hide file tree
Showing 56 changed files with 7,811 additions and 0 deletions.
Binary file removed SnbtCmd.zip
Binary file not shown.
409 changes: 409 additions & 0 deletions SourceCode_SnbtCmd/Nbt/SnbtMaker.cs

Large diffs are not rendered by default.

407 changes: 407 additions & 0 deletions SourceCode_SnbtCmd/Nbt/SnbtParser.cs

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions SourceCode_SnbtCmd/Nbt/TryashtarUtils.Nbt.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>

<ItemGroup>
<None Remove="**/desktop.ini" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\fNbt\fNbt.csproj" />
<ProjectReference Include="..\Utility\TryashtarUtils.Utility.csproj" />
</ItemGroup>

</Project>
6 changes: 6 additions & 0 deletions SourceCode_SnbtCmd/Nbt/TryashtarUtils.Nbt.csproj.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<_LastSelectedProfileId>D:\Projects\Visual Studio\NbtStudio\utils\Nbt\Properties\PublishProfiles\FolderProfile.pubxml</_LastSelectedProfileId>
</PropertyGroup>
</Project>
43 changes: 43 additions & 0 deletions SourceCode_SnbtCmd/SnbtCmd.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31229.75
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SnbtCmd", "SnbtCmd\SnbtCmd.csproj", "{07BABE76-0388-47CA-8596-38CDD94B45BC}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "fNbt", "fNbt\fNbt.csproj", "{F65C199F-A480-44FE-9C74-E8C5DF442FE7}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TryashtarUtils.Nbt", "Nbt\TryashtarUtils.Nbt.csproj", "{AC99CE65-8EEB-4416-A568-B3DDC852EC7B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TryashtarUtils.Utility", "Utility\TryashtarUtils.Utility.csproj", "{79207E4F-7D25-42D1-B0E9-F04907A8EA05}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{07BABE76-0388-47CA-8596-38CDD94B45BC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{07BABE76-0388-47CA-8596-38CDD94B45BC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{07BABE76-0388-47CA-8596-38CDD94B45BC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{07BABE76-0388-47CA-8596-38CDD94B45BC}.Release|Any CPU.Build.0 = Release|Any CPU
{F65C199F-A480-44FE-9C74-E8C5DF442FE7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F65C199F-A480-44FE-9C74-E8C5DF442FE7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F65C199F-A480-44FE-9C74-E8C5DF442FE7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F65C199F-A480-44FE-9C74-E8C5DF442FE7}.Release|Any CPU.Build.0 = Release|Any CPU
{AC99CE65-8EEB-4416-A568-B3DDC852EC7B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AC99CE65-8EEB-4416-A568-B3DDC852EC7B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AC99CE65-8EEB-4416-A568-B3DDC852EC7B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AC99CE65-8EEB-4416-A568-B3DDC852EC7B}.Release|Any CPU.Build.0 = Release|Any CPU
{79207E4F-7D25-42D1-B0E9-F04907A8EA05}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{79207E4F-7D25-42D1-B0E9-F04907A8EA05}.Debug|Any CPU.Build.0 = Debug|Any CPU
{79207E4F-7D25-42D1-B0E9-F04907A8EA05}.Release|Any CPU.ActiveCfg = Release|Any CPU
{79207E4F-7D25-42D1-B0E9-F04907A8EA05}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {F6E30B92-391C-4680-B92B-5500D1D33E6A}
EndGlobalSection
EndGlobal
62 changes: 62 additions & 0 deletions SourceCode_SnbtCmd/SnbtCmd/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using System.IO;
using TryashtarUtils.Nbt;

namespace SnbtCmd
{
class Program
{
static void Main(string[] args)
{
if (args.Length == 0)
{
Console.WriteLine("Use:");
Console.WriteLine("First type mode 'path' or 'raw'");
Console.WriteLine("If using 'path', next type the file path");
Console.WriteLine("Next type 'to-snbt' or 'to-nbt'");
Console.WriteLine("If using 'to-snbt', add 'expanded' for pretty-print)");
Console.WriteLine("If using 'to-nbt', add 'gzip' for g-zip compression)");
return;
}
var consumable_args = new List<string>(args);
Stream input_stream;
if (consumable_args[0] == "path")
{
string path = consumable_args[1];
consumable_args.RemoveRange(0, 2);
input_stream = File.OpenRead(path);
}
else if (consumable_args[0] == "raw")
{
input_stream = Console.OpenStandardInput();
}
else
throw new ArgumentException();
using Stream stdout = Console.OpenStandardOutput();
using var writer = new StreamWriter(stdout);
if (consumable_args[0] == "to-snbt")
{
var nbt_file = new fNbt.NbtFile();
nbt_file.LoadFromStream(input_stream, fNbt.NbtCompression.AutoDetect);
var options = SnbtOptions.Default;
if (consumable_args.Count >= 2 && consumable_args[1] == "expanded")
options = SnbtOptions.DefaultExpanded;
writer.Write(Snbt.ToSnbt(nbt_file.RootTag, options));
}
else if (consumable_args[0] == "to-nbt")
{
using var stream = new StreamReader(input_stream);
var snbt = stream.ReadToEnd();
var data = SnbtParser.Parse(snbt, false);
data.Name = "";
var file = new fNbt.NbtFile(data);
var compression = fNbt.NbtCompression.None;
if (consumable_args.Count >= 2 && consumable_args[1] == "gzip")
compression = fNbt.NbtCompression.GZip;
file.SaveToStream(stdout, compression);
}
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<PublishDir>bin\publish\</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<History>True|2021-08-30T06:39:19.4597144Z;False|2021-08-30T00:39:07.9672725-06:00;False|2021-08-30T00:38:58.2229138-06:00;False|2021-08-30T00:38:39.4869038-06:00;False|2021-08-30T00:38:36.9843404-06:00;False|2021-08-30T00:38:32.2305977-06:00;False|2021-08-30T00:38:29.3484061-06:00;True|2021-08-30T00:37:45.8662062-06:00;False|2021-08-30T00:37:23.5339491-06:00;True|2021-08-30T00:36:54.5434631-06:00;True|2021-08-30T00:36:17.7566495-06:00;</History>
</PropertyGroup>
</Project>
16 changes: 16 additions & 0 deletions SourceCode_SnbtCmd/SnbtCmd/SnbtCmd.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<PublishSingleFile>true</PublishSingleFile>
<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
<PublishTrimmed>true</PublishTrimmed>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Nbt\TryashtarUtils.Nbt.csproj" />
</ItemGroup>

</Project>
6 changes: 6 additions & 0 deletions SourceCode_SnbtCmd/SnbtCmd/SnbtCmd.csproj.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<_LastSelectedProfileId>D:\Projects\Visual Studio\SnbtCmd\SnbtCmd\Properties\PublishProfiles\FolderProfile.pubxml</_LastSelectedProfileId>
</PropertyGroup>
</Project>
132 changes: 132 additions & 0 deletions SourceCode_SnbtCmd/Utility/DataUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Globalization;

namespace TryashtarUtils.Utility
{
public static class DataUtils
{
private static readonly Dictionary<string, (double d, float f)> SpecialFloatingPoints = new(StringComparer.OrdinalIgnoreCase)
{
{ "", (double.PositiveInfinity, float.PositiveInfinity) },
{ "+∞", (double.PositiveInfinity, float.PositiveInfinity) },
{ "-∞", (double.NegativeInfinity, float.NegativeInfinity) },
{ "Infinity", (double.PositiveInfinity, float.PositiveInfinity) },
{ "+Infinity", (double.PositiveInfinity, float.PositiveInfinity) },
{ "-Infinity", (double.NegativeInfinity, float.NegativeInfinity) },
{ "NaN", (double.NaN, float.NaN) }
};

public static double? TryParseSpecialDouble(string value)
{
if (SpecialFloatingPoints.TryGetValue(value, out var result))
return result.d;
return null;
}

public static float? TryParseSpecialFloat(string value)
{
if (SpecialFloatingPoints.TryGetValue(value, out var result))
return result.f;
return null;
}

public static double ParseDouble(string value)
{
return TryParseSpecialDouble(value) ??
double.Parse(value, NumberStyles.Float, CultureInfo.InvariantCulture);
}

public static float ParseFloat(string value)
{
return TryParseSpecialFloat(value) ??
float.Parse(value, NumberStyles.Float, CultureInfo.InvariantCulture);
}

public static string DoubleToString(double d)
{
return d.ToString("0." + new string('#', 339), CultureInfo.InvariantCulture);
}

public static string FloatToString(float f)
{
return f.ToString("0." + new string('#', 339), CultureInfo.InvariantCulture);
}

public static byte[] GetBytes(int value, bool little_endian = false)
{
byte[] result = BitConverter.GetBytes(value);
if (BitConverter.IsLittleEndian != little_endian)
Array.Reverse(result);
return result;
}

public static int ToInt32(params byte[] bytes)
{
if (BitConverter.IsLittleEndian)
{
byte[] swap = bytes.Take(4).Reverse().ToArray();
return BitConverter.ToInt32(swap, 0);
}
else
return BitConverter.ToInt32(bytes, 0);
}

public static byte[] ToByteArray(params short[] shorts)
{
byte[] result = new byte[shorts.Length * sizeof(short)];
Buffer.BlockCopy(shorts, 0, result, 0, result.Length);
return result;
}

public static byte[] ToByteArray(params int[] ints)
{
byte[] result = new byte[ints.Length * sizeof(int)];
Buffer.BlockCopy(ints, 0, result, 0, result.Length);
return result;
}

public static byte[] ToByteArray(params long[] longs)
{
byte[] result = new byte[longs.Length * sizeof(long)];
Buffer.BlockCopy(longs, 0, result, 0, result.Length);
return result;
}

public static short[] ToShortArray(params byte[] bytes)
{
var size = bytes.Length / sizeof(short);
var shorts = new short[size];
for (int index = 0; index < size; index++)
{
shorts[index] = BitConverter.ToInt16(bytes, index * sizeof(short));
}
return shorts;
}

public static int[] ToIntArray(params byte[] bytes)
{
var size = bytes.Length / sizeof(int);
var ints = new int[size];
for (int index = 0; index < size; index++)
{
ints[index] = BitConverter.ToInt32(bytes, index * sizeof(int));
}
return ints;
}

public static long[] ToLongArray(params byte[] bytes)
{
var size = bytes.Length / sizeof(long);
var longs = new long[size];
for (int index = 0; index < size; index++)
{
longs[index] = BitConverter.ToInt64(bytes, index * sizeof(long));
}
return longs;
}
}
}
Loading

0 comments on commit 644e490

Please sign in to comment.