Skip to content
Merged

Fixes #235

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions LibNoDaveConnectionLibrary/General/ZipHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#endif

namespace DotNetSiemensPLCToolBoxLibrary.General
{
{
public class ZipHelper
{
#if SHARPZIPLIB
Expand Down Expand Up @@ -98,9 +98,9 @@ public ZipHelper(string file)
this._zipFile = null;
this._zipFile = new ZipFile(file);
}
catch(Exception)
catch (Exception)
{ }
}
}
#endif
}

Expand All @@ -109,7 +109,7 @@ private ZipHelper(Stream file)
#if SHARPZIPLIB
if (file != null)
{
this._zipFile = new ZipFile(file);
this._zipFile = new ZipFile(file);
}
#endif
}
Expand All @@ -118,7 +118,7 @@ public void Close()
{
#if SHARPZIPLIB
if (_zipFile != null)
{
{
_zipFile.Close();
_zipFile = null;
}
Expand All @@ -132,7 +132,7 @@ public Stream GetReadStream(string file)
#if SHARPZIPLIB
if (_zipFile == null)
{
#endif
#endif
return new FileStream(file, FileMode.Open, FileAccess.Read, System.IO.FileShare.ReadWrite);
#if SHARPZIPLIB
}
Expand All @@ -141,15 +141,15 @@ public Stream GetReadStream(string file)
ZipFile zf = (ZipFile)_zipFile;
int fileEntry = zf.FindEntry(file.Replace("\\", "/"), true);
return zf.GetInputStream(fileEntry);

}
#endif
}

public bool IsZipped()
{
#if SHARPZIPLIB
if (_zipFile!=null)
if (_zipFile != null)
return true;
#endif
return false;
Expand Down Expand Up @@ -202,7 +202,7 @@ public void WriteBackStream(string file, Stream strm)
if (_zipFile == null)
{
#endif
strm.Close();
strm.Close();
#if SHARPZIPLIB
}
else
Expand All @@ -212,9 +212,9 @@ public void WriteBackStream(string file, Stream strm)

int nr = _zipFile.FindEntry(file.Replace("\\", "/"), true);
_zipFile.Delete(_zipFile[nr]);

CustomStaticDataSource sds = new CustomStaticDataSource();
sds.SetStream(strm);
sds.SetStream(strm);
_zipFile.Add(sds, file.Replace("\\", "/"));
_zipFile.CommitUpdate();
_zipFile.Close();
Expand All @@ -231,7 +231,7 @@ public void WriteBackStream(string file, Stream strm)
#endif
}


public long GetStreamLength(string file, Stream strm)
{
#if SHARPZIPLIB
Expand Down Expand Up @@ -262,11 +262,11 @@ public bool FileExists(string file)
{
ZipFile zf = (ZipFile)_zipFile;
//return zf.ContainsEntry(file.Replace("\\", "/"));
int fileEntry = zf.FindEntry(file.Replace("\\","/"), true);
return fileEntry >= 0;
int fileEntry = zf.FindEntry(file.Replace("\\", "/"), true);
return fileEntry >= 0;
}
#endif
}

}
}
48 changes: 26 additions & 22 deletions LibNoDaveConnectionLibrary/Projectfiles/Step5Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ public Step5Project(string filename, bool showDeleted)
this._ziphelper = new ZipHelper(filename);
_projectfilename = _ziphelper.GetFirstZipEntryWithEnding(".s5d");
if (string.IsNullOrEmpty(_projectfilename))
throw new Exception("Zip-File contains no valid Step5 Project !");
throw new Exception("Zip-File contains no valid Step5 Project !");
}
else
{
this._ziphelper = new ZipHelper(filename);
}

ProjectFile = filename;
Expand All @@ -43,11 +47,11 @@ internal Step5Project(ZipHelper _ziphelper, string filename, bool showDeleted)
{
_showDeleted = showDeleted;
this._ziphelper = _ziphelper;

_projectfilename = _ziphelper.GetFirstZipEntryWithEnding(".s5d");
if (string.IsNullOrEmpty(_projectfilename))
throw new Exception("Zip-File contains no valid Step5 Project !");
if (string.IsNullOrEmpty(_projectfilename))
throw new Exception("Zip-File contains no valid Step5 Project !");

ProjectFile = filename;

LoadProject();
Expand Down Expand Up @@ -76,10 +80,10 @@ protected override void LoadProject()
ProjectName = System.Text.Encoding.UTF7.GetString(s5ProjectByteArray, 0x08, 8);

//Read the Project Size
Size = s5ProjectByteArray[0x14] + s5ProjectByteArray[0x15]*0x100;
Size = s5ProjectByteArray[0x14] + s5ProjectByteArray[0x15] * 0x100;

//Create the main Project Folder
ProjectStructure = new Step5ProgrammFolder() {Project = this, Name = this.ToString()};
ProjectStructure = new Step5ProgrammFolder() { Project = this, Name = this.ToString() };
_allFolders.Add(ProjectStructure);

//int startpos = s5ProjectByteArray[0x12] * 0x80;
Expand All @@ -90,12 +94,12 @@ protected override void LoadProject()

for (int j = 0; j < anz_sections; j++)
{
int pos = 0x44 + j*19;
sections_lst.Add(s5ProjectByteArray[pos + 15] + s5ProjectByteArray[pos + 16]*0x100);
int pos = 0x44 + j * 19;
sections_lst.Add(s5ProjectByteArray[pos + 15] + s5ProjectByteArray[pos + 16] * 0x100);
}


Step5BlocksFolder blkFld = new Step5BlocksFolder() {Name = "Blocks", Project = this, Parent = ProjectStructure};
Step5BlocksFolder blkFld = new Step5BlocksFolder() { Name = "Blocks", Project = this, Parent = ProjectStructure };
BlocksFolder = blkFld;
ProjectStructure.SubItems.Add(blkFld);

Expand All @@ -107,7 +111,7 @@ protected override void LoadProject()

foreach (int secpos in sections_lst)
{
int section_start = secpos*0x80;
int section_start = secpos * 0x80;
/* The len for a Section is not always calculated right, so if the Section does not begin with the filename add 0x80 until it works */
/* But I don't know why it's wrong */

Expand Down Expand Up @@ -136,7 +140,7 @@ protected override void LoadProject()
for (int j = 0; j < anzbst; j++)
{
byte[] tmp = new byte[15];
Array.Copy(s5ProjectByteArray, section_start + 68 + j*15, tmp, 0, 15);
Array.Copy(s5ProjectByteArray, section_start + 68 + j * 15, tmp, 0, 15);
bstHeaders.Add(tmp);
}

Expand All @@ -154,7 +158,7 @@ protected override void LoadProject()
*/

//Don't know wich Information is in the Section Header!
int section_header_size = s5ProjectByteArray[section_start + 18]*0x80;
int section_header_size = s5ProjectByteArray[section_start + 18] * 0x80;



Expand All @@ -166,7 +170,7 @@ protected override void LoadProject()
// n += 0x80;

while (akanz < anzbst && n + 1 < s5ProjectByteArray.Length)
//n < section_start + section_size)
//n < section_start + section_size)
{
akanz++;
int len = 0;
Expand Down Expand Up @@ -294,23 +298,23 @@ protected override void LoadProject()
if (_showDeleted)
{
//Read also the deleted Blocks, that means, don't use the Section Headers ...
int akpos = s5ProjectByteArray[0x12]*0x80;
int akpos = s5ProjectByteArray[0x12] * 0x80;

while (akpos <= s5ProjectByteArray.Length - 0x80)
{
while (!IsCurrentPosABlockStart(s5ProjectByteArray, akpos) &&
akpos <= s5ProjectByteArray.Length - 0x80)
akpos += 0x80;

if (akpos <= s5ProjectByteArray.Length - 0x80)
{
bool blkExists = ByteAddressOFExistingBlocks.Contains(akpos);
var tmp=AddBlockInfo(s5ProjectByteArray, ref akpos, blkFld, null);
var tmp = AddBlockInfo(s5ProjectByteArray, ref akpos, blkFld, null);
if (!blkExists)
{
tmp.Deleted = true;
blkFld.step5BlocksinfoList.Add(tmp);
}
}
}
}
}
Expand All @@ -319,7 +323,7 @@ protected override void LoadProject()
{
Stream symTabStream = _ziphelper.GetReadStream(_projectfilename.ToLower().Replace("st.s5d", "z0.seq"));

SymbolTable symtab=new SymbolTable();
SymbolTable symtab = new SymbolTable();
symtab.LoadSymboltable(symTabStream);
symTabStream.Close();
symtab.Parent = ProjectStructure;
Expand All @@ -328,7 +332,7 @@ protected override void LoadProject()
_allFolders.Add(symtab);
}

var refFld = new ReferenceData((Step5ProgrammFolder) ProjectStructure, this);
var refFld = new ReferenceData((Step5ProgrammFolder)ProjectStructure, this);
ProjectStructure.SubItems.Add(refFld); // { Parent = ProjectStructure, Project = this });
_allFolders.Add(refFld);

Expand Down Expand Up @@ -470,7 +474,7 @@ public override string ToString()
retVal += "(zipped)";
if (_showDeleted == true)
retVal += " (show deleted)";
return retVal;
return retVal;
}
}
}
}
Loading