Ejemplo n.º 1
0
        /// <summary>
        ///     Legacy <see cref="Integration.HandleContextMenu" />
        /// </summary>
        internal static bool HandleContextMenu(IntegrationOption option)
        {
            try
            {
                switch (option)
                {
                case IntegrationOption.Add:

                    string fullPath = Info.ExeLocation;

                    // Add command and icon to command
                    string[] addCode =
                    {
                        "@echo off",
                        $"reg.exe add {REG_SHELL_CMD} /ve /d \"{fullPath} \"\"%%1\"\"\" /f >nul",
                        $"reg.exe add {REG_SHELL} /v Icon /d \"{fullPath}\" /f >nul"
                    };

                    Command.RunBatch(addCode, true);

                    break;

                case IntegrationOption.Remove:

                    string[] removeCode =
                    {
                        "@echo off",
                        $@"reg.exe delete {REG_SHELL} /f >nul"
                    };

                    Command.RunBatch(removeCode, true);


                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(option), option, null);
                }

                return(true);
            }
            catch (Exception e)
            {
                NConsole.WriteError("Context menu error: {0}", e.Message);
                NConsole.WaitForSecond();
                return(false);
            }
        }
Ejemplo n.º 2
0
        internal static void HandlePath(IntegrationOption option)
        {
            switch (option)
            {
            case IntegrationOption.Add:
            {
                string oldValue = OS.EnvironmentPath;

                string appFolder = RuntimeInfo.AppFolder;

                if (RuntimeInfo.IsAppFolderInPath)
                {
                    return;
                }


                bool appFolderInPath = oldValue
                                       .Split(OS.PATH_DELIM)
                                       .Any(p => p == appFolder);

                string cd  = Environment.CurrentDirectory;
                string exe = Path.Combine(cd, RuntimeInfo.NAME_EXE);

                if (!appFolderInPath)
                {
                    string newValue = oldValue + OS.PATH_DELIM + cd;
                    OS.EnvironmentPath = newValue;
                }

                break;
            }

            case IntegrationOption.Remove:
                OS.RemoveFromPath(RuntimeInfo.AppFolder);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(option), option, null);
            }
        }
Ejemplo n.º 3
0
        internal static void HandleContextMenu(IntegrationOption option)
        {
            switch (option)
            {
            case IntegrationOption.Add:
                string fullPath = RuntimeInfo.ExeLocation;

                // Add command and icon to command
                string[] addCode =
                {
                    "@echo off",
                    $"reg.exe add {REG_SHELL_CMD} /ve /d \"{fullPath} \"\"%%1\"\"\" /f >nul",
                    $"reg.exe add {REG_SHELL} /v Icon /d \"{fullPath}\" /f >nul"
                };


                BatchFileCommand.CreateAndRun(addCode, true);

                break;

            case IntegrationOption.Remove:

                string[] removeCode =
                {
                    "@echo off",
                    $@"reg.exe delete {REG_SHELL} /f >nul"
                };


                BatchFileCommand.CreateAndRun(removeCode, true);

                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(option), option, null);
            }
        }
Ejemplo n.º 4
0
        /// <returns><c>true</c> if operation succeeded; <c>false</c> otherwise</returns>
        internal static bool HandleContextMenu(IntegrationOption option)
        {
            /*
             * New context menu
             */

            switch (option)
            {
            case IntegrationOption.Add:

                RegistryKey regMenu = null;
                RegistryKey regCmd  = null;

                string fullPath = Info.ExeLocation;

                try
                {
                    regMenu = Registry.CurrentUser.CreateSubKey(REG_SHELL);
                    regMenu?.SetValue(String.Empty, Info.NAME);
                    regMenu?.SetValue("Icon", $"\"{fullPath}\"");

                    regCmd = Registry.CurrentUser.CreateSubKey(REG_SHELL_CMD);
                    regCmd?.SetValue(String.Empty, $"\"{fullPath}\" \"%1\"");
                }
                catch (Exception ex)
                {
                    NConsole.WriteError("{0}", ex.Message);
                    NConsole.WaitForInput();
                    return(false);
                }
                finally
                {
                    regMenu?.Close();
                    regCmd?.Close();
                }

                break;

            case IntegrationOption.Remove:

                try
                {
                    var reg = Registry.CurrentUser.OpenSubKey(REG_SHELL_CMD);

                    if (reg != null)
                    {
                        reg.Close();
                        Registry.CurrentUser.DeleteSubKey(REG_SHELL_CMD);
                    }

                    reg = Registry.CurrentUser.OpenSubKey(REG_SHELL);

                    if (reg != null)
                    {
                        reg.Close();
                        Registry.CurrentUser.DeleteSubKey(REG_SHELL);
                    }
                }
                catch (Exception ex)
                {
                    NConsole.WriteError("{0}", ex.Message);
                    NConsole.WaitForInput();
                    return(false);
                }

                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(option), option, null);
            }


            return(true);
        }