示例#1
0
 private string GetCliProperties()
 {
     if (FormMethods.VerifyIntegrity())
     {
         // https://stackoverflow.com/a/11350038
         var    cliProperties = FileVersionInfo.GetVersionInfo(Main.VGAudioCli);
         string cliName       = cliProperties.ProductName;
         string cliVersion    = cliProperties.FileVersion;
         return(string.Format("{0} {1}", cliName, cliVersion));
     }
     return("(Unknown)");
 }
示例#2
0
        public string LoadCommand(string arguments = null, string workingDirectory = null)
        {
            if (!FormMethods.VerifyIntegrity())
            {
                return(null);
            }

            // If there's an opened file, use its location as a working directory
            if (workingDirectory == null)
            {
                if (Info.ContainsKey("Path"))
                {
                    workingDirectory = Path.GetDirectoryName(Info["Path"]);
                }
                else
                {
                    workingDirectory = Path.GetDirectoryName(Main.VGAudioCli);
                }
            }
            else
            {
                if (!Directory.Exists(workingDirectory))
                {
                    workingDirectory = Path.GetDirectoryName(Main.VGAudioCli);
                }
            }

            ProcessStartInfo procInfo = new ProcessStartInfo
            {
                FileName               = Main.VGAudioCli,
                WorkingDirectory       = workingDirectory,
                Arguments              = arguments,
                RedirectStandardOutput = true,
                UseShellExecute        = false,
                CreateNoWindow         = true,
                WindowStyle            = ProcessWindowStyle.Hidden
            };
            var proc = Process.Start(procInfo);

            proc.WaitForExit();
            if (proc.ExitCode == 0)
            {
                return(proc.StandardOutput.ReadToEnd());
            }
            else
            {
                return(null);
            }
        }
示例#3
0
        public bool Convert()
        {
            if (!File.Exists(Info["Path"]))
            {
                throw new FileNotFoundException("The opened file no longer exists!");
            }

            // Check if the export file extension is the correct one
            if (Path.GetExtension(ExportInfo["Path"]).ToLower() != ExportInfo["Extension"].ToLower())
            {
                // Error occurs when the user replaces an existing file
                // with invalid export extension through the dialog box
                throw new ArgumentException("The file extension selected is invalid!");
            }

            string arguments = GenerateConversionParams(ExportInfo["PathEscaped"]);

            if (string.IsNullOrEmpty(arguments))
            {
                throw new Exception("Internal Error: No parameters!");
            }
            if (!FormMethods.VerifyIntegrity())
            {
                return(false);
            }
            Lock(false); // Unlock the file

            ProcessStartInfo procInfo = new ProcessStartInfo
            {
                FileName               = Main.VGAudioCli,
                WorkingDirectory       = Path.GetDirectoryName(Info["Path"]),
                Arguments              = arguments,
                RedirectStandardOutput = true,
                UseShellExecute        = false,
                CreateNoWindow         = true,
                WindowStyle            = ProcessWindowStyle.Hidden
            };
            var proc = Process.Start(procInfo);

            string line = "";

            while (!proc.StandardOutput.EndOfStream)
            {
                line += proc.StandardOutput.ReadLine() + "\r\n";
            }
            string[] standardConsoleOutput = line.Split(
                new[] { "\r\n", "\r", "\n" },
                StringSplitOptions.None
                );
            Lock(true); // Relock the file

            // Invalid parameter passed to the CLI
            if (proc.ExitCode != 0)
            {
                throw new ArgumentException(standardConsoleOutput[0]);
            }

            // Progress bar [####   ] starts with '[' and success starts with, well, 'Success!'
            if (!standardConsoleOutput[0].StartsWith("[") && !standardConsoleOutput[0].StartsWith("Success!"))
            {
                throw new NotSupportedException(standardConsoleOutput[0]);
            }

            // Get the time elapsed during the conversion
            string timeElapsed = standardConsoleOutput[1].Substring(standardConsoleOutput[1].IndexOf(":") + 1);

            ExportResult["TimeElapsed"] = TimeSpan.FromSeconds(System.Convert.ToDouble(timeElapsed)).ToString(@"hh\:mm\:ss\.fff");
            return(true);
        }