diff --git a/WorldPredownload/Cache/CacheManager.cs b/WorldPredownload/Cache/CacheManager.cs index 8b465fa..80794c1 100644 --- a/WorldPredownload/Cache/CacheManager.cs +++ b/WorldPredownload/Cache/CacheManager.cs @@ -4,10 +4,8 @@ using System.IO; using System.Security.Cryptography; using System.Text; -using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities; using MelonLoader; using WorldPredownload.Helpers; -using Int32 = Il2CppSystem.Int32; namespace WorldPredownload.Cache { @@ -21,7 +19,7 @@ public static void UpdateDirectories() Stopwatch.Restart(); Directories.Clear(); var files = Directory.GetDirectories(GetCache().path, "*", SearchOption.TopDirectoryOnly); - for (int i = 0; i < files.Length; i++) + for (var i = 0; i < files.Length; i++) Directories.Add(Path.GetFileName(files[i])); Stopwatch.Stop(); MelonLogger.Msg($"Finished getting {Directories.Count} cache entries in {Stopwatch.ElapsedMilliseconds}ms"); @@ -31,7 +29,7 @@ public static void AddDirectory(string hash) { Directories.Add(hash); } - + public static bool HasDownloadedWorld(string url) { @@ -45,11 +43,12 @@ public static bool HasDownloadedWorld(string url) return false; } - + public static string ComputeAssetHash(string url) { var id = Utilities.ExtractFileId(url); - return Utilities.ByteArrayToString(SHA256.Create().ComputeHash(Encoding.UTF8.GetBytes(id))).ToUpper().Substring(0, 16); + return Utilities.ByteArrayToString(SHA256.Create().ComputeHash(Encoding.UTF8.GetBytes(id))).ToUpper() + .Substring(0, 16); } public static UnityEngine.Cache GetCache() @@ -69,11 +68,11 @@ private static bool HasVersion(string hash, string url) public static string ComputeVersionString(string url) //Int to Little Endian Hex String { - string fileversion = Utilities.ExtractFileVersion(url); + var fileversion = Utilities.ExtractFileVersion(url); if (string.IsNullOrEmpty(fileversion)) MelonLogger.Error("This is going to lead to an error shortly. uh oh..."); - - var version = Int32.Parse(fileversion); + + var version = int.Parse(fileversion); var bytes = BitConverter.GetBytes(version); var result = ""; foreach (var b in bytes) result += b.ToString("x2"); diff --git a/WorldPredownload/DownloadManager/DownloadComplete.cs b/WorldPredownload/DownloadManager/DownloadComplete.cs index 6608889..6c94fd3 100644 --- a/WorldPredownload/DownloadManager/DownloadComplete.cs +++ b/WorldPredownload/DownloadManager/DownloadComplete.cs @@ -44,14 +44,14 @@ public static partial class WorldDownloadManager // level = CompressionLevel.High, // blockSize = 131072U // }, 0, ThreadPriority.Normal); - + var operation = AssetBundle.RecompressAssetBundleAsync(file, file, new BuildCompression { compression = CompressionType.Lz4, level = CompressionLevel.High, blockSize = 131072U }, 0, ThreadPriority.Normal); - + operation.add_completed(DelegateSupport.ConvertDelegate>( new System.Action( delegate @@ -90,8 +90,9 @@ private static async void OnRecompress() { Utilities.GoToWorld(DownloadInfo.ApiWorld, DownloadInfo.InstanceIDTags, false); } + break; - + case DownloadType.Invite: if (!ModSettings.autoFollowInvites) { @@ -102,8 +103,9 @@ private static async void OnRecompress() { Utilities.GoToWorld(DownloadInfo.ApiWorld, DownloadInfo.InstanceIDTags, true); } + break; - + case DownloadType.World: if (!ModSettings.autoFollowWorlds) { @@ -114,8 +116,8 @@ private static async void OnRecompress() { Utilities.GoToWorld(DownloadInfo.ApiWorld, DownloadInfo.InstanceIDTags, false); } + break; - } } } diff --git a/WorldPredownload/Helpers/Delegates.cs b/WorldPredownload/Helpers/Delegates.cs index 4b1128e..b50c818 100644 --- a/WorldPredownload/Helpers/Delegates.cs +++ b/WorldPredownload/Helpers/Delegates.cs @@ -7,6 +7,7 @@ using VRC.Core; using VRC.UI; using Delegate = System.Delegate; + // ReSharper disable HeuristicUnreachableCode // ReSharper disable NotNullMemberIsNotInitialized // ReSharper disable ConditionIsAlwaysTrueOrFalse @@ -62,7 +63,7 @@ public static LoadUserDelegate GetLoadUserDelegate return loadUserDelegate; } } - + public static ShowDismissPopupDelegate GetShowDismissPopupDelegate { get @@ -145,6 +146,5 @@ public static AdvancedInvitesInviteDelegate GetAdvancedInvitesInviteDelegate return advancedInvitesInviteDelegate; } } - } } \ No newline at end of file diff --git a/WorldPredownload/Helpers/Utilities.cs b/WorldPredownload/Helpers/Utilities.cs index 516d9f3..c2f7387 100644 --- a/WorldPredownload/Helpers/Utilities.cs +++ b/WorldPredownload/Helpers/Utilities.cs @@ -18,6 +18,11 @@ namespace WorldPredownload.Helpers [SuppressMessage("ReSharper", "HeuristicUnreachableCode")] public static class Utilities { + private static readonly Regex fileIdRegex = new("/file_[0-9A-Za-z-]+/", RegexOptions.Compiled); + + private static readonly Regex fileVersionRegex = + new("(?:\\/file_[0-9A-Za-z-]+\\/)([0-9]+)", RegexOptions.Compiled); + public static void AdvancedInvitesHandleInvite(Notification notification) { #if DEBUG @@ -136,15 +141,10 @@ public static string ExtractFileId(string txt) { return fileIdRegex.Match(txt).Groups[1].Value; } - + public static string ExtractFileVersion(string txt) { return fileVersionRegex.Match(txt).Groups[1].Value; } - - private static Regex fileIdRegex = new ("/file_[0-9A-Za-z-]+/", RegexOptions.Compiled); - - private static Regex fileVersionRegex = new Regex("(?:\\/file_[0-9A-Za-z-]+\\/)([0-9]+)", RegexOptions.Compiled); - } } \ No newline at end of file