public static void RegisterUriScheme(string appid, string steamid = null, string arguments = null) { string applicationLocation = UriScheme.GetApplicationLocation(); if (applicationLocation == null) { return; } string scheme = "discord-" + appid; string str1 = "Run game " + appid + " protocol"; string str2 = applicationLocation; string str3 = string.Format("{0} {1}", (object)applicationLocation, (object)arguments); if (!string.IsNullOrEmpty(steamid)) { string steamLocation = UriScheme.GetSteamLocation(); if (steamLocation != null) { str3 = string.Format("\"{0}\" steam://rungameid/{1}", (object)steamLocation, (object)steamid); } } string friendlyName = str1; string defaultIcon = str2; string command = str3; UriScheme.CreateUriScheme(scheme, friendlyName, defaultIcon, command); }
/// <summary> /// Registers the URI scheme. If Steam ID is passed, the application will be launched through steam instead of directly. /// <para>Additional arguments can be supplied if required.</para> /// </summary> /// <param name="logger">The logger to report messages too.</param> /// <param name="appid">The ID of the discord application</param> /// <param name="steamid">Optional field to indicate if this game should be launched through steam instead</param> public void RegisterUriScheme(ILogger logger, string appid, string steamid = null) { //Prepare our location string location = UriScheme.GetApplicationLocation(); if (location == null) { logger.Error("Failed to register application because the location was null."); return; } //Prepare the Scheme, Friendly name, default icon and default command string scheme = "discord-" + appid; string friendlyName = "Run game " + appid + " protocol"; string defaultIcon = location; string command = location; //We have a steam ID, so attempt to replce the command with a steam command if (!string.IsNullOrEmpty(steamid)) { //Try to get the steam location. If found, set the command to a run steam instead. string steam = GetSteamLocation(); if (steam != null) { command = string.Format("\"{0}\" steam://rungameid/{1}", steam, steamid); } } //Okay, now actually register it CreateUriScheme(scheme, friendlyName, defaultIcon, command); }
public void RegisterUriScheme(ILogger logger, string appid, string steamid = null) { //var home = Environment.GetEnvironmentVariable("HOME"); //if (string.IsNullOrEmpty(home)) return; //TODO: Log Error string exe = UriScheme.GetApplicationLocation(); if (string.IsNullOrEmpty(exe)) { logger.Error("Failed to register because the application could not be located."); return; } logger.Trace("Registering Steam Command"); //Prepare the command string command = exe; if (!string.IsNullOrEmpty(steamid)) { command = "steam://rungameid/" + steamid; } else { logger.Warning("This library does not fully support MacOS URI Scheme Registration."); } //get the folder ready string filepath = "~/Library/Application Support/discord/games"; var directory = Directory.CreateDirectory(filepath); if (!directory.Exists) { logger.Error("Failed to register because {0} does not exist", filepath); return; } //Write the contents to file File.WriteAllText(filepath + "/" + appid + ".json", "{ \"command\": \"" + command + "\" }"); }
public void RegisterUriScheme(ILogger logger, string appid, string steamid = null) { var home = Environment.GetEnvironmentVariable("HOME"); if (string.IsNullOrEmpty(home)) { logger.Error("Failed to register because the HOME variable was not set."); return; } string exe = UriScheme.GetApplicationLocation(); if (string.IsNullOrEmpty(exe)) { logger.Error("Failed to register because the application was not located."); return; } //Prepare the command string command = null; if (!string.IsNullOrEmpty(steamid)) { //A steam command isntead command = "xdg-open steam://rungameid/" + steamid; } else { //Just a regular discord command command = exe; } //Prepare the file string desktopFileFormat = @"[Desktop Entry] Name=Game {0} Exec={1} %u Type=Application NoDisplay=true Categories=Discord;Games; MimeType=x-scheme-handler/discord-{2}"; string file = string.Format(desktopFileFormat, appid, command, appid); //Prepare the path string filename = "/discord-" + appid + ".desktop"; string filepath = home + "/.local/share/applications"; var directory = Directory.CreateDirectory(filepath); if (!directory.Exists) { logger.Error("Failed to register because {0} does not exist", filepath); return; } //Write the file File.WriteAllText(filepath + filename, file); //Register the Mime type if (!RegisterMime(appid)) { logger.Error("Failed to register because the Mime failed."); return; } }