Ejemplo n.º 1
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());
        }