Ejemplo n.º 1
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.º 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
        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.º 4
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.º 5
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.º 6
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.º 7
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.º 8
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));
        }