-
Notifications
You must be signed in to change notification settings - Fork 4
/
EEP_ini_files.html
345 lines (298 loc) · 10.7 KB
/
EEP_ini_files.html
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
<!DOCTYPE html>
<!--
Analyze .ini files of EEP
Definition:
https://wiki.eepshopping.de/index.php?title=Externe_*.ini-Dateien_der_Modelle
Icons:
https://wiki.eepshopping.de/index.php?title=Modellicons
File Models.db contains some more data:
dwGrp
sName Model name
sPath File path
sSection Model type
dwEpoch Epoch number
dwCountry Country number
dwCoModel
dwCoOriginal
dwIcon Icon number
-->
<html lang="de">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Einstellungskombinationen von EEP-ini-Dateien</title>
<meta name="description" content="Dieses Programm liest .ini-Dateien und zeigt die darin enthaltenen Einstellungskombinationen an.">
<meta name="author" content="Frank Buchholz">
<meta name="keywords" content="EEP,.anl3,Rollmaterialien, Signale" />
<meta name="language" content="de" />
<link rel="icon" href="https://www.eepforum.de/images/favicon.ico" type="image/x-icon">
<style>
.hidden {
display: none;
}
fieldset {
border-width: 0;
margin-inline-start: 0;
margin-inline-end: 0;
padding-block-start: 0;
padding-inline-start: 0;
padding-inline-end: 0;
padding-block-end: 0;
}
</style>
<script type="text/javascript" src="js/EEP_Signale_Daten.js"></script><!-- Lade Zusatzdaten zu Signalen: Name, Signalstellung -->
<script type="text/javascript" src="js/EEP_MovableAxis_Data.js"></script><!-- Lade Zusatzdaten zu beweglichen Achsen -->
<script type="text/javascript">
<!-- - - - - - - -->
function readIniFiles(fileList) {
// Selection screen
document.getElementById("fileselector").classList.add("hidden");
const promises = [];
for (const file of fileList) {
const filePromise = new Promise(resolve => {
const reader = new FileReader();
reader.readAsText(file, 'windows-1252');
reader.onload = (ProgressEvent) => {
resolve({
file: file,
section: parseIniString(reader.result)
});
}
});
promises.push(filePromise);
}
Promise.all(promises).then(iniFiles => {
// iniFiles will be an array containing contents of the files
const settingsCombinations = {};
for (const iniFile of iniFiles) {
iniFile.combination = {}; // Setting
iniFile.settingsCombination = 0; // Hash code which represents the set of settings
// Is it a signal file?
let section = 'Model_SignalFunc'; // specific section for signals
let pattern = /^Pos(\d+)_Fn_Name_/ // Signal position: Pos01_Fn_Name_GER
if (!iniFile.section[section]) {
// no signal file, let's try to interpret movable axis
section = 'FileInfo'; // Movable axis
pattern = /^MovAxis(\d+)_/; // Movable axis: MovAxis3_GER
}
if (iniFile.section[section]) {
for (const parameter in iniFile.section[section]) {
const match = parameter.match(pattern);
if (match) {
const id = Number(match[1]);
if (iniFile.combination[id]) { // Only process the first entry per position/axis
continue;
}
iniFile.combination[id] = { // Get all languages in one step
DE : iniFile.section[section][match[0] + 'GER'],
EN : iniFile.section[section][match[0] + 'ENG'],
FR : iniFile.section[section][match[0] + 'FRA'],
}
if (section == 'Model_SignalFunc') { // Signals
iniFile.combination[id].Pos = id;
} else if (section == 'FileInfo') { // Others
iniFile.combination[id].MovAxis = id;
}
}
}
// Generate ID
if (iniFile.combination != {}) {
iniFile.settingsCombination = Math.abs(JSON.stringify(iniFile.combination).hashCode());
/*
Beispiele zu settingsCombinationen:
[0256533125] = { 1 : Halt, 2 : Fahrt, }
[1275122147] = { 1 : Fahrt, 2 : Halt, }
*/
}
if (!settingsCombinations[iniFile.settingsCombination]) {
settingsCombinations[iniFile.settingsCombination] = {
combinationArray : iniFile.combination,
Entries : [],
};
}
// Cross reference
settingsCombinations[iniFile.settingsCombination].Entries.push(
iniFile.file.name.substr(0, iniFile.file.name.length - 4) + ", '" + iniFile.section.FileInfo.Name_GER + "', '" + iniFile.section.FileInfo.Description_GER + "'"
);
}
}
showIniFiles(iniFiles, settingsCombinations);
});
}
String.prototype.hashCode = function() {
let hash = 0;
if (this.length === 0) return hash;
for (let i = 0; i < this.length; i++) {
const chr = this.charCodeAt(i);
hash = ((hash << 5) - hash) + chr;
hash |= 0; // Convert to 32bit integer
}
return hash;
};
function parseIniString(data){
const regex = {
section: /^\s*\[\s*([^\]]*)\s*\]\s*$/,
param: /^\s*([^=]+?)\s*=\s*\"?(.*?)\"?\s*$/,
comment: /^\s*;.*$/,
};
const value = {};
const lines = data.split(/[\r\n]+/);
let section = null;
for (const line of lines) {
if (regex.comment.test(line)) {
continue;
} else if (regex.param.test(line)) {
const match = line.match(regex.param);
if (section) {
value[section][match[1]] = match[2];
} else {
value[match[1]] = match[2];
}
} else if (regex.section.test(line)) {
const match = line.match(regex.section);
value[match[1]] = {};
section = match[1];
} else if (line.length == 0 && section) {
section = null;
};
}
return value;
}
function showIniFiles(iniFiles, settingsCombinations) {
function orderByFileName(a,b) {
// Sort by text ascending
const NameA = iniFiles[a].file.name.toLowerCase();
const NameB = iniFiles[b].file.name.toLowerCase();
if (NameA < NameB) { return -1; }
if (NameA > NameB) { return 1; }
return 0;
}
const unknownOnly = document.getElementById('checkboxUnknownOnly').checked;
const target = document.getElementById('container');
let div, p;
div = document.createElement('div');
target.appendChild(div);
if ( document.querySelector('input[name="outputFormat"]:checked').id === "list" ) { // list, code
// Show list grouped by settingsCombination
for (const settingsCombination in settingsCombinations) {
// Header
p = document.createElement('p');
div.appendChild(p);
p.innerHTML =
`<b>Einstellungskombination ${('0000000000' + settingsCombination).slice(-10)}` + '</b><br>'
;
// settingsCombinations
p = document.createElement('p');
div.appendChild(p);
if ( Object.keys(settingsCombinations[settingsCombination].combinationArray).length === 0 ) {
p.innerHTML = '[empty]';
} else {
for (const combinationNr in settingsCombinations[settingsCombination].combinationArray) {
const combination = settingsCombinations[settingsCombination].combinationArray[combinationNr];
p.innerHTML +=
combinationNr + ' : '
+ (combination.DE ? '"' + combination.DE + '" ' : '')
+ (combination.EN ? '"' + combination.EN + '" ' : '')
+ (combination.FR ? '"' + combination.FR + '" ' : '')
+ '<br>'
;
}
}
// Entries
p = document.createElement('p');
div.appendChild(p);
for (const index in settingsCombinations[settingsCombination].Entries) {
p.innerHTML +=
`${settingsCombinations[settingsCombination].Entries[index]}<br>`
;
}
}
} else { // outputFormat = code
// Stringify data for usage in EEP_Gleisplan.html and EEP_Inventar.html
p = document.createElement('p');
div.appendChild(p);
p.innerHTML = 'const data = {';
// for (const iniFile of iniFiles) {
Object.keys(iniFiles).sort(orderByFileName).forEach(function(key, index) {
const iniFile = iniFiles[key];
let filename = iniFile.file.name.substr(0, iniFile.file.name.length - 4);
if (!iniFile.section.Model_SignalFunc) {
filename = filename.toUpperCase(); // Upper case file name for rolling stocks
}
if ( !unknownOnly || ( !Signalstellung[filename] && !MovableAxis[filename] ) ) { // Ignore known data
if ( Object.keys(iniFile.combination).length > 0 ) {
p.innerHTML += `<br> "${filename}" : `+'{'; // Show file name as key
const FileInfo = iniFile.section.FileInfo;
if (FileInfo) {
p.innerHTML += '<br> '
+'Name'
+' : {' // Show name as data
+ (FileInfo.Name_GER ? `DE : "${FileInfo.Name_GER}", ` : '')
+ (FileInfo.Name_ENG ? `EN : "${FileInfo.Name_ENG}", ` : '')
+ (FileInfo.Name_FRA ? `FR : "${FileInfo.Name_FRA}", ` : '')
+ '},'
//+ `Desc = ${FileInfo.Description_GER}<br>`
//+ `settingsCombination = ${iniFile.settingsCombination}<br>`
;
if (FileInfo.Icon) {
p.innerHTML += '<br> '
+'Icon'
+' : ' + FileInfo.Icon + ',';
}
}
p.innerHTML += '<br> ' // Show position for signals respective movable axis for others
+ (iniFile.section.Model_SignalFunc ? 'Pos' : 'MovAxis' )
+ ' : {'
//p = document.createElement('p');
//div.appendChild(p);
// for (const id in iniFile.combination) {
let index = 0;
for (key of Object.keys(iniFile.combination).sort((a, b) => (a - b))) { // Sorted output
const entry = iniFile.combination[key];
let id = key;
if (entry.MovAxis) {
index++;
id = index;
}
p.innerHTML += `<br> ${id} : `
+'{'
+ (entry.DE ? `DE : "${entry.DE}", ` : '')
+ (entry.EN ? `EN : "${entry.EN}", ` : '')
+ (entry.FR ? `FR : "${entry.FR}", ` : '')
+ (entry.MovAxis ? `axis : ${entry.MovAxis}, ` : '')
+ '},'
;
}
p.innerHTML += '<br> }},';
}
}
// }
})
p.innerHTML += '<br>}';
}
}
</script>
</head>
<body>
<h3>EEP .ini-Dateien</h3>
<section id='fileselector'> <!-- Selection screen -->
<form action='#' onsubmit="return false;"> <!-- better not to use inline listener, explizit register is better -->
<label for="fileinput">Wähle und lade eine oder mehrere EEP .ini-Dateien</label>
<input type='file' id='inifile' accept='.ini' multiple onchange='readIniFiles(this.files)'>
<!-- An extra button is not neccessary -->
<!-- <input type='button' id='btnLoad' value='Load' onclick='loadFile();'> -->
</form>
<p>Die .ini-Dateien im Ordner C:\EEP15\Resourcen.unp\ werden über das EEP-Programm mit der Funktion "Extras ⭢ Ressourcen-Extraktor" erstellt.</p>
<p>Die Ausgabe erfolgt gruppiert nach der Kombination der in der .ini-Datei enthaltenen Einstellungen. Dafür wird je Kombination eine eindeutige ID generiert.</P>
<form>
<fieldset>
Format der Ausgabe:
<input type="radio" name="outputFormat" id="list" checked /><label for="list">Liste</label>
<input type="radio" name="outputFormat" id="code" /><label for="code">Code</label>
<input id="checkboxUnknownOnly" type="checkbox"><label for="checkboxUnknownOnly">Nur Daten zu bislang unbekannten Dateien anzeigen</label
</fieldset>
</form>
<p><small>(c) Frank Buchholz, 2022</small></p>
</section> <!-- fileselector -->
<div id='container'></div>
</body>
</html>