Ejemplo n.º 1
0
        public virtual void PrepareUnregisteringPrig(PrigViewModel vm)
        {
            vm.BeginMachineWideProcessProgress(MachineWideProcesses.Uninstalling);

            var machinePreq = new MachinePrerequisite(Resources.NuGetRootPackageVersion);

            machinePreq.ProfilerStatusChecking += profLoc => vm.ReportProfilerStatusCheckingProgress(50u, profLoc);

            if (!MachineWideInstaller.HasBeenInstalled(machinePreq))
            {
                vm.ShowSkippedMachineWideProcessMessage(SkippedReasons.AlreadyRegistered);
                vm.EndSkippedMachineWideProcessProgress(SkippedReasons.AlreadyRegistered);
                return;
            }


            if (!WindowsIdentity.GetCurrent().IsElevated())
            {
                vm.ShowVisualStudioHasNotBeenElevatedYetMessage();
                if (ProcessMixin.RestartCurrentProcessWith(_ => { _.Verb = "runas"; }))
                {
                    return;
                }

                vm.EndSkippedMachineWideProcessProgress(SkippedReasons.CanceledByUser);
            }
            else
            {
                UnregisterPrig(vm);
            }
        }
Ejemplo n.º 2
0
        public async Task <IList <string> > InjectDrivers(string path, string windowsRootPath)
        {
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }

            var outputSubject = new Subject <string>();

            var subscription = outputSubject.Subscribe(Log.Verbose);

            var args = new[]
            {
                "/Add-Driver",
                $"/Image:{windowsRootPath}",
                $@"/Driver:""{path}""",
                IsUniqueFile(path) ? "" : "/Recurse",
            };

            var processResults = await ProcessMixin.RunProcess(WindowsCommandLineUtils.Dism, args.Join(" "), outputObserver : outputSubject, errorObserver : outputSubject);

            subscription.Dispose();

            if (processResults.ExitCode != 0)
            {
                throw new DeploymentException(
                          $"There has been a problem during deployment: DISM exited with code {processResults.ExitCode}. Output: {processResults.StandardOutput.Join()}");
            }

            return(StringExtensions.ExtractFileNames(string.Concat(processResults.StandardOutput)).ToList());
        }
Ejemplo n.º 3
0
        private async Task Run(string args, IOperationProgress progressObserver, CancellationToken token)
        {
            var dismName = WindowsCommandLineUtils.Dism;
            ISubject <string> outputSubject         = new Subject <string>();
            IDisposable       stdOutputSubscription = null;

            if (progressObserver != null)
            {
                stdOutputSubscription = outputSubject
                                        .Select(GetPercentage)
                                        .Where(d => !double.IsNaN(d))
                                        .Subscribe(progressObserver.Percentage);
            }

            Log.Verbose("We are about to run DISM: {ExecName} {Parameters}", dismName, args);
            var processResults = await ProcessMixin.RunProcess(dismName, args, outputSubject, cancellationToken : token);

            progressObserver?.Percentage.OnNext(double.NaN);

            if (processResults.ExitCode != 0)
            {
                Log.Error("There has been a problem during deployment: DISM failed {Results}", processResults);
                throw new DeploymentException($"There has been a problem during deployment: DISM exited with code {processResults.ExitCode}");
            }

            stdOutputSubscription?.Dispose();
        }
Ejemplo n.º 4
0
        public void ConvertCommandLineArgsToArguments_should_throw_ArgumentNullException_if_passed_parameter_is_null()
        {
            // Arrange
            var commandLineArgs = default(string[]);

            // Act, Assert
            Assert.Throws <ArgumentNullException>(() => ProcessMixin.ConvertCommandLineArgsToArguments(commandLineArgs));
        }
Ejemplo n.º 5
0
        public async Task <string> Invoke(string command)
        {
            var processResults = await ProcessMixin.RunProcess(bcdEdit, $@"{commonArgs} {command}");

            var output = string.Join("\n", processResults.StandardOutput);
            var errors = string.Join("\n", processResults.StandardError);

            return(string.Join(";", output, errors));
        }
Ejemplo n.º 6
0
        public void ConvertCommandLineArgsToArguments_should_ignore_the_first_element()
        {
            // Arrange
            var commandLineArgs = new[] { "a a a" };

            // Act
            var result = ProcessMixin.ConvertCommandLineArgsToArguments(commandLineArgs);

            // Assert
            Assert.AreEqual(string.Empty, result);
        }
Ejemplo n.º 7
0
        public void ConvertCommandLineArgsToArguments_should_not_enclose_by_double_quote_if_there_is_no_delimiter()
        {
            // Arrange
            var commandLineArgs = new[] { "a", "bbb" };

            // Act
            var result = ProcessMixin.ConvertCommandLineArgsToArguments(commandLineArgs);

            // Assert
            Assert.AreEqual("bbb", result);
        }
Ejemplo n.º 8
0
        public void ConvertCommandLineArgsToArguments_should_enclose_by_double_quote_if_an_arg_contains_tab()
        {
            // Arrange
            var commandLineArgs = new[] { "a", "b\tb" };

            // Act
            var result = ProcessMixin.ConvertCommandLineArgsToArguments(commandLineArgs);

            // Assert
            Assert.AreEqual("\"b\tb\"", result);
        }
Ejemplo n.º 9
0
        public void ConvertCommandLineArgsToArguments_should_return_empty_if_passed_parameter_is_empty()
        {
            // Arrange
            var commandLineArgs = new string[0];

            // Act
            var result = ProcessMixin.ConvertCommandLineArgsToArguments(commandLineArgs);

            // Assert
            Assert.AreEqual(string.Empty, result);
        }
Ejemplo n.º 10
0
        public async Task MakeBootable(string systemRoot, string windowsPath)
        {
            Log.Verbose("Making Windows installation bootable...");

            var bcdInvoker = bcdInvokerFactory(systemRoot.CombineRelativeBcdPath());

            await ProcessMixin.RunProcess(WindowsCommandLineUtils.BcdBoot, $@"{windowsPath} /f UEFI /s {systemRoot} /l en-us");

            await bcdInvoker.Invoke("/set {default} testsigning on");

            await bcdInvoker.Invoke("/set {default} nointegritychecks on");
        }
Ejemplo n.º 11
0
        public async Task RemoveDriver(string path, string windowsRootPath)
        {
            var outputSubject  = new Subject <string>();
            var subscription   = outputSubject.Subscribe(Log.Verbose);
            var processResults = await ProcessMixin.RunProcess(WindowsCommandLineUtils.Dism, $@"/Remove-Driver /Image:{windowsRootPath} /Driver:""{path}""", outputObserver : outputSubject, errorObserver : outputSubject);

            subscription.Dispose();

            if (processResults.ExitCode != 0)
            {
                throw new DeploymentException(
                          $"There has been a problem during removal: DISM exited with code {processResults}.");
            }
        }
Ejemplo n.º 12
0
        public async Task MakeBootable(IPartition systemPartition, IPartition windowsPartition)
        {
            Log.Verbose("Making Windows installation bootable...");

            var bcdInvoker  = bcdInvokerFactory.Create(systemPartition.Root.CombineRelativeBcdPath());
            var windowsPath = Path.Combine(windowsPartition.Root, "Windows");

            await ProcessMixin.RunProcess(WindowsCommandLineUtils.BcdBoot, $@"{windowsPath} /f UEFI /s {systemPartition.Root} /l en-us");

            await bcdInvoker.Invoke("/set {default} testsigning on");

            await bcdInvoker.Invoke("/set {default} nointegritychecks on");

            await systemPartition.SetGptType(PartitionType.Esp);
        }
Ejemplo n.º 13
0
        public async Task Flash(IDisk disk, string imagePath, IOperationProgress progressObserver = null)
        {
            Log.Information("Flashing GPT image...");

            ISubject <string> outputSubject         = new Subject <string>();
            IDisposable       stdOutputSubscription = null;
            bool isValidating = false;

            if (progressObserver != null)
            {
                stdOutputSubscription = outputSubject
                                        .Do(s =>
                {
                    if (!isValidating && CultureInfo.CurrentCulture.CompareInfo.IndexOf(s, "validating", 0, CompareOptions.IgnoreCase) != -1)
                    {
                        progressObserver?.Percentage.OnNext(double.NaN);
                        Log.Information("Validating flashed image...");
                        isValidating = true;
                    }
                })
                                        .Select(GetPercentage)
                                        .Where(d => !double.IsNaN(d))
                                        .Subscribe(progressObserver.Percentage);
            }

            var args = $@"-d \\.\PHYSICALDRIVE{disk.Number} ""{imagePath}"" --yes --no-unmount";

            Log.Verbose("We are about to run Etcher: {ExecName} {Parameters}", EtcherPath, args);
            var processResults = await ProcessMixin.RunProcess(EtcherPath, args, outputObserver : outputSubject);

            if (processResults.ExitCode != 0)
            {
                Log.Error("Cannot flash the image with Etcher. Execution results: {Results}", processResults);
                throw new FlashException($"Cannot flash the image: {imagePath} to {disk}");
            }

            progressObserver?.Percentage.OnNext(double.NaN);

            stdOutputSubscription?.Dispose();

            await disk.Refresh();

            await EnsureDiskHasNewGuid(disk);

            Log.Information("GPT image flashed");
        }
Ejemplo n.º 14
0
        protected virtual void OnCompletedUnregisterPrig(PrigViewModel vm, MachineWideProcessResults result)
        {
            switch (result)
            {
            case MachineWideProcessResults.Skipped:
                vm.ShowSkippedMachineWideProcessMessage(SkippedReasons.AlreadyRegistered);
                vm.EndSkippedMachineWideProcessProgress(SkippedReasons.AlreadyRegistered);
                break;

            case MachineWideProcessResults.Completed:
                var restarts = vm.ConfirmRestartingVisualStudioToTakeEffect();
                vm.EndCompletedMachineWideProcessProgress();
                if (!restarts)
                {
                    return;
                }

                ProcessMixin.RestartCurrentProcess();
                break;
            }
        }
Ejemplo n.º 15
0
        protected override async Task ExecuteCore()
        {
            var outputSubject  = new Subject <string>();
            var subscription   = outputSubject.Subscribe(Log.Verbose);
            var processResults = await ProcessMixin.RunProcess(WindowsCommandLineUtils.Dism, args,
                                                               outputObserver : outputSubject, errorObserver : outputSubject, workingDirectory : workingDirectory);

            subscription.Dispose();

            if (processResults.ExitCode != 0)
            {
                throw new DeploymentException(
                          $"There has been a problem during deployment: DISM exited with code {processResults.ExitCode}. Output: {processResults.StandardOutput}");
            }

            var injectedDrivers = Zafiro.Core.StringExtensions.ExtractFileNames(string.Concat(processResults.StandardOutput)).ToList();

            var metadataPath = GetMetadataFilename();

            SaveMetadata(injectedDrivers, Path.Combine(AppPaths.Metadata, "Injected Drivers", metadataPath));
        }