Fixed bug #4. Code now searches for CEmbOne instead of relying on a set number of bytes. Many small improvements and bug fixes.

Branch_1.5.0
Nathan Crawford 2007-10-13 04:24:16 +00:00
rodzic e9810ac2b8
commit 1329dbb402
13 zmienionych plików z 80 dodań i 39 usunięć

Wyświetl plik

@ -62,7 +62,7 @@ namespace PesFile
try
{
_filename = filename;
fileIn = new System.IO.BinaryReader(System.IO.File.Open(filename, System.IO.FileMode.Open));
fileIn = new System.IO.BinaryReader(System.IO.File.Open(filename, System.IO.FileMode.Open,System.IO.FileAccess.Read));
string startFileSig = "";
for (int i = 0; i < 8; i++)//8 bytes
@ -78,47 +78,81 @@ namespace PesFile
return;
}
pesNum = startFileSig.Substring(4);
int pesHeaderLength = 0;
//int pesHeaderLength = 0;
switch (pesNum)
{
case "0001":
pesHeaderLength = 8; //bytes
//pesHeaderLength = 8; //bytes
break;
case "0020":
pesHeaderLength = 17; //bytes
//pesHeaderLength = 17; //bytes
break;
case "0030":
//pesHeaderLength = 19; //bytes
break;
case "0050":
pesHeaderLength = 185;//bytes;
//pesHeaderLength = 185;//bytes;
colorWarning = true;
break;
case "0060":
//pesHeaderLength = -1;//use search method
colorWarning = true;
break;
default:
readyStatus = statusEnum.ReadError;
lastError = "Unknown PES number";
lastError = "Unknown PES number " + pesNum;
fileIn.Close();
return;
}
for (int i = 0; i < pesHeaderLength; i++)
//if (pesHeaderLength > 0)
//{
// for (int i = 0; i < pesHeaderLength; i++)
// {
// pesHeader.Add(fileIn.ReadInt16());
// }
// string embOneHeaderString = "";
// for (int i = 0; i < 7; i++)//7 bytes
// {
// //message += fileIn.ReadChar();
// embOneHeaderString += fileIn.ReadChar();
// }
// if (embOneHeaderString != "CEmbOne")//probably a corrupted file
// {
// readyStatus = statusEnum.ReadError;
// lastError = "Missing CEmbOne header";
// fileIn.Close();
// return;
// }
//}
//else
//{
long restorePos = fileIn.BaseStream.Position;
//char[] tempchars = fileIn.ReadChars(1024);
/*ReadChars has a problem reading some characters,
*seems to skip them. Use ReadBytes instaed*/
byte[] tempbytes = fileIn.ReadBytes(1024);
int foundCEmbOne = -1;
for (int s = 0; s + 6 < tempbytes.Length; s++)
{
pesHeader.Add(fileIn.ReadInt16());
if (tempbytes[s] == 67 && tempbytes[s + 1] == 69 && tempbytes[s + 2] == 109 && tempbytes[s + 3] == 98 && tempbytes[s + 4] == 79 && tempbytes[s + 5] == 110 && tempbytes[s + 6] == 101)
{
foundCEmbOne = s;
break;
}
}
string embOneHeaderString = "";
for (int i = 0; i < 7; i++)//7 bytes
{
//message += fileIn.ReadChar();
embOneHeaderString += fileIn.ReadChar();
}
if (embOneHeaderString != "CEmbOne")//probably a corrupted file
if (foundCEmbOne == -1)
{
readyStatus = statusEnum.ReadError;
lastError = "Missing CEmbOne header";
fileIn.Close();
return;
}
//message += Environment.NewLine;
//MessageBox.Show(message);
else
{
fileIn.BaseStream.Position = restorePos + foundCEmbOne + 7;
}
//}
//message = "";
//int headerValNum = 1;
for (int i = 0; i < 33; i++) //read 66 bytes
{
Int16 tmpval;
@ -154,23 +188,16 @@ namespace PesFile
fileIn.Close();
return;
}
int strangeVal0 = -1;
for (int i = 0; i < 5; i++)//10 bytes
{
Int16 temp = fileIn.ReadInt16();
//if (i == 1)//second value is starting color
//{
// lastColorIndex = temp;
// //Console.WriteLine("starting color" + temp.ToString());
//}
//if (i == 2)//third value is how many stitches until the next block
//{
// stitchesLeft = temp;
//}
csewsegHeader.Add(temp);
switch (i)
{
case 0://start new block indicator?
strangeVal0 = temp;
break;
case 1://second value is starting color
lastColorIndex = temp;
break;
@ -200,7 +227,7 @@ namespace PesFile
if (realx == -32765)
{
if (realy == 1) //end of block
if (realy == strangeVal0) //end of block
{
stitchBlock tmp = new stitchBlock();
tmp.stitches = new Point[currentBlock.Count];
@ -273,13 +300,19 @@ namespace PesFile
{
readyStatus = statusEnum.IOError;
lastError = ioex.Message;
fileIn.Close();
if (fileIn != null)
{
fileIn.Close();
}
}
catch (Exception ex)
{
readyStatus = statusEnum.ReadError;
lastError = ex.Message;
fileIn.Close();
if (fileIn!=null)
{
fileIn.Close();
}
}
}

Wyświetl plik

@ -31,5 +31,5 @@ using System.Runtime.InteropServices;
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.47")]
[assembly: AssemblyFileVersion("1.0.0.47")]
[assembly: AssemblyVersion("1.0.0.101")]
[assembly: AssemblyFileVersion("1.0.0.101")]

Plik binarny nie jest wyświetlany.

Plik binarny nie jest wyświetlany.

Plik binarny nie jest wyświetlany.

Plik binarny nie jest wyświetlany.

Wyświetl plik

@ -75,6 +75,10 @@ namespace embroideryReader
{
toolStripStatusLabel1.Text = "Colors shown for this design may be inaccurate";
}
else
{
toolStripStatusLabel1.Text = "";
}
}
else
{
@ -135,9 +139,13 @@ namespace embroideryReader
xGraph = Graphics.FromImage(DrawArea);
for (int i = 0; i < design.blocks.Count; i++)
{
if (design.blocks[i].stitches.Length > 0)
if (design.blocks[i].stitches.Length > 1)//must have 2 points to make a line
{
xGraph.DrawLines(new Pen(design.blocks[i].color, threadThickness), design.blocks[i].stitches);
Pen tempPen = new Pen(design.blocks[i].color, threadThickness);
tempPen.StartCap = System.Drawing.Drawing2D.LineCap.Round;
tempPen.EndCap = System.Drawing.Drawing2D.LineCap.Round;
tempPen.LineJoin = System.Drawing.Drawing2D.LineJoin.Round;
xGraph.DrawLines(tempPen, design.blocks[i].stitches);
}
}
xGraph.Dispose();

Wyświetl plik

@ -29,5 +29,5 @@ using System.Runtime.InteropServices;
// Build Number
// Revision
//
[assembly: AssemblyVersion("1.0.1.270")]
[assembly: AssemblyFileVersion("1.0.1.270")]
[assembly: AssemblyVersion("1.1.0.324")]
[assembly: AssemblyFileVersion("1.1.0.324")]

Plik binarny nie jest wyświetlany.

Plik binarny nie jest wyświetlany.

Plik binarny nie jest wyświetlany.

Plik binarny nie jest wyświetlany.

Plik binarny nie jest wyświetlany.