From cf03399f1c782b3d5869bf1f5cfe7cf2f7daecf6 Mon Sep 17 00:00:00 2001 From: Arne Kiesewetter Date: Sun, 12 Jan 2025 20:44:52 +0100 Subject: [PATCH] Add a fix for https://github.com/Yellow-Dog-Man/Resonite-Issues/issues/785 --- .../ImportWebFilesAsUrls.cs | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 CommunityBugFixCollection/ImportWebFilesAsUrls.cs diff --git a/CommunityBugFixCollection/ImportWebFilesAsUrls.cs b/CommunityBugFixCollection/ImportWebFilesAsUrls.cs new file mode 100644 index 0000000..a5ecc5c --- /dev/null +++ b/CommunityBugFixCollection/ImportWebFilesAsUrls.cs @@ -0,0 +1,79 @@ +using Elements.Assets; +using Elements.Core; +using FrooxEngine; +using HarmonyLib; +using MonkeyLoader.Resonite; +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.IO; +using System.Text; + +namespace CommunityBugFixCollection +{ + [HarmonyPatchCategory(nameof(ImportWebFilesAsUrls))] + [HarmonyPatch(typeof(AssetHelper), nameof(AssetHelper.IdentifyClass))] + internal sealed class ImportWebFilesAsUrls : ResoniteMonkey + { + public override bool CanBeDisabled => true; + + private static bool Prefix(out AssetClass __result, string path) + { + if (path is null) + { + __result = AssetClass.Unknown; + return false; + } + + if (Directory.Exists(path)) + { + __result = AssetClass.Folder; + return false; + } + + try + { + if (!Uri.TryCreate(path, UriKind.Absolute, out var result)) + { + if (Path.IsPathRooted(path)) + { + __result = AssetHelper.ClassifyExtension(Path.GetExtension(path)); + return false; + } + + __result = AssetClass.Unknown; + return false; + } + + if (AssetHelper.IsVideoStreamingService(result) || AssetHelper.IsStreamingProtocol(result)) + { + __result = AssetClass.Video; + return false; + } + + __result = AssetHelper.ClassifyExtension(Path.GetExtension(result.LocalPath)); + + if (__result is not AssetClass.Unknown and not AssetClass.Package and not AssetClass.Text) + return false; + + if (!string.IsNullOrEmpty(result.Query)) + { + foreach (KeyValuePair item in StringHelper.ParseQueryString(result.Query)) + { + __result = AssetHelper.ClassifyExtension(Path.GetExtension(item.Value)); + + if (__result != AssetClass.Unknown) + return false; + } + } + } + catch + { } + + __result = AssetClass.Unknown; + return false; + } + + private static bool Prepare() => Enabled; + } +} \ No newline at end of file