added check for valid input for texture nine patch command.

This commit is contained in:
Harrison Deng 2019-01-04 12:23:42 -06:00
parent c62361da2f
commit 5e9d64e181

View File

@ -8,6 +8,11 @@ namespace RecrownedAthenaeum.Tools.NinePatchTools
{ {
public class NinePatchCommand : EngineCommand public class NinePatchCommand : EngineCommand
{ {
private enum SupportedExtensions
{
jpeg, jpg, png
}
public NinePatchCommand() : base("9p", "ninepatch", "9patch") public NinePatchCommand() : base("9p", "ninepatch", "9patch")
{ {
help = "Generates a 9 patch file for a given image."; help = "Generates a 9 patch file for a given image.";
@ -41,6 +46,9 @@ namespace RecrownedAthenaeum.Tools.NinePatchTools
NinePatchData npData = new NinePatchData(Path.GetFileName(imagePath), leftBound, rightBound, bottomBound, topBound); NinePatchData npData = new NinePatchData(Path.GetFileName(imagePath), leftBound, rightBound, bottomBound, topBound);
string serialized = JsonConvert.SerializeObject(npData, Formatting.Indented); string serialized = JsonConvert.SerializeObject(npData, Formatting.Indented);
if (!File.Exists(imagePath)) throw new ArgumentException("Input file does not exist.");
SupportedExtensions extension;
if (!Enum.TryParse<SupportedExtensions>(Path.GetExtension(imagePath).ToLower().Substring(1), out extension)) throw new ArgumentException("Input file extension not supported.");
using (StreamWriter stringWriter = new StreamWriter(outPath + ".9p")) using (StreamWriter stringWriter = new StreamWriter(outPath + ".9p"))
{ {
stringWriter.WriteLine(serialized); stringWriter.WriteLine(serialized);