Singularity/Assets/Plugins/ImaginationOverflow/UniversalDeepLinking/Scripts/Providers/ProviderHelpers.cs
2024-05-06 11:45:45 -07:00

91 lines
2.6 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
#if STANDALONE_HELPERS
namespace ImaginationOverflow.UniversalDeepLinking.Helpers
#else
namespace ImaginationOverflow.UniversalDeepLinking
#endif
{
public static class ProviderHelpers
{
public const string LauncherRelativeFolder = "ImaginationOverflow\\UniversalDeepLink\\";
public const string LauncherName = "UDLLauncher.exe";
public const string LauncherConfigFileName = LauncherName + ".config";
public const string LauncherSharedFileName = "udlsharedfile.dat";
#if !UDL_DLL_BUILD
private static string _editorLauncherFolder;
public static void SetWindowsMockLauncherLocation(string launcherPluginFolder)
{
_editorLauncherFolder = launcherPluginFolder.Replace("/", "\\");
}
public static string GetLauncherFolder()
{
if (string.IsNullOrEmpty(_editorLauncherFolder))
return LauncherFolder();
return _editorLauncherFolder;
}
private static string LauncherFolder()
{
return Path.Combine(Application.streamingAssetsPath.Replace('/', '\\'), LauncherRelativeFolder);
}
public static string GetLauncherFullFilename()
{
return Path.Combine(GetLauncherFolder(), LauncherName);
}
public static string GetLauncherConfigFullFilename()
{
return Path.Combine(GetLauncherFolder(), LauncherConfigFileName);
}
public static string GetLauncherSharedFileFullFilename()
{
return Path.Combine(GetLauncherFolder(), LauncherSharedFileName);
}
#endif
public static string GetExecutingPath()
{
try
{
return System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
}
#pragma warning disable 168
catch (Exception e)
#pragma warning restore 168
{
// ignored
}
var exe = Environment.GetCommandLineArgs()[0];
var parentDataDir = Directory.GetParent(Application.dataPath).FullName;
if (exe.Contains("/"))
parentDataDir = parentDataDir.Replace('\\', Path.PathSeparator);
else
parentDataDir = parentDataDir.Replace('/', Path.PathSeparator);
if (exe.StartsWith(parentDataDir))
return exe;
return Path.Combine(parentDataDir, Path.GetFileName(exe));
}
}
}