Пример #1
0
        public async Task SetGptType(GptType gptType)
        {
            Log.Verbose("Setting new GPT partition type {Type} to {Partition}", gptType, this);

            if (Equals(GptType, gptType))
            {
                return;
            }

            var part = await this.GetPsPartition();

            await PowerShellMixin.ExecuteCommand("Set-Partition",
                                                 ("InputObject", part),
                                                 ("GptType", $"{{{gptType.Guid}}}")
                                                 );

            await Disk.Refresh();

            Log.Verbose("New GPT type set correctly", gptType, this);
        }
Пример #2
0
        public async Task Flash(Disk disk, string imagePath, IDownloadProgress progressObserver = null)
        {
            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 resultCode = await ProcessUtils.RunProcessAsync(EtcherPath, args, outputObserver : outputSubject);

            if (resultCode != 0)
            {
                throw new DeploymentException($"There has been a problem during deployment: Etcher exited with code {resultCode}.");
            }

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

            stdOutputSubscription?.Dispose();
            await disk.Refresh();

            await disk.SetGuid(new Guid());
        }