Skip to content

Commit efa2ee5

Browse files
ComputerEliteComputerElite
authored andcommitted
Fix lots of stuff
1 parent 549f593 commit efa2ee5

File tree

15 files changed

+217
-85
lines changed

15 files changed

+217
-85
lines changed

QuestAppVersionSwitcher/Assets/html/script.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ function CheckFolderPermission() {
4848
if (text == "True") {
4949
// Do nothing, we already got access to the folder
5050
} else {
51+
if(updateAvailable) return
52+
CloseGetPasswordPopup();
5153
OpenRestorePopup();
5254
GotoStep("12")
5355
}
@@ -788,7 +790,7 @@ document.getElementById("grantAccess").onclick = () => {
788790
}
789791

790792
document.getElementById("deleteAllMods").onclick = () => {
791-
fetch("deleteallmods").then(res => {
793+
fetch("/mods/deleteallmods").then(res => {
792794
res.text().then(t => {
793795
if(res.status == 200) {
794796
TextBoxGood("updateTextBox", t)
@@ -934,11 +936,13 @@ function CloseGetPasswordPopup() {
934936
CheckUpdate()
935937

936938
document.getElementById("checkUpdate").onclick = () => CheckUpdate()
937-
939+
var updateAvailable = false
938940
function CheckUpdate() {
939941
TextBoxText("updateTextBox", "Checking for updates...")
940942
fetch("/questappversionswitcher/checkupdate").then(res => res.json().then(json => {
941943
if(json.isUpdateAvailable) {
944+
updatePromptOpen = true
945+
CloseRestorePopup()
942946
OpenGetPasswordPopup()
943947
GotoStep(11)
944948
document.getElementById("updateAvailableText").innerHTML = json.msg + "<br><br>" + json.changelog.replace(/\n/g, "<br>")
@@ -950,6 +954,8 @@ function CheckUpdate() {
950954

951955
document.getElementById("cancelupdate").onclick = () => {
952956
CloseGetPasswordPopup()
957+
updateAvailable = false;
958+
CheckFolderPermission()
953959
}
954960

955961
document.getElementById("updateqavs").onclick = () => {

QuestAppVersionSwitcher/ClientModels.cs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,27 +39,14 @@ public class About
3939
public List<string> browserIPs { get; set; } = new List<string>();
4040
}
4141

42-
public class AppBackup
42+
public enum BackupInfoVersion
4343
{
44-
public string backupName { get; set; } = "";
45-
public string backupLocation { get; set; } = "";
46-
public bool containsGamedata { get; set; } = false;
47-
public long backupSize { get; set; } = 0;
48-
public string backupSizeString { get; set; } = "";
49-
50-
public AppBackup(string name, bool gamedata, string location, long size, string sizestr)
51-
{
52-
this.backupName = name;
53-
this.containsGamedata = gamedata;
54-
this.backupLocation = location;
55-
this.backupSize = size;
56-
this.backupSizeString = sizestr;
57-
}
44+
V1
5845
}
5946

6047
public class BackupList
6148
{
62-
public List<AppBackup> backups { get; set; } = new List<AppBackup>();
49+
public List<BackupInfo> backups { get; set; } = new List<BackupInfo>();
6350
public string lastRestored { get; set; } = "";
6451
public long backupsSize { get; set; } = 0;
6552
public string backupsSizeString { get; set; } = "";
@@ -79,9 +66,16 @@ public class DownloadRequest
7966
public string app { get; set; } = "";
8067
public string parentId { get; set; } = "";
8168
public bool isObb { get; set; } = false;
69+
public List<ObbEntry> obbList { get; set; } = new List<ObbEntry>();
8270
public string packageName { get; set; } = "";
8371
}
8472

73+
public class ObbEntry
74+
{
75+
public string id { get; set; } = "";
76+
public string name { get; set; } = "";
77+
}
78+
8579
public class DownloadProgress
8680
{
8781
public string packageName { get; set; } = "";

QuestAppVersionSwitcher/CoreService.cs

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,15 @@ public class CoreService
3434
public static Version version = Assembly.GetExecutingAssembly().GetName().Version;
3535
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";
3636
public static ActivityResultLauncher launcher;
37+
public static bool started = false;
3738

3839
public static async void Start()
3940
{
41+
if (started)
42+
{
43+
AfterPermissionGrantStart();
44+
return;
45+
}
4046
// Accept every ssl certificate, may be a security risk but it's the only way to get the mod list (CoPilot)
4147
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate { return true; });
4248
// Check permissions and request if needed
@@ -66,7 +72,7 @@ public static async void Start()
6672
// Manage storage permission
6773
Android.Net.Uri uri = Android.Net.Uri.Parse("package:com.ComputerElite.questappversionswitcher");
6874
Intent i = new Intent(Settings.ActionManageAppAllFilesAccessPermission, uri);
69-
AndroidCore.context.StartActivity(i);
75+
launcher.Launch(i);
7076
return;
7177
}
7278
AfterPermissionGrantStart();
@@ -75,8 +81,6 @@ public static async void Start()
7581

7682
public static void AfterPermissionGrantStart()
7783
{
78-
79-
8084
//Set webbrowser settings
8185
browser.SetWebChromeClient(new WebChromeClient());
8286
browser.Settings.JavaScriptEnabled = true;
@@ -93,26 +97,29 @@ public static void AfterPermissionGrantStart()
9397
browser.Settings.AllowFileAccess = true;
9498
browser.SetDownloadListener(new DownloadListener());
9599
CookieManager.Instance.SetAcceptThirdPartyCookies(browser, true);
100+
101+
Logger.displayLogInConsole = true;
96102

97103
// Create all directories and files
98-
FileManager.CreateDirectoryIfNotExisting(coreVars.QAVSDir);
99-
FileManager.CreateDirectoryIfNotExisting(coreVars.QAVSBackupDir);
100-
FileManager.RecreateDirectoryIfExisting(coreVars.QAVSTmpDowngradeDir);
101-
FileManager.RecreateDirectoryIfExisting(coreVars.QAVSTmpPatchingDir);
102-
FileManager.CreateDirectoryIfNotExisting(coreVars.QAVSPatchingFilesDir);
103-
FileManager.CreateDirectoryIfNotExisting(coreVars.QAVSModAssetsDir);
104-
FileManager.RecreateDirectoryIfExisting(coreVars.QAVSTmpModsDir);
105-
106-
Logger.SetLogFile(coreVars.QAVSDir + "qavslog.log");
104+
if (!started)
105+
{
106+
FileManager.CreateDirectoryIfNotExisting(coreVars.QAVSDir);
107+
FileManager.CreateDirectoryIfNotExisting(coreVars.QAVSBackupDir);
108+
FileManager.RecreateDirectoryIfExisting(coreVars.QAVSTmpDowngradeDir);
109+
FileManager.RecreateDirectoryIfExisting(coreVars.QAVSTmpPatchingDir);
110+
FileManager.CreateDirectoryIfNotExisting(coreVars.QAVSPatchingFilesDir);
111+
FileManager.CreateDirectoryIfNotExisting(coreVars.QAVSModAssetsDir);
112+
FileManager.RecreateDirectoryIfExisting(coreVars.QAVSTmpModsDir);
113+
Logger.SetLogFile(coreVars.QAVSDir + "qavslog.log");
114+
ExternalFilesDownloader.DownloadUrl("https://raw.githubusercontent.com/Lauriethefish/QuestPatcher/main/QuestPatcher.Core/Resources/file-copy-paths.json", coreVars.QAVSFileCopiesFile);
115+
if (!File.Exists(coreVars.QAVSConfigLocation)) File.WriteAllText(coreVars.QAVSConfigLocation, JsonSerializer.Serialize(coreVars));
116+
coreVars = JsonSerializer.Deserialize<CoreVars>(File.ReadAllText(coreVars.QAVSConfigLocation));
117+
QAVSModManager.Init();
118+
CoreVars.cosmetics = Cosmetics.LoadCosmetics();
119+
}
107120

108-
// Download file copies file
109-
ExternalFilesDownloader.DownloadUrl("https://raw.githubusercontent.com/Lauriethefish/QuestPatcher/main/QuestPatcher.Core/Resources/file-copy-paths.json", coreVars.QAVSFileCopiesFile);
110-
if (!File.Exists(coreVars.QAVSConfigLocation)) File.WriteAllText(coreVars.QAVSConfigLocation, JsonSerializer.Serialize(coreVars));
111-
coreVars = JsonSerializer.Deserialize<CoreVars>(File.ReadAllText(coreVars.QAVSConfigLocation));
112-
CoreVars.cosmetics = Cosmetics.LoadCosmetics();
113-
Logger.displayLogInConsole = true;
114-
QAVSModManager.Init();
115121
qAVSWebserver.Start();
122+
started = true;
116123
}
117124
}
118125

QuestAppVersionSwitcher/DownloadManager.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public class DownloadManager : DownloadProgress
2222
public bool isObb = false;
2323
public WebClient downloader = new WebClient();
2424
public bool canceled = false;
25+
public string obbFileName = "";
2526

2627
public void StopDownload()
2728
{
@@ -34,8 +35,9 @@ public void StopDownload()
3435
if (File.Exists(tmpPath)) File.Delete(tmpPath);
3536
}
3637

37-
public void StartDownload(string binaryid, string password, string version, string app, string appId, bool isObb, string packageName)
38+
public void StartDownload(string binaryid, string password, string version, string app, string appId, bool isObb, string packageName, string obbFileName = "")
3839
{
40+
this.obbFileName = obbFileName;
3941
this.packageName = packageName;
4042
this.version = version;
4143
this.isObb = isObb;

QuestAppVersionSwitcher/FolderPermission.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,24 @@ public static void CreateDirectoryIfNotExisting(string path)
215215
if (directory.FindFile(name) == null) directory.CreateDirectory(name);
216216
}
217217

218+
/// <summary>
219+
/// Deletes all files in a directory
220+
/// </summary>
221+
/// <param name="dir"></param>
222+
public static void DeleteDirectoryContent(string dir)
223+
{
224+
if (Build.VERSION.SdkInt <= BuildVersionCodes.Q)
225+
{
226+
FileManager.RecreateDirectoryIfExisting(dir);
227+
return;
228+
}
229+
DocumentFile destDir = GetAccessToFile(dir);
230+
foreach (DocumentFile f in destDir.ListFiles())
231+
{
232+
f.Delete();
233+
}
234+
}
235+
218236
public static void DirectoryCopy(string sourceDirName, string destDirName)
219237
{
220238
if (Build.VERSION.SdkInt <= BuildVersionCodes.Q)
@@ -305,6 +323,28 @@ public static void InternalDirectoryCopy(DocumentFile dir, string destDirName)
305323
catch (Exception e) { Logger.Log("Error copying " + file.Name + ": " + e, LoggingType.Error); }
306324
}
307325
}
326+
327+
/// <summary>
328+
/// Gets all files of a directory
329+
/// </summary>
330+
/// <param name="path"></param>
331+
/// <returns></returns>
332+
public static List<string> GetFiles(string path)
333+
{
334+
if (Build.VERSION.SdkInt <= BuildVersionCodes.Q)
335+
{
336+
return Directory.GetFiles(path).ToList();
337+
}
338+
339+
if (path.EndsWith(Path.DirectorySeparatorChar)) path = path.Substring(0, path.Length - 1);
340+
DocumentFile directory = GetAccessToFile(path);
341+
List<string> files = new List<string>();
342+
foreach (DocumentFile f in directory.ListFiles())
343+
{
344+
if (!f.IsDirectory) files.Add(f.Name);
345+
}
346+
return files;
347+
}
308348
}
309349

310350
public class FolderPermissionCallback : Java.Lang.Object, IActivityResultCallback

QuestAppVersionSwitcher/MainActivity.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
namespace QuestAppVersionSwitcher
2222
{
23-
[Activity(Theme = "@style/AppTheme", MainLauncher = true)]
23+
[Activity(Theme = "@style/AppTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.ScreenSize)]
2424
public class MainActivity : AppCompatActivity
2525
{
2626
WebView webView;
@@ -39,6 +39,8 @@ protected override void OnCreate(Bundle savedInstanceState)
3939
AndroidCore.context = this;
4040
AndroidCore.activity = this;
4141
AndroidCore.assetManager = this.Assets;
42+
AndroidCore.installLauncher = RegisterForActivityResult(new ActivityResultContracts.StartActivityForResult(),
43+
new InstallLaucherResult());
4244

4345
FolderPermission.l = AndroidCore.activity.RegisterForActivityResult(
4446
new ActivityResultContracts.StartActivityForResult(), new FolderPermissionCallback());

QuestAppVersionSwitcher/Mods/ExternalFilesDownloader.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System;
2+
using System.IO;
23
using System.Net;
34
using System.Threading.Tasks;
5+
using ComputerUtils.Android.Logging;
46

57
namespace QuestAppVersionSwitcher.Mods
68
{
@@ -10,7 +12,17 @@ public static void DownloadUrl(string downloadUrlString, string path)
1012
{
1113
WebClient client = new WebClient();
1214
Uri uri = new Uri(downloadUrlString);
13-
client.DownloadFile(uri, path);
15+
TempFile temp = new TempFile();
16+
try
17+
{
18+
client.DownloadFile(uri, temp.Path);
19+
if (File.Exists(path)) File.Delete(path);
20+
File.Move(temp.Path, path);
21+
}
22+
catch (Exception e)
23+
{
24+
Logger.Log("Error downloading file from " +downloadUrlString + ": " + e, LoggingType.Warning);
25+
}
1426
}
1527
}
1628
}

QuestAppVersionSwitcher/Mods/ModManager.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class ModManager
2121
public string ModsPath => $"/sdcard/Android/data/{CoreService.coreVars.currentApp}/files/mods/";
2222
public string LibsPath => $"/sdcard/Android/data/{CoreService.coreVars.currentApp}/files/libs/";
2323

24-
private string ConfigPath => CoreService.coreVars.QAVSModsDir + $"{CoreService.coreVars.currentApp}/modsStatus.json";
24+
public string ConfigPath => CoreService.coreVars.QAVSModsDir + $"{CoreService.coreVars.currentApp}/modsStatus.json";
2525
public string ModsExtractPath => CoreService.coreVars.QAVSModsDir + $"{CoreService.coreVars.currentApp}/installedMods/";
2626

2727
private readonly Dictionary<string, IModProvider> _modProviders = new Dictionary<string, IModProvider>();
@@ -131,8 +131,7 @@ public async Task LoadModsForCurrentApp()
131131

132132
try
133133
{
134-
await using Stream configStream = File.OpenRead(ConfigPath);
135-
ModConfig? modConfig = await JsonSerializer.DeserializeAsync<ModConfig>(configStream, _configSerializationOptions);
134+
ModConfig? modConfig = JsonSerializer.Deserialize<ModConfig>(File.ReadAllText(ConfigPath), _configSerializationOptions);
136135
if (modConfig != null)
137136
{
138137
modConfig.Mods.ForEach(ModLoadedCallback);
@@ -187,6 +186,7 @@ internal void ModLoadedCallback(IMod mod)
187186
mod.hasCover = mod.OpenCover().Length > 0;
188187
(mod.IsLibrary ? Libraries : Mods).Add(mod);
189188
_modConfig?.Mods.Add(mod);
189+
190190
foreach (var copyType in mod.FileCopyTypes)
191191
{
192192
_otherFilesManager.RegisterFileCopy(CoreService.coreVars.currentApp, copyType);

QuestAppVersionSwitcher/Mods/OtherFilesManager.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,17 @@ public List<FileCopyType> CurrentDestinations
3131

3232
public OtherFilesManager()
3333
{
34-
var copyIndex = JsonSerializer.Deserialize<Dictionary<string, List<FileCopyType>>>(File.ReadAllText(CoreService.coreVars.QAVSFileCopiesFile));
35-
Debug.Assert(copyIndex != null);
36-
_copyIndex = copyIndex;
34+
if (File.Exists(CoreService.coreVars.QAVSFileCopiesFile))
35+
{
36+
37+
var copyIndex = JsonSerializer.Deserialize<Dictionary<string, List<FileCopyType>>>(File.ReadAllText(CoreService.coreVars.QAVSFileCopiesFile));
38+
Debug.Assert(copyIndex != null);
39+
_copyIndex = copyIndex;
40+
}
41+
else
42+
{
43+
_copyIndex = new Dictionary<string, List<FileCopyType>>();
44+
}
3745
}
3846

3947
/// <summary>

QuestAppVersionSwitcher/Mods/QAVSModManager.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,5 +262,14 @@ public static byte[] GetModCover(string id)
262262
}
263263
return new byte[0];
264264
}
265+
266+
public static void DeleteAllMods()
267+
{
268+
FileManager.RecreateDirectoryIfExisting(modManager.ModsExtractPath);
269+
FolderPermission.DeleteDirectoryContent(modManager.ModsPath);
270+
FolderPermission.DeleteDirectoryContent(modManager.LibsPath);
271+
File.Delete(modManager.ConfigPath);
272+
Update();
273+
}
265274
}
266275
}

0 commit comments

Comments
 (0)