Exemple #1
0
 public UpdatePreviewError([NotNull] ToUpdatePreview toUpdate, [NotNull] string message, [CanBeNull] WhatsGoingOn whatsGoingOn)
 {
     ToUpdate     = toUpdate;
     Message      = message;
     WhatsGoingOn = whatsGoingOn;
 }
Exemple #2
0
 public static Task <IReadOnlyList <UpdatePreviewError> > Run(this ToUpdatePreview toUpdate, UpdatePreviewMode?mode = null, string presetFilename = null)
 {
     return(new[] { toUpdate }.Run(mode, presetFilename));
 }
Exemple #3
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
                    });
                }));
            }
        }