71 lines
No EOL
2.2 KiB
C#
71 lines
No EOL
2.2 KiB
C#
using System.Text;
|
|
using Newtonsoft.Json;
|
|
using Exception = System.Exception;
|
|
|
|
namespace RecipeRevamper
|
|
{
|
|
class Program
|
|
{
|
|
static void Main(string[] args)
|
|
{
|
|
Console.WriteLine($"Got {args.Length} recipe files to convert ...");
|
|
foreach (string recipePath in args)
|
|
{
|
|
MinecraftRecipe recipe;
|
|
try
|
|
{
|
|
recipe = GetRecipeFromFile(recipePath);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
Console.WriteLine("Exception occurred during parsing skipping this file ...");
|
|
continue;
|
|
}
|
|
|
|
WriteRecipeToOutput(recipe, "test");
|
|
}
|
|
|
|
|
|
Console.WriteLine("... Done");
|
|
Console.WriteLine("Press ENTER to exit the program ...");
|
|
}
|
|
|
|
static MinecraftRecipe ConvertRecipe(MinecraftRecipe oldRecipe)
|
|
{
|
|
var newRecipe = oldRecipe.Copy();
|
|
return newRecipe;
|
|
}
|
|
|
|
static void WriteRecipeToOutput(MinecraftRecipe recipe, string name)
|
|
{
|
|
if (!Directory.Exists("./output"))
|
|
{
|
|
Directory.CreateDirectory("./output");
|
|
}
|
|
|
|
byte[] bytes = Encoding.UTF8.GetBytes(recipe.Serialize());
|
|
var fileStream = File.Create($"./output/{name}.json");
|
|
fileStream.Write(bytes, 0, bytes.Length);
|
|
fileStream.Close();
|
|
}
|
|
|
|
static MinecraftRecipe GetRecipeFromFile(string path)
|
|
{
|
|
try
|
|
{
|
|
return JsonConvert.DeserializeObject<MinecraftRecipe>(File.ReadAllText(path)) ??
|
|
throw new InvalidOperationException();
|
|
}
|
|
catch (FileNotFoundException)
|
|
{
|
|
Console.WriteLine($"File: {path} could not be found.");
|
|
throw;
|
|
}
|
|
catch (InvalidOperationException)
|
|
{
|
|
Console.WriteLine($"File: {path} could not be parsed.");
|
|
throw;
|
|
}
|
|
}
|
|
}
|
|
} |