Skip to content
This repository has been archived by the owner on May 17, 2023. It is now read-only.

Commit

Permalink
Add Support For Aids ML Versions
Browse files Browse the repository at this point in the history
  • Loading branch information
MistressPlague authored Sep 15, 2021
1 parent f035085 commit a39e0d2
Showing 1 changed file with 51 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,21 @@ namespace UniversalFavsExporter
{
public class FavsExporterByPlague : MelonMod
{
public override void VRChat_OnUiManagerInit()
public override void OnApplicationStart()
{
MelonCoroutines.Start(VRChat_OnUiManagerInit());
}

public IEnumerator VRChat_OnUiManagerInit()
{
while (VRCUiManager.prop_VRCUiManager_0 == null)
{
yield return new WaitForSeconds(1f);
}

MelonCoroutines.Start(DelayedUIInit());

yield break;
}

public IEnumerator DelayedUIInit()
Expand Down Expand Up @@ -72,7 +84,7 @@ public IEnumerator DelayedUIInit()
}

var FilePath = Environment.CurrentDirectory + "\\ExportedFavs\\" +
Child.Find("Button/TitleText").GetComponent<Text>().text + ".json";
MakeValidFileName(Child.Find("Button/TitleText").GetComponent<Text>().text) + ".json";

File.WriteAllText(FilePath, Json);

Expand Down Expand Up @@ -113,6 +125,43 @@ public IEnumerator DelayedUIInit()
yield break;
}

static char[] _invalids;

/// <summary>Replaces characters in <c>text</c> that are not allowed in
/// file names with the specified replacement character.</summary>
/// <param name="text">Text to make into a valid filename. The same string is returned if it is valid already.</param>
/// <param name="replacement">Replacement character, or null to simply remove bad characters.</param>
/// <param name="fancy">Whether to replace quotes and slashes with the non-ASCII characters ” and ⁄.</param>
/// <returns>A string that can be used as a filename. If the output string would otherwise be empty, returns "_".</returns>
public static string MakeValidFileName(string text, char? replacement = '_', bool fancy = true)
{
StringBuilder sb = new StringBuilder(text.Length);
var invalids = _invalids ?? (_invalids = Path.GetInvalidFileNameChars());
bool changed = false;
for (int i = 0; i < text.Length; i++)
{
char c = text[i];
if (invalids.Contains(c))
{
changed = true;
var repl = replacement ?? '\0';
if (fancy)
{
if (c == '"') repl = '”'; // U+201D right double quotation mark
else if (c == '\'') repl = '’'; // U+2019 right single quotation mark
else if (c == '/') repl = '⁄'; // U+2044 fraction slash
}
if (repl != '\0')
sb.Append(repl);
}
else
sb.Append(c);
}
if (sb.Length == 0)
return "_";
return changed ? sb.ToString() : text;
}

internal enum PopupType
{
FullScreen,
Expand Down

0 comments on commit a39e0d2

Please sign in to comment.