コード例 #1
0
        private async Task Apply()
        {
            if (_resultDirectory == null)
            {
                return;
            }

            using (var waiting = new WaitingDialog {
                Owner = Application.Current?.MainWindow
            }) {
                try {
                    var car = _toUpdate[0].Car;
                    await ImageUtils.ApplyPreviewsAsync(AcRootDirectory.Instance.RequireValue, car.Id, _resultDirectory, ResizePreviews,
                                                        new AcPreviewImageInformation {
                        Name  = car.DisplayName,
                        Style = Path.GetFileNameWithoutExtension(UserPresetsControl.SelectedPresetFilename)
                    }, waiting, waiting.CancellationToken);
                } catch (Exception e) {
                    NonfatalError.Notify(AppStrings.CarPreviews_CannotSave, e);
                }
            }
        }
コード例 #2
0
        private async Task ShootCar([NotNull] ToUpdatePreview toUpdate, string filterId, bool manualMode, bool applyImmediately, CancellationToken cancellation)
        {
            if (toUpdate == null)
            {
                throw new ArgumentNullException(nameof(toUpdate));
            }

            try {
                _currentCar      = toUpdate.Car;
                _resultDirectory = await Showroom.ShotAsync(new Showroom.ShotProperties {
                    AcRoot                = AcRootDirectory.Instance.Value,
                    CarId                 = toUpdate.Car.Id,
                    ShowroomId            = SelectedShowroom.Id,
                    SkinIds               = toUpdate.Skins?.Select(x => x.Id).ToArray(),
                    Filter                = filterId,
                    Fxaa                  = EnableFxaa,
                    SpecialResolution     = UseSpecialResolution,
                    MaximizeVideoSettings = MaximizeVideoSettings,
                    Mode                  = manualMode ? Showroom.ShotMode.ClassicManual : Showroom.ShotMode.Fixed,
                    UseBmp                = true,
                    DisableWatermark      = DisableWatermark,
                    DisableSweetFx        = DisableSweetFx,
                    ClassicCameraDx       = 0.0,
                    ClassicCameraDy       = 0.0,
                    ClassicCameraDistance = 5.5,
                    FixedCameraPosition   = CameraPosition,
                    FixedCameraLookAt     = CameraLookAt,
                    FixedCameraFov        = CameraFov,
                    FixedCameraExposure   = CameraExposure ?? 0d,
                }, this, cancellation);

                if (cancellation.IsCancellationRequested)
                {
                    return;
                }
            } catch (ProcessExitedException e) when(applyImmediately)
            {
                Errors.Add(new UpdatePreviewError(toUpdate, e.Message, AcLogHelper.TryToDetermineWhatsGoingOn()));
                return;
            }

            if (applyImmediately)
            {
                if (_resultDirectory == null)
                {
                    Errors.Add(new UpdatePreviewError(toUpdate, AppStrings.CarPreviews_SomethingWentWrong, AcLogHelper.TryToDetermineWhatsGoingOn()));
                }
                else
                {
                    Progress = AsyncProgressEntry.Indetermitate;
                    await ImageUtils.ApplyPreviewsAsync(AcRootDirectory.Instance.RequireValue, toUpdate.Car.Id, _resultDirectory, ResizePreviews,
                                                        new AcPreviewImageInformation {
                        Name  = toUpdate.Car.DisplayName,
                        Style = Path.GetFileNameWithoutExtension(UserPresetsControl.SelectedPresetFilename)
                    }, new Progress <Tuple <string, double?> >(t => {
                        Progress = new AsyncProgressEntry($"Applying freshly made previews ({t.Item1})…", t.Item2);
                    }), cancellation);
                }
            }
            else
            {
                if (_resultDirectory == null)
                {
                    SelectPhase(Phase.Error, AppStrings.CarPreviews_SomethingWentWrong, AcLogHelper.TryToDetermineWhatsGoingOn());
                    return;
                }

                ResultPreviewComparisons = new ObservableCollection <ResultPreviewComparison>(
                    Directory.GetFiles(_resultDirectory, "*.*").Select(x => {
                    var id = (Path.GetFileNameWithoutExtension(x) ?? "").ToLower();
                    return(new ResultPreviewComparison {
                        Name = toUpdate.Car.GetSkinById(id)?.DisplayName ?? id,

                        /* custom paths, because theoretically skin might no longer exist at this point */
                        LiveryImage = Path.Combine(toUpdate.Car.Location, @"skins", id, @"livery.png"),
                        OriginalImage = Path.Combine(toUpdate.Car.Location, @"skins", id, @"preview.jpg"),
                        UpdatedImage = x
                    });
                }));
            }
        }