public static string GetDotnetBasePath(string workingDirectory)
        {
            // Ensure we get output in the locale that we require for parsing.
            var environmentVariables = new Dictionary <string, string>
            {
                ["DOTNET_CLI_UI_LANGUAGE"] = "en-US"
            };

            var processResult = ProcessRunner.CreateProcess(
                "dotnet", "--info", lowPriority: false, workingDirectory, captureOutput: true,
                displayWindow: false, environmentVariables).Result.Result;

            if (processResult.ExitCode != 0)
            {
                // when error running dotnet command, consider dotnet as not available
                return(null);
            }

            var outputString = string.Join(Environment.NewLine, processResult.OutputLines);
            var matched      = DotnetBasePathRegex.Match(outputString);

            if (!matched.Success)
            {
                return(null);
            }

            return(matched.Groups[1].Value.Trim());
        }
        internal async Task <int> PerformNuGetRestore(string workspaceFilePath)
        {
            var processInfo   = ProcessRunner.CreateProcess("dotnet", $"restore \"{workspaceFilePath}\"", captureOutput: true, displayWindow: false);
            var restoreResult = await processInfo.Result;

            return(restoreResult.ExitCode);
        }
Example #3
0
        /// <summary>
        /// Checks the current version of youtube-dl
        /// </summary>
        private void CheckYtdlVersion()
        {
            if (String.IsNullOrEmpty(ytdlLocation))
            {
                return;
            }

            if (versionChecked)
            {
                // avoid checking every time if we don't have to
                return;
            }

            string ytdlPath = settings.YtdlLocation;

            ytdlPath += @"\youtube-dl.exe";

            Process ytdlProcess = ProcessRunner.CreateProcess(ytdlPath, "--version");

            ytdlProcess.OutputDataReceived += VersionOutputReceived;

            try
            {
                ytdlProcess.Start();
                ytdlProcess.BeginOutputReadLine();
            }
            catch (Exception e)
            {
                YtdlOutput = e.Message;
            }

            versionChecked = true;
            fileService.SaveSettings(settings);
        }
Example #4
0
        public static async Task <int> PerformRestoreAsync(string workspaceFilePath, ILogger logger)
        {
            var processInfo   = ProcessRunner.CreateProcess("dotnet", $"restore \"{workspaceFilePath}\"", captureOutput: true, displayWindow: false);
            var restoreResult = await processInfo.Result;

            logger.LogDebug(string.Join(Environment.NewLine, restoreResult.OutputLines));

            return(restoreResult.ExitCode);
        }
Example #5
0
        public static async Task <int> PerformRestore(string workspaceFilePath, ITestOutputHelper output)
        {
            var workspacePath = Path.Combine(TestProjectsPathHelper.GetProjectsDirectory(), workspaceFilePath);

            var processInfo   = ProcessRunner.CreateProcess("dotnet", $"restore \"{workspacePath}\"", captureOutput: true, displayWindow: false);
            var restoreResult = await processInfo.Result;

            output.WriteLine(string.Join(Environment.NewLine, restoreResult.OutputLines));

            return(restoreResult.ExitCode);
        }
Example #6
0
        public CodeFormatterTests(ITestOutputHelper output, MSBuildFixture msBuildFixture, TestProjectsPathFixture testProjectsPathFixture)
        {
            _output = output;

            testProjectsPathFixture.SetCurrentDirectory();
            msBuildFixture.RegisterInstance(_output);

            // For NetStandard projects to resolve framework references, the project.assets.json files must
            // be constructed by a NuGet restore.
            ProcessRunner.CreateProcess("dotnet", $"restore \"{CodeStyleSolutionFilePath}\"").Result.GetAwaiter().GetResult();
        }
Example #7
0
        private void UpdateYtdl()
        {
            string ytdlPath = settings.YtdlLocation;

            ytdlPath += @"\youtube-dl.exe";

            Process ytdlProcess = ProcessRunner.CreateProcess(ytdlPath, "--update");

            ytdlProcess.OutputDataReceived += OutputReceived;

            ytdlProcess.Start();
            ytdlProcess.BeginOutputReadLine();

            versionChecked = false;
            CheckYtdlVersion();
        }
Example #8
0
        private static bool TryGetDotNetCliVersion([NotNullWhen(returnValue: true)] out string?dotnetVersion)
        {
            try
            {
                var processInfo   = ProcessRunner.CreateProcess("dotnet", "--version", captureOutput: true, displayWindow: false);
                var versionResult = processInfo.Result.GetAwaiter().GetResult();

                dotnetVersion = versionResult.OutputLines[0].Trim();
                return(true);
            }
            catch
            {
                dotnetVersion = null;
                return(false);
            }
        }
Example #9
0
        public static async Task <int> NewProject(string templateName, string outputPath, string languageName, ITestOutputHelper output)
        {
            var language = languageName switch
            {
                LanguageNames.CSharp => "C#",
                LanguageNames.VisualBasic => "VB",
                LanguageNames.FSharp => "F#",
                _ => throw new ArgumentOutOfRangeException(nameof(languageName), actualValue: languageName, message: "Only C#, F# and VB.NET project are supported.")
            };

            var processInfo   = ProcessRunner.CreateProcess("dotnet", $"new \"{templateName}\" -o \"{outputPath}\" --language \"{language}\"", captureOutput: true, displayWindow: false);
            var restoreResult = await processInfo.Result;

            output.WriteLine(string.Join(Environment.NewLine, restoreResult.OutputLines));

            return(restoreResult.ExitCode);
        }
Example #10
0
        private async Task ConvertAsync()
        {
            if (!String.IsNullOrEmpty(settings.FfmpegLocation))
            {
                NotifySettingsError();
                return;
            }

            string destinationPath = Path.ChangeExtension(ConvertPath, ".mp4");

            if (File.Exists(destinationPath))
            {
                // file already exists, warn the user somehow and bail from converting
                return;
            }

            string processArgs = $"-i \"{ConvertPath}\" -codec copy \"{destinationPath}\"";

            convertProcess = ProcessRunner.CreateProcess(ffmpegPath, processArgs);

            ConvertPct        = 0;
            ConvertInProgress = true;
            ConvertEnabled    = false;

            fileSize   = new FileInfo(ConvertPath).Length;
            fileSizeKB = fileSize / 1024;
            DebugSize  = fileSizeKB.ToString();

            convertProcess.OutputDataReceived += ConvertProcess_OutputDataReceived;
            convertProcess.ErrorDataReceived  += ConvertProcess_ErrorDataReceived;
            convertProcess.Exited             += ConvertProcess_Exited;

            try
            {
                convertProcess.Start();
                convertProcess.BeginOutputReadLine();
                convertProcess.BeginErrorReadLine();
                PollForUpdate();
            }
            catch (Exception e)
            {
                // how to log these...
                ;
            }
        }
Example #11
0
        private async Task DownloadAsync()
        {
            // OKAY how do we make this thing actually run async
            if (settings == null)
            {
                // what the heck? Settings not loaded
                YtdlOutput = "Settings failed to load D:";
                return;
            }

            if (String.IsNullOrEmpty(App.Settings.YtdlLocation))
            {
                // prompt user to specify a youtube-dl location
                YtdlOutput = "Please specify a Youtube-dl Location in Settings!";
                SettingsWarning?.Invoke(this, null);
                return;
            }

            if (String.IsNullOrEmpty(App.Settings.DownloadLocation))
            {
                // prompt user to specify a download location

                // maybe a popup that allows them to proceed and default
                // to saving in the youtube-dl folder?
                YtdlOutput = "Please specify a Download Location in Settings!";
                SettingsWarning?.Invoke(this, null);
                return;
            }

            if (String.IsNullOrEmpty(downloadURL))
            {
                YtdlOutput = "Please enter a URL to download!";
                URLWarning?.Invoke(this, null);
                return;
            }

            YtdlOutput = "began downloading " + downloadURL + "...";

            DownloadPct  = 0;
            DlInProgress = true;
            DlEnabled    = false;

            string ytdlPath = App.Settings.YtdlLocation;

            ytdlPath += @"\youtube-dl.exe";
            string downloadPath = App.Settings.DownloadLocation;
            string newFileName  = String.IsNullOrEmpty(fileName) ? @"%(title)s.%(ext)s" : fileName + @".%(ext)s";

            downloadPath += @"\" + newFileName;
            string videoFormat = "";

            if (VideoRadioValue)
            {
                videoFormat = "bestvideo";
            }
            else if (AudioRadioValue)
            {
                videoFormat = "bestaudio";
            }
            else              // BothRadioValue
            {
                videoFormat = "best";
            }

            string processArguments = "-f " + videoFormat + " -o \"" + downloadPath + "\" \"" + downloadURL + "\"";

            //Process ytdlProcess = ProcessRunner.CreateProcess(ytdlPath, processArguments);
            dlProcess = ProcessRunner.CreateProcess(ytdlPath, processArguments);

            //ytdlProcess.OutputDataReceived += OutputReceived;
            //ytdlProcess.Exited += YtdlProcess_Exited;

            //ytdlProcess.Start();
            //ytdlProcess.BeginOutputReadLine();

            dlProcess.OutputDataReceived += OutputReceived;
            dlProcess.ErrorDataReceived  += ErrorReceived;
            dlProcess.Exited             += YtdlProcess_Exited;

            try
            {
                dlProcess.Start();
                dlProcess.BeginOutputReadLine();
                dlProcess.BeginErrorReadLine();
            }
            catch (Exception e)
            {
                YtdlOutput = e.Message;
            }

            // example cmd line usage:
            // youtube-dl -f 137 -o "your\download\location\%(title)s.%(ext)s" "https://www.youtube.com/watch?v=5RsOkhR6KBc"
        }