Skip to content

Commit 5751686

Browse files
authored
Merge pull request #235 from dotnetprojects/fixes
Fixes
2 parents 756a22e + 61b9866 commit 5751686

File tree

2 files changed

+41
-37
lines changed

2 files changed

+41
-37
lines changed

LibNoDaveConnectionLibrary/General/ZipHelper.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#endif
88

99
namespace DotNetSiemensPLCToolBoxLibrary.General
10-
{
10+
{
1111
public class ZipHelper
1212
{
1313
#if SHARPZIPLIB
@@ -98,9 +98,9 @@ public ZipHelper(string file)
9898
this._zipFile = null;
9999
this._zipFile = new ZipFile(file);
100100
}
101-
catch(Exception)
101+
catch (Exception)
102102
{ }
103-
}
103+
}
104104
#endif
105105
}
106106

@@ -109,7 +109,7 @@ private ZipHelper(Stream file)
109109
#if SHARPZIPLIB
110110
if (file != null)
111111
{
112-
this._zipFile = new ZipFile(file);
112+
this._zipFile = new ZipFile(file);
113113
}
114114
#endif
115115
}
@@ -118,7 +118,7 @@ public void Close()
118118
{
119119
#if SHARPZIPLIB
120120
if (_zipFile != null)
121-
{
121+
{
122122
_zipFile.Close();
123123
_zipFile = null;
124124
}
@@ -132,7 +132,7 @@ public Stream GetReadStream(string file)
132132
#if SHARPZIPLIB
133133
if (_zipFile == null)
134134
{
135-
#endif
135+
#endif
136136
return new FileStream(file, FileMode.Open, FileAccess.Read, System.IO.FileShare.ReadWrite);
137137
#if SHARPZIPLIB
138138
}
@@ -141,15 +141,15 @@ public Stream GetReadStream(string file)
141141
ZipFile zf = (ZipFile)_zipFile;
142142
int fileEntry = zf.FindEntry(file.Replace("\\", "/"), true);
143143
return zf.GetInputStream(fileEntry);
144-
144+
145145
}
146146
#endif
147147
}
148148

149149
public bool IsZipped()
150150
{
151151
#if SHARPZIPLIB
152-
if (_zipFile!=null)
152+
if (_zipFile != null)
153153
return true;
154154
#endif
155155
return false;
@@ -202,7 +202,7 @@ public void WriteBackStream(string file, Stream strm)
202202
if (_zipFile == null)
203203
{
204204
#endif
205-
strm.Close();
205+
strm.Close();
206206
#if SHARPZIPLIB
207207
}
208208
else
@@ -212,9 +212,9 @@ public void WriteBackStream(string file, Stream strm)
212212

213213
int nr = _zipFile.FindEntry(file.Replace("\\", "/"), true);
214214
_zipFile.Delete(_zipFile[nr]);
215-
215+
216216
CustomStaticDataSource sds = new CustomStaticDataSource();
217-
sds.SetStream(strm);
217+
sds.SetStream(strm);
218218
_zipFile.Add(sds, file.Replace("\\", "/"));
219219
_zipFile.CommitUpdate();
220220
_zipFile.Close();
@@ -231,7 +231,7 @@ public void WriteBackStream(string file, Stream strm)
231231
#endif
232232
}
233233

234-
234+
235235
public long GetStreamLength(string file, Stream strm)
236236
{
237237
#if SHARPZIPLIB
@@ -262,11 +262,11 @@ public bool FileExists(string file)
262262
{
263263
ZipFile zf = (ZipFile)_zipFile;
264264
//return zf.ContainsEntry(file.Replace("\\", "/"));
265-
int fileEntry = zf.FindEntry(file.Replace("\\","/"), true);
266-
return fileEntry >= 0;
265+
int fileEntry = zf.FindEntry(file.Replace("\\", "/"), true);
266+
return fileEntry >= 0;
267267
}
268268
#endif
269269
}
270-
270+
271271
}
272272
}

LibNoDaveConnectionLibrary/Projectfiles/Step5Project.cs

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ public Step5Project(string filename, bool showDeleted)
3131
this._ziphelper = new ZipHelper(filename);
3232
_projectfilename = _ziphelper.GetFirstZipEntryWithEnding(".s5d");
3333
if (string.IsNullOrEmpty(_projectfilename))
34-
throw new Exception("Zip-File contains no valid Step5 Project !");
34+
throw new Exception("Zip-File contains no valid Step5 Project !");
35+
}
36+
else
37+
{
38+
this._ziphelper = new ZipHelper(filename);
3539
}
3640

3741
ProjectFile = filename;
@@ -43,11 +47,11 @@ internal Step5Project(ZipHelper _ziphelper, string filename, bool showDeleted)
4347
{
4448
_showDeleted = showDeleted;
4549
this._ziphelper = _ziphelper;
46-
50+
4751
_projectfilename = _ziphelper.GetFirstZipEntryWithEnding(".s5d");
48-
if (string.IsNullOrEmpty(_projectfilename))
49-
throw new Exception("Zip-File contains no valid Step5 Project !");
50-
52+
if (string.IsNullOrEmpty(_projectfilename))
53+
throw new Exception("Zip-File contains no valid Step5 Project !");
54+
5155
ProjectFile = filename;
5256

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

7882
//Read the Project Size
79-
Size = s5ProjectByteArray[0x14] + s5ProjectByteArray[0x15]*0x100;
83+
Size = s5ProjectByteArray[0x14] + s5ProjectByteArray[0x15] * 0x100;
8084

8185
//Create the main Project Folder
82-
ProjectStructure = new Step5ProgrammFolder() {Project = this, Name = this.ToString()};
86+
ProjectStructure = new Step5ProgrammFolder() { Project = this, Name = this.ToString() };
8387
_allFolders.Add(ProjectStructure);
8488

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

9195
for (int j = 0; j < anz_sections; j++)
9296
{
93-
int pos = 0x44 + j*19;
94-
sections_lst.Add(s5ProjectByteArray[pos + 15] + s5ProjectByteArray[pos + 16]*0x100);
97+
int pos = 0x44 + j * 19;
98+
sections_lst.Add(s5ProjectByteArray[pos + 15] + s5ProjectByteArray[pos + 16] * 0x100);
9599
}
96100

97101

98-
Step5BlocksFolder blkFld = new Step5BlocksFolder() {Name = "Blocks", Project = this, Parent = ProjectStructure};
102+
Step5BlocksFolder blkFld = new Step5BlocksFolder() { Name = "Blocks", Project = this, Parent = ProjectStructure };
99103
BlocksFolder = blkFld;
100104
ProjectStructure.SubItems.Add(blkFld);
101105

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

108112
foreach (int secpos in sections_lst)
109113
{
110-
int section_start = secpos*0x80;
114+
int section_start = secpos * 0x80;
111115
/* 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 */
112116
/* But I don't know why it's wrong */
113117

@@ -136,7 +140,7 @@ protected override void LoadProject()
136140
for (int j = 0; j < anzbst; j++)
137141
{
138142
byte[] tmp = new byte[15];
139-
Array.Copy(s5ProjectByteArray, section_start + 68 + j*15, tmp, 0, 15);
143+
Array.Copy(s5ProjectByteArray, section_start + 68 + j * 15, tmp, 0, 15);
140144
bstHeaders.Add(tmp);
141145
}
142146

@@ -154,7 +158,7 @@ protected override void LoadProject()
154158
*/
155159

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

159163

160164

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

168172
while (akanz < anzbst && n + 1 < s5ProjectByteArray.Length)
169-
//n < section_start + section_size)
173+
//n < section_start + section_size)
170174
{
171175
akanz++;
172176
int len = 0;
@@ -294,23 +298,23 @@ protected override void LoadProject()
294298
if (_showDeleted)
295299
{
296300
//Read also the deleted Blocks, that means, don't use the Section Headers ...
297-
int akpos = s5ProjectByteArray[0x12]*0x80;
301+
int akpos = s5ProjectByteArray[0x12] * 0x80;
298302

299303
while (akpos <= s5ProjectByteArray.Length - 0x80)
300304
{
301305
while (!IsCurrentPosABlockStart(s5ProjectByteArray, akpos) &&
302306
akpos <= s5ProjectByteArray.Length - 0x80)
303307
akpos += 0x80;
304-
308+
305309
if (akpos <= s5ProjectByteArray.Length - 0x80)
306310
{
307311
bool blkExists = ByteAddressOFExistingBlocks.Contains(akpos);
308-
var tmp=AddBlockInfo(s5ProjectByteArray, ref akpos, blkFld, null);
312+
var tmp = AddBlockInfo(s5ProjectByteArray, ref akpos, blkFld, null);
309313
if (!blkExists)
310314
{
311315
tmp.Deleted = true;
312316
blkFld.step5BlocksinfoList.Add(tmp);
313-
}
317+
}
314318
}
315319
}
316320
}
@@ -319,7 +323,7 @@ protected override void LoadProject()
319323
{
320324
Stream symTabStream = _ziphelper.GetReadStream(_projectfilename.ToLower().Replace("st.s5d", "z0.seq"));
321325

322-
SymbolTable symtab=new SymbolTable();
326+
SymbolTable symtab = new SymbolTable();
323327
symtab.LoadSymboltable(symTabStream);
324328
symTabStream.Close();
325329
symtab.Parent = ProjectStructure;
@@ -328,7 +332,7 @@ protected override void LoadProject()
328332
_allFolders.Add(symtab);
329333
}
330334

331-
var refFld = new ReferenceData((Step5ProgrammFolder) ProjectStructure, this);
335+
var refFld = new ReferenceData((Step5ProgrammFolder)ProjectStructure, this);
332336
ProjectStructure.SubItems.Add(refFld); // { Parent = ProjectStructure, Project = this });
333337
_allFolders.Add(refFld);
334338

@@ -470,7 +474,7 @@ public override string ToString()
470474
retVal += "(zipped)";
471475
if (_showDeleted == true)
472476
retVal += " (show deleted)";
473-
return retVal;
477+
return retVal;
474478
}
475-
}
479+
}
476480
}

0 commit comments

Comments
 (0)