Added path validity check and catch.

This commit is contained in:
Harrison Deng 2018-12-29 01:10:25 -06:00
parent 5c3e060d14
commit d154f1f749

View File

@ -24,6 +24,7 @@ namespace RecrownedAthenaeum.Tools.TextureAtlas
int powLimit;
Node masterNode;
Dictionary<string, ImageHandler> imageHandlersDictionary;
Dictionary<string, NinePatchData> ninePatchDictionary;
int tpl;
int TexturePowerLength { get { return tpl; } set { TextureLength = (int)Math.Pow(2, value); tpl = value; } }
public int TextureLength { get; private set; }
@ -37,7 +38,15 @@ namespace RecrownedAthenaeum.Tools.TextureAtlas
internal TexturePacker(string rootDirectoryPath, int powLimit = 12, int startingPower = 8)
{
this.powLimit = powLimit;
string[] paths = Directory.GetFiles(rootDirectoryPath);
string[] paths;
try
{
paths = Directory.GetFiles(rootDirectoryPath);
} catch (DirectoryNotFoundException)
{
throw new ArgumentException("Path " + rootDirectoryPath + " couldn't be found.");
}
TexturePowerLength = startingPower;
List<ImageHandler> imageHandlers = new List<ImageHandler>();
int minAreaRequired = 0;
@ -49,11 +58,20 @@ namespace RecrownedAthenaeum.Tools.TextureAtlas
ImageHandler image = new ImageHandler(paths[pathID]);
imageHandlers.Add(image);
minAreaRequired += image.Area;
while (minAreaRequired > TextureLength*TextureLength)
while (minAreaRequired > TextureLength * TextureLength)
{
TexturePowerLength++;
}
}
else if (Path.GetExtension(paths[pathID]).ToLower() == ".9p")
{
if (ninePatchDictionary == null) ninePatchDictionary = new Dictionary<string, NinePatchData>();
using (StreamReader streamReader = new StreamReader(paths[pathID]))
{
NinePatchData npData = JsonConvert.DeserializeObject<NinePatchData>(streamReader.ReadLine());
ninePatchDictionary.Add(npData.textureName, npData);
}
}
}
imageHandlers.Sort();
this.imageHandlersDictionary = new Dictionary<string, ImageHandler>();
@ -88,8 +106,12 @@ namespace RecrownedAthenaeum.Tools.TextureAtlas
imageHandlerQueue.Clear();
Build(AutoCorrectAtlasSize);
}
if (ninePatchDictionary.ContainsKey(imageHandler.Name))
{
imageHandler.ninePatchData = ninePatchDictionary[imageHandler.Name];
}
}
}
/// <summary>