Add configkeys.h download option

This commit is contained in:
Michal Moskal 2019-01-06 19:35:51 +00:00
parent 881bc93ca6
commit f2217cd8ff
3 changed files with 42 additions and 14 deletions

View file

@ -27,6 +27,7 @@
.btn-dl:hover {
background-color: green;
float: right;
color: white;
}
</style>
</head>
@ -34,7 +35,6 @@
<body ondrop="dropHandler(event);" ondragover="dragOverHandler(event);">
<section class="page-header">
<h1 class="project-name">CF2 patcher</h1>
</section>
<section class="main-content">
@ -45,6 +45,9 @@
<h2>Information</h2>
<pre><code id="currconfig">Drop UF2 file above to see its config.</code></pre>
<p>
<a href="#" onclick="defines()">Download configkeys.h</a>
</p>
</section>
<script>

View file

@ -196,6 +196,25 @@ const UF2_MAGIC_END = 0x0AB16F30 // Ditto
const CFG_MAGIC0 = 0x1e9e10f1
const CFG_MAGIC1 = 0x20227a79
function configkeysH() {
let r = "#ifndef __CONFIGKEYS_H\n#define __CONFIGKEYS_H 1\n\n"
r += "#define CFG_MAGIC0 0x1e9e10f1\n"
r += "#define CFG_MAGIC1 0x20227a79\n\n"
for (let k of Object.keys(configKeys)) {
r += `#define CFG_${k} ${configKeys[k]}\n`
}
for (let k of Object.keys(enums)) {
r += "\n"
for (let kk of Object.keys(enums[k])) {
r += `#define ${k}_${kk} ${enums[k][kk]}\n`
}
}
r += "\n#endif // __CONFIGKEYS_H\n"
return r
}
function err(msg) {
log("Fatal error: " + msg)
if (typeof window == "undefined") {

View file

@ -11,6 +11,21 @@ function restorePatch() {
document.getElementById("apply").onclick = applyPatch
}
function download(buf, name) {
let blob = new Blob([buf], {
type: "application/x-uf2"
});
let url = URL.createObjectURL(blob);
let a = document.createElement("a");
document.body.appendChild(a);
a.style = "display: none";
a.href = url;
a.download = name;
a.click();
window.URL.revokeObjectURL(url);
}
let currUF2 = null
let currUF2Name = ""
@ -28,7 +43,10 @@ function wrap(f) {
log("Exception: " + e.message)
showMSG()
}
}
function defines() {
download(configkeysH(), "configkeys.h")
}
function applyPatch() {
@ -47,19 +65,7 @@ function applyPatch() {
} else {
log("\nChanges:\n" + changes)
log("Downloading " + currUF2Name)
let blob = new Blob([buf], {
type: "application/x-uf2"
});
let url = URL.createObjectURL(blob);
let a = document.createElement("a");
document.body.appendChild(a);
a.style = "display: none";
a.href = url;
a.download = currUF2Name
a.click();
window.URL.revokeObjectURL(url);
download(buf, currUF2Name)
}
}
})