Initial Commit
This commit is contained in:
commit
69a2ef0686
10 changed files with 209 additions and 0 deletions
71
Program.cs
Normal file
71
Program.cs
Normal file
|
@ -0,0 +1,71 @@
|
|||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue