|  | @@ -13,662 +13,759 @@ using PicView.Core.Gallery;
 | 
											
												
													
														|  |  using PicView.Core.Navigation;
 |  |  using PicView.Core.Navigation;
 | 
											
												
													
														|  |  using Timer = System.Timers.Timer;
 |  |  using Timer = System.Timers.Timer;
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -namespace PicView.Avalonia.Navigation;
 |  | 
 | 
											
												
													
														|  | -public sealed class ImageIterator : IDisposable
 |  | 
 | 
											
												
													
														|  | 
 |  | +namespace PicView.Avalonia.Navigation
 | 
											
												
													
														|  |  {
 |  |  {
 | 
											
												
													
														|  | -    #region Properties
 |  | 
 | 
											
												
													
														|  | 
 |  | +    public sealed class ImageIterator : IDisposable
 | 
											
												
													
														|  | 
 |  | +    {
 | 
											
												
													
														|  | 
 |  | +        #region Properties
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -    private bool _disposed;
 |  | 
 | 
											
												
													
														|  | 
 |  | +        private bool _disposed;
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -    public List<string> ImagePaths { get; private set; }
 |  | 
 | 
											
												
													
														|  | 
 |  | +        public List<string> ImagePaths { get; private set; }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -    public bool IsRenamingInProgress { get; set; }
 |  | 
 | 
											
												
													
														|  | 
 |  | +        public bool IsRenamingInProgress { get; set; }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -    public int CurrentIndex{ get; private set; }
 |  | 
 | 
											
												
													
														|  | -    
 |  | 
 | 
											
												
													
														|  | -    public FileInfo InitialFileInfo{ get; private set; } = null!;
 |  | 
 | 
											
												
													
														|  | -    public bool IsReversed { get; private set; }
 |  | 
 | 
											
												
													
														|  | -    private PreLoader PreLoader { get; } = new();
 |  | 
 | 
											
												
													
														|  | 
 |  | +        public int CurrentIndex { get; private set; }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -    private static FileSystemWatcher? _watcher;
 |  | 
 | 
											
												
													
														|  | -    private static bool _isRunning;
 |  | 
 | 
											
												
													
														|  | -    private readonly MainViewModel? _vm;
 |  | 
 | 
											
												
													
														|  | -    private readonly Lock _lock = new();
 |  | 
 | 
											
												
													
														|  | 
 |  | +        public FileInfo InitialFileInfo { get; private set; } = null!;
 | 
											
												
													
														|  | 
 |  | +        public bool IsReversed { get; private set; }
 | 
											
												
													
														|  | 
 |  | +        private PreLoader PreLoader { get; } = new();
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -    #endregion
 |  | 
 | 
											
												
													
														|  | 
 |  | +        private static FileSystemWatcher? _watcher;
 | 
											
												
													
														|  | 
 |  | +        private static bool _isRunning;
 | 
											
												
													
														|  | 
 |  | +        private readonly MainViewModel? _vm;
 | 
											
												
													
														|  | 
 |  | +        private readonly Lock _lock = new();
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -    #region Constructors
 |  | 
 | 
											
												
													
														|  | 
 |  | +        #endregion
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -    public ImageIterator(FileInfo fileInfo, MainViewModel vm)
 |  | 
 | 
											
												
													
														|  | -    {
 |  | 
 | 
											
												
													
														|  | -        ArgumentNullException.ThrowIfNull(fileInfo);
 |  | 
 | 
											
												
													
														|  | -        _vm = vm;
 |  | 
 | 
											
												
													
														|  | -        ImagePaths = vm.PlatformService.GetFiles(fileInfo);
 |  | 
 | 
											
												
													
														|  | -        CurrentIndex = Directory.Exists(fileInfo.FullName) ? 0 : ImagePaths.IndexOf(fileInfo.FullName);
 |  | 
 | 
											
												
													
														|  | -        InitiateFileSystemWatcher(fileInfo);
 |  | 
 | 
											
												
													
														|  | -    }
 |  | 
 | 
											
												
													
														|  | -    
 |  | 
 | 
											
												
													
														|  | -    public ImageIterator(FileInfo fileInfo, List<string> imagePaths, int currentIndex, MainViewModel vm)
 |  | 
 | 
											
												
													
														|  | -    {
 |  | 
 | 
											
												
													
														|  | -        ArgumentNullException.ThrowIfNull(fileInfo);
 |  | 
 | 
											
												
													
														|  | -        _vm = vm;
 |  | 
 | 
											
												
													
														|  | -        ImagePaths = imagePaths;
 |  | 
 | 
											
												
													
														|  | -        CurrentIndex = currentIndex;
 |  | 
 | 
											
												
													
														|  | -        InitiateFileSystemWatcher(fileInfo);
 |  | 
 | 
											
												
													
														|  | -    }
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -    #endregion
 |  | 
 | 
											
												
													
														|  | 
 |  | +        #region Constructors
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -    #region File Watcher
 |  | 
 | 
											
												
													
														|  | -    
 |  | 
 | 
											
												
													
														|  | -    private void InitiateFileSystemWatcher(FileInfo fileInfo)
 |  | 
 | 
											
												
													
														|  | -    {
 |  | 
 | 
											
												
													
														|  | -        InitialFileInfo = fileInfo;
 |  | 
 | 
											
												
													
														|  | -        if (_watcher is not null)
 |  | 
 | 
											
												
													
														|  | 
 |  | +        public ImageIterator(FileInfo fileInfo, MainViewModel vm)
 | 
											
												
													
														|  |          {
 |  |          {
 | 
											
												
													
														|  | -            _watcher.Dispose();
 |  | 
 | 
											
												
													
														|  | -            _watcher = null;
 |  | 
 | 
											
												
													
														|  | 
 |  | +            ArgumentNullException.ThrowIfNull(fileInfo);
 | 
											
												
													
														|  | 
 |  | +            _vm = vm;
 | 
											
												
													
														|  | 
 |  | +            ImagePaths = vm.PlatformService.GetFiles(fileInfo);
 | 
											
												
													
														|  | 
 |  | +            CurrentIndex = Directory.Exists(fileInfo.FullName) ? 0 : ImagePaths.IndexOf(fileInfo.FullName);
 | 
											
												
													
														|  | 
 |  | +            InitiateFileSystemWatcher(fileInfo);
 | 
											
												
													
														|  |          }
 |  |          }
 | 
											
												
													
														|  | -        _watcher = new FileSystemWatcher();
 |  | 
 | 
											
												
													
														|  | -#if DEBUG
 |  | 
 | 
											
												
													
														|  | -        Debug.Assert(fileInfo.DirectoryName != null, "fileInfo.DirectoryName != null");
 |  | 
 | 
											
												
													
														|  | -#endif
 |  | 
 | 
											
												
													
														|  | -        _watcher.Path = fileInfo.DirectoryName;
 |  | 
 | 
											
												
													
														|  | -        _watcher.EnableRaisingEvents = true;
 |  | 
 | 
											
												
													
														|  | -        _watcher.Filter = "*.*";
 |  | 
 | 
											
												
													
														|  | -        _watcher.IncludeSubdirectories = SettingsHelper.Settings.Sorting.IncludeSubDirectories;
 |  | 
 | 
											
												
													
														|  | -        _watcher.Created += async (_, e) => await OnFileAdded(e);
 |  | 
 | 
											
												
													
														|  | -        _watcher.Deleted += async (_, e) => await OnFileDeleted(e);
 |  | 
 | 
											
												
													
														|  | -        _watcher.Renamed += async (_, e) => await OnFileRenamed(e);
 |  | 
 | 
											
												
													
														|  | -    }
 |  | 
 | 
											
												
													
														|  | -    
 |  | 
 | 
											
												
													
														|  | -    private async Task OnFileAdded(FileSystemEventArgs e)
 |  | 
 | 
											
												
													
														|  | -    {
 |  | 
 | 
											
												
													
														|  | -        if (IsRenamingInProgress)
 |  | 
 | 
											
												
													
														|  | -        {
 |  | 
 | 
											
												
													
														|  | -            return;
 |  | 
 | 
											
												
													
														|  | -        }
 |  | 
 | 
											
												
													
														|  | -        if (ImagePaths.Contains(e.FullPath))
 |  | 
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        public ImageIterator(FileInfo fileInfo, List<string> imagePaths, int currentIndex, MainViewModel vm)
 | 
											
												
													
														|  |          {
 |  |          {
 | 
											
												
													
														|  | -            return;
 |  | 
 | 
											
												
													
														|  | 
 |  | +            ArgumentNullException.ThrowIfNull(fileInfo);
 | 
											
												
													
														|  | 
 |  | +            _vm = vm;
 | 
											
												
													
														|  | 
 |  | +            ImagePaths = imagePaths;
 | 
											
												
													
														|  | 
 |  | +            CurrentIndex = currentIndex;
 | 
											
												
													
														|  | 
 |  | +            InitiateFileSystemWatcher(fileInfo);
 | 
											
												
													
														|  |          }
 |  |          }
 | 
											
												
													
														|  | -        if (e.FullPath.IsSupported() == false)
 |  | 
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        #endregion
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        #region File Watcher
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        private void InitiateFileSystemWatcher(FileInfo fileInfo)
 | 
											
												
													
														|  |          {
 |  |          {
 | 
											
												
													
														|  | -            return;
 |  | 
 | 
											
												
													
														|  | 
 |  | +            InitialFileInfo = fileInfo;
 | 
											
												
													
														|  | 
 |  | +            if (_watcher is not null)
 | 
											
												
													
														|  | 
 |  | +            {
 | 
											
												
													
														|  | 
 |  | +                _watcher.Dispose();
 | 
											
												
													
														|  | 
 |  | +                _watcher = null;
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            _watcher = new FileSystemWatcher();
 | 
											
												
													
														|  | 
 |  | +#if DEBUG
 | 
											
												
													
														|  | 
 |  | +            Debug.Assert(fileInfo.DirectoryName != null, "fileInfo.DirectoryName != null");
 | 
											
												
													
														|  | 
 |  | +#endif
 | 
											
												
													
														|  | 
 |  | +            _watcher.Path = fileInfo.DirectoryName;
 | 
											
												
													
														|  | 
 |  | +            _watcher.EnableRaisingEvents = true;
 | 
											
												
													
														|  | 
 |  | +            _watcher.Filter = "*.*";
 | 
											
												
													
														|  | 
 |  | +            _watcher.IncludeSubdirectories = SettingsHelper.Settings.Sorting.IncludeSubDirectories;
 | 
											
												
													
														|  | 
 |  | +            _watcher.Created += async (_, e) => await OnFileAdded(e);
 | 
											
												
													
														|  | 
 |  | +            _watcher.Deleted += async (_, e) => await OnFileDeleted(e);
 | 
											
												
													
														|  | 
 |  | +            _watcher.Renamed += async (_, e) => await OnFileRenamed(e);
 | 
											
												
													
														|  |          }
 |  |          }
 | 
											
												
													
														|  | -        var fileInfo = new FileInfo(e.FullPath);
 |  | 
 | 
											
												
													
														|  | -        if (fileInfo.Exists == false) { return; }
 |  | 
 | 
											
												
													
														|  | -        
 |  | 
 | 
											
												
													
														|  | -        var retries = 0;
 |  | 
 | 
											
												
													
														|  | -        while (_isRunning && retries < 10)
 |  | 
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        private async Task OnFileAdded(FileSystemEventArgs e)
 | 
											
												
													
														|  |          {
 |  |          {
 | 
											
												
													
														|  | -            await Task.Delay(200);
 |  | 
 | 
											
												
													
														|  | -            retries++;
 |  | 
 | 
											
												
													
														|  | -        }
 |  | 
 | 
											
												
													
														|  | -        _isRunning = true;
 |  | 
 | 
											
												
													
														|  | 
 |  | +            if (IsRenamingInProgress)
 | 
											
												
													
														|  | 
 |  | +            {
 | 
											
												
													
														|  | 
 |  | +                return;
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -        var newList = await Task.FromResult(_vm.PlatformService.GetFiles(fileInfo));
 |  | 
 | 
											
												
													
														|  | -        if (newList.Count == 0) { return; }
 |  | 
 | 
											
												
													
														|  | -        if (newList.Count == ImagePaths.Count) { return; }
 |  | 
 | 
											
												
													
														|  | 
 |  | +            if (ImagePaths.Contains(e.FullPath))
 | 
											
												
													
														|  | 
 |  | +            {
 | 
											
												
													
														|  | 
 |  | +                return;
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -        if (fileInfo.Exists == false) { return; }
 |  | 
 | 
											
												
													
														|  | -        
 |  | 
 | 
											
												
													
														|  | -        ImagePaths = newList;
 |  | 
 | 
											
												
													
														|  | 
 |  | +            if (e.FullPath.IsSupported() == false)
 | 
											
												
													
														|  | 
 |  | +            {
 | 
											
												
													
														|  | 
 |  | +                return;
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -        _isRunning = false;
 |  | 
 | 
											
												
													
														|  | 
 |  | +            var fileInfo = new FileInfo(e.FullPath);
 | 
											
												
													
														|  | 
 |  | +            if (fileInfo.Exists == false)
 | 
											
												
													
														|  | 
 |  | +            {
 | 
											
												
													
														|  | 
 |  | +                return;
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -        var index = ImagePaths.IndexOf(e.FullPath);
 |  | 
 | 
											
												
													
														|  | -        if (index < 0) { return; }
 |  | 
 | 
											
												
													
														|  | 
 |  | +            var retries = 0;
 | 
											
												
													
														|  | 
 |  | +            while (_isRunning && retries < 10)
 | 
											
												
													
														|  | 
 |  | +            {
 | 
											
												
													
														|  | 
 |  | +                await Task.Delay(200);
 | 
											
												
													
														|  | 
 |  | +                retries++;
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -        var nextIndex = index + 1;
 |  | 
 | 
											
												
													
														|  | -        if (index >= ImagePaths.Count)
 |  | 
 | 
											
												
													
														|  | -        {
 |  | 
 | 
											
												
													
														|  | -            nextIndex = 0;
 |  | 
 | 
											
												
													
														|  | -        }
 |  | 
 | 
											
												
													
														|  | -        var prevIndex = index - 1;
 |  | 
 | 
											
												
													
														|  | -        if (prevIndex < 0)
 |  | 
 | 
											
												
													
														|  | -        {
 |  | 
 | 
											
												
													
														|  | -            prevIndex = ImagePaths.Count - 1;
 |  | 
 | 
											
												
													
														|  | -        }
 |  | 
 | 
											
												
													
														|  | 
 |  | +            _isRunning = true;
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -        var cleared = false;
 |  | 
 | 
											
												
													
														|  | -        if (PreLoader.Contains(index, ImagePaths) || PreLoader.Contains(nextIndex, ImagePaths) || PreLoader.Contains(prevIndex, ImagePaths))
 |  | 
 | 
											
												
													
														|  | -        {
 |  | 
 | 
											
												
													
														|  | -            PreLoader.Clear();
 |  | 
 | 
											
												
													
														|  | -            cleared = true;
 |  | 
 | 
											
												
													
														|  | -        }
 |  | 
 | 
											
												
													
														|  | 
 |  | +            var newList = await Task.FromResult(_vm.PlatformService.GetFiles(fileInfo));
 | 
											
												
													
														|  | 
 |  | +            if (newList.Count == 0)
 | 
											
												
													
														|  | 
 |  | +            {
 | 
											
												
													
														|  | 
 |  | +                return;
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -        SetTitleHelper.SetTitle(_vm);
 |  | 
 | 
											
												
													
														|  | -        
 |  | 
 | 
											
												
													
														|  | -        var isGalleryItemAdded = await GalleryFunctions.AddGalleryItem(index, fileInfo, _vm);
 |  | 
 | 
											
												
													
														|  | -        if (isGalleryItemAdded)
 |  | 
 | 
											
												
													
														|  | -        {
 |  | 
 | 
											
												
													
														|  | -            if (SettingsHelper.Settings.Gallery.IsBottomGalleryShown && ImagePaths.Count > 1)
 |  | 
 | 
											
												
													
														|  | 
 |  | +            if (newList.Count == ImagePaths.Count)
 | 
											
												
													
														|  | 
 |  | +            {
 | 
											
												
													
														|  | 
 |  | +                return;
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            if (fileInfo.Exists == false)
 | 
											
												
													
														|  | 
 |  | +            {
 | 
											
												
													
														|  | 
 |  | +                return;
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            ImagePaths = newList;
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            _isRunning = false;
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            var index = ImagePaths.IndexOf(e.FullPath);
 | 
											
												
													
														|  | 
 |  | +            if (index < 0)
 | 
											
												
													
														|  | 
 |  | +            {
 | 
											
												
													
														|  | 
 |  | +                return;
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            var nextIndex = index + 1;
 | 
											
												
													
														|  | 
 |  | +            if (index >= ImagePaths.Count)
 | 
											
												
													
														|  |              {
 |  |              {
 | 
											
												
													
														|  | -                if (_vm.GalleryMode is GalleryMode.BottomToClosed or GalleryMode.FullToClosed)
 |  | 
 | 
											
												
													
														|  | 
 |  | +                nextIndex = 0;
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            var prevIndex = index - 1;
 | 
											
												
													
														|  | 
 |  | +            if (prevIndex < 0)
 | 
											
												
													
														|  | 
 |  | +            {
 | 
											
												
													
														|  | 
 |  | +                prevIndex = ImagePaths.Count - 1;
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            var cleared = false;
 | 
											
												
													
														|  | 
 |  | +            if (PreLoader.Contains(index, ImagePaths) || PreLoader.Contains(nextIndex, ImagePaths) ||
 | 
											
												
													
														|  | 
 |  | +                PreLoader.Contains(prevIndex, ImagePaths))
 | 
											
												
													
														|  | 
 |  | +            {
 | 
											
												
													
														|  | 
 |  | +                PreLoader.Clear();
 | 
											
												
													
														|  | 
 |  | +                cleared = true;
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            SetTitleHelper.SetTitle(_vm);
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            var isGalleryItemAdded = await GalleryFunctions.AddGalleryItem(index, fileInfo, _vm);
 | 
											
												
													
														|  | 
 |  | +            if (isGalleryItemAdded)
 | 
											
												
													
														|  | 
 |  | +            {
 | 
											
												
													
														|  | 
 |  | +                if (SettingsHelper.Settings.Gallery.IsBottomGalleryShown && ImagePaths.Count > 1)
 | 
											
												
													
														|  |                  {
 |  |                  {
 | 
											
												
													
														|  | -                    _vm.GalleryMode = GalleryMode.ClosedToBottom;
 |  | 
 | 
											
												
													
														|  | 
 |  | +                    if (_vm.GalleryMode is GalleryMode.BottomToClosed or GalleryMode.FullToClosed)
 | 
											
												
													
														|  | 
 |  | +                    {
 | 
											
												
													
														|  | 
 |  | +                        _vm.GalleryMode = GalleryMode.ClosedToBottom;
 | 
											
												
													
														|  | 
 |  | +                    }
 | 
											
												
													
														|  |                  }
 |  |                  }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +                var indexOf = ImagePaths.IndexOf(_vm.FileInfo.FullName);
 | 
											
												
													
														|  | 
 |  | +                _vm.SelectedGalleryItemIndex = indexOf; // Fixes deselection bug
 | 
											
												
													
														|  | 
 |  | +                CurrentIndex = indexOf;
 | 
											
												
													
														|  | 
 |  | +                GalleryNavigation.CenterScrollToSelectedItem(_vm);
 | 
											
												
													
														|  |              }
 |  |              }
 | 
											
												
													
														|  | -            var indexOf = ImagePaths.IndexOf(_vm.FileInfo.FullName);
 |  | 
 | 
											
												
													
														|  | -            _vm.SelectedGalleryItemIndex = indexOf; // Fixes deselection bug
 |  | 
 | 
											
												
													
														|  | -            CurrentIndex = indexOf;
 |  | 
 | 
											
												
													
														|  | -            GalleryNavigation.CenterScrollToSelectedItem(_vm);
 |  | 
 | 
											
												
													
														|  | -        }
 |  | 
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -        if (cleared)
 |  | 
 | 
											
												
													
														|  | -        {
 |  | 
 | 
											
												
													
														|  | -            await Preload();
 |  | 
 | 
											
												
													
														|  | -        }
 |  | 
 | 
											
												
													
														|  | -    }
 |  | 
 | 
											
												
													
														|  | -    
 |  | 
 | 
											
												
													
														|  | -    private async Task OnFileDeleted(FileSystemEventArgs e)
 |  | 
 | 
											
												
													
														|  | -    {
 |  | 
 | 
											
												
													
														|  | -        if (IsRenamingInProgress)
 |  | 
 | 
											
												
													
														|  | -        {
 |  | 
 | 
											
												
													
														|  | -            return;
 |  | 
 | 
											
												
													
														|  | -        }
 |  | 
 | 
											
												
													
														|  | -        if (e.FullPath.IsSupported() == false)
 |  | 
 | 
											
												
													
														|  | -        {
 |  | 
 | 
											
												
													
														|  | -            return;
 |  | 
 | 
											
												
													
														|  | 
 |  | +            if (cleared)
 | 
											
												
													
														|  | 
 |  | +            {
 | 
											
												
													
														|  | 
 |  | +                await Preload();
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  |          }
 |  |          }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -        if (ImagePaths.Contains(e.FullPath) == false)
 |  | 
 | 
											
												
													
														|  | 
 |  | +        private async Task OnFileDeleted(FileSystemEventArgs e)
 | 
											
												
													
														|  |          {
 |  |          {
 | 
											
												
													
														|  | -            return;
 |  | 
 | 
											
												
													
														|  | -        }
 |  | 
 | 
											
												
													
														|  | 
 |  | +            if (IsRenamingInProgress)
 | 
											
												
													
														|  | 
 |  | +            {
 | 
											
												
													
														|  | 
 |  | +                return;
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -        if (_isRunning)
 |  | 
 | 
											
												
													
														|  | -        {
 |  | 
 | 
											
												
													
														|  | -            return;
 |  | 
 | 
											
												
													
														|  | -        }
 |  | 
 | 
											
												
													
														|  | -        _isRunning = true;
 |  | 
 | 
											
												
													
														|  | -        var index = ImagePaths.IndexOf(e.FullPath);
 |  | 
 | 
											
												
													
														|  | -        if (index < 0) { return; }
 |  | 
 | 
											
												
													
														|  | 
 |  | +            if (e.FullPath.IsSupported() == false)
 | 
											
												
													
														|  | 
 |  | +            {
 | 
											
												
													
														|  | 
 |  | +                return;
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -        var nextIndex = index + 1;
 |  | 
 | 
											
												
													
														|  | -        if (index >= ImagePaths.Count)
 |  | 
 | 
											
												
													
														|  | -        {
 |  | 
 | 
											
												
													
														|  | -            nextIndex = 0;
 |  | 
 | 
											
												
													
														|  | -        }
 |  | 
 | 
											
												
													
														|  | -        var prevIndex = index - 1;
 |  | 
 | 
											
												
													
														|  | -        if (prevIndex < 0)
 |  | 
 | 
											
												
													
														|  | -        {
 |  | 
 | 
											
												
													
														|  | -            prevIndex = ImagePaths.Count - 1;
 |  | 
 | 
											
												
													
														|  | -        }
 |  | 
 | 
											
												
													
														|  | 
 |  | +            if (ImagePaths.Contains(e.FullPath) == false)
 | 
											
												
													
														|  | 
 |  | +            {
 | 
											
												
													
														|  | 
 |  | +                return;
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -        var cleared = false;
 |  | 
 | 
											
												
													
														|  | -        if (PreLoader.Contains(index, ImagePaths) || PreLoader.Contains(nextIndex, ImagePaths) || PreLoader.Contains(prevIndex, ImagePaths))
 |  | 
 | 
											
												
													
														|  | -        {
 |  | 
 | 
											
												
													
														|  | -            PreLoader.Clear();
 |  | 
 | 
											
												
													
														|  | -            cleared = true;
 |  | 
 | 
											
												
													
														|  | -        }
 |  | 
 | 
											
												
													
														|  | -        else
 |  | 
 | 
											
												
													
														|  | -        {
 |  | 
 | 
											
												
													
														|  | -            PreLoader.Remove(index, ImagePaths);
 |  | 
 | 
											
												
													
														|  | -        }
 |  | 
 | 
											
												
													
														|  | -        
 |  | 
 | 
											
												
													
														|  | -        var sameFile = CurrentIndex == index;
 |  | 
 | 
											
												
													
														|  | -        if (!ImagePaths.Remove(e.FullPath))
 |  | 
 | 
											
												
													
														|  | -        {
 |  | 
 | 
											
												
													
														|  | -            return;
 |  | 
 | 
											
												
													
														|  | -        }
 |  | 
 | 
											
												
													
														|  | -        
 |  | 
 | 
											
												
													
														|  | -        if (sameFile)
 |  | 
 | 
											
												
													
														|  | -        {
 |  | 
 | 
											
												
													
														|  | -            if (ImagePaths.Count <= 0)
 |  | 
 | 
											
												
													
														|  | 
 |  | +            if (_isRunning)
 | 
											
												
													
														|  |              {
 |  |              {
 | 
											
												
													
														|  | -                ErrorHandling.ShowStartUpMenu(_vm);
 |  | 
 | 
											
												
													
														|  |                  return;
 |  |                  return;
 | 
											
												
													
														|  |              }
 |  |              }
 | 
											
												
													
														|  | -            await NavigationHelper.Iterate(next:false, _vm);
 |  | 
 | 
											
												
													
														|  | -        }
 |  | 
 | 
											
												
													
														|  | -        else
 |  | 
 | 
											
												
													
														|  | -        {
 |  | 
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            _isRunning = true;
 | 
											
												
													
														|  | 
 |  | +            var index = ImagePaths.IndexOf(e.FullPath);
 | 
											
												
													
														|  | 
 |  | +            if (index < 0)
 | 
											
												
													
														|  | 
 |  | +            {
 | 
											
												
													
														|  | 
 |  | +                return;
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            var nextIndex = index + 1;
 | 
											
												
													
														|  | 
 |  | +            if (index >= ImagePaths.Count)
 | 
											
												
													
														|  | 
 |  | +            {
 | 
											
												
													
														|  | 
 |  | +                nextIndex = 0;
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            var prevIndex = index - 1;
 | 
											
												
													
														|  | 
 |  | +            if (prevIndex < 0)
 | 
											
												
													
														|  | 
 |  | +            {
 | 
											
												
													
														|  | 
 |  | +                prevIndex = ImagePaths.Count - 1;
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            var cleared = false;
 | 
											
												
													
														|  | 
 |  | +            if (PreLoader.Contains(index, ImagePaths) || PreLoader.Contains(nextIndex, ImagePaths) ||
 | 
											
												
													
														|  | 
 |  | +                PreLoader.Contains(prevIndex, ImagePaths))
 | 
											
												
													
														|  | 
 |  | +            {
 | 
											
												
													
														|  | 
 |  | +                PreLoader.Clear();
 | 
											
												
													
														|  | 
 |  | +                cleared = true;
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +            else
 | 
											
												
													
														|  | 
 |  | +            {
 | 
											
												
													
														|  | 
 |  | +                PreLoader.Remove(index, ImagePaths);
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            var sameFile = CurrentIndex == index;
 | 
											
												
													
														|  | 
 |  | +            if (!ImagePaths.Remove(e.FullPath))
 | 
											
												
													
														|  | 
 |  | +            {
 | 
											
												
													
														|  | 
 |  | +                return;
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            if (sameFile)
 | 
											
												
													
														|  | 
 |  | +            {
 | 
											
												
													
														|  | 
 |  | +                if (ImagePaths.Count <= 0)
 | 
											
												
													
														|  | 
 |  | +                {
 | 
											
												
													
														|  | 
 |  | +                    ErrorHandling.ShowStartUpMenu(_vm);
 | 
											
												
													
														|  | 
 |  | +                    return;
 | 
											
												
													
														|  | 
 |  | +                }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +                await NavigationHelper.Iterate(false, _vm);
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +            else
 | 
											
												
													
														|  | 
 |  | +            {
 | 
											
												
													
														|  | 
 |  | +                SetTitleHelper.SetTitle(_vm);
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            var removed = GalleryFunctions.RemoveGalleryItem(index, _vm);
 | 
											
												
													
														|  | 
 |  | +            if (removed)
 | 
											
												
													
														|  | 
 |  | +            {
 | 
											
												
													
														|  | 
 |  | +                if (SettingsHelper.Settings.Gallery.IsBottomGalleryShown)
 | 
											
												
													
														|  | 
 |  | +                {
 | 
											
												
													
														|  | 
 |  | +                    if (ImagePaths.Count == 1)
 | 
											
												
													
														|  | 
 |  | +                    {
 | 
											
												
													
														|  | 
 |  | +                        _vm.GalleryMode = GalleryMode.BottomToClosed;
 | 
											
												
													
														|  | 
 |  | +                    }
 | 
											
												
													
														|  | 
 |  | +                }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +                var indexOf = ImagePaths.IndexOf(_vm.FileInfo.FullName);
 | 
											
												
													
														|  | 
 |  | +                _vm.SelectedGalleryItemIndex = indexOf; // Fixes deselection bug
 | 
											
												
													
														|  | 
 |  | +                CurrentIndex = indexOf;
 | 
											
												
													
														|  | 
 |  | +                GalleryNavigation.CenterScrollToSelectedItem(_vm);
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            FileHistoryNavigation.Remove(e.FullPath);
 | 
											
												
													
														|  | 
 |  | +            _isRunning = false;
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  |              SetTitleHelper.SetTitle(_vm);
 |  |              SetTitleHelper.SetTitle(_vm);
 | 
											
												
													
														|  | 
 |  | +            if (cleared)
 | 
											
												
													
														|  | 
 |  | +            {
 | 
											
												
													
														|  | 
 |  | +                await Preload();
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  |          }
 |  |          }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -        var removed = GalleryFunctions.RemoveGalleryItem(index, _vm);
 |  | 
 | 
											
												
													
														|  | -        if (removed)
 |  | 
 | 
											
												
													
														|  | 
 |  | +        private async Task OnFileRenamed(RenamedEventArgs e)
 | 
											
												
													
														|  |          {
 |  |          {
 | 
											
												
													
														|  | -            if (SettingsHelper.Settings.Gallery.IsBottomGalleryShown)
 |  | 
 | 
											
												
													
														|  | 
 |  | +            if (IsRenamingInProgress)
 | 
											
												
													
														|  |              {
 |  |              {
 | 
											
												
													
														|  | -                if (ImagePaths.Count == 1)
 |  | 
 | 
											
												
													
														|  | 
 |  | +                return;
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            if (e.FullPath.IsSupported() == false)
 | 
											
												
													
														|  | 
 |  | +            {
 | 
											
												
													
														|  | 
 |  | +                if (ImagePaths.Contains(e.OldFullPath))
 | 
											
												
													
														|  |                  {
 |  |                  {
 | 
											
												
													
														|  | -                    _vm.GalleryMode = GalleryMode.BottomToClosed;
 |  | 
 | 
											
												
													
														|  | 
 |  | +                    ImagePaths.Remove(e.OldFullPath);
 | 
											
												
													
														|  |                  }
 |  |                  }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +                return;
 | 
											
												
													
														|  |              }
 |  |              }
 | 
											
												
													
														|  | -            var indexOf = ImagePaths.IndexOf(_vm.FileInfo.FullName);
 |  | 
 | 
											
												
													
														|  | -            _vm.SelectedGalleryItemIndex = indexOf; // Fixes deselection bug
 |  | 
 | 
											
												
													
														|  | -            CurrentIndex = indexOf;
 |  | 
 | 
											
												
													
														|  | -            GalleryNavigation.CenterScrollToSelectedItem(_vm);
 |  | 
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            if (_isRunning)
 | 
											
												
													
														|  | 
 |  | +            {
 | 
											
												
													
														|  | 
 |  | +                return;
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            _isRunning = true;
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            var oldIndex = ImagePaths.IndexOf(e.OldFullPath);
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            var fileInfo = new FileInfo(e.FullPath);
 | 
											
												
													
														|  | 
 |  | +            if (fileInfo.Exists == false)
 | 
											
												
													
														|  | 
 |  | +            {
 | 
											
												
													
														|  | 
 |  | +                return;
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            var newList = FileListHelper.RetrieveFiles(fileInfo).ToList();
 | 
											
												
													
														|  | 
 |  | +            if (newList.Count == 0)
 | 
											
												
													
														|  | 
 |  | +            {
 | 
											
												
													
														|  | 
 |  | +                return;
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            if (fileInfo.Exists == false)
 | 
											
												
													
														|  | 
 |  | +            {
 | 
											
												
													
														|  | 
 |  | +                return;
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            ImagePaths = newList;
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            var index = ImagePaths.IndexOf(e.FullPath);
 | 
											
												
													
														|  | 
 |  | +            if (index < 0)
 | 
											
												
													
														|  | 
 |  | +            {
 | 
											
												
													
														|  | 
 |  | +                return;
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            if (fileInfo.Exists == false)
 | 
											
												
													
														|  | 
 |  | +            {
 | 
											
												
													
														|  | 
 |  | +                return;
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            SetTitleHelper.SetTitle(_vm);
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            await PreLoader.RefreshFileInfo(oldIndex, ImagePaths);
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            _isRunning = false;
 | 
											
												
													
														|  | 
 |  | +            FileHistoryNavigation.Rename(e.OldFullPath, e.FullPath);
 | 
											
												
													
														|  | 
 |  | +            GalleryFunctions.RemoveGalleryItem(oldIndex, _vm);
 | 
											
												
													
														|  | 
 |  | +            await GalleryFunctions.AddGalleryItem(index, fileInfo, _vm);
 | 
											
												
													
														|  | 
 |  | +            await GalleryFunctions.SortGalleryItems(ImagePaths, _vm);
 | 
											
												
													
														|  |          }
 |  |          }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | 
 |  | +        #endregion
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -        FileHistoryNavigation.Remove(e.FullPath);
 |  | 
 | 
											
												
													
														|  | -        _isRunning = false;
 |  | 
 | 
											
												
													
														|  | 
 |  | +        #region Preloader
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -        SetTitleHelper.SetTitle(_vm);
 |  | 
 | 
											
												
													
														|  | -        if (cleared)
 |  | 
 | 
											
												
													
														|  | 
 |  | +        public void Clear()
 | 
											
												
													
														|  |          {
 |  |          {
 | 
											
												
													
														|  | -            await Preload();
 |  | 
 | 
											
												
													
														|  | 
 |  | +            PreLoader.Clear();
 | 
											
												
													
														|  |          }
 |  |          }
 | 
											
												
													
														|  | -    }
 |  | 
 | 
											
												
													
														|  | -    
 |  | 
 | 
											
												
													
														|  | -    private async Task OnFileRenamed(RenamedEventArgs e)
 |  | 
 | 
											
												
													
														|  | -    {
 |  | 
 | 
											
												
													
														|  | -        if (IsRenamingInProgress)
 |  | 
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        public async Task Preload()
 | 
											
												
													
														|  |          {
 |  |          {
 | 
											
												
													
														|  | -            return;
 |  | 
 | 
											
												
													
														|  | 
 |  | +            await PreLoader.PreLoadAsync(CurrentIndex, ImagePaths.Count, IsReversed, ImagePaths).ConfigureAwait(false);
 | 
											
												
													
														|  |          }
 |  |          }
 | 
											
												
													
														|  | -        if (e.FullPath.IsSupported() == false)
 |  | 
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        public async Task AddAsync(int index, ImageModel imageModel)
 | 
											
												
													
														|  |          {
 |  |          {
 | 
											
												
													
														|  | -            if (ImagePaths.Contains(e.OldFullPath))
 |  | 
 | 
											
												
													
														|  | -            {
 |  | 
 | 
											
												
													
														|  | -                ImagePaths.Remove(e.OldFullPath);
 |  | 
 | 
											
												
													
														|  | -            }
 |  | 
 | 
											
												
													
														|  | -            return;
 |  | 
 | 
											
												
													
														|  | 
 |  | +            await PreLoader.AddAsync(index, ImagePaths, imageModel).ConfigureAwait(false);
 | 
											
												
													
														|  |          }
 |  |          }
 | 
											
												
													
														|  | -        if (_isRunning) { return; }
 |  | 
 | 
											
												
													
														|  | -        _isRunning = true;
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -        var oldIndex = ImagePaths.IndexOf(e.OldFullPath);
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -        var fileInfo = new FileInfo(e.FullPath);
 |  | 
 | 
											
												
													
														|  | -        if (fileInfo.Exists == false) { return; }
 |  | 
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -        var newList = FileListHelper.RetrieveFiles(fileInfo).ToList();
 |  | 
 | 
											
												
													
														|  | -        if (newList.Count == 0) { return; }
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -        if (fileInfo.Exists == false) { return; }
 |  | 
 | 
											
												
													
														|  | -        
 |  | 
 | 
											
												
													
														|  | -        ImagePaths = newList;
 |  | 
 | 
											
												
													
														|  | 
 |  | +        public PreLoader.PreLoadValue? GetPreLoadValue(int index)
 | 
											
												
													
														|  | 
 |  | +        {
 | 
											
												
													
														|  | 
 |  | +            return PreLoader.Get(index, ImagePaths);
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -        var index = ImagePaths.IndexOf(e.FullPath);
 |  | 
 | 
											
												
													
														|  | -        if (index < 0) { return; }
 |  | 
 | 
											
												
													
														|  | 
 |  | +        public PreLoader.PreLoadValue? GetCurrentPreLoadValue()
 | 
											
												
													
														|  | 
 |  | +        {
 | 
											
												
													
														|  | 
 |  | +            return PreLoader.Get(CurrentIndex, ImagePaths);
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -        if (fileInfo.Exists == false)
 |  | 
 | 
											
												
													
														|  | 
 |  | +        public async Task<PreLoader.PreLoadValue?> GetCurrentPreLoadValueAsync()
 | 
											
												
													
														|  |          {
 |  |          {
 | 
											
												
													
														|  | -            return;
 |  | 
 | 
											
												
													
														|  | 
 |  | +            return await PreLoader.GetAsync(CurrentIndex, ImagePaths);
 | 
											
												
													
														|  |          }
 |  |          }
 | 
											
												
													
														|  | -        
 |  | 
 | 
											
												
													
														|  | -        SetTitleHelper.SetTitle(_vm);
 |  | 
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -        await PreLoader.RefreshFileInfo(oldIndex, ImagePaths);
 |  | 
 | 
											
												
													
														|  | 
 |  | +        public PreLoader.PreLoadValue? GetNextPreLoadValue()
 | 
											
												
													
														|  | 
 |  | +        {
 | 
											
												
													
														|  | 
 |  | +            var nextIndex = GetIteration(CurrentIndex, NavigateTo.Next);
 | 
											
												
													
														|  | 
 |  | +            return PreLoader.Get(nextIndex, ImagePaths);
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -        _isRunning = false;
 |  | 
 | 
											
												
													
														|  | -        FileHistoryNavigation.Rename(e.OldFullPath, e.FullPath);
 |  | 
 | 
											
												
													
														|  | -        GalleryFunctions.RemoveGalleryItem(oldIndex, _vm);
 |  | 
 | 
											
												
													
														|  | -        await GalleryFunctions.AddGalleryItem(index,fileInfo, _vm);
 |  | 
 | 
											
												
													
														|  | -        await GalleryFunctions.SortGalleryItems(ImagePaths, _vm);
 |  | 
 | 
											
												
													
														|  | -    }
 |  | 
 | 
											
												
													
														|  | 
 |  | +        public async Task<PreLoader.PreLoadValue?>? GetNextPreLoadValueAsync()
 | 
											
												
													
														|  | 
 |  | +        {
 | 
											
												
													
														|  | 
 |  | +            var nextIndex = GetIteration(CurrentIndex, NavigateTo.Next);
 | 
											
												
													
														|  | 
 |  | +            return await PreLoader.GetAsync(nextIndex, ImagePaths);
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -    #endregion
 |  | 
 | 
											
												
													
														|  | 
 |  | +        public void RemoveItemFromPreLoader(int index)
 | 
											
												
													
														|  | 
 |  | +        {
 | 
											
												
													
														|  | 
 |  | +            PreLoader.Remove(index, ImagePaths);
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -    #region Preloader
 |  | 
 | 
											
												
													
														|  | 
 |  | +        public void RemoveCurrentItemFromPreLoader()
 | 
											
												
													
														|  | 
 |  | +        {
 | 
											
												
													
														|  | 
 |  | +            PreLoader.Remove(CurrentIndex, ImagePaths);
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -    public void Clear()
 |  | 
 | 
											
												
													
														|  | -    {
 |  | 
 | 
											
												
													
														|  | -        PreLoader.Clear();
 |  | 
 | 
											
												
													
														|  | -    }
 |  | 
 | 
											
												
													
														|  | -    
 |  | 
 | 
											
												
													
														|  | -    public async Task Preload()
 |  | 
 | 
											
												
													
														|  | -    {
 |  | 
 | 
											
												
													
														|  | -        await PreLoader.PreLoadAsync(CurrentIndex, ImagePaths.Count, IsReversed, ImagePaths).ConfigureAwait(false);
 |  | 
 | 
											
												
													
														|  | -    }
 |  | 
 | 
											
												
													
														|  | 
 |  | +        #endregion
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -    public async Task AddAsync(int index, ImageModel imageModel)
 |  | 
 | 
											
												
													
														|  | -    {
 |  | 
 | 
											
												
													
														|  | -        await PreLoader.AddAsync(index, ImagePaths, imageModel).ConfigureAwait(false);
 |  | 
 | 
											
												
													
														|  | -    }
 |  | 
 | 
											
												
													
														|  | 
 |  | +        #region Navigation
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -    public PreLoader.PreLoadValue? GetPreLoadValue(int index)
 |  | 
 | 
											
												
													
														|  | -    {
 |  | 
 | 
											
												
													
														|  | -        return PreLoader.Get(index, ImagePaths);
 |  | 
 | 
											
												
													
														|  | -    }
 |  | 
 | 
											
												
													
														|  | -    
 |  | 
 | 
											
												
													
														|  | -    public PreLoader.PreLoadValue? GetCurrentPreLoadValue()
 |  | 
 | 
											
												
													
														|  | -    {
 |  | 
 | 
											
												
													
														|  | -        return PreLoader.Get(CurrentIndex, ImagePaths);
 |  | 
 | 
											
												
													
														|  | -    }
 |  | 
 | 
											
												
													
														|  | -    
 |  | 
 | 
											
												
													
														|  | -    public async Task<PreLoader.PreLoadValue?> GetCurrentPreLoadValueAsync()
 |  | 
 | 
											
												
													
														|  | -    {
 |  | 
 | 
											
												
													
														|  | -        return await PreLoader.GetAsync(CurrentIndex, ImagePaths);
 |  | 
 | 
											
												
													
														|  | -    }
 |  | 
 | 
											
												
													
														|  | -    
 |  | 
 | 
											
												
													
														|  | -    public void RemoveItemFromPreLoader(int index)
 |  | 
 | 
											
												
													
														|  | -    {
 |  | 
 | 
											
												
													
														|  | -        PreLoader.Remove(index, ImagePaths);
 |  | 
 | 
											
												
													
														|  | -    }
 |  | 
 | 
											
												
													
														|  | -    
 |  | 
 | 
											
												
													
														|  | -    public void RemoveCurrentItemFromPreLoader()
 |  | 
 | 
											
												
													
														|  | -    {
 |  | 
 | 
											
												
													
														|  | -        PreLoader.Remove(CurrentIndex, ImagePaths);
 |  | 
 | 
											
												
													
														|  | -    }
 |  | 
 | 
											
												
													
														|  | -    
 |  | 
 | 
											
												
													
														|  | -    #endregion
 |  | 
 | 
											
												
													
														|  | -    
 |  | 
 | 
											
												
													
														|  | -    #region Navigation
 |  | 
 | 
											
												
													
														|  | -    
 |  | 
 | 
											
												
													
														|  | -    public async Task ReloadFileList()
 |  | 
 | 
											
												
													
														|  | -    {
 |  | 
 | 
											
												
													
														|  | -        ImagePaths = await Task.FromResult(_vm.PlatformService.GetFiles(InitialFileInfo)).ConfigureAwait(false);
 |  | 
 | 
											
												
													
														|  | -        CurrentIndex = ImagePaths.IndexOf(InitialFileInfo.FullName);
 |  | 
 | 
											
												
													
														|  | -        InitiateFileSystemWatcher(InitialFileInfo);
 |  | 
 | 
											
												
													
														|  | -    }
 |  | 
 | 
											
												
													
														|  | 
 |  | +        public async Task ReloadFileList()
 | 
											
												
													
														|  | 
 |  | +        {
 | 
											
												
													
														|  | 
 |  | +            ImagePaths = await Task.FromResult(_vm.PlatformService.GetFiles(InitialFileInfo)).ConfigureAwait(false);
 | 
											
												
													
														|  | 
 |  | +            CurrentIndex = ImagePaths.IndexOf(InitialFileInfo.FullName);
 | 
											
												
													
														|  | 
 |  | +            InitiateFileSystemWatcher(InitialFileInfo);
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -    public int GetIteration(int index, NavigateTo navigateTo)
 |  | 
 | 
											
												
													
														|  | -    {
 |  | 
 | 
											
												
													
														|  | -        int next;
 |  | 
 | 
											
												
													
														|  | -        switch (navigateTo)
 |  | 
 | 
											
												
													
														|  | 
 |  | +        public int GetIteration(int index, NavigateTo navigateTo, bool skip1 = false)
 | 
											
												
													
														|  |          {
 |  |          {
 | 
											
												
													
														|  | -            case NavigateTo.Next:
 |  | 
 | 
											
												
													
														|  | -            case NavigateTo.Previous:
 |  | 
 | 
											
												
													
														|  | -                var indexChange = navigateTo == NavigateTo.Next ? 1 : -1;
 |  | 
 | 
											
												
													
														|  | -                IsReversed = navigateTo == NavigateTo.Previous;
 |  | 
 | 
											
												
													
														|  | -                if (SettingsHelper.Settings.UIProperties.Looping)
 |  | 
 | 
											
												
													
														|  | -                {
 |  | 
 | 
											
												
													
														|  | -                    next = (index + indexChange + ImagePaths.Count) % ImagePaths.Count;
 |  | 
 | 
											
												
													
														|  | -                }
 |  | 
 | 
											
												
													
														|  | -                else
 |  | 
 | 
											
												
													
														|  | -                {
 |  | 
 | 
											
												
													
														|  | -                    var newIndex = index + indexChange;
 |  | 
 | 
											
												
													
														|  | -                    if (newIndex < 0)
 |  | 
 | 
											
												
													
														|  | 
 |  | +            int next;
 | 
											
												
													
														|  | 
 |  | +            var skipAmount = skip1 ? 2 : 1;
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            switch (navigateTo)
 | 
											
												
													
														|  | 
 |  | +            {
 | 
											
												
													
														|  | 
 |  | +                case NavigateTo.Next:
 | 
											
												
													
														|  | 
 |  | +                case NavigateTo.Previous:
 | 
											
												
													
														|  | 
 |  | +                    var indexChange = navigateTo == NavigateTo.Next ? skipAmount : -skipAmount;
 | 
											
												
													
														|  | 
 |  | +                    IsReversed = navigateTo == NavigateTo.Previous;
 | 
											
												
													
														|  | 
 |  | +            
 | 
											
												
													
														|  | 
 |  | +                    if (SettingsHelper.Settings.UIProperties.Looping)
 | 
											
												
													
														|  |                      {
 |  |                      {
 | 
											
												
													
														|  | -                        return 0;
 |  | 
 | 
											
												
													
														|  | 
 |  | +                        next = (index + indexChange + ImagePaths.Count) % ImagePaths.Count;
 | 
											
												
													
														|  |                      }
 |  |                      }
 | 
											
												
													
														|  | -                    if (newIndex >= ImagePaths.Count)
 |  | 
 | 
											
												
													
														|  | 
 |  | +                    else
 | 
											
												
													
														|  |                      {
 |  |                      {
 | 
											
												
													
														|  | -                        return ImagePaths.Count - 1;
 |  | 
 | 
											
												
													
														|  | 
 |  | +                        var newIndex = index + indexChange;
 | 
											
												
													
														|  | 
 |  | +                
 | 
											
												
													
														|  | 
 |  | +                        // Ensure the new index doesn't go out of bounds
 | 
											
												
													
														|  | 
 |  | +                        if (newIndex < 0)
 | 
											
												
													
														|  | 
 |  | +                        {
 | 
											
												
													
														|  | 
 |  | +                            return 0;
 | 
											
												
													
														|  | 
 |  | +                        }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +                        if (newIndex >= ImagePaths.Count)
 | 
											
												
													
														|  | 
 |  | +                        {
 | 
											
												
													
														|  | 
 |  | +                            return ImagePaths.Count - 1;
 | 
											
												
													
														|  | 
 |  | +                        }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +                        next = newIndex;
 | 
											
												
													
														|  |                      }
 |  |                      }
 | 
											
												
													
														|  | -                    next = newIndex;
 |  | 
 | 
											
												
													
														|  | -                }
 |  | 
 | 
											
												
													
														|  | 
 |  | +                    break;
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -                break;
 |  | 
 | 
											
												
													
														|  | 
 |  | +                case NavigateTo.First:
 | 
											
												
													
														|  | 
 |  | +                case NavigateTo.Last:
 | 
											
												
													
														|  | 
 |  | +                    if (ImagePaths.Count > PreLoader.MaxCount)
 | 
											
												
													
														|  | 
 |  | +                    {
 | 
											
												
													
														|  | 
 |  | +                        PreLoader.Clear();
 | 
											
												
													
														|  | 
 |  | +                    }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -            case NavigateTo.First:
 |  | 
 | 
											
												
													
														|  | -            case NavigateTo.Last:
 |  | 
 | 
											
												
													
														|  | -                if (ImagePaths.Count > PreLoader.MaxCount)
 |  | 
 | 
											
												
													
														|  | -                    PreLoader.Clear();
 |  | 
 | 
											
												
													
														|  | -                next = navigateTo == NavigateTo.First ? 0 : ImagePaths.Count - 1;
 |  | 
 | 
											
												
													
														|  | -                break;
 |  | 
 | 
											
												
													
														|  | 
 |  | +                    next = navigateTo == NavigateTo.First ? 0 : ImagePaths.Count - 1;
 | 
											
												
													
														|  | 
 |  | +                    break;
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -            default: return -1;
 |  | 
 | 
											
												
													
														|  | -        }
 |  | 
 | 
											
												
													
														|  | -        return next;
 |  | 
 | 
											
												
													
														|  | -    }
 |  | 
 | 
											
												
													
														|  | 
 |  | +                default: 
 | 
											
												
													
														|  | 
 |  | +                    return -1;
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -    public async Task NextIteration(NavigateTo navigateTo)
 |  | 
 | 
											
												
													
														|  | -    {
 |  | 
 | 
											
												
													
														|  | -        var index = GetIteration(CurrentIndex, navigateTo);
 |  | 
 | 
											
												
													
														|  | -        if (index < 0)
 |  | 
 | 
											
												
													
														|  | -        {
 |  | 
 | 
											
												
													
														|  | -            return;
 |  | 
 | 
											
												
													
														|  | 
 |  | +            return next;
 | 
											
												
													
														|  |          }
 |  |          }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -        if (!MainKeyboardShortcuts.IsKeyHeldDown)
 |  | 
 | 
											
												
													
														|  | 
 |  | +        public async Task NextIteration(NavigateTo navigateTo)
 | 
											
												
													
														|  |          {
 |  |          {
 | 
											
												
													
														|  | -            await IterateToIndex(index);
 |  | 
 | 
											
												
													
														|  | -        }
 |  | 
 | 
											
												
													
														|  | -        else
 |  | 
 | 
											
												
													
														|  | -        { 
 |  | 
 | 
											
												
													
														|  | -            await TimerIteration(index);
 |  | 
 | 
											
												
													
														|  | -        }
 |  | 
 | 
											
												
													
														|  | -    }
 |  | 
 | 
											
												
													
														|  | 
 |  | +            var index = GetIteration(CurrentIndex, navigateTo, SettingsHelper.Settings.ImageScaling.ShowImageSideBySide);
 | 
											
												
													
														|  | 
 |  | +            if (index < 0)
 | 
											
												
													
														|  | 
 |  | +            {
 | 
											
												
													
														|  | 
 |  | +                return;
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -    public async Task IterateToIndex(int index)
 |  | 
 | 
											
												
													
														|  | -    {
 |  | 
 | 
											
												
													
														|  | -        if (index < 0 || index >= ImagePaths.Count)
 |  | 
 | 
											
												
													
														|  | -        {
 |  | 
 | 
											
												
													
														|  | -            ErrorHandling.ShowStartUpMenu(_vm);
 |  | 
 | 
											
												
													
														|  | -            return;
 |  | 
 | 
											
												
													
														|  | 
 |  | +            if (!MainKeyboardShortcuts.IsKeyHeldDown)
 | 
											
												
													
														|  | 
 |  | +            {
 | 
											
												
													
														|  | 
 |  | +                await IterateToIndex(index);
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +            else
 | 
											
												
													
														|  | 
 |  | +            {
 | 
											
												
													
														|  | 
 |  | +                await TimerIteration(index);
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  |          }
 |  |          }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -        try
 |  | 
 | 
											
												
													
														|  | 
 |  | +        public async Task IterateToIndex(int index)
 | 
											
												
													
														|  |          {
 |  |          {
 | 
											
												
													
														|  | -            lock (_lock)
 |  | 
 | 
											
												
													
														|  | 
 |  | +            if (index < 0 || index >= ImagePaths.Count)
 | 
											
												
													
														|  |              {
 |  |              {
 | 
											
												
													
														|  | -                CurrentIndex = index;
 |  | 
 | 
											
												
													
														|  | 
 |  | +                ErrorHandling.ShowStartUpMenu(_vm);
 | 
											
												
													
														|  | 
 |  | +                return;
 | 
											
												
													
														|  |              }
 |  |              }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -            // ReSharper disable once MethodHasAsyncOverload
 |  | 
 | 
											
												
													
														|  | -            var preloadValue = PreLoader.Get(index, ImagePaths);
 |  | 
 | 
											
												
													
														|  | -            if (preloadValue is not null)
 |  | 
 | 
											
												
													
														|  | 
 |  | +            try
 | 
											
												
													
														|  |              {
 |  |              {
 | 
											
												
													
														|  | -                if (preloadValue.IsLoading)
 |  | 
 | 
											
												
													
														|  | 
 |  | +                lock (_lock)
 | 
											
												
													
														|  | 
 |  | +                {
 | 
											
												
													
														|  | 
 |  | +                    CurrentIndex = index;
 | 
											
												
													
														|  | 
 |  | +                }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +                // ReSharper disable once MethodHasAsyncOverload
 | 
											
												
													
														|  | 
 |  | +                var preloadValue = PreLoader.Get(index, ImagePaths);
 | 
											
												
													
														|  | 
 |  | +                if (preloadValue is not null)
 | 
											
												
													
														|  | 
 |  | +                {
 | 
											
												
													
														|  | 
 |  | +                    if (preloadValue.IsLoading)
 | 
											
												
													
														|  | 
 |  | +                    {
 | 
											
												
													
														|  | 
 |  | +                        if (index == CurrentIndex)
 | 
											
												
													
														|  | 
 |  | +                        {
 | 
											
												
													
														|  | 
 |  | +                            LoadingPreview(index);
 | 
											
												
													
														|  | 
 |  | +                        }
 | 
											
												
													
														|  | 
 |  | +                    }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +                    while (preloadValue.IsLoading)
 | 
											
												
													
														|  | 
 |  | +                    {
 | 
											
												
													
														|  | 
 |  | +                        await Task.Delay(20);
 | 
											
												
													
														|  | 
 |  | +                        lock (_lock)
 | 
											
												
													
														|  | 
 |  | +                        {
 | 
											
												
													
														|  | 
 |  | +                            if (CurrentIndex != index)
 | 
											
												
													
														|  | 
 |  | +                            {
 | 
											
												
													
														|  | 
 |  | +                                // Skip loading if user went to next value
 | 
											
												
													
														|  | 
 |  | +                                return;
 | 
											
												
													
														|  | 
 |  | +                            }
 | 
											
												
													
														|  | 
 |  | +                        }
 | 
											
												
													
														|  | 
 |  | +                    }
 | 
											
												
													
														|  | 
 |  | +                }
 | 
											
												
													
														|  | 
 |  | +                else
 | 
											
												
													
														|  |                  {
 |  |                  {
 | 
											
												
													
														|  |                      if (index == CurrentIndex)
 |  |                      if (index == CurrentIndex)
 | 
											
												
													
														|  |                      {
 |  |                      {
 | 
											
												
													
														|  |                          LoadingPreview(index);
 |  |                          LoadingPreview(index);
 | 
											
												
													
														|  |                      }
 |  |                      }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +                    preloadValue = await PreLoader.GetAsync(CurrentIndex, ImagePaths);
 | 
											
												
													
														|  |                  }
 |  |                  }
 | 
											
												
													
														|  | -                while (preloadValue.IsLoading)
 |  | 
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +                lock (_lock)
 | 
											
												
													
														|  |                  {
 |  |                  {
 | 
											
												
													
														|  | -                    await Task.Delay(20);
 |  | 
 | 
											
												
													
														|  | -                    lock (_lock)
 |  | 
 | 
											
												
													
														|  | 
 |  | +                    if (CurrentIndex != index)
 | 
											
												
													
														|  |                      {
 |  |                      {
 | 
											
												
													
														|  | -                        if (CurrentIndex != index)
 |  | 
 | 
											
												
													
														|  | -                        {
 |  | 
 | 
											
												
													
														|  | -                            // Skip loading if user went to next value
 |  | 
 | 
											
												
													
														|  | -                            return;
 |  | 
 | 
											
												
													
														|  | -                        }
 |  | 
 | 
											
												
													
														|  | 
 |  | +                        // Skip loading if user went to next value
 | 
											
												
													
														|  | 
 |  | +                        return;
 | 
											
												
													
														|  |                      }
 |  |                      }
 | 
											
												
													
														|  |                  }
 |  |                  }
 | 
											
												
													
														|  | -            }
 |  | 
 | 
											
												
													
														|  | -            else
 |  | 
 | 
											
												
													
														|  | -            {
 |  | 
 | 
											
												
													
														|  | -                if (index == CurrentIndex)
 |  | 
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +                if (SettingsHelper.Settings.ImageScaling.ShowImageSideBySide)
 | 
											
												
													
														|  |                  {
 |  |                  {
 | 
											
												
													
														|  | -                    LoadingPreview(index);
 |  | 
 | 
											
												
													
														|  | 
 |  | +                    var nextPreloadValue = await GetNextPreLoadValueAsync();
 | 
											
												
													
														|  | 
 |  | +                    _vm.SecondaryImageSource = nextPreloadValue.ImageModel.Image;
 | 
											
												
													
														|  | 
 |  | +                    await UpdateSource(index, preloadValue, nextPreloadValue);
 | 
											
												
													
														|  | 
 |  | +                }
 | 
											
												
													
														|  | 
 |  | +                else
 | 
											
												
													
														|  | 
 |  | +                {
 | 
											
												
													
														|  | 
 |  | +                    await UpdateSource(index, preloadValue);
 | 
											
												
													
														|  |                  }
 |  |                  }
 | 
											
												
													
														|  | -                preloadValue = await PreLoader.GetAsync(CurrentIndex, ImagePaths);
 |  | 
 | 
											
												
													
														|  | -            }
 |  | 
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -            lock (_lock)
 |  | 
 | 
											
												
													
														|  | -            {
 |  | 
 | 
											
												
													
														|  | -                if (CurrentIndex != index)
 |  | 
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +                if (ImagePaths.Count > 1)
 | 
											
												
													
														|  |                  {
 |  |                  {
 | 
											
												
													
														|  | -                    // Skip loading if user went to next value
 |  | 
 | 
											
												
													
														|  | -                    return;
 |  | 
 | 
											
												
													
														|  | 
 |  | +                    if (SettingsHelper.Settings.UIProperties.IsTaskbarProgressEnabled)
 | 
											
												
													
														|  | 
 |  | +                    {
 | 
											
												
													
														|  | 
 |  | +                        _vm.PlatformService.SetTaskbarProgress(index / (double)ImagePaths.Count);
 | 
											
												
													
														|  | 
 |  | +                    }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +                    await Preload();
 | 
											
												
													
														|  |                  }
 |  |                  }
 | 
											
												
													
														|  | -            }
 |  | 
 | 
											
												
													
														|  | -            
 |  | 
 | 
											
												
													
														|  | -            await UpdateSource(index, preloadValue);
 |  | 
 | 
											
												
													
														|  | -            if (ImagePaths.Count > 1)
 |  | 
 | 
											
												
													
														|  | -            {
 |  | 
 | 
											
												
													
														|  | -                if (SettingsHelper.Settings.UIProperties.IsTaskbarProgressEnabled)
 |  | 
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +                // Add recent files, except when browsing archive
 | 
											
												
													
														|  | 
 |  | +                if (string.IsNullOrWhiteSpace(TempFileHelper.TempFilePath) && ImagePaths.Count > index)
 | 
											
												
													
														|  |                  {
 |  |                  {
 | 
											
												
													
														|  | -                    _vm.PlatformService.SetTaskbarProgress(index / (double)ImagePaths.Count);
 |  | 
 | 
											
												
													
														|  | 
 |  | +                    FileHistoryNavigation.Add(ImagePaths[index]);
 | 
											
												
													
														|  |                  }
 |  |                  }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -                await Preload();
 |  | 
 | 
											
												
													
														|  | 
 |  | +                await AddAsync(index, preloadValue.ImageModel);
 | 
											
												
													
														|  |              }
 |  |              }
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -            // Add recent files, except when browsing archive
 |  | 
 | 
											
												
													
														|  | -            if (string.IsNullOrWhiteSpace(TempFileHelper.TempFilePath) && ImagePaths.Count > index)
 |  | 
 | 
											
												
													
														|  | 
 |  | +            catch (Exception e)
 | 
											
												
													
														|  |              {
 |  |              {
 | 
											
												
													
														|  | -                FileHistoryNavigation.Add(ImagePaths[index]);
 |  | 
 | 
											
												
													
														|  | 
 |  | +#if DEBUG
 | 
											
												
													
														|  | 
 |  | +                Console.WriteLine($"{nameof(IterateToIndex)} exception: \n{e.Message}");
 | 
											
												
													
														|  | 
 |  | +                await TooltipHelper.ShowTooltipMessageAsync(e.Message);
 | 
											
												
													
														|  | 
 |  | +#endif
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +            finally
 | 
											
												
													
														|  | 
 |  | +            {
 | 
											
												
													
														|  | 
 |  | +                _vm.IsLoading = false;
 | 
											
												
													
														|  |              }
 |  |              }
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -            await AddAsync(index, preloadValue.ImageModel);
 |  | 
 | 
											
												
													
														|  | -        }
 |  | 
 | 
											
												
													
														|  | -        catch (Exception e)
 |  | 
 | 
											
												
													
														|  | -        {
 |  | 
 | 
											
												
													
														|  | -    #if DEBUG
 |  | 
 | 
											
												
													
														|  | -            Console.WriteLine($"{nameof(IterateToIndex)} exception: \n{e.Message}");
 |  | 
 | 
											
												
													
														|  | -            await TooltipHelper.ShowTooltipMessageAsync(e.Message);
 |  | 
 | 
											
												
													
														|  | -    #endif
 |  | 
 | 
											
												
													
														|  | -        }
 |  | 
 | 
											
												
													
														|  | -        finally
 |  | 
 | 
											
												
													
														|  | -        {
 |  | 
 | 
											
												
													
														|  | -            _vm.IsLoading = false;
 |  | 
 | 
											
												
													
														|  |          }
 |  |          }
 | 
											
												
													
														|  | -    }
 |  | 
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -    private static Timer? _timer;
 |  | 
 | 
											
												
													
														|  | 
 |  | +        private static Timer? _timer;
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -    internal async Task TimerIteration(int index)
 |  | 
 | 
											
												
													
														|  | -    {
 |  | 
 | 
											
												
													
														|  | -        if (_timer is null)
 |  | 
 | 
											
												
													
														|  | 
 |  | +        internal async Task TimerIteration(int index)
 | 
											
												
													
														|  |          {
 |  |          {
 | 
											
												
													
														|  | -            _timer = new Timer
 |  | 
 | 
											
												
													
														|  | 
 |  | +            if (_timer is null)
 | 
											
												
													
														|  |              {
 |  |              {
 | 
											
												
													
														|  | -                AutoReset = false,
 |  | 
 | 
											
												
													
														|  | -                Enabled = true
 |  | 
 | 
											
												
													
														|  | -            };
 |  | 
 | 
											
												
													
														|  | -        }
 |  | 
 | 
											
												
													
														|  | -        else if (_timer.Enabled)
 |  | 
 | 
											
												
													
														|  | -        {
 |  | 
 | 
											
												
													
														|  | -            if (!MainKeyboardShortcuts.IsKeyHeldDown)
 |  | 
 | 
											
												
													
														|  | -            {
 |  | 
 | 
											
												
													
														|  | -                _timer = null;
 |  | 
 | 
											
												
													
														|  | 
 |  | +                _timer = new Timer
 | 
											
												
													
														|  | 
 |  | +                {
 | 
											
												
													
														|  | 
 |  | +                    AutoReset = false,
 | 
											
												
													
														|  | 
 |  | +                    Enabled = true
 | 
											
												
													
														|  | 
 |  | +                };
 | 
											
												
													
														|  |              }
 |  |              }
 | 
											
												
													
														|  | -            return;
 |  | 
 | 
											
												
													
														|  | -        }
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -        _timer.Interval = TimeSpan.FromSeconds(SettingsHelper.Settings.UIProperties.NavSpeed).TotalMilliseconds;
 |  | 
 | 
											
												
													
														|  | -        _timer.Start();
 |  | 
 | 
											
												
													
														|  | -        await IterateToIndex(index);
 |  | 
 | 
											
												
													
														|  | -    }
 |  | 
 | 
											
												
													
														|  | -    
 |  | 
 | 
											
												
													
														|  | -    public void UpdateFileListAndIndex(List<string> fileList, int index)
 |  | 
 | 
											
												
													
														|  | -    {
 |  | 
 | 
											
												
													
														|  | -        ImagePaths = fileList;
 |  | 
 | 
											
												
													
														|  | -        CurrentIndex = index;
 |  | 
 | 
											
												
													
														|  | -    }
 |  | 
 | 
											
												
													
														|  | -    
 |  | 
 | 
											
												
													
														|  | -    #endregion
 |  | 
 | 
											
												
													
														|  | 
 |  | +            else if (_timer.Enabled)
 | 
											
												
													
														|  | 
 |  | +            {
 | 
											
												
													
														|  | 
 |  | +                if (!MainKeyboardShortcuts.IsKeyHeldDown)
 | 
											
												
													
														|  | 
 |  | +                {
 | 
											
												
													
														|  | 
 |  | +                    _timer = null;
 | 
											
												
													
														|  | 
 |  | +                }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -    #region Update Source and Preview
 |  | 
 | 
											
												
													
														|  | 
 |  | +                return;
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -    private async Task UpdateSource(int index, PreLoader.PreLoadValue? preLoadValue)
 |  | 
 | 
											
												
													
														|  | -    {
 |  | 
 | 
											
												
													
														|  | -        preLoadValue ??= await PreLoader.GetAsync(index, ImagePaths);
 |  | 
 | 
											
												
													
														|  | -        if (preLoadValue.ImageModel?.Image is null)
 |  | 
 | 
											
												
													
														|  | -        {
 |  | 
 | 
											
												
													
														|  | -            var fileInfo = preLoadValue.ImageModel?.FileInfo ?? new FileInfo(ImagePaths[index]);
 |  | 
 | 
											
												
													
														|  | -            preLoadValue.ImageModel = await ImageHelper.GetImageModelAsync(fileInfo).ConfigureAwait(false);
 |  | 
 | 
											
												
													
														|  | 
 |  | +            _timer.Interval = TimeSpan.FromSeconds(SettingsHelper.Settings.UIProperties.NavSpeed).TotalMilliseconds;
 | 
											
												
													
														|  | 
 |  | +            _timer.Start();
 | 
											
												
													
														|  | 
 |  | +            await IterateToIndex(index);
 | 
											
												
													
														|  |          }
 |  |          }
 | 
											
												
													
														|  | -        _vm.IsLoading = false;
 |  | 
 | 
											
												
													
														|  | -        ExifHandling.SetImageModel(preLoadValue.ImageModel, vm: _vm);
 |  | 
 | 
											
												
													
														|  | -        _vm.ImageSource = preLoadValue.ImageModel.Image;
 |  | 
 | 
											
												
													
														|  | -        if (preLoadValue.ImageModel.ImageType is ImageType.AnimatedGif or ImageType.AnimatedWebp)
 |  | 
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        public void UpdateFileListAndIndex(List<string> fileList, int index)
 | 
											
												
													
														|  |          {
 |  |          {
 | 
											
												
													
														|  | -            _vm.ImageViewer.MainImage.InitialAnimatedSource = preLoadValue.ImageModel.FileInfo.FullName;
 |  | 
 | 
											
												
													
														|  | 
 |  | +            ImagePaths = fileList;
 | 
											
												
													
														|  | 
 |  | +            CurrentIndex = index;
 | 
											
												
													
														|  |          }
 |  |          }
 | 
											
												
													
														|  | -        _vm.ImageType = preLoadValue.ImageModel.ImageType;
 |  | 
 | 
											
												
													
														|  | -        await Dispatcher.UIThread.InvokeAsync(() =>
 |  | 
 | 
											
												
													
														|  | -        {
 |  | 
 | 
											
												
													
														|  | -            WindowHelper.SetSize(preLoadValue.ImageModel.PixelWidth, preLoadValue.ImageModel.PixelHeight, preLoadValue.ImageModel.Rotation, _vm);
 |  | 
 | 
											
												
													
														|  | -            SetTitleHelper.SetTitle(_vm, preLoadValue.ImageModel);
 |  | 
 | 
											
												
													
														|  | -        });
 |  | 
 | 
											
												
													
														|  | -        
 |  | 
 | 
											
												
													
														|  | -        if (_vm.RotationAngle != 0)
 |  | 
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        #endregion
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        #region Update Source and Preview
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        private async Task UpdateSource(int index, PreLoader.PreLoadValue? preLoadValue, PreLoader.PreLoadValue? nextPreloadValue = null)
 | 
											
												
													
														|  |          {
 |  |          {
 | 
											
												
													
														|  | -            await Dispatcher.UIThread.InvokeAsync(() =>
 |  | 
 | 
											
												
													
														|  | 
 |  | +            preLoadValue ??= await PreLoader.GetAsync(index, ImagePaths);
 | 
											
												
													
														|  | 
 |  | +            if (preLoadValue.ImageModel?.Image is null)
 | 
											
												
													
														|  |              {
 |  |              {
 | 
											
												
													
														|  | -                _vm.ImageViewer.Rotate(_vm.RotationAngle);
 |  | 
 | 
											
												
													
														|  | -            });
 |  | 
 | 
											
												
													
														|  | -        }
 |  | 
 | 
											
												
													
														|  | -        if (SettingsHelper.Settings.WindowProperties.KeepCentered)
 |  | 
 | 
											
												
													
														|  | -        {
 |  | 
 | 
											
												
													
														|  | 
 |  | +                var fileInfo = preLoadValue.ImageModel?.FileInfo ?? new FileInfo(ImagePaths[index]);
 | 
											
												
													
														|  | 
 |  | +                preLoadValue.ImageModel = await ImageHelper.GetImageModelAsync(fileInfo).ConfigureAwait(false);
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            _vm.IsLoading = false;
 | 
											
												
													
														|  | 
 |  | +            ExifHandling.SetImageModel(preLoadValue.ImageModel, _vm);
 | 
											
												
													
														|  | 
 |  | +            _vm.ImageSource = preLoadValue.ImageModel.Image;
 | 
											
												
													
														|  | 
 |  | +            if (preLoadValue.ImageModel.ImageType is ImageType.AnimatedGif or ImageType.AnimatedWebp)
 | 
											
												
													
														|  | 
 |  | +            {
 | 
											
												
													
														|  | 
 |  | +                _vm.ImageViewer.MainImage.InitialAnimatedSource = preLoadValue.ImageModel.FileInfo.FullName;
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            _vm.ImageType = preLoadValue.ImageModel.ImageType;
 | 
											
												
													
														|  |              await Dispatcher.UIThread.InvokeAsync(() =>
 |  |              await Dispatcher.UIThread.InvokeAsync(() =>
 | 
											
												
													
														|  |              {
 |  |              {
 | 
											
												
													
														|  | -                WindowHelper.CenterWindowOnScreen(false);
 |  | 
 | 
											
												
													
														|  | 
 |  | +                WindowHelper.SetSize(preLoadValue.ImageModel.PixelWidth, preLoadValue.ImageModel.PixelHeight,
 | 
											
												
													
														|  | 
 |  | +                   nextPreloadValue?.ImageModel?.PixelWidth ?? 0, nextPreloadValue?.ImageModel?.PixelHeight ?? 0, preLoadValue.ImageModel.Rotation, _vm);
 | 
											
												
													
														|  | 
 |  | +                SetTitleHelper.SetTitle(_vm, preLoadValue.ImageModel);
 | 
											
												
													
														|  |              });
 |  |              });
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            if (_vm.RotationAngle != 0)
 | 
											
												
													
														|  | 
 |  | +            {
 | 
											
												
													
														|  | 
 |  | +                await Dispatcher.UIThread.InvokeAsync(() => { _vm.ImageViewer.Rotate(_vm.RotationAngle); });
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            if (SettingsHelper.Settings.WindowProperties.KeepCentered)
 | 
											
												
													
														|  | 
 |  | +            {
 | 
											
												
													
														|  | 
 |  | +                await Dispatcher.UIThread.InvokeAsync(() => { WindowHelper.CenterWindowOnScreen(false); });
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            _vm.GetIndex = index + 1;
 | 
											
												
													
														|  | 
 |  | +            if (_vm.SelectedGalleryItemIndex != index)
 | 
											
												
													
														|  | 
 |  | +            {
 | 
											
												
													
														|  | 
 |  | +                _vm.SelectedGalleryItemIndex = index;
 | 
											
												
													
														|  | 
 |  | +                if (SettingsHelper.Settings.Gallery.IsBottomGalleryShown)
 | 
											
												
													
														|  | 
 |  | +                {
 | 
											
												
													
														|  | 
 |  | +                    GalleryNavigation.CenterScrollToSelectedItem(_vm);
 | 
											
												
													
														|  | 
 |  | +                }
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            await Dispatcher.UIThread.InvokeAsync(TooltipHelper.CloseToolTipMessage);
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            ExifHandling.UpdateExifValues(preLoadValue.ImageModel, _vm);
 | 
											
												
													
														|  |          }
 |  |          }
 | 
											
												
													
														|  | -        
 |  | 
 | 
											
												
													
														|  | -        _vm.GetIndex = index + 1;
 |  | 
 | 
											
												
													
														|  | -        if (_vm.SelectedGalleryItemIndex != index)
 |  | 
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        public void LoadingPreview(int index)
 | 
											
												
													
														|  |          {
 |  |          {
 | 
											
												
													
														|  | 
 |  | +            if (index != CurrentIndex)
 | 
											
												
													
														|  | 
 |  | +            {
 | 
											
												
													
														|  | 
 |  | +                return;
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            SetTitleHelper.SetLoadingTitle(_vm);
 | 
											
												
													
														|  |              _vm.SelectedGalleryItemIndex = index;
 |  |              _vm.SelectedGalleryItemIndex = index;
 | 
											
												
													
														|  |              if (SettingsHelper.Settings.Gallery.IsBottomGalleryShown)
 |  |              if (SettingsHelper.Settings.Gallery.IsBottomGalleryShown)
 | 
											
												
													
														|  |              {
 |  |              {
 | 
											
												
													
														|  |                  GalleryNavigation.CenterScrollToSelectedItem(_vm);
 |  |                  GalleryNavigation.CenterScrollToSelectedItem(_vm);
 | 
											
												
													
														|  |              }
 |  |              }
 | 
											
												
													
														|  | -        }
 |  | 
 | 
											
												
													
														|  | -        await Dispatcher.UIThread.InvokeAsync(TooltipHelper.CloseToolTipMessage);
 |  | 
 | 
											
												
													
														|  | -        
 |  | 
 | 
											
												
													
														|  | -        ExifHandling.UpdateExifValues(preLoadValue.ImageModel, vm: _vm);
 |  | 
 | 
											
												
													
														|  | -    }
 |  | 
 | 
											
												
													
														|  | -    
 |  | 
 | 
											
												
													
														|  | -    public void LoadingPreview(int index)
 |  | 
 | 
											
												
													
														|  | -    {
 |  | 
 | 
											
												
													
														|  | -        if (index != CurrentIndex)
 |  | 
 | 
											
												
													
														|  | -        {
 |  | 
 | 
											
												
													
														|  | -            return;
 |  | 
 | 
											
												
													
														|  | -        }
 |  | 
 | 
											
												
													
														|  | -        SetTitleHelper.SetLoadingTitle(_vm);
 |  | 
 | 
											
												
													
														|  | -        _vm.SelectedGalleryItemIndex = index;
 |  | 
 | 
											
												
													
														|  | -        if (SettingsHelper.Settings.Gallery.IsBottomGalleryShown)
 |  | 
 | 
											
												
													
														|  | -        {
 |  | 
 | 
											
												
													
														|  | -            GalleryNavigation.CenterScrollToSelectedItem(_vm);
 |  | 
 | 
											
												
													
														|  | -        }
 |  | 
 | 
											
												
													
														|  | -        using var image = new MagickImage();
 |  | 
 | 
											
												
													
														|  | -        image.Ping(_vm.ImageIterator.ImagePaths[index]);
 |  | 
 | 
											
												
													
														|  | -        var thumb = image.GetExifProfile()?.CreateThumbnail();
 |  | 
 | 
											
												
													
														|  | -        if (thumb is null)
 |  | 
 | 
											
												
													
														|  | -        {
 |  | 
 | 
											
												
													
														|  | -            if (index == CurrentIndex)
 |  | 
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            using var image = new MagickImage();
 | 
											
												
													
														|  | 
 |  | +            image.Ping(_vm.ImageIterator.ImagePaths[index]);
 | 
											
												
													
														|  | 
 |  | +            var thumb = image.GetExifProfile()?.CreateThumbnail();
 | 
											
												
													
														|  | 
 |  | +            if (thumb is null)
 | 
											
												
													
														|  |              {
 |  |              {
 | 
											
												
													
														|  | -                _vm.IsLoading = true;
 |  | 
 | 
											
												
													
														|  | -                _vm.ImageSource = null;
 |  | 
 | 
											
												
													
														|  | 
 |  | +                if (index == CurrentIndex)
 | 
											
												
													
														|  | 
 |  | +                {
 | 
											
												
													
														|  | 
 |  | +                    _vm.IsLoading = true;
 | 
											
												
													
														|  | 
 |  | +                    _vm.ImageSource = null;
 | 
											
												
													
														|  | 
 |  | +                }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +                return;
 | 
											
												
													
														|  |              }
 |  |              }
 | 
											
												
													
														|  | -            return;
 |  | 
 | 
											
												
													
														|  | -        }
 |  | 
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -        var byteArray = thumb.ToByteArray();
 |  | 
 | 
											
												
													
														|  | -        if (byteArray is null)
 |  | 
 | 
											
												
													
														|  | -        {
 |  | 
 | 
											
												
													
														|  | -            if (index == CurrentIndex)
 |  | 
 | 
											
												
													
														|  | 
 |  | +            var byteArray = thumb.ToByteArray();
 | 
											
												
													
														|  | 
 |  | +            if (byteArray is null)
 | 
											
												
													
														|  |              {
 |  |              {
 | 
											
												
													
														|  | -                _vm.IsLoading = true;
 |  | 
 | 
											
												
													
														|  | -                _vm.ImageSource = null;
 |  | 
 | 
											
												
													
														|  | 
 |  | +                if (index == CurrentIndex)
 | 
											
												
													
														|  | 
 |  | +                {
 | 
											
												
													
														|  | 
 |  | +                    _vm.IsLoading = true;
 | 
											
												
													
														|  | 
 |  | +                    _vm.ImageSource = null;
 | 
											
												
													
														|  | 
 |  | +                }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +                return;
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            var stream = new MemoryStream(byteArray);
 | 
											
												
													
														|  | 
 |  | +            if (index != CurrentIndex)
 | 
											
												
													
														|  | 
 |  | +            {
 | 
											
												
													
														|  | 
 |  | +                return;
 | 
											
												
													
														|  |              }
 |  |              }
 | 
											
												
													
														|  | -            return;
 |  | 
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            _vm.ImageSource = new Bitmap(stream);
 | 
											
												
													
														|  | 
 |  | +            _vm.ImageType = ImageType.Bitmap;
 | 
											
												
													
														|  | 
 |  | +            //WindowHelper.SetSize(image?.Width ?? 0, image?.Height ?? 0, 0,0, 0, _vm);
 | 
											
												
													
														|  |          }
 |  |          }
 | 
											
												
													
														|  | -        var stream = new MemoryStream(byteArray);
 |  | 
 | 
											
												
													
														|  | -        if (index != CurrentIndex)
 |  | 
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        #endregion
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        #region IDisposable
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        public void Dispose()
 | 
											
												
													
														|  |          {
 |  |          {
 | 
											
												
													
														|  | -            return;
 |  | 
 | 
											
												
													
														|  | 
 |  | +            Dispose(true);
 | 
											
												
													
														|  | 
 |  | +            GC.SuppressFinalize(this);
 | 
											
												
													
														|  |          }
 |  |          }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -        _vm.ImageSource = new Bitmap(stream);
 |  | 
 | 
											
												
													
														|  | -        _vm.ImageType = ImageType.Bitmap;
 |  | 
 | 
											
												
													
														|  | -        WindowHelper.SetSize(image?.Width ?? 0, image?.Height ?? 0, 0, _vm);
 |  | 
 | 
											
												
													
														|  | -    }
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -    #endregion
 |  | 
 | 
											
												
													
														|  | -    
 |  | 
 | 
											
												
													
														|  | -    #region IDisposable
 |  | 
 | 
											
												
													
														|  | 
 |  | +        private void Dispose(bool disposing)
 | 
											
												
													
														|  | 
 |  | +        {
 | 
											
												
													
														|  | 
 |  | +            if (_disposed)
 | 
											
												
													
														|  | 
 |  | +            {
 | 
											
												
													
														|  | 
 |  | +                return;
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -    public void Dispose()
 |  | 
 | 
											
												
													
														|  | -    {
 |  | 
 | 
											
												
													
														|  | -        Dispose(true);
 |  | 
 | 
											
												
													
														|  | -        GC.SuppressFinalize(this);
 |  | 
 | 
											
												
													
														|  | -    }
 |  | 
 | 
											
												
													
														|  | 
 |  | +            if (disposing)
 | 
											
												
													
														|  | 
 |  | +            {
 | 
											
												
													
														|  | 
 |  | +                _watcher?.Dispose();
 | 
											
												
													
														|  | 
 |  | +                Clear();
 | 
											
												
													
														|  | 
 |  | +                _timer?.Dispose();
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -    private void Dispose(bool disposing)
 |  | 
 | 
											
												
													
														|  | -    {
 |  | 
 | 
											
												
													
														|  | -        if (_disposed)
 |  | 
 | 
											
												
													
														|  | -            return;
 |  | 
 | 
											
												
													
														|  | 
 |  | +            _disposed = true;
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -        if (disposing)
 |  | 
 | 
											
												
													
														|  | 
 |  | +        ~ImageIterator()
 | 
											
												
													
														|  |          {
 |  |          {
 | 
											
												
													
														|  | -            _watcher?.Dispose();
 |  | 
 | 
											
												
													
														|  | -            Clear();
 |  | 
 | 
											
												
													
														|  | -            _timer?.Dispose();
 |  | 
 | 
											
												
													
														|  | 
 |  | +            Dispose(false);
 | 
											
												
													
														|  |          }
 |  |          }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -        _disposed = true;
 |  | 
 | 
											
												
													
														|  | -    }
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -    ~ImageIterator()
 |  | 
 | 
											
												
													
														|  | -    {
 |  | 
 | 
											
												
													
														|  | -        Dispose(false);
 |  | 
 | 
											
												
													
														|  | 
 |  | +        #endregion
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  | -    
 |  | 
 | 
											
												
													
														|  | -    #endregion
 |  | 
 | 
											
												
													
														|  | -}
 |  | 
 | 
											
												
													
														|  | 
 |  | +}
 |