Browse Source

Remove unnecessary error checking

Ruben 4 years ago
parent
commit
143552e10e
1 changed files with 54 additions and 60 deletions
  1. 54 60
      PicView/ChangeImage/LoadPic.cs

+ 54 - 60
PicView/ChangeImage/LoadPic.cs

@@ -107,6 +107,8 @@ namespace PicView.ChangeImage
             }
             }
         }
         }
 
 
+        #region LoadPicAtValue
+
         /// <summary>
         /// <summary>
         /// Determine proper path from given string value
         /// Determine proper path from given string value
         /// </summary>
         /// </summary>
@@ -370,7 +372,7 @@ namespace PicView.ChangeImage
             // Check if works, if not show error message
             // Check if works, if not show error message
             if (preloadValue is not null)
             if (preloadValue is not null)
             {
             {
-                while (preloadValue != null && preloadValue.isLoading)
+                while (preloadValue.isLoading)
                 {
                 {
                     // Wait for finnished result
                     // Wait for finnished result
                     await Task.Delay(5).ConfigureAwait(false);
                     await Task.Delay(5).ConfigureAwait(false);
@@ -383,20 +385,6 @@ namespace PicView.ChangeImage
                         return;
                         return;
                     }
                     }
                 }
                 }
-                if (preloadValue is null) // Error correctiom
-                {
-                    await Preloader.AddAsync(index).ConfigureAwait(false);
-                    preloadValue = Preloader.Get(Navigation.Pics[index]);
-                }
-                if (preloadValue is null)
-                {
-                    await ConfigureWindows.GetMainWindow.Dispatcher.BeginInvoke(DispatcherPriority.Normal, () =>
-                    {
-                        Error_Handling.Unload();
-                        ShowTooltipMessage(Application.Current.Resources["UnexpectedError"]);
-                    });
-                    return;
-                }
                 if (preloadValue.bitmapSource == null)
                 if (preloadValue.bitmapSource == null)
                 {
                 {
                     preloadValue = new Preloader.PreloadValue(ImageFunctions.ImageErrorMessage(), false);
                     preloadValue = new Preloader.PreloadValue(ImageFunctions.ImageErrorMessage(), false);
@@ -458,6 +446,55 @@ namespace PicView.ChangeImage
             }
             }
         }
         }
 
 
+        /// <summary>
+        /// Handle logic if user wants to load from a folder
+        /// </summary>
+        /// <param name="folder"></param>
+        internal static async Task LoadPicFromFolderAsync(string folder)
+        {
+            // TODO add new function that can go to next/prev folder
+            await ConfigureWindows.GetMainWindow.Dispatcher.BeginInvoke(DispatcherPriority.Normal, () =>
+            {
+                ChangeFolder(true);
+            });
+
+
+            // If searching subdirectories, it might freeze UI, so wrap it in task
+            await Task.Run(() =>
+            {
+                Pics = FileList(folder);
+            }).ConfigureAwait(false);
+
+            if (Pics?.Count > 0)
+            {
+                await LoadPicAtIndexAsync(0).ConfigureAwait(false);
+            }
+            else
+            {
+                await ReloadAsync(true).ConfigureAwait(false);
+            }
+            await ConfigureWindows.GetMainWindow.Dispatcher.BeginInvoke(DispatcherPriority.Background, async () =>
+            {
+                if (GetImageSettingsMenu is not null)
+                {
+                    GetImageSettingsMenu.GoToPic.GoToPicBox.Text = (FolderIndex + 1).ToString(CultureInfo.CurrentCulture);
+                }
+
+                // Load new gallery values, if changing folder
+                if (GetPicGallery != null && Properties.Settings.Default.FullscreenGalleryHorizontal || GetPicGallery != null && Properties.Settings.Default.FullscreenGalleryVertical)
+                {
+                    if (GetPicGallery.Container.Children.Count == 0)
+                    {
+                        await GalleryLoad.Load().ConfigureAwait(false);
+                    }
+                }
+            });
+        }
+
+        #endregion
+
+        #region UpdatePic
+
         /// <summary>
         /// <summary>
         /// Update picture, size it and set the title from index
         /// Update picture, size it and set the title from index
         /// </summary>
         /// </summary>
@@ -620,51 +657,6 @@ namespace PicView.ChangeImage
             await UpdatePic(b64, pic).ConfigureAwait(false);
             await UpdatePic(b64, pic).ConfigureAwait(false);
         }
         }
 
 
-        /// <summary>
-        /// Handle logic if user wants to load from a folder
-        /// </summary>
-        /// <param name="folder"></param>
-        internal static async Task LoadPicFromFolderAsync(string folder)
-        {
-            // TODO add new function that can go to next/prev folder
-            await ConfigureWindows.GetMainWindow.Dispatcher.BeginInvoke(DispatcherPriority.Normal, () =>
-            {
-                ChangeFolder(true);
-            });
-
-
-            // If searching subdirectories, it might freeze UI, so wrap it in task
-            await Task.Run(() =>
-            {
-                Pics = FileList(folder);
-            }).ConfigureAwait(false);
-
-            if (Pics?.Count > 0)
-            {
-                await LoadPicAtIndexAsync(0).ConfigureAwait(false);
-            }
-            else
-            {
-                await ReloadAsync(true).ConfigureAwait(false);
-            }
-            await ConfigureWindows.GetMainWindow.Dispatcher.BeginInvoke(DispatcherPriority.Background, async () =>
-            {
-                if (GetImageSettingsMenu is not null)
-                {
-                    GetImageSettingsMenu.GoToPic.GoToPicBox.Text = (FolderIndex + 1).ToString(CultureInfo.CurrentCulture);
-                }
-
-                // Load new gallery values, if changing folder
-                if (GetPicGallery != null && Properties.Settings.Default.FullscreenGalleryHorizontal || GetPicGallery != null && Properties.Settings.Default.FullscreenGalleryVertical)
-                {
-                    if (GetPicGallery.Container.Children.Count == 0)
-                    {
-                        await GalleryLoad.Load().ConfigureAwait(false);
-                    }
-                }
-            });
-        }
-
         /// <summary>
         /// <summary>
         /// Update after FastPic() was used
         /// Update after FastPic() was used
         /// </summary>
         /// </summary>
@@ -714,5 +706,7 @@ namespace PicView.ChangeImage
                 UpdatePic(FolderIndex, preloadValue.bitmapSource);
                 UpdatePic(FolderIndex, preloadValue.bitmapSource);
             });
             });
         }
         }
+
+        #endregion
     }
     }
 }
 }