-
Notifications
You must be signed in to change notification settings - Fork 308
/
frmBrowseFiles.cs
452 lines (414 loc) · 20.4 KB
/
frmBrowseFiles.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.IO;
namespace VAGSuite
{
public partial class frmBrowseFiles : DevExpress.XtraEditors.XtraForm
{
public frmBrowseFiles()
{
InitializeComponent();
}
private void buttonEdit1_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
{
FolderBrowserDialog fbd = new FolderBrowserDialog();
fbd.ShowNewFolderButton = false;
try
{
fbd.SelectedPath = buttonEdit1.Text;
}
catch (Exception)
{
}
if (fbd.ShowDialog() == DialogResult.OK)
{
buttonEdit1.Text = fbd.SelectedPath;
Application.DoEvents();
LoadFiles();
}
}
private bool cancelLoad = false;
private bool loading = false;
private void LoadFiles()
{
loading = true;
simpleButton1.Text = "Cancel";
simpleButton2.Enabled = false;
SetProgressVisibility(true);
SetScanProgress("scanning...", 0);
Application.DoEvents();
ctrlAirmassResult airmassResult = new ctrlAirmassResult();
partNumberConverter pnc = new partNumberConverter();
List<ScannedFile> detectedFiles = new List<ScannedFile>();
int fileCounter = 0;
if (Directory.Exists(buttonEdit1.Text))
{
string[] files = Directory.GetFiles(buttonEdit1.Text, "*.*", SearchOption.AllDirectories);
foreach (string file in files)
{
fileCounter++;
int percentage = (fileCounter * 100) / files.Length;
SetScanProgress("importing...", percentage);
if (cancelLoad)
{
cancelLoad = false;
break;
}
FileInfo fi = new FileInfo(file);
this.Text = "Library builder - " + Path.GetFileNameWithoutExtension(file);
Application.DoEvents();
if (IsValidLength(fi.Length))
{
IEDCFileParser parser = Tools.Instance.GetParserForFile(file, false);
byte[] allBytes = File.ReadAllBytes(file);
string boschPartnumber = parser.ExtractBoschPartnumber(allBytes);
List<CodeBlock> newCodeBlocks = new List<CodeBlock>();
List<AxisHelper> newAxisHelpers = new List<AxisHelper>();
if (boschPartnumber != string.Empty)
{
//string additionalInfo = parser.ExtractInfo(allBytes);
SymbolCollection sc = parser.parseFile(file, out newCodeBlocks, out newAxisHelpers);
ECUInfo info = pnc.ConvertPartnumber(boschPartnumber, allBytes.Length);
ScannedFile newFile = new ScannedFile();
newFile.CarMake = info.CarMake;
newFile.CarType = info.CarType;
newFile.EcuType = info.EcuType;
newFile.EngineType = info.EngineType;
newFile.FuellingType = info.FuellingType;
newFile.FuelType = info.FuelType;
newFile.HP = info.HP;
newFile.PartNumber = info.PartNumber;
newFile.SoftwareID = info.SoftwareID;
newFile.TQ = info.TQ;
if (info.EcuType.Contains("EDC15P-6"))
{
newFile.Filetype = EDCFileType.EDC15P6;
}
else if (info.EcuType.Contains("EDC15P"))
{
newFile.Filetype = EDCFileType.EDC15P;
}
else if (info.EcuType.Contains("EDC15M"))
{
newFile.Filetype = EDCFileType.EDC15M;
}
else if (info.EcuType.Contains("EDC15V-5."))
{
newFile.Filetype = EDCFileType.MSA15;
}
else if (info.EcuType.Contains("EDC15V"))
{
newFile.Filetype = EDCFileType.EDC15V;
}
else if (info.EcuType.Contains("EDC15C"))
{
newFile.Filetype = EDCFileType.EDC15C;
}
else if (info.EcuType.Contains("EDC16"))
{
newFile.Filetype = EDCFileType.EDC16;
}
else if (info.EcuType.Contains("EDC17"))
{
newFile.Filetype = EDCFileType.EDC17;
}
else if (info.EcuType.Contains("MSA15"))
{
newFile.Filetype = EDCFileType.MSA15;
}
else if (info.EcuType.Contains("MSA12"))
{
newFile.Filetype = EDCFileType.MSA12;
}
else if (info.EcuType.Contains("MSA11"))
{
newFile.Filetype = EDCFileType.MSA11;
}
else if (info.EcuType.Contains("MSA6"))
{
newFile.Filetype = EDCFileType.MSA6;
}
else if (boschPartnumber != string.Empty)
{
if (fi.Length == 1024 * 1024 * 2)
{
newFile.Filetype = EDCFileType.EDC17;
}
else if(boschPartnumber.StartsWith("EDC17"))
{
newFile.Filetype = EDCFileType.EDC17;
}
else
{
newFile.Filetype = EDCFileType.EDC15V;
}
}
else
{
newFile.Filetype = EDCFileType.EDC16; // default to EDC16???
}
newFile.Filename = file;
newFile.Filesize = (int)fi.Length;
ChecksumResultDetails crd = Tools.Instance.UpdateChecksum(file, true);
string chkType = string.Empty;
if (crd.TypeResult == ChecksumType.VAG_EDC15P_V41) chkType = "VAG EDC15P V4.1";
else if (crd.TypeResult == ChecksumType.VAG_EDC15P_V41V2) chkType = "VAG EDC15P V4.1v2";
else if (crd.TypeResult == ChecksumType.VAG_EDC15P_V41_2002) chkType = "VAG EDC15P V4.1 2002+";
newFile.ChecksumType = chkType;
newFile.ChecksumResult = crd.CalculationResult.ToString();
newFile.NumberChecksums = crd.NumberChecksumsTotal;
newFile.NumberChecksumsFail = crd.NumberChecksumsFail;
newFile.NumberChecksumsOk = crd.NumberChecksumsOk;
newFile.NumberMapsDetected = sc.Count;
string _message = string.Empty;
newFile.MapsOk = CheckMajorMapsPresent(sc, newFile.Filetype, out _message);
newFile.Messages = _message;
foreach (SymbolHelper sh in sc)
{
if (!sh.Varname.StartsWith("3D") && !sh.Varname.StartsWith("2D"))
{
newFile.NumberMapsRecognized++;
}
}
try
{
airmassResult.Currentfile = file;
airmassResult.Symbols = sc;
airmassResult.Currentfile_size = (int)fi.Length;
string additionalInfo = parser.ExtractInfo(allBytes);
airmassResult.NumberCylinders = pnc.GetNumberOfCylinders(info.EngineType, additionalInfo);
airmassResult.ECUType = info.EcuType;
PerformanceResults pr = airmassResult.Calculate(file, sc);
newFile.RealHP = pr.Horsepower;
newFile.RealTQ = pr.Torque;
}
catch (Exception)
{
}
detectedFiles.Add(newFile);
}
else if (file.ToUpper().EndsWith(".BIN") || file.ToUpper().EndsWith(".ORI"))
{
Console.WriteLine("Missed " + file);
// add it as well
if (checkEdit1.Checked)
{
ScannedFile newFile = new ScannedFile();
newFile.CarMake = "";
newFile.CarType = "";
newFile.EcuType = "Unknown";
newFile.EngineType = "";
newFile.FuellingType = "";
newFile.FuelType = "";
newFile.HP = 0;
newFile.PartNumber = "";
newFile.SoftwareID = "";
newFile.TQ = 0;
newFile.Filetype = EDCFileType.Unknown;
newFile.Filename = file;
newFile.Filesize = (int)fi.Length;
newFile.ChecksumType = "";
newFile.ChecksumResult = "";
newFile.NumberChecksums = 0;
newFile.NumberChecksumsFail = 0;
newFile.NumberChecksumsOk = 0;
newFile.NumberMapsDetected = 0;
newFile.MapsOk = false;
newFile.Messages = "";
newFile.NumberMapsRecognized = 0;
detectedFiles.Add(newFile);
}
}
}
}
gridControl1.DataSource = detectedFiles;
}
loading = false;
SetScanProgress("done", 100);
SetProgressVisibility(false);
this.Text = "Library builder";
simpleButton1.Text = "Close";
simpleButton2.Enabled = true;
Application.DoEvents();
}
private bool CheckMajorMapsPresent(SymbolCollection newSymbols, EDCFileType type, out string _message)
{
_message = string.Empty;
if (type == EDCFileType.EDC15C || type == EDCFileType.EDC15M || type == EDCFileType.EDC16 || type == EDCFileType.EDC17) return false; ;
if (type == EDCFileType.EDC15P || type == EDCFileType.EDC15P6)
{
if (MapsWithNameMissing("Injector duration", newSymbols)) _message += "Injector duration maps missing" + Environment.NewLine;
if (MapsWithNameMissing("Inverse driver wish", newSymbols)) _message += "Inverse driver wish map missing" + Environment.NewLine;
}
if (type == EDCFileType.EDC15P || type == EDCFileType.EDC15P6 || type == EDCFileType.EDC15V)
{
if (MapsWithNameMissing("MAF correction", newSymbols)) _message += "MAF correction map missing" + Environment.NewLine;
if (MapsWithNameMissing("MAF linearization", newSymbols)) _message += "MAF linearization map missing" + Environment.NewLine;
if (MapsWithNameMissing("MAP linearization", newSymbols)) _message += "MAP linearization map missing" + Environment.NewLine;
if (MapsWithNameMissing("SOI limiter", newSymbols)) _message += "SOI limiter missing" + Environment.NewLine;
}
if (MapsWithNameMissing("Idle RPM", newSymbols)) _message += "Idle RPM map missing" + Environment.NewLine;
if (MapsWithNameMissing("EGR", newSymbols)) _message += "EGR maps missing" + Environment.NewLine;
if (MapsWithNameMissing("SVBL", newSymbols)) _message += "SVBL missing" + Environment.NewLine;
if (MapsWithNameMissing("Torque limiter", newSymbols)) _message += "Torque limiter missing" + Environment.NewLine;
if (MapsWithNameMissing("Smoke limiter", newSymbols)) _message += "Smoke limiter missing" + Environment.NewLine;
//if (MapsWithNameMissing("IQ by MAF limiter", newSymbols)) _message += "IQ by MAF limiter missing" + Environment.NewLine;
if (MapsWithNameMissing("Start of injection", newSymbols)) _message += "Start of injection maps missing" + Environment.NewLine;
if (MapsWithNameMissing("N75 duty cycle", newSymbols)) _message += "N75 duty cycle map missing" + Environment.NewLine;
if (MapsWithNameMissing("Boost target map", newSymbols)) _message += "Boost target map missing" + Environment.NewLine;
if (MapsWithNameMissing("Driver wish", newSymbols)) _message += "Driver wish map missing" + Environment.NewLine;
if (MapsWithNameMissing("Boost limit map", newSymbols)) _message += "Boost limit map missing" + Environment.NewLine;
if (_message == "") return true;
return false;
}
private bool MapsWithNameMissing(string varName, SymbolCollection newSymbols)
{
foreach (SymbolHelper sh in newSymbols)
{
if (sh.Varname.StartsWith(varName)) return false;
}
return true;
}
private bool IsValidLength(long len)
{
if (len == 0x8000) return true;
else if (len == 0x10000) return true;
else if (len == 0x20000) return true;
else if (len == 0x40000) return true;
else if (len == 0x80000) return true;
else if (len == 0x100000) return true;
else if (len == 0x200000) return true;
return false;
}
private void buttonEdit1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
if (!loading)
{
LoadFiles();
}
}
else if (e.KeyCode == Keys.Escape)
{
if (loading) cancelLoad = true;
}
}
private void simpleButton1_Click(object sender, EventArgs e)
{
if (loading) cancelLoad = true;
else this.Close();
}
private void simpleButton2_Click(object sender, EventArgs e)
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "Excel worksheets|*.xlsx";
if (sfd.ShowDialog() == DialogResult.OK)
{
try
{
gridControl1.ExportToXlsx(sfd.FileName);
}
catch (Exception)
{
}
}
}
private void SetProgressVisibility(bool visible)
{
labelControl2.Visible = visible;
progressBarControl1.Visible = visible;
Application.DoEvents();
}
private void SetScanProgress(string text, int percentage)
{
try
{
bool _update = false;
if (labelControl2.Text != text)
{
labelControl2.Text = text;
_update = true;
}
if (Convert.ToInt32(progressBarControl1.EditValue) != percentage)
{
progressBarControl1.EditValue = percentage;
_update = true;
}
if (_update) Application.DoEvents();
}
catch (Exception)
{
}
}
private void simpleButton3_Click(object sender, EventArgs e)
{
FolderBrowserDialog fbd = new FolderBrowserDialog();
if (fbd.ShowDialog() == DialogResult.OK)
{
if (gridControl1.DataSource != null)
{
if (gridControl1.DataSource is List<ScannedFile>)
{
List<ScannedFile> detectedFiles = (List<ScannedFile>)gridControl1.DataSource;
foreach (ScannedFile sf in detectedFiles)
{
string outputFolder = fbd.SelectedPath;
if (sf.Filetype.ToString() != string.Empty)
{
outputFolder = Path.Combine(outputFolder, sf.Filetype.ToString());
if (!Directory.Exists(outputFolder))
{
Directory.CreateDirectory(outputFolder);
}
}
if (sf.CarMake != string.Empty)
{
outputFolder = Path.Combine(outputFolder, sf.CarMake);
if (!Directory.Exists(outputFolder))
{
Directory.CreateDirectory(outputFolder);
}
}
if (sf.CarType != string.Empty)
{
outputFolder = Path.Combine(outputFolder, sf.CarType);
if (!Directory.Exists(outputFolder))
{
Directory.CreateDirectory(outputFolder);
}
}
string filename = sf.PartNumber;
if (filename == string.Empty) filename = Path.GetFileName(sf.Filename);
if (sf.SoftwareID != string.Empty) filename += "_" + sf.SoftwareID;
if (sf.EngineType != string.Empty) filename += "_" + sf.EngineType;
if (sf.RealHP != 0) filename += "_" + sf.RealHP.ToString() +"hp";
if (sf.RealTQ != 0) filename += "_" + sf.RealTQ.ToString() + "Nm";
if (sf.NumberChecksumsFail > 0)
{
filename += "_CHKFAIL";
}
//if (sf.NumberChecksumsFail == 0)
{
// only valid checksummed files to the output
try
{
File.Copy(sf.Filename, Path.Combine(outputFolder, filename), false);
}
catch (Exception)
{
}
}
}
}
}
}
}
}
}