public bool RegisterUriScheme(UriSchemeRegister register)
        {
            //Prepare our location
            string location = register.ExecutablePath;

            if (location == null)
            {
                logger.Error("Failed to register application because the location was null.");
                return(false);
            }

            //Prepare the Scheme, Friendly name, default icon and default command
            string scheme       = "discord-" + register.ApplicationID;
            string friendlyName = "Run game " + register.ApplicationID + " protocol";
            string defaultIcon  = location;
            string command      = location;

            //We have a steam ID, so attempt to replce the command with a steam command
            if (register.UsingSteamApp)
            {
                //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, register.SteamAppID);
                }
            }

            //Okay, now actually register it
            CreateUriScheme(scheme, friendlyName, defaultIcon, command);
            return(true);
        }
Esempio n. 2
0
        public bool RegisterUriScheme(UriSchemeRegister register)
        {
            //var home = Environment.GetEnvironmentVariable("HOME");
            //if (string.IsNullOrEmpty(home)) return;     //TODO: Log Error

            string exe = register.ExecutablePath;

            if (string.IsNullOrEmpty(exe))
            {
                logger.Error("Failed to register because the application could not be located.");
                return(false);
            }

            logger.Trace("Registering Steam Command");

            //Prepare the command
            string command = exe;

            if (register.UsingSteamApp)
            {
                command = "steam://rungameid/" + register.SteamAppID;
            }
            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(false);
            }

            //Write the contents to file
            File.WriteAllText(filepath + "/" + register.ApplicationID + ".json", "{ \"command\": \"" + command + "\" }");
            logger.Trace("Registered {0}, {1}", filepath + "/" + register.ApplicationID + ".json", command);
            return(true);
        }
 public bool RegisterUriScheme(UriSchemeRegister register)
 {
     throw new PlatformNotSupportedException("Library has been built exluding Win32. This has removed the ability for Windows to register the UriScheme");
 }
Esempio n. 4
0
        public bool RegisterUriScheme(UriSchemeRegister register)
        {
            var home = Environment.GetEnvironmentVariable("HOME");

            if (string.IsNullOrEmpty(home))
            {
                logger.Error("Failed to register because the HOME variable was not set.");
                return(false);
            }

            string exe = register.ExecutablePath;

            if (string.IsNullOrEmpty(exe))
            {
                logger.Error("Failed to register because the application was not located.");
                return(false);
            }

            //Prepare the command
            string command = null;

            if (register.UsingSteamApp)
            {
                //A steam command isntead
                command = "xdg-open steam://rungameid/" + register.SteamAppID;
            }
            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, register.ApplicationID, command, register.ApplicationID);

            //Prepare the path
            string filename  = "/discord-" + register.ApplicationID + ".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(false);
            }

            //Write the file
            File.WriteAllText(filepath + filename, file);

            //Register the Mime type
            if (!RegisterMime(register.ApplicationID))
            {
                logger.Error("Failed to register because the Mime failed.");
                return(false);
            }

            logger.Trace("Registered {0}, {1}, {2}", filepath + filename, file, command);
            return(true);
        }