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

62 lines
2.0 KiB
C#

using System;
using System.IO;
#if !(NET_Standard_2_0 || NET_Standard || NET_STANDARD_2_0)
using Microsoft.Win32;
using UnityEngine;
#if UDL_DLL_BUILD && STANDALONE_HELPERS
using ImaginationOverflow.UniversalDeepLinking.Helpers;
namespace ImaginationOverflow.UniversalDeepLinking.Providers.Helpers
#else
namespace ImaginationOverflow.UniversalDeepLinking.Providers
#endif
{
public class WindowsRegistryHelper
{
public static string GetSteamPath()
{
var steamExe = Registry.CurrentUser.OpenSubKey("Software", false)
.OpenSubKey("Classes")
.OpenSubKey("Steam")
.OpenSubKey("shell")
.OpenSubKey("open")
.OpenSubKey("command")
.GetValue("").ToString();
steamExe = steamExe.Replace(" \"%1\"", string.Empty).Replace("\"", String.Empty);
return steamExe;
}
public static bool SetProtocol( string activationProtocol, string executingExe, string exeArgs)
{
var key = Registry.CurrentUser.OpenSubKey("Software", true);
var classes = key.OpenSubKey("Classes", true);
if (classes == null)
return false;
var appkey = classes.OpenSubKey(activationProtocol);
if (appkey != null)
{
classes.DeleteSubKeyTree(activationProtocol);
}
appkey = classes.CreateSubKey(activationProtocol);
appkey.SetValue("", string.Format("URL:{0} Protocol", activationProtocol));
appkey.SetValue("URL Protocol", "");
appkey
.CreateSubKey("shell")
.CreateSubKey("open")
.CreateSubKey("command")
.SetValue("", string.Format("\"{0}\" {1} \"%1\"", executingExe, exeArgs));
var defaultIcon = appkey.CreateSubKey("DefaultIcon");
defaultIcon.SetValue("", string.Format("\"{0}\",-1", ProviderHelpers.GetExecutingPath()));
return true;
}
}
}
#endif