From 35f955bb70ef70f42487cf4c81edf5c84c85e493 Mon Sep 17 00:00:00 2001 From: jkuehner Date: Fri, 6 Jun 2025 22:59:14 +0200 Subject: [PATCH] fix step 5 project --- .../General/ZipHelper.cs | 30 ++++++------ .../Projectfiles/Step5Project.cs | 48 ++++++++++--------- 2 files changed, 41 insertions(+), 37 deletions(-) diff --git a/LibNoDaveConnectionLibrary/General/ZipHelper.cs b/LibNoDaveConnectionLibrary/General/ZipHelper.cs index acc30fd5..09581017 100644 --- a/LibNoDaveConnectionLibrary/General/ZipHelper.cs +++ b/LibNoDaveConnectionLibrary/General/ZipHelper.cs @@ -7,7 +7,7 @@ #endif namespace DotNetSiemensPLCToolBoxLibrary.General -{ +{ public class ZipHelper { #if SHARPZIPLIB @@ -98,9 +98,9 @@ public ZipHelper(string file) this._zipFile = null; this._zipFile = new ZipFile(file); } - catch(Exception) + catch (Exception) { } - } + } #endif } @@ -109,7 +109,7 @@ private ZipHelper(Stream file) #if SHARPZIPLIB if (file != null) { - this._zipFile = new ZipFile(file); + this._zipFile = new ZipFile(file); } #endif } @@ -118,7 +118,7 @@ public void Close() { #if SHARPZIPLIB if (_zipFile != null) - { + { _zipFile.Close(); _zipFile = null; } @@ -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 } @@ -141,7 +141,7 @@ public Stream GetReadStream(string file) ZipFile zf = (ZipFile)_zipFile; int fileEntry = zf.FindEntry(file.Replace("\\", "/"), true); return zf.GetInputStream(fileEntry); - + } #endif } @@ -149,7 +149,7 @@ public Stream GetReadStream(string file) public bool IsZipped() { #if SHARPZIPLIB - if (_zipFile!=null) + if (_zipFile != null) return true; #endif return false; @@ -202,7 +202,7 @@ public void WriteBackStream(string file, Stream strm) if (_zipFile == null) { #endif - strm.Close(); + strm.Close(); #if SHARPZIPLIB } else @@ -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(); @@ -231,7 +231,7 @@ public void WriteBackStream(string file, Stream strm) #endif } - + public long GetStreamLength(string file, Stream strm) { #if SHARPZIPLIB @@ -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 } - + } } diff --git a/LibNoDaveConnectionLibrary/Projectfiles/Step5Project.cs b/LibNoDaveConnectionLibrary/Projectfiles/Step5Project.cs index fe3709b2..4b9d8724 100644 --- a/LibNoDaveConnectionLibrary/Projectfiles/Step5Project.cs +++ b/LibNoDaveConnectionLibrary/Projectfiles/Step5Project.cs @@ -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; @@ -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(); @@ -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; @@ -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); @@ -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 */ @@ -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); } @@ -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; @@ -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; @@ -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); - } + } } } } @@ -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; @@ -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); @@ -470,7 +474,7 @@ public override string ToString() retVal += "(zipped)"; if (_showDeleted == true) retVal += " (show deleted)"; - return retVal; + return retVal; } - } + } }