Fixed reading drawing loops

This commit is contained in:
2019-04-20 15:18:01 -04:00
parent e3b3f2ee8b
commit 186311eebc
4 changed files with 59 additions and 5 deletions

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using PepLib.Codes;
using PepLib.IO;
namespace PepLib
@@ -30,6 +31,58 @@ namespace PepLib
return reader.Drawing;
}
public void ResolveLoops()
{
for (int i = 0; i < Loops.Count; ++i)
{
var loop = Loops[i];
ResolveLoops(loop);
}
}
private void ResolveLoops(Program pgm)
{
for (int i = 0; i < pgm.Count; ++i)
{
var code = pgm[i];
if (code.CodeType() != CodeType.SubProgramCall)
continue;
var subpgmcall = (SubProgramCall)code;
var loop = GetLoop(subpgmcall.LoopId);
if (loop == null)
throw new Exception("Loop not found");
subpgmcall.Loop = loop;
}
}
public Loop GetLoop(int id)
{
string name = GetLoopName(id);
return GetLoop(name);
}
private Loop GetLoop(string name)
{
for (int i = 0; i < Loops.Count; ++i)
{
if (Loops[i].Name == name)
return Loops[i];
}
return null;
}
private string GetLoopName(int loopId)
{
return string.Format("{0}.loop-{1}", Info.Name, loopId.ToString().PadLeft(3, '0'));
}
public static bool TryLoad(string nestfile, out Drawing drawing)
{
try

View File

@@ -22,7 +22,6 @@ namespace PepLib.IO
public void Read(Stream stream)
{
var drawing = new Drawing();
var zipStream = new ZipInputStream(stream);
ZipEntry theEntry;
@@ -58,12 +57,14 @@ namespace PepLib.IO
}
if (Regex.IsMatch(extension, "loop-\\d\\d\\d"))
drawing.Loops.Add(ReadLoop(theEntry.FileName, memstream));
Drawing.Loops.Add(ReadLoop(theEntry.FileName, memstream));
memstream.Close();
}
zipStream.Close();
Drawing.ResolveLoops();
}
public void Read(string nestFile)

View File

@@ -33,8 +33,8 @@
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="DotNetZip, Version=1.12.0.0, Culture=neutral, PublicKeyToken=6583c7c814667745, processorArchitecture=MSIL">
<HintPath>..\packages\DotNetZip.1.12.0\lib\net20\DotNetZip.dll</HintPath>
<Reference Include="DotNetZip, Version=1.13.3.0, Culture=neutral, PublicKeyToken=6583c7c814667745, processorArchitecture=MSIL">
<HintPath>..\..\packages\DotNetZip.1.13.3\lib\net40\DotNetZip.dll</HintPath>
</Reference>
<Reference Include="System" />
</ItemGroup>

View File

@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="DotNetZip" version="1.12.0" targetFramework="net461" />
<package id="DotNetZip" version="1.13.3" targetFramework="net461" />
</packages>