Try to catch errors when color number is out of range in PesFile.OpenFile()

Also cleanup some unneeded namespace specifiers
master
Nathan Crawford 2017-12-14 16:43:03 -05:00
rodzic c16f3e7fb0
commit afd3e80907
3 zmienionych plików z 14 dodań i 5 usunięć

Wyświetl plik

@ -29,7 +29,7 @@ using System.IO;
namespace PesFile
{
public class PECFormatException : System.Exception
public class PECFormatException : Exception
{
public PECFormatException(string message) : base(message) { }
}
@ -200,8 +200,14 @@ namespace PesFile
curBlock.stitches = new Stitch[tempStitches.Count];
tempStitches.CopyTo(curBlock.stitches);
curBlock.stitchesTotal = tempStitches.Count;
colorNum++;
if(colorNum >= colorList.Count)
{
throw new IndexOutOfRangeException("colorNum (" + colorNum + ") out of range (" + colorList.Count + ") in end of stitches block");
}
colorIndex = colorList[colorNum];
curBlock.colorIndex = colorIndex;
curBlock.color = GetColorFromIndex(colorIndex);
blocks.Add(curBlock);
@ -214,8 +220,14 @@ namespace PesFile
curBlock.stitches = new Stitch[tempStitches.Count];
tempStitches.CopyTo(curBlock.stitches);
curBlock.stitchesTotal = tempStitches.Count;
colorNum++;
if (colorNum >= colorList.Count)
{
throw new IndexOutOfRangeException("colorNum (" + colorNum + ") out of range (" + colorList.Count + ") in color switch block");
}
colorIndex = colorList[colorNum];
curBlock.colorIndex = colorIndex;
curBlock.color = GetColorFromIndex(colorIndex);
//read useless(?) byte

Wyświetl plik

@ -36,7 +36,7 @@ namespace PesFile
public byte unknownStartByte;
public StitchBlock()
{
color = System.Drawing.Color.Black;
color = Color.Black;
}
}
}

Wyświetl plik

@ -1,9 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
namespace embroideryReader
{