Skip to content

Commit d6e5279

Browse files
committed
Do downgrade tab
1 parent 18a60bd commit d6e5279

File tree

3 files changed

+134
-6
lines changed

3 files changed

+134
-6
lines changed

QuestAppVersionSwitcher/Assets/html/index.html

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
</div>
1818
<div class="menuItem selected" section="backup">Backup</div>
1919
<div class="menuItem" section="downgrade">Downgrade
20-
<div class="button" id="reloadDowngradeIframe" onclick="ReloadDowngradeIFrame()">Reload</div></div>
20+
<div class="button" id="reloadDowngradeIframe" onclick="UpdateDowngrades()">Reload</div></div>
2121
<div class="menuItem" section="download">Download progress</div>
2222
<div class="menuItem" section="patching">Mod my game</div>
2323
<div class="menuItem" section="mods" id="modsButton">Installed Mods</div>
@@ -259,11 +259,21 @@ <h2>You can download mods and cosmetics from the following sites. Only QMods are
259259
<label><input type="checkbox" id="appdata" value="only backup app data" style="width: auto;">Only backup app data</label>
260260
<div id="backupTextBox" class="textBox"></div>
261261
</div>
262-
</div>y
263-
<div class="contentItem hidden" style="padding: 0px; position: relative" id="downgrade" style="padding: 0px;">
264-
<h2>Available downgrades</h2>
265-
<div class="infiniteList" id="downgradeList"></div>
266-
<h1>This is ToDo</h1>
262+
</div>
263+
<div class="contentItem hidden" style="position: relative" id="downgrade">
264+
<h3>Compatible downgrades for <div class="inline packageName"></div></h3>
265+
<div id="currentVersionDowngrade" class="inline"></div>
266+
<br>
267+
<table id="compatibleDowngrades">
268+
</table>
269+
<br>
270+
<br>
271+
<h3>Downgrades available if you install other versions</h3>
272+
These versions can only be downgraded to once you install the version shown at the left before.
273+
<table id="availableDowngrades">
274+
275+
</table>
276+
267277
</div>
268278
<div class="contentItem hidden" id="download">
269279
<h2>Game Downloads</h2>

QuestAppVersionSwitcher/Assets/html/script.js

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,99 @@ socket.onclose = function (e) {
3232
// reconnect
3333
socket = new WebSocket("ws://" + window.location.hostname + ":" + (parseInt(window.location.port) + 1) + "/");
3434
}
35+
setTimeout(() => {
36+
UpdateDowngrades()
37+
}, 2500)
38+
39+
function DownloadDowngrade(package, sourceSha, targetSha, targetVersion) {
40+
fetch("/api/downloaddiff", {
41+
method: "POST", body: JSON.stringify({
42+
packageName: package,
43+
sourceSha: sourceSha,
44+
targetSha: targetSha,
45+
targetVersion: targetVersion
46+
})
47+
})
48+
OpenTab("download")
49+
}
50+
function UpdateDowngrades() {
51+
document.getElementById("compatibleDowngrades").innerHTML = `Loading downgrades${squareLoader}`
52+
fetch(`https://raw.githubusercontent.com/ComputerElite/APKDowngrader/main/versions.json`).then(res => res.json().then(res => {
53+
54+
document.getElementById("compatibleDowngrades").innerHTML = `Checking compatibility. This may take 2 minutes${squareLoader}`
55+
fetch(`/api/currentsha256`).then(s => s.json().then(s => {
56+
var sha = s.msg
57+
var compatible = []
58+
var available = []
59+
for(const version of res.versions) {
60+
if(version.appid == config.currentApp) {
61+
if(version.SSHA256 == sha) {
62+
compatible.push(version)
63+
} else {
64+
available.push(version)
65+
}
66+
}
67+
}
68+
var html = ""
69+
if(compatible.length > 0) {
70+
html = `<tr>
71+
<th>Version</th>
72+
<th></th>
73+
<th>Info</th>
74+
</tr>`
75+
for(const version of compatible) {
76+
html += `
77+
<tr>
78+
<td>${version.TV}</td>
79+
<td><div onclick="DownloadDowngrade('${config.currentApp}', '${version.SSHA256}', '${version.TSHA256}', '${version.TV}')" class="button">Download</div></td>
80+
<td>${version.Annotation ? version.Annotation : "None"}</td>
81+
</tr>`
82+
}
83+
} else {
84+
html = "No compatible versions found for currently installed version. Please refer to below"
85+
}
86+
document.getElementById("compatibleDowngrades").innerHTML = html
87+
88+
if(available.length > 0) {
89+
html = `<tr>
90+
<th>Needed Version</th>
91+
<th>Target Version</th>
92+
<th>Info</th>
93+
</tr>`
94+
for(const version of available) {
95+
html += `
96+
<tr>
97+
<td>${version.SV}</td>
98+
<td>${version.TV}</td>
99+
<td>${version.Annotation ? version.Annotation : "None"}</td>
100+
</tr>`
101+
}
102+
} else {
103+
html = "No other downgrades available for this game."
104+
}
105+
document.getElementById("availableDowngrades").innerHTML = html
106+
107+
}))
108+
})).catch(e => {
109+
document.getElementById("compatibleDowngrades").innerHTML = `<span style="color: #EE0000;">Error loading downgrades</span>`
110+
})
111+
fetch(`/api/patching/getmodstatus`).then(res => res.json().then(res => {
112+
document.getElementById("currentVersionDowngrade").innerHTML = `Current installed version: ${res.version} ${res.isPatched ? "(Patched)" : ""}`
113+
}))
114+
}
115+
116+
function FormatBytes(bytes, decimals = 2) {
117+
if (bytes > 1099511627776) return (input / 1099511627776.0).toFixed(decimals) + " TB";
118+
// GB
119+
else if (bytes > 1073741824) return (input / 1073741824.0).toFixed(decimals) + " GB";
120+
// MB
121+
else if (bytes > 1048576) return (input / 1048576.0).toFixed(decimals) + " MB";
122+
// KB
123+
else if (bytes > 1024) return (input / 1024.0).toFixed(decimals) + " KB";
124+
// Bytes
125+
else return bytes + " Bytes";
126+
}
127+
35128

36129
socket.onmessage = function (e) {
37130
var data = JSON.parse(e.data);

QuestAppVersionSwitcher/Assets/html/style.css

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,11 @@ body {
277277
background-color: #000000EE;
278278
}
279279

280+
.downgradesList {
281+
display: flex;
282+
flex-direction: column;
283+
}
284+
280285
.menuContainer {
281286
background-color: #414141;
282287
width: 100%;
@@ -599,6 +604,26 @@ iframe {
599604
z-index: 5;
600605
}
601606

607+
table {
608+
border-collapse: collapse;
609+
width: 100%;
610+
background-color: #1F1F1F;
611+
border-radius: 10px;
612+
}
613+
614+
th {
615+
text-align: left;
616+
padding: 10px;
617+
}
618+
619+
tr {
620+
border-bottom: 1px solid #FFFFFF;
621+
}
622+
623+
td {
624+
padding: 10px;
625+
}
626+
602627
.listContainer {
603628
display: flex;
604629
align-items: center;

0 commit comments

Comments
 (0)