Skip to content

Commit 52fdc4f

Browse files
ComputerEliteComputerElite
authored andcommitted
lots of stuff
1 parent 6bcc556 commit 52fdc4f

File tree

9 files changed

+70
-30
lines changed

9 files changed

+70
-30
lines changed

Assets/html/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ <h2>To download mods simply download any mod from one of the following sites</h2
267267
<div class="button" id="abortPassword">Abort Download</div>
268268
</div>
269269
<div class="buttonContainer buttonMargin">
270-
<div class="button" id="confirmPassword">Start dowload</div>
270+
<div class="button" id="confirmPassword">Start download</div>
271271
</div>
272272
</div>
273273
</div>

Assets/html/script.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const toastsE = document.getElementById("toasts")
1616
document.getElementById("downgradeframe").src = `https://oculusdb.rui2015.me/search?query=Beat+Saber&headsets=MONTEREY%2CHOLLYWOOD${IsOnQuest() ? `&isqavs=true` : ``}`
1717

1818
function IsOnQuest() {
19-
return location.host.startsWith("127.0.0.1")
19+
return location.host.startsWith("127.0.0.1") ||location.host.startsWith("localhost")
2020
}
2121

2222
function BrowserGo(direction) {
@@ -69,17 +69,21 @@ function UpdatePatchingStatus() {
6969
res.json().then(res => {
7070
if(res.isPatched) {
7171
document.getElementById("modsButton").style.visibility = "visible"
72+
document.getElementById("getModsButton").style.visibility = "visible"
7273
patchStatus.innerHTML = "<h2>Game is already patched. You can install mods</h2>"
7374
} else if(!res.isInstalled) {
7475
patchStatus.innerHTML = `<h2>Game is not installed. Please restore a backup or install the app so the game can get patched</h2>`
7576
document.getElementById("modsButton").style.visibility = "hidden"
77+
document.getElementById("getModsButton").style.visibility = "hidden"
7678
} else if(res.canBePatched) {
7779
patchStatus.innerHTML = `<h2>Game is not patched.</h2>
7880
<div class="button" onclick="PatchGame()">Patch it now</div>`
7981
document.getElementById("modsButton").style.visibility = "hidden"
82+
document.getElementById("getModsButton").style.visibility = "hidden"
8083
} else {
8184
patchStatus.innerHTML = "<h2>Game can not be modded</h2>"
8285
document.getElementById("modsButton").style.visibility = "hidden"
86+
document.getElementById("getModsButton").style.visibility = "hidden"
8387
}
8488

8589
if(!IsOnQuest() && !res.isPatched && false) {
@@ -388,6 +392,7 @@ setInterval(() => {
388392
<div class="downloadProgressContainer">
389393
<div class="downloadProgressBar" style="width: ${d.percentage * 100}%;"></div>
390394
</div>
395+
<input type="button" class="DownloadText" value="Cancel" onclick="StopDownload('${d.backupName}')">
391396
<div class="DownloadText" style="color: ${d.textColor};">
392397
${d.backupName} ${d.percentageString} ${d.doneString} / ${d.totalString} ${d.speedString} ETA ${d.eTAString}
393398
</div>
@@ -738,6 +743,8 @@ window.onmessage = (e) => {
738743
OpenGetPasswordPopup()
739744
}
740745
document.getElementById("abortPassword").onclick = () => {
746+
document.getElementById("abortPassword").innerHTML = "Abort Download"
747+
document.getElementById("confirmPassword").style.display = "block"
741748
CloseGetPasswordPopup()
742749
}
743750
document.getElementById("confirmPassword").onclick = () => {
@@ -749,14 +756,17 @@ document.getElementById("confirmPassword").onclick = () => {
749756
TextBoxError("step7box", text)
750757
} else if (res.status == 200) {
751758
TextBoxGood("step7box", text)
752-
setTimeout(() => {
753-
CloseGetPasswordPopup()
754-
}, 5000)
759+
document.getElementById("abortPassword").innerHTML = "Close Popup"
760+
document.getElementById("confirmPassword").style.display = "none"
755761
}
756762
})
757763
})
758764
}
759765

766+
function StopDownload(name) {
767+
fetch(`/canceldownload?name=${name}`)
768+
}
769+
760770
document.getElementById("logs").onclick = () => {
761771
TextBoxText("logsText", "Working.. please wait")
762772
fetch("/questappversionswitcher/uploadlogs?password=" + document.getElementById("logspwd").value).then(res => {

CoreService.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
using QuestAppVersionSwitcher.Mods;
1010
using System;
1111
using System.IO;
12+
using System.Net.Security;
13+
using System.Net;
1214
using System.Reflection;
1315
using System.Text.Json;
1416
using System.Threading;
@@ -25,9 +27,10 @@ public class CoreService
2527
public static string ua = "Mozilla/5.0 (X11; Linux x86_64; Quest) AppleWebKit/537.36 (KHTML, like Gecko) OculusBrowser/23.2.0.4.49.401374055 SamsungBrowser/4.0 Chrome/104.0.5112.111 VR Safari/537.36";
2628
public async void Start()
2729
{
28-
29-
// Check permissions and request if needed
30-
if (await Permissions.RequestAsync<Permissions.StorageWrite>() != PermissionStatus.Granted)
30+
// Accept every ssl certificate, may be a security risk but it's the only way to get the mod list (CoPilot)
31+
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate { return true; });
32+
// Check permissions and request if needed
33+
if (await Permissions.RequestAsync<Permissions.StorageWrite>() != PermissionStatus.Granted)
3134
{
3235
if (await Permissions.RequestAsync<Permissions.StorageWrite>() != PermissionStatus.Granted) return;
3336
}

DownloadListener.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Android.Webkit;
2+
using ComputerUtils.Android.Logging;
23
using Java.Interop;
34
using Java.Lang;
45
using QuestAppVersionSwitcher.Core;
@@ -12,8 +13,9 @@ namespace QuestAppVersionSwitcher
1213
public class DownloadListener : Java.Lang.Object, IDownloadListener
1314
{
1415
public void OnDownloadStart(string url, string userAgent, string contentDisposition, string mimetype, long contentLength)
15-
{
16-
CoreService.browser.EvaluateJavascript("ShowToast('Downloading mod', '#FFFFFF', '#222222')", null);
16+
{
17+
Logger.Log("Downloading mod from " + url);
18+
CoreService.browser.EvaluateJavascript("ShowToast('Downloading mod', '#FFFFFF', '#222222')", null);
1719
string modPath = CoreService.coreVars.QAVSTmpModsDir + "downloadedmod" + DateTime.Now.Ticks + ".qmod";
1820
DownloadManager m = new DownloadManager();
1921
m.DownloadFinishedEvent += (manager) =>

DownloadManager.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,25 @@ public class DownloadManager : DownloadProgress
1919
public string tmpPath = "";
2020
public bool isObb = false;
2121
public string packageName = "";
22+
public WebClient downloader = new WebClient();
23+
public bool canceled = false;
24+
25+
public void StopDownload()
26+
{
27+
canceled = true;
28+
downloader.CancelAsync();
29+
SetEmpty(false);
30+
this.backupName = "Download Canceled";
31+
this.textColor = "#EE0000";
32+
if (File.Exists(tmpPath)) File.Delete(tmpPath);
33+
}
2234

23-
public void StartDownload(string binaryid, string password, string version, string app, string appId, bool isObb, string packageName)
35+
public void StartDownload(string binaryid, string password, string version, string app, string appId, bool isObb, string packageName)
2436
{
2537
this.packageName = packageName;
2638
this.isObb = isObb;
2739
string decodedToken = PasswordEncryption.Decrypt(CoreService.coreVars.token, password);
28-
WebClient downloader = new WebClient();
40+
downloader = new WebClient();
2941
tmpPath = CoreService.coreVars.QAVSTmpDowngradeDir + DateTime.Now.Ticks + (isObb ? ".obb" : ".apk");
3042
List<long> lastBytesPerSec = new List<long>();
3143
DateTime lastUpdate = DateTime.Now;
@@ -72,6 +84,7 @@ public void StartDownload(string binaryid, string password, string version, stri
7284
};
7385
downloader.DownloadFileCompleted += (o, e) =>
7486
{
87+
if (canceled) return;
7588
if (e.Error != null)
7689
{
7790
Logger.Log(e.Error.ToString(), LoggingType.Error);

Mods/QAVSModManager.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using ComputerUtils.Android.Logging;
2+
using QuestAppVersionSwitcher.Core;
3+
using System;
24
using System.Collections.Generic;
35
using System.IO;
46
using System.Linq;
@@ -20,8 +22,9 @@ public enum QAVSOperationType
2022
ModDisable,
2123
ModDelete,
2224
DependencyDownload,
23-
Other
24-
}
25+
Other,
26+
Error
27+
}
2528

2629
public class QAVSOperation
2730
{
@@ -63,8 +66,17 @@ public static void InstallMod(byte[] modBytes, string fileName)
6366

6467
TempFile f = new TempFile(Path.GetExtension(fileName));
6568
File.WriteAllBytes(f.Path, modBytes);
66-
IMod mod = modManager.TryParseMod(f.Path).Result;
67-
mod.Install().Wait();
69+
try
70+
{
71+
IMod mod = modManager.TryParseMod(f.Path).Result;
72+
mod.Install().Wait();
73+
} catch (Exception e)
74+
{
75+
runningOperations.Remove(operationId);
76+
operationId = operations;
77+
operations++;
78+
runningOperations.Add(operationId, new QAVSOperation { type = QAVSOperationType.Error, name = "Error installing mod: " + e.Message + "\nTo remove this message restart QuestAppVersionSwitcher" });
79+
}
6880
runningOperations.Remove(operationId);
6981
modManager.ForceSave();
7082
}

Properties/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="1.8.3" package="com.ComputerElite.questappversionswitcher" android:installLocation="preferExternal" android:versionCode="33">
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="1.8.4" package="com.ComputerElite.questappversionswitcher" android:installLocation="preferExternal" android:versionCode="34">
33
<uses-sdk android:minSdkVersion="28" android:targetSdkVersion="29" />
44
<uses-permission android:name="oculus.permission.handtracking" />
55
<uses-permission android:name="com.oculus.permission.HAND_TRACKING" />

Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@
2222
// Minor Version
2323
// Build Number
2424
// Revision
25-
[assembly: AssemblyVersion("1.8.3.0")]
26-
[assembly: AssemblyFileVersion("1.8.3.0")]
25+
[assembly: AssemblyVersion("1.8.4.0")]
26+
[assembly: AssemblyFileVersion("1.8.4.0")]

WebServer.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ namespace QuestAppVersionSwitcher
4242
{
4343
public class QAVSWebViewClient : WebViewClient
4444
{
45-
public bool wasOnOculus = false;
4645
public string navButtonsScript = "var qavsInjectionDiv = document.createElement(\"div\");qavsInjectionDiv.style = \"color: #EEEEEE; position: fixed; top: 10px; right: 10px; background-color: #414141; border-radius: 5px; padding: 5px; display: flex; z-index: 50000;\"; qavsInjectionDiv.innerHTML += `<div style=\"border-radius: 5px; font-size: 100%; background-color: #5B5B5B; width: fit-content; height: fit-content; padding: 5px; cursor: pointer; flex-shrink: 0; user-select: none;\" onclick=\"history.go(-1)\">Back</div><div style=\"border-radius: 5px; font-size: 100%; background-color: #5B5B5B; width: fit-content; height: fit-content; padding: 5px; cursor: pointer; flex-shrink: 0; user-select: none;\" onclick=\"history.go(1)\">Forward</div><div style=\"border-radius: 5px; font-size: 100%; background-color: #5B5B5B; width: fit-content; height: fit-content; padding: 5px; cursor: pointer; flex-shrink: 0; user-select: none;\" onclick=\"location = 'http://localhost:" + CoreService.coreVars.serverPort + "'\">QuestAppVersionSwitcher</div><div style=\\\"border-radius: 5px; font-size: 100%; background-color: #5B5B5B; width: fit-content; height: fit-content; padding: 5px; cursor: pointer; flex-shrink: 0; user-select: none;\\\" onclick=\\\"location = 'https://oculus.com/experiences/quest'\\\">Oculus (Login)</div>`; document.body.appendChild(qavsInjectionDiv)";
4746
public string toastCode = "var QAVSScript = document.createElement(\"script\");QAVSScript.innerHTML = `var QAVSToastsE = document.createElement(\"div\");document.body.appendChild(QAVSToastsE);let QAVStoasts = 0;let currentQAVSToasts = 0;function ShowToast(msg, color, bgc) { QAVStoasts++; currentQAVSToasts++; let QAVStoastId = QAVStoasts; QAVSToastsE.innerHTML += \\`<div id=\"QAVStoast\\${QAVStoastId}\" style=\"background-color: \\${bgc}; color: \\${color}; padding: 5px; height: 100px; width: 250px; position: fixed; bottom: \\${(currentQAVSToasts - 1) * 120 + 20}px; right: 30px; border-radius: 10px\">\\${msg}</div>\\`; setTimeout(() => { document.getElementById(\\`QAVStoast\\${QAVStoastId}\\`).remove(); currentQAVSToasts--; }, 5000)}`; document.body.appendChild(QAVSScript);";
4847
// Grab token
@@ -52,19 +51,15 @@ public override void OnPageFinished(WebView view, string url)
5251
Logger.Log(url);
5352
if (url.Split("?")[0].Contains("oculus.com"))
5453
{
55-
if (wasOnOculus)
56-
{
57-
view.EvaluateJavascript("var mySpans = document.getElementsByTagName(\"svg\");for(var i=0;i<mySpans.length;i++){if(mySpans[i].ariaLabel == 'Open Side Navigation Menu'){mySpans[i].parentElement.click();break;}}setTimeout(() => { mySpans = document.getElementsByTagName(\"h6\"); for (var i = 0; i < mySpans.length; i++) { if (mySpans[i].innerHTML == 'Log in / Sign up') { mySpans[i].click(); break; } } }, 600)", null);
58-
}
59-
wasOnOculus = true;
54+
// click login button
55+
view.EvaluateJavascript("SetTimeout(() => {var mySpans = document.getElementsByTagName(\"svg\");for(var i=0;i<mySpans.length;i++){if(mySpans[i].ariaLabel == 'Open Side Navigation Menu'){mySpans[i].parentElement.click();break;}}setTimeout(() => { mySpans = document.getElementsByTagName(\"h6\"); for (var i = 0; i < mySpans.length; i++) { if (mySpans[i].innerHTML == 'Log in / Sign up') { mySpans[i].click(); break; } } }, 600)}, 1000)", null);
6056

57+
// send token to QAVS
6158
view.EvaluateJavascript("var ws = new WebSocket('ws://localhost:" + CoreService.coreVars.serverPort + "/' + document.body.innerHTML.substr(document.body.innerHTML.indexOf(\"accessToken\"), 200).split('\"')[2]);", null);
6259
}
63-
else if (url.Split("?")[0] == "https://auth.meta.com/settings/")
60+
else if (url.StartsWith("https://auth.meta.com/settings"))
6461
{
65-
wasOnOculus = false;
6662
view.LoadUrl("https://oculus.com/experiences/quest");
67-
6863
}
6964
else if(!url.ToLower().Contains("localhost") && !url.ToLower().Contains("http://127.0.0.1"))
7065
{
@@ -826,10 +821,15 @@ public void Start()
826821
m.StartDownload(r.binaryId, r.password, r.version, r.app, r.parentId, r.isObb, r.packageName);
827822
m.DownloadFinishedEvent += DownloadCompleted;
828823
managers.Add(m);
829-
serverRequest.SendString("Added to downloads. Check download progress tab. Pop up will close in 5 seconds");
824+
serverRequest.SendString("Added to downloads. Check download progress tab.");
830825
return true;
831826
}));
832-
server.AddRoute("GET", "/downloads", new Func<ServerRequest, bool>(serverRequest =>
827+
server.AddRoute("GET", "/canceldownload", new Func<ServerRequest, bool>(serverRequest =>
828+
{
829+
managers.Find(x => x.backupName == serverRequest.queryString.Get("name")).StopDownload();
830+
return true;
831+
}));
832+
server.AddRoute("GET", "/downloads", new Func<ServerRequest, bool>(serverRequest =>
833833
{
834834
List<DownloadProgress> progress = new List<DownloadProgress>();
835835
foreach (DownloadManager m in managers)

0 commit comments

Comments
 (0)