-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrash_report_model_info_parser.html
More file actions
178 lines (165 loc) · 5.62 KB
/
crash_report_model_info_parser.html
File metadata and controls
178 lines (165 loc) · 5.62 KB
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
<!DOCTYPE html>
<style>
table {
border-collapse: collapse;
}
td, th {
margin: 0;
padding: 5px;
}
td + td, th + th {
border-left: solid black 1px;
}
tbody > tr {
border-top: solid black 1px;
}
caption {
position: sticky;
top: 0;
z-index: 2;
text-align: left;
background: white;
padding: 0.83em 0;
font-size: 1.5em;
font-weight: bold;
}
th {
position: sticky;
top: calc(0.83em * 2 + 2.7em);
/* tbody内のセルより手前に表示する */
z-index: 1;
background-color: white;
}
.center {
text-align: center;
}
</style>
<script src="./external/pako.es5.min.js"></script>
<h1>FixRTM Crash Report ModelPack information parser</h1>
<div id="file-accept">
Please choose file or drop crash report here: <input type="file" id="file">
</div>
<div id="status-reading-file" hidden>
Reading file...
</div>
<div id="status-parsing-file" hidden>
Parsing file...
</div>
<div id="output-area" hidden>
</div>
<script>
const preEB = "-----BEGIN REAL TRAIN MOD MODEL PACK INFORMATION-----"
const postEB = "-----END REAL TRAIN MOD MODEL PACK INFORMATION-----"
const accept = document.getElementById("file-accept")
const statusReadingFile = document.getElementById("status-reading-file")
const statusParsing = document.getElementById("status-parsing-file")
const outputArea = document.getElementById("output-area")
/** @type HTMLInputElement */
const file = document.getElementById("file")
file.addEventListener("change", () => {
const inputFile = file.files[0];
accept.hidden = true;
statusReadingFile.hidden = false;
const reader = new FileReader();
reader.onload = (e) => {
statusReadingFile.hidden = true;
statusParsing.hidden = false;
setTimeout(() => {
parseFile(e.target.result)
}, 10);
}
reader.readAsBinaryString(inputFile);
})
/**
* @param binStr {string} binaryString
*/
function parseFile(binStr) {
try {
const preEBAt = binStr.indexOf(preEB);
if (preEBAt < 0) return alert("invalid crash report: preEB not found");
const postEBAt = binStr.indexOf(postEB, preEBAt);
if (postEBAt < 0) return alert("invalid crash report: postEBAt not found");
const base64 = binStr.substring(preEBAt + preEB.length, postEBAt);
const data = b2Uint8Array(atob(base64.replace(/\s+/g, '')));
const gunziped = pako.ungzip(data);
const json = (new TextDecoder('utf-8')).decode(gunziped);
const obj = JSON.parse(json);
const version = obj[0]
switch (version) {
case 1:
parseVersion1(obj)
break
default:
return alert(`invalid crash report: unsupported version: ${version}`);
}
statusParsing.hidden = true;
outputArea.hidden = false;
} catch (e) {
return alert(`invalid crash report: unexpected error: ${e}`);
}
}
function parseVersion1(obj) {
// format information copied from fixrtm
/*
the json formant
[version, value]
// v1.0 format
[1,Map<model_pack:String,List<ModelPack>>]
ModelPack=[state:string,id:string,sourceName:string,includedInSMP:boolean]
*/
const data = obj[1]
for (const [modelPack, models] of Object.entries(data)) {
const tbody = makeElement("tbody")
outputArea.appendChild(makeElement("table", {
children: [
makeElement("caption", { text: modelPack }),
makeElement("thead", {
children: [
makeElement("tr", {
children: [
makeElement("th", {text: "Id"}),
makeElement("th", {text: "State"}),
makeElement("th", {text: "source file"}),
makeElement("th", {text: "IncludedInSMP", classes: "center"}),
],
}),
],
}),
tbody,
],
}));
for (const model of models) {
tbody.appendChild(makeElement("tr", {
children: [
makeElement("td", {text: model[1]}),
makeElement("td", {text: model[0]}),
makeElement("td", {text: model[2]}),
makeElement("td", {text: `${model[3]}`, classes: "center"}),
],
}));
}
}
}
function makeElement(name, config) {
const element = document.createElement(name)
if (config?.text)
element.textContent = config.text
if (config?.children)
for (const child of config.children) element.appendChild(child)
if (config?.classes)
element.classList.add(config.classes.split(' '))
return element
}
/**
* @param binStr {string} binary string
* @returns {Uint8Array}
*/
function b2Uint8Array(binStr) {
const len = binStr.length;
const bytes = new Uint8Array(len);
for (let i = 0; i < len; i++) {
bytes[i] = binStr.charCodeAt(i);
}
return bytes;
}
</script>