Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix URLs appearing as text or resonitepackage failing to import instead of showing up as a hyperlink #13

Merged
merged 1 commit into from
Jan 15, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions CommunityBugFixCollection/ImportWebFilesAsUrls.cs
Original file line number Diff line number Diff line change
@@ -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<ImportWebFilesAsUrls>
{
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<string, string> 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;
}
}
Loading