From 5e9d64e181ee45049f524bb4d9ed6a1c1e7f7d6b Mon Sep 17 00:00:00 2001 From: Harrison Deng Date: Fri, 4 Jan 2019 12:23:42 -0600 Subject: [PATCH] added check for valid input for texture nine patch command. --- .../NinePatchTools/NinePatchCommand.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/RecrownedAthenaeum.ConsoleTools/NinePatchTools/NinePatchCommand.cs b/RecrownedAthenaeum.ConsoleTools/NinePatchTools/NinePatchCommand.cs index d07960b..4e4b216 100644 --- a/RecrownedAthenaeum.ConsoleTools/NinePatchTools/NinePatchCommand.cs +++ b/RecrownedAthenaeum.ConsoleTools/NinePatchTools/NinePatchCommand.cs @@ -8,6 +8,11 @@ namespace RecrownedAthenaeum.Tools.NinePatchTools { public class NinePatchCommand : EngineCommand { + private enum SupportedExtensions + { + jpeg, jpg, png + } + public NinePatchCommand() : base("9p", "ninepatch", "9patch") { 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); string serialized = JsonConvert.SerializeObject(npData, Formatting.Indented); + if (!File.Exists(imagePath)) throw new ArgumentException("Input file does not exist."); + SupportedExtensions extension; + if (!Enum.TryParse(Path.GetExtension(imagePath).ToLower().Substring(1), out extension)) throw new ArgumentException("Input file extension not supported."); using (StreamWriter stringWriter = new StreamWriter(outPath + ".9p")) { stringWriter.WriteLine(serialized);