Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
gompocp committed Aug 22, 2021
1 parent a23c66d commit cfbefe9
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 22 deletions.
17 changes: 8 additions & 9 deletions WorldPredownload/Cache/CacheManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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");
Expand All @@ -31,7 +29,7 @@ public static void AddDirectory(string hash)
{
Directories.Add(hash);
}


public static bool HasDownloadedWorld(string url)
{
Expand All @@ -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()
Expand All @@ -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");
Expand Down
12 changes: 7 additions & 5 deletions WorldPredownload/DownloadManager/DownloadComplete.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Action<AsyncOperation>>(
new System.Action<AsyncOperation>(
delegate
Expand Down Expand Up @@ -90,8 +90,9 @@ private static async void OnRecompress()
{
Utilities.GoToWorld(DownloadInfo.ApiWorld, DownloadInfo.InstanceIDTags, false);
}

break;

case DownloadType.Invite:
if (!ModSettings.autoFollowInvites)
{
Expand All @@ -102,8 +103,9 @@ private static async void OnRecompress()
{
Utilities.GoToWorld(DownloadInfo.ApiWorld, DownloadInfo.InstanceIDTags, true);
}

break;

case DownloadType.World:
if (!ModSettings.autoFollowWorlds)
{
Expand All @@ -114,8 +116,8 @@ private static async void OnRecompress()
{
Utilities.GoToWorld(DownloadInfo.ApiWorld, DownloadInfo.InstanceIDTags, false);
}

break;

}
}
}
Expand Down
4 changes: 2 additions & 2 deletions WorldPredownload/Helpers/Delegates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using VRC.Core;
using VRC.UI;
using Delegate = System.Delegate;

// ReSharper disable HeuristicUnreachableCode
// ReSharper disable NotNullMemberIsNotInitialized
// ReSharper disable ConditionIsAlwaysTrueOrFalse
Expand Down Expand Up @@ -62,7 +63,7 @@ public static LoadUserDelegate GetLoadUserDelegate
return loadUserDelegate;
}
}

public static ShowDismissPopupDelegate GetShowDismissPopupDelegate
{
get
Expand Down Expand Up @@ -145,6 +146,5 @@ public static AdvancedInvitesInviteDelegate GetAdvancedInvitesInviteDelegate
return advancedInvitesInviteDelegate;
}
}

}
}
12 changes: 6 additions & 6 deletions WorldPredownload/Helpers/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);

}
}

0 comments on commit cfbefe9

Please sign in to comment.