Exemplo n.º 1
0
        public string Run(string filePath)
        {
            if (!string.IsNullOrEmpty(filePath) && CheckExtensions(filePath) && !string.IsNullOrEmpty(Path) && File.Exists(Path))
            {
                filePath = filePath.Trim('"');

                try
                {
                    string outputPath = "";

                    using (Process process = new Process())
                    {
                        ProcessStartInfo psi = new ProcessStartInfo(Path);

                        if (string.IsNullOrEmpty(Args))
                        {
                            psi.Arguments = '"' + filePath + '"';
                        }
                        else
                        {
                            if (!string.IsNullOrEmpty(OutputExtension))
                            {
                                outputPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(filePath), System.IO.Path.GetFileNameWithoutExtension(filePath));

                                if (!OutputExtension.Contains("."))
                                {
                                    OutputExtension = "." + OutputExtension;
                                }

                                outputPath += OutputExtension;
                            }
                            else
                            {
                                outputPath = filePath;
                            }

                            psi.Arguments = CodeMenuEntryActions.Parse(Args, filePath, outputPath);
                        }

                        if (HiddenWindow)
                        {
                            psi.WindowStyle    = ProcessWindowStyle.Hidden;
                            psi.CreateNoWindow = true;
                        }

                        process.StartInfo = psi;

                        DebugHelper.WriteLine(string.Format("Running {0} with arguments: {1}", Path, psi.Arguments));

                        process.Start();
                        process.WaitForExit();
                    }

                    if (!string.IsNullOrEmpty(outputPath) && File.Exists(outputPath))
                    {
                        return(outputPath);
                    }

                    return(filePath);
                }
                catch (Exception e)
                {
                    DebugHelper.WriteException(e);
                }
            }

            return(filePath);
        }
Exemplo n.º 2
0
        public string Run(string inputPath)
        {
            pendingInputFilePath = null;
            string path = GetFullPath();

            if (!string.IsNullOrEmpty(path) && File.Exists(path) && !string.IsNullOrWhiteSpace(inputPath))
            {
                inputPath = inputPath.Trim('"');

                if (CheckExtension(inputPath))
                {
                    try
                    {
                        string outputPath = inputPath;

                        string arguments;

                        if (string.IsNullOrEmpty(Args))
                        {
                            arguments = '"' + inputPath + '"';
                        }
                        else
                        {
                            if (!string.IsNullOrWhiteSpace(OutputExtension))
                            {
                                outputPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(inputPath), System.IO.Path.GetFileNameWithoutExtension(inputPath));

                                if (!OutputExtension.StartsWith("."))
                                {
                                    outputPath += ".";
                                }

                                outputPath += OutputExtension;
                            }

                            arguments = CodeMenuEntryActions.Parse(Args, inputPath, outputPath);
                        }

                        using (Process process = new Process())
                        {
                            ProcessStartInfo psi = new ProcessStartInfo()
                            {
                                FileName        = path,
                                Arguments       = arguments,
                                UseShellExecute = false,
                                CreateNoWindow  = HiddenWindow
                            };

                            DebugHelper.WriteLine($"Action input: \"{inputPath}\" [{Helpers.GetFileSizeReadable(inputPath)}]");
                            DebugHelper.WriteLine($"Action run: \"{psi.FileName}\" {psi.Arguments}");

                            process.StartInfo = psi;
                            process.Start();
                            process.WaitForExit();
                        }

                        if (!string.IsNullOrEmpty(outputPath) && File.Exists(outputPath))
                        {
                            DebugHelper.WriteLine($"Action output: \"{outputPath}\" [{Helpers.GetFileSizeReadable(outputPath)}]");

                            if (DeleteInputFile && !inputPath.Equals(outputPath, StringComparison.OrdinalIgnoreCase))
                            {
                                pendingInputFilePath = inputPath;
                            }

                            return(outputPath);
                        }

                        return(inputPath);
                    }
                    catch (Exception e)
                    {
                        DebugHelper.WriteException(e);
                    }
                }
            }

            return(null);
        }