Ejemplo n.º 1
0
        // IAssembler
        public AssemblerResults RunAssembler(BackgroundWorker worker)
        {
            Debug.Assert(mPathNames.Count == 2);
            string pathName = StripWorkDirectory(mPathNames[0]);
            string cfgName  = StripWorkDirectory(mPathNames[1]);

            AssemblerConfig config =
                AssemblerConfig.GetConfig(AppSettings.Global, AssemblerInfo.Id.Cc65);

            if (string.IsNullOrEmpty(config.ExecutablePath))
            {
                Debug.WriteLine("Assembler not configured");
                return(null);
            }

            string cfgOpt = " -C \"" + cfgName + "\"";

            worker.ReportProgress(0, Properties.Resources.PROGRESS_ASSEMBLING);

            // Wrap pathname in quotes in case it has spaces.
            // (Do we need to shell-escape quotes in the pathName?)
            ShellCommand cmd = new ShellCommand(config.ExecutablePath,
                                                OPTIONS + cfgOpt + " \"" + pathName + "\"", mWorkDirectory, null);

            cmd.Execute();

            // Can't really do anything with a "cancel" request.

            // Output filename is the input filename without the ".S".  Since the filename
            // was generated by us we can be confident in the format.
            string outputFile = mPathNames[0].Substring(0, mPathNames[0].Length - 2);

            return(new AssemblerResults(cmd.FullCommandLine, cmd.ExitCode, cmd.Stdout,
                                        cmd.Stderr, outputFile));
        }
        /// <summary>
        /// 执行shell命令
        /// </summary>
        /// <param name="device"></param>
        /// <param name="sh"></param>
        /// <returns></returns>
        public static Tuple <Output, int> Shell(this IDevice device, string sh)
        {
            var cmd    = new ShellCommand(device, sh);
            var result = cmd.Execute();

            return(new Tuple <Output, int>(result.Output, result.ExitCode));
        }
        public void ShellRun(string cmd, string filename = "cmd.exe")
        {
            var args = filename == "cmd.exe" ? $"/C {cmd}" : $"{cmd}";

            var startInfo = ShellCommand.SetProcessStartInfo(filename, arguments: args, createNoWindow: true);

            ShellCommand.Execute(startInfo);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 检查是否有SU权限
        /// </summary>
        /// <param name="device"></param>
        /// <returns></returns>
        public static bool HaveSU(this IDevice device)
        {
            ///话说是哪位鬼才想到的使用不验证 su 存在直接用 su -c 检查有没有 root 的?
            ///var command = new SuCommand(device, "ls");


            /// 这玩意太长,我是不满意
            /// 顺便在控制台执行的时候遇到了一些神奇的问题
            /// 话说啥时候 ShellCommand 负责解释的是 sh 而不是 adb -s <device> shell <cmd> 呢?
            var testSuCommandAvailability = new ShellCommand(device, "echo id | su | grep uid=0 >/dev/null");

            return(testSuCommandAvailability.Execute().ExitCode == 0);
        }
Ejemplo n.º 5
0
        // IAssembler
        public AssemblerResults RunAssembler(BackgroundWorker worker)
        {
            // Reduce input file to a partial path if possible.  This is really just to make
            // what we display to the user a little easier to read.
            string pathName = PathNames[0];

            if (pathName.StartsWith(WorkDirectory))
            {
                pathName = pathName.Remove(0, WorkDirectory.Length + 1);
            }
            else
            {
                // Unexpected, but shouldn't be a problem.
                Debug.WriteLine("NOTE: source file is not in work directory");
            }

            //string home = AppSettings.Global.GetString(AppSettings.ASM_CC65_HOME, null);
            //string cl65 = AppSettings.Global.GetString(AppSettings.ASM_CC65_EXECUTABLE, null);
            //Debug.Assert(!string.IsNullOrEmpty(cl65));
            //Debug.Assert(!string.IsNullOrEmpty(home));

            //Dictionary<string, string> envVars = new Dictionary<string, string>(1);
            //envVars.Add("CC65_HOME", home);

            //string exePath = Path.Combine(home, cl65);

            string cl65 = AppSettings.Global.GetString(AppSettings.ASM_CC65_EXECUTABLE, null);

            if (string.IsNullOrEmpty(cl65))
            {
                Debug.WriteLine("Assembler not configured");
                return(null);
            }

            // Wrap pathname in quotes in case it has spaces.
            // (Do we need to shell-escape quotes in the pathName?)
            ShellCommand cmd = new ShellCommand(cl65,
                                                "--target none \"" + pathName + "\"", WorkDirectory, null);

            cmd.Execute();

            // Can't really do anything with a "cancel" request.

            // Output filename is the input filename without the ".S".  Since the filename
            // was generated by us we can be confident in the format.
            string outputFile = PathNames[0].Substring(0, PathNames[0].Length - 2);

            return(new AssemblerResults(cmd.FullCommandLine, cmd.ExitCode, cmd.Stdout,
                                        cmd.Stderr, outputFile));
        }
Ejemplo n.º 6
0
        // IAssembler
        public AssemblerResults RunAssembler(BackgroundWorker worker)
        {
            // Reduce input file to a partial path if possible.  This is really just to make
            // what we display to the user a little easier to read.
            string pathName = mPathNames[0];

            if (pathName.StartsWith(mWorkDirectory))
            {
                pathName = pathName.Remove(0, mWorkDirectory.Length + 1);
            }
            else
            {
                // Unexpected, but shouldn't be a problem.
                Debug.WriteLine("NOTE: source file is not in work directory");
            }

            AssemblerConfig config =
                AssemblerConfig.GetConfig(AppSettings.Global, AssemblerInfo.Id.Acme);

            if (string.IsNullOrEmpty(config.ExecutablePath))
            {
                Debug.WriteLine("Assembler not configured");
                return(null);
            }

            worker.ReportProgress(0, Res.Strings.PROGRESS_ASSEMBLING);

            // Output file name is source file name with the ".a".
            string outFileName = pathName.Substring(0, pathName.Length - 2);

            // Wrap pathname in quotes in case it has spaces.
            // (Do we need to shell-escape quotes in the pathName?)
            ShellCommand cmd = new ShellCommand(config.ExecutablePath,
                                                OPTIONS + " -o \"" + outFileName + "\"" + " \"" + pathName + "\"",
                                                mWorkDirectory, null);

            cmd.Execute();

            // Can't really do anything with a "cancel" request.

            // Output filename is the input filename without the ".a".  Since the filename
            // was generated by us we can be confident in the format.
            string outputFile = mPathNames[0].Substring(0, mPathNames[0].Length - 2);

            return(new AssemblerResults(cmd.FullCommandLine, cmd.ExitCode, cmd.Stdout,
                                        cmd.Stderr, outputFile));
        }
Ejemplo n.º 7
0
        // IAssembler
        public AssemblerVersion QueryVersion()
        {
            AssemblerConfig config =
                AssemblerConfig.GetConfig(AppSettings.Global, AssemblerInfo.Id.Cc65);

            if (config == null || string.IsNullOrEmpty(config.ExecutablePath))
            {
                return(null);
            }

            ShellCommand cmd = new ShellCommand(config.ExecutablePath, "--version",
                                                Directory.GetCurrentDirectory(), null);

            cmd.Execute();
            if (string.IsNullOrEmpty(cmd.Stdout))
            {
                return(null);
            }

            // Windows - Stderr: "cl65.exe V2.17\r\n"
            // Linux - Stderr:   "cl65 V2.17 - Git N/A\n"
            // Other platforms may not have the ".exe".  Find first occurrence of " V".

            const string PREFIX = " V";
            string       str    = cmd.Stderr;
            int          start  = str.IndexOf(PREFIX);
            int          end    = (start < 0) ? -1 : str.IndexOfAny(new char[] { ' ', '\r', '\n' }, start + 1);

            if (start < 0 || end < 0 || start + PREFIX.Length >= end)
            {
                Debug.WriteLine("Couldn't find version in " + str);
                return(null);
            }
            start += PREFIX.Length;
            string versionStr = str.Substring(start, end - start);

            CommonUtil.Version version = CommonUtil.Version.Parse(versionStr);
            if (!version.IsValid)
            {
                return(null);
            }
            return(new AssemblerVersion(versionStr, version));
        }
Ejemplo n.º 8
0
 private void Execute(Func <ProcessStartInfo, Process> startProcess, ProcessStartInfo info)
 {
     try
     {
         ShellCommand.Execute(startProcess, info);
     }
     catch (FileNotFoundException e)
     {
         var name    = "Plugin: Shell";
         var message = $"Command not found: {e.Message}";
         context.API.ShowMsg(name, message);
     }
     catch (Win32Exception e)
     {
         var name    = "Plugin: Shell";
         var message = $"Error running the command: {e.Message}";
         context.API.ShowMsg(name, message);
     }
 }
Ejemplo n.º 9
0
        // IAssembler
        public AssemblerVersion QueryVersion()
        {
            AssemblerConfig config =
                AssemblerConfig.GetConfig(AppSettings.Global, AssemblerInfo.Id.Tass64);

            if (config == null || string.IsNullOrEmpty(config.ExecutablePath))
            {
                return(null);
            }

            ShellCommand cmd = new ShellCommand(config.ExecutablePath, "--version",
                                                Directory.GetCurrentDirectory(), null);

            cmd.Execute();
            if (string.IsNullOrEmpty(cmd.Stdout))
            {
                return(null);
            }

            // Windows - Stdout: "64tass Turbo Assembler Macro V1.53.1515\r\n"
            // Linux - Stdout:   "64tass Turbo Assembler Macro V1.53.1515?\n"

            const string PREFIX = "Macro V";
            string       str    = cmd.Stdout;
            int          start  = str.IndexOf(PREFIX);
            int          end    = (start < 0) ? -1 : str.IndexOfAny(new char[] { '?', '\r', '\n' }, start + 1);

            if (start < 0 || end < 0 || start + PREFIX.Length >= end)
            {
                Debug.WriteLine("Couldn't find version in " + str);
                return(null);
            }
            start += PREFIX.Length;
            string versionStr = str.Substring(start, end - start);

            CommonUtil.Version version = CommonUtil.Version.Parse(versionStr);
            if (!version.IsValid)
            {
                return(null);
            }
            return(new AssemblerVersion(versionStr, version));
        }
Ejemplo n.º 10
0
        // IAssembler
        public AssemblerVersion QueryVersion()
        {
            AssemblerConfig config =
                AssemblerConfig.GetConfig(AppSettings.Global, AssemblerInfo.Id.Acme);

            if (config == null || string.IsNullOrEmpty(config.ExecutablePath))
            {
                return(null);
            }

            ShellCommand cmd = new ShellCommand(config.ExecutablePath, "--version",
                                                Directory.GetCurrentDirectory(), null);

            cmd.Execute();
            if (string.IsNullOrEmpty(cmd.Stdout))
            {
                return(null);
            }

            // Windows - Stdout: "This is ACME, release 0.96.4 ("Fenchurch"), 22 Dec 2017 ..."
            // Linux - Stderr:   "This is ACME, release 0.96.4 ("Fenchurch"), 20 Apr 2019 ..."

            const string PREFIX = "release ";
            string       str    = cmd.Stdout;
            int          start  = str.IndexOf(PREFIX);
            int          end    = (start < 0) ? -1 : str.IndexOf(' ', start + PREFIX.Length + 1);

            if (start < 0 || end < 0 || start + PREFIX.Length >= end)
            {
                Debug.WriteLine("Couldn't find version in " + str);
                return(null);
            }
            start += PREFIX.Length;
            string versionStr = str.Substring(start, end - start);

            CommonUtil.Version version = CommonUtil.Version.Parse(versionStr);
            if (!version.IsValid)
            {
                return(null);
            }
            return(new AssemblerVersion(versionStr, version));
        }
Ejemplo n.º 11
0
        // IAssembler
        public AssemblerVersion QueryVersion()
        {
            AssemblerConfig config =
                AssemblerConfig.GetConfig(AppSettings.Global, AssemblerInfo.Id.Merlin32);

            if (config == null || string.IsNullOrEmpty(config.ExecutablePath))
            {
                return(null);
            }

            ShellCommand cmd = new ShellCommand(config.ExecutablePath, string.Empty,
                                                Directory.GetCurrentDirectory(), null);

            cmd.Execute();
            if (string.IsNullOrEmpty(cmd.Stdout))
            {
                return(null);
            }

            // Stdout: "C:\Src\WorkBench\Merlin32.exe v 1.0, (c) Brutal Deluxe ..."
            // Other platforms may not have the ".exe".  Find first occurrence of " v ".

            const string PREFIX = " v ";    // not expecting this to appear in the path
            string       str    = cmd.Stdout;
            int          start  = str.IndexOf(PREFIX);
            int          end    = (start < 0) ? -1 : str.IndexOf(',', start);

            if (start < 0 || end < 0 || start + PREFIX.Length >= end)
            {
                Debug.WriteLine("Couldn't find version in " + str);
                return(null);
            }
            start += PREFIX.Length;
            string versionStr = str.Substring(start, end - start);

            CommonUtil.Version version = CommonUtil.Version.Parse(versionStr);
            if (!version.IsValid)
            {
                return(null);
            }
            return(new AssemblerVersion(versionStr, version));
        }
Ejemplo n.º 12
0
        private List <Result> Commands()
        {
            var results = new List <Result>();

            results.AddRange(new[]
            {
                new Result
                {
                    Title    = "Shutdown",
                    SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_shutdown_computer"),
                    Glyph    = new GlyphInfo(FontFamily: "/Resources/#Segoe Fluent Icons", Glyph: "\xe7e8"),
                    IcoPath  = "Images\\shutdown.png",
                    Action   = c =>
                    {
                        var reuslt = MessageBox.Show(
                            context.API.GetTranslation("flowlauncher_plugin_sys_dlgtext_shutdown_computer"),
                            context.API.GetTranslation("flowlauncher_plugin_sys_shutdown_computer"),
                            MessageBoxButton.YesNo, MessageBoxImage.Warning);
                        if (reuslt == MessageBoxResult.Yes)
                        {
                            Process.Start("shutdown", "/s /t 0");
                        }

                        return(true);
                    }
                },
                new Result
                {
                    Title    = "Restart",
                    SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_restart_computer"),
                    Glyph    = new GlyphInfo(FontFamily: "/Resources/#Segoe Fluent Icons", Glyph: "\xe777"),
                    IcoPath  = "Images\\restart.png",
                    Action   = c =>
                    {
                        var result = MessageBox.Show(
                            context.API.GetTranslation("flowlauncher_plugin_sys_dlgtext_restart_computer"),
                            context.API.GetTranslation("flowlauncher_plugin_sys_restart_computer"),
                            MessageBoxButton.YesNo, MessageBoxImage.Warning);
                        if (result == MessageBoxResult.Yes)
                        {
                            Process.Start("shutdown", "/r /t 0");
                        }

                        return(true);
                    }
                },
                new Result
                {
                    Title    = "Restart With Advanced Boot Options",
                    SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_restart_advanced"),
                    Glyph    = new GlyphInfo(FontFamily: "/Resources/#Segoe Fluent Icons", Glyph: "\xecc5"),
                    IcoPath  = "Images\\restart_advanced.png",
                    Action   = c =>
                    {
                        var result = MessageBox.Show(
                            context.API.GetTranslation("flowlauncher_plugin_sys_dlgtext_restart_computer_advanced"),
                            context.API.GetTranslation("flowlauncher_plugin_sys_restart_computer"),
                            MessageBoxButton.YesNo, MessageBoxImage.Warning);

                        if (result == MessageBoxResult.Yes)
                        {
                            Process.Start("shutdown", "/r /o /t 0");
                        }

                        return(true);
                    }
                },
                new Result
                {
                    Title    = "Log Off",
                    SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_log_off"),
                    Glyph    = new GlyphInfo(FontFamily: "/Resources/#Segoe Fluent Icons", Glyph: "\xe77b"),
                    IcoPath  = "Images\\logoff.png",
                    Action   = c => ExitWindowsEx(EWX_LOGOFF, 0)
                },
                new Result
                {
                    Title    = "Lock",
                    SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_lock"),
                    Glyph    = new GlyphInfo(FontFamily: "/Resources/#Segoe Fluent Icons", Glyph: "\xe72e"),
                    IcoPath  = "Images\\lock.png",
                    Action   = c =>
                    {
                        LockWorkStation();
                        return(true);
                    }
                },
                new Result
                {
                    Title    = "Sleep",
                    SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_sleep"),
                    Glyph    = new GlyphInfo(FontFamily: "/Resources/#Segoe Fluent Icons", Glyph: "\xec46"),
                    IcoPath  = "Images\\sleep.png",
                    Action   = c => FormsApplication.SetSuspendState(PowerState.Suspend, false, false)
                },
                new Result
                {
                    Title    = "Hibernate",
                    SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_hibernate"),
                    Glyph    = new GlyphInfo(FontFamily: "/Resources/#Segoe Fluent Icons", Glyph: "\xe945"),
                    IcoPath  = "Images\\hibernate.png",
                    Action   = c =>
                    {
                        var info             = ShellCommand.SetProcessStartInfo("shutdown", arguments: "/h");
                        info.WindowStyle     = ProcessWindowStyle.Hidden;
                        info.UseShellExecute = true;

                        ShellCommand.Execute(info);

                        return(true);
                    }
                },
                new Result
                {
                    Title    = "Empty Recycle Bin",
                    SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_emptyrecyclebin"),
                    IcoPath  = "Images\\recyclebin.png",
                    Glyph    = new GlyphInfo(FontFamily: "/Resources/#Segoe Fluent Icons", Glyph: "\xe74d"),
                    Action   = c =>
                    {
                        // http://www.pinvoke.net/default.aspx/shell32/SHEmptyRecycleBin.html
                        // FYI, couldn't find documentation for this but if the recycle bin is already empty, it will return -2147418113 (0x8000FFFF (E_UNEXPECTED))
                        // 0 for nothing
                        var result = SHEmptyRecycleBin(new WindowInteropHelper(Application.Current.MainWindow).Handle, 0);
                        if (result != (uint)HRESULT.S_OK && result != (uint)0x8000FFFF)
                        {
                            MessageBox.Show($"Error emptying recycle bin, error code: {result}\n" +
                                            "please refer to https://msdn.microsoft.com/en-us/library/windows/desktop/aa378137",
                                            "Error",
                                            MessageBoxButton.OK, MessageBoxImage.Error);
                        }

                        return(true);
                    }
                },
                new Result
                {
                    Title    = "Exit",
                    SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_exit"),
                    IcoPath  = "Images\\app.png",
                    Action   = c =>
                    {
                        Application.Current.MainWindow.Close();
                        return(true);
                    }
                },
                new Result
                {
                    Title    = "Save Settings",
                    SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_save_all_settings"),
                    IcoPath  = "Images\\app.png",
                    Action   = c =>
                    {
                        context.API.SaveAppAllSettings();
                        context.API.ShowMsg(context.API.GetTranslation("flowlauncher_plugin_sys_dlgtitle_success"),
                                            context.API.GetTranslation("flowlauncher_plugin_sys_dlgtext_all_settings_saved"));
                        return(true);
                    }
                },
                new Result
                {
                    Title    = "Restart Flow Launcher",
                    SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_restart"),
                    IcoPath  = "Images\\app.png",
                    Action   = c =>
                    {
                        context.API.RestartApp();
                        return(false);
                    }
                },
                new Result
                {
                    Title    = "Settings",
                    SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_setting"),
                    IcoPath  = "Images\\app.png",
                    Action   = c =>
                    {
                        context.API.OpenSettingDialog();
                        return(true);
                    }
                },
                new Result
                {
                    Title    = "Reload Plugin Data",
                    SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_reload_plugin_data"),
                    IcoPath  = "Images\\app.png",
                    Action   = c =>
                    {
                        // Hide the window first then show msg after done because sometimes the reload could take a while, so not to make user think it's frozen.
                        Application.Current.MainWindow.Hide();

                        context.API.ReloadAllPluginData().ContinueWith(_ =>
                                                                       context.API.ShowMsg(
                                                                           context.API.GetTranslation("flowlauncher_plugin_sys_dlgtitle_success"),
                                                                           context.API.GetTranslation(
                                                                               "flowlauncher_plugin_sys_dlgtext_all_applicableplugins_reloaded")));

                        return(true);
                    }
                },
                new Result
                {
                    Title    = "Check For Update",
                    SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_check_for_update"),
                    IcoPath  = "Images\\checkupdate.png",
                    Action   = c =>
                    {
                        Application.Current.MainWindow.Hide();
                        context.API.CheckForNewUpdate();
                        return(true);
                    }
                },
                new Result
                {
                    Title    = "Open Log Location",
                    SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_open_log_location"),
                    IcoPath  = "Images\\app.png",
                    Action   = c =>
                    {
                        var logPath = Path.Combine(DataLocation.DataDirectory(), "Logs", Constant.Version);
                        context.API.OpenDirectory(logPath);
                        return(true);
                    }
                },
                new Result
                {
                    Title    = "Flow Launcher Tips",
                    SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_open_docs_tips"),
                    IcoPath  = "Images\\app.png",
                    Action   = c =>
                    {
                        context.API.OpenUrl(Constant.Documentation);
                        return(true);
                    }
                },
                new Result
                {
                    Title    = "Flow Launcher UserData Folder",
                    SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_open_userdata_location"),
                    IcoPath  = "Images\\app.png",
                    Action   = c =>
                    {
                        context.API.OpenDirectory(DataLocation.DataDirectory());
                        return(true);
                    }
                }
            });

            return(results);
        }