예제 #1
0
 private static IEnumerable <string> GetBitmaps()
 {
     try {
         return(FileUtils.GetFilesSafe(AcPaths.GetDocumentsScreensDirectory())
                .Where(file => file.EndsWith(@".bmp", StringComparison.OrdinalIgnoreCase)));
     } catch (Exception e) {
         Logging.Error("Can’t get files without extension: " + e);
         return(new string[0]);
     }
 }
예제 #2
0
        private static async Task ShotAndApply(string filename, bool isEnabled, Func <Task> run)
        {
            if (Keyboard.Modifiers.HasFlag(ModifierKeys.Alt))
            {
                await ApplyExisting(filename);

                return;
            }

            if (!isEnabled)
            {
                return;
            }
            if (!ValuesStorage.Get <bool>(KeyUpdatePreviewMessageShown) && ModernDialog.ShowMessage(
                    ImportantTips.Entries.GetByIdOrDefault(@"trackPreviews")?.Content, AppStrings.Common_HowTo_Title, MessageBoxButton.OKCancel) !=
                MessageBoxResult.OK)
            {
                return;
            }

            var directory = AcPaths.GetDocumentsScreensDirectory();
            var shots     = FileUtils.GetFilesSafe(directory);

            await run();

            if (ScreenshotsConverter.CurrentConversion?.IsCompleted == false)
            {
                await ScreenshotsConverter.CurrentConversion;
            }

            var newShots = FileUtils.GetFilesSafe(directory)
                           .Where(x => !shots.ArrayContains(x) && Regex.IsMatch(x, @"\.(jpe?g|png|bmp)$", RegexOptions.IgnoreCase)).ToList();

            if (!newShots.Any())
            {
                NonfatalError.Notify(ControlsStrings.AcObject_CannotUpdatePreview, ControlsStrings.AcObject_CannotUpdatePreview_TrackCommentary);
                return;
            }

            ValuesStorage.Set(KeyUpdatePreviewMessageShown, true);

            var shot = new ImageViewer <string>(newShots, null, Path.GetFileName)
            {
                MaxImageHeight = CommonAcConsts.TrackPreviewHeight,
                MaxImageWidth  = CommonAcConsts.TrackPreviewWidth
            }.SelectDialog();

            if (shot == null)
            {
                return;
            }

            ApplyExisting(shot, filename);
        }
예제 #3
0
        private static Task ApplyExisting(string previewImage)
        {
            var dialog = new OpenFileDialog {
                Filter           = FileDialogFilters.ImagesFilter,
                Title            = AppStrings.Common_SelectImageForPreview,
                InitialDirectory = AcPaths.GetDocumentsScreensDirectory(),
                RestoreDirectory = true
            };

            if (dialog.ShowDialog() == true)
            {
                ApplyExisting(dialog.FileName, previewImage);
            }

            return(Task.Delay(0));
        }
예제 #4
0
            private string WaitShot(DateTime?from = null, int time = int.MaxValue)
            {
                if (from == null)
                {
                    from = DateTime.Now;
                }

                for (; time > 0; time -= WaitTimeoutStep)
                {
                    var files = FileUtils.GetFilesSafe(AcPaths.GetDocumentsScreensDirectory(), $"Showroom_{CarId}_*.bmp")
                                .Where(x => new FileInfo(x).CreationTime > from).ToList();
                    if (files.Any())
                    {
                        Wait(WaitTimeoutEnsure);
                        return(files[0]);
                    }

                    Wait(WaitTimeoutStep);
                }

                return(null);
            }
예제 #5
0
 public void Load()
 {
     _directory = AcPaths.GetDocumentsScreensDirectory();
     _images    = GetFiles(_directory, _filter).ToList();
 }
예제 #6
0
 public async Task LoadAsync(CancellationToken cancellationToken)
 {
     _directory = AcPaths.GetDocumentsScreensDirectory();
     _images    = await Task.Run(() => GetFiles(_directory, _filter).ToList(), cancellationToken);
 }