Browse Source

Preloader updates

Ruben 6 years ago
parent
commit
66a201b7cb

+ 19 - 3
PicView/App.config

@@ -1,12 +1,12 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
 <configuration>
     <configSections>
         <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
-            <section name="PicView.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
+            <section name="PicView.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
         </sectionGroup>
     </configSections>
     <startup> 
-        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
+        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
     </startup>
     <userSettings>
         <PicView.Properties.Settings>
@@ -117,4 +117,20 @@
             </setting>
         </PicView.Properties.Settings>
     </userSettings>
+  <runtime>
+    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+      <dependentAssembly>
+        <assemblyIdentity name="System.Numerics.Vectors" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.1.5.0" newVersion="4.1.5.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.5.0" newVersion="4.0.5.0" />
+      </dependentAssembly>
+    </assemblyBinding>
+  </runtime>
 </configuration>

+ 6 - 2
PicView/Error Handling/Error_Handling.cs

@@ -1,16 +1,17 @@
 using PicView.PreLoading;
 using System;
+using System.Diagnostics;
 using System.IO;
 using System.Windows.Media.Imaging;
 using static PicView.DeleteFiles;
+using static PicView.Fields;
 using static PicView.FileLists;
 using static PicView.Helper;
-using static PicView.Fields;
 using static PicView.ImageManager;
+using static PicView.Interface;
 using static PicView.Navigation;
 using static PicView.Resize_and_Zoom;
 using static PicView.Rotate_and_Flip;
-using static PicView.Interface;
 
 namespace PicView
 {
@@ -22,6 +23,9 @@ namespace PicView
         /// <param name="x">The index to start from</param>
         internal static bool PicErrorFix(int x)
         {
+#if DEBUG
+            Trace.WriteLine("Entered PicErrorFix");
+#endif
             if (Pics == null)
             {
                 Reload(true);

+ 0 - 18
PicView/Helpers/Helper.cs

@@ -1,8 +1,6 @@
 using Microsoft.WindowsAPICodePack.Taskbar;
 using System.Diagnostics;
-using System.IO;
 using System.Windows;
-using static PicView.Fields;
 
 namespace PicView
 {
@@ -40,22 +38,6 @@ namespace PicView
             prog.SetProgressState(TaskbarProgressBarState.NoProgress);
         }
 
-        /// <summary>
-        /// Returns a Windows Thumbnail
-        /// </summary>
-        /// <param name="path">The path to the file</param>
-        /// <returns></returns>
-        internal static System.Windows.Media.Imaging.BitmapSource GetWindowsThumbnail(string path, bool extralarge = false)
-        {
-            if (!File.Exists(path))
-                return null;
-
-            if (extralarge)
-                return Microsoft.WindowsAPICodePack.Shell.ShellFile.FromFilePath(path).Thumbnail.ExtraLargeBitmapSource;
-
-            return Microsoft.WindowsAPICodePack.Shell.ShellFile.FromFilePath(path).Thumbnail.BitmapSource;
-        }
-
         /// <summary>
         /// Sends the file to Windows print system
         /// </summary>

+ 17 - 6
PicView/Image Logic/ImageManager.cs

@@ -3,7 +3,6 @@ using System;
 using System.IO;
 using System.Windows;
 using System.Windows.Media.Imaging;
-using static PicView.Helper;
 
 namespace PicView
 {
@@ -25,11 +24,8 @@ namespace PicView
                 var mrs = new MagickReadSettings()
                 {
                     Density = new Density(300, 300),
-                    //Width = Fields.MonitorInfo.Width,
-                    //Height = Fields.MonitorInfo.Height,
                     BackgroundColor = MagickColors.Transparent,
-                    //Format = MagickFormat.Jpeg
-                };           
+                };
 
                 try
                 {
@@ -49,7 +45,6 @@ namespace PicView
                 magick.Dispose();
                 return pic;
             }
-
         }
 
         internal static BitmapSource GetBitmapSourceThumb(string path)
@@ -329,5 +324,21 @@ namespace PicView
                 return;
             }          
         }
+
+        /// <summary>
+        /// Returns a Windows Thumbnail
+        /// </summary>
+        /// <param name="path">The path to the file</param>
+        /// <returns></returns>
+        internal static BitmapSource GetWindowsThumbnail(string path, bool extralarge = false)
+        {
+            if (!File.Exists(path))
+                return null;
+
+            if (extralarge)
+                return Microsoft.WindowsAPICodePack.Shell.ShellFile.FromFilePath(path).Thumbnail.ExtraLargeBitmapSource;
+
+            return Microsoft.WindowsAPICodePack.Shell.ShellFile.FromFilePath(path).Thumbnail.BitmapSource;
+        }
     }
 }

+ 5 - 2
PicView/Image Logic/Navigation.cs

@@ -314,8 +314,11 @@ namespace PicView
             if (end)
             {
                 FolderIndex = next ? Pics.Count - 1 : 0;
-                PreloadCount = 4;
-                Preloader.Clear();
+                if (Pics.Count > 20)
+                {
+                    PreloadCount = 4;
+                    Preloader.Clear();
+                }
             }
             // Go to next or previous
             else

+ 38 - 38
PicView/Loading/Preloader.cs

@@ -34,7 +34,7 @@ namespace PicView.PreLoading
         /// <summary>
         /// Preloader list of BitmapSources
         /// </summary>
-        private static ConcurrentDictionary<string, BitmapSource> Sources = new ConcurrentDictionary<string, BitmapSource>();
+        private static readonly ConcurrentDictionary<string, BitmapSource> Sources = new ConcurrentDictionary<string, BitmapSource>();
 
         /// <summary>
         /// When Preloader is adding an image
@@ -232,6 +232,7 @@ namespace PicView.PreLoading
                 var toLoad = 5;
                 var extraToLoad = 3;
                 var cleanUpLoad = toLoad + extraToLoad;
+                var noCleanUp = cleanUpLoad + toLoad;
 
 
                 // Not looping
@@ -256,7 +257,7 @@ namespace PicView.PreLoading
                         }
 
                         //Clean up behind
-                        if (Pics.Count > 20 && !freshStartup)
+                        if (Pics.Count > noCleanUp && !freshStartup)
                         {
                             for (int i = index - cleanUpLoad; i < index - toLoad; i++)
                             {
@@ -288,7 +289,7 @@ namespace PicView.PreLoading
                         }
 
                         //Clean up infront
-                        if (Pics.Count > 20 && !freshStartup)
+                        if (Pics.Count > noCleanUp && !freshStartup)
                         {
                             for (int i = index + toLoad; i < index + cleanUpLoad; i++)
                             {
@@ -318,7 +319,7 @@ namespace PicView.PreLoading
                         }
 
                         //Clean up behind
-                        if (Pics.Count > 20 && !freshStartup)
+                        if (Pics.Count > noCleanUp && !freshStartup)
                         {
                             for (int i = index - cleanUpLoad + Pics.Count; i < index + Pics.Count; i++)
                             {
@@ -330,11 +331,40 @@ namespace PicView.PreLoading
                     else
                     {
                         // Add 5 elements behind
-                        for (int i = index; i <= toLoad; i++) // Need proper working solution
+                        int y = 0;
+                        for (int i = index - 1; i > index - toLoad; i--)
                         {
-                            Add(i % Pics.Count); 
+                            y++;
+                            if (i < 0)
+                            {
+                                for (int x = Pics.Count - 1; x >= Pics.Count - y; x--)
+                                {
+                                    Add(x);
+                                }
+                                break;
+                            }
+                            Add(i);
                         }
 
+                        #region Discarded code
+                        //for (int i = index; i <= toLoad; i++) // Need proper working solution
+                        //{
+                        //    Add(i % Pics.Count); 
+                        //}
+                        //for (int i = index - 1; i >= Pics.Count - toLoad; i--)
+                        //{
+                        //    if (i == 0)
+                        //    {
+                        //        for (int x = Pics.Count - 1; x >= toLoad - i; x--)
+                        //        {
+                        //            Add(i);
+                        //        }
+                        //        break;
+                        //    }
+
+                        //    Add(i);
+                        //}
+
                         // Non-working, runs more than it should
                         //for (int i = index - 1; i >= index - (toLoad + 1); i--)
                         //{
@@ -343,6 +373,7 @@ namespace PicView.PreLoading
 
                         //    Add(i % Pics.Count);
                         //}
+                        #endregion
 
                         // Add 3 elements
                         for (int i = index; i <= index + extraToLoad; i++) // Somewhat untested
@@ -351,44 +382,13 @@ namespace PicView.PreLoading
                         }
 
                         //Clean up infront
-                        if (Pics.Count > 20 && !freshStartup)
+                        if (Pics.Count > noCleanUp && !freshStartup)
                         {
                             for (int i = index + toLoad; i <= index + cleanUpLoad; i++)
                             {
                                 Remove(i % Pics.Count);
                             }
                         }
-
-                        ////Add first three
-                        //int i = index - 1 < 0 ? Pics.Count : index - 1;
-                        //Add(i);
-                        //i = i - 1 < 0 ? Pics.Count : i - 1;
-                        //Add(i);
-                        //i = i - 1 < 0 ? Pics.Count : i - 1;
-                        //Add(i);
-
-                        ////Add two behind
-                        //i = index + 1 >= Pics.Count ? (i + 1) - Pics.Count : index + 1;
-                        //Add(i);
-                        //i = i + 1 >= Pics.Count ? (i + 1) - Pics.Count : i + 1;
-                        //Add(i);
-
-                        ////Add one more infront
-                        //i = index - 4 < 0 ? (index + 4) - Pics.Count : index - 4;
-                        //Add(i);
-
-                        //if (Pics.Count > 20 && !freshStartup)
-                        //{
-                        //    //Clean up behind
-                        //    var arr = new string[3];
-                        //    i = index + 3 > Pics.Count - 1 ? Pics.Count - 1 : index + 3;
-                        //    arr[0] = Pics[i];
-                        //    i = index + 4 > Pics.Count - 1 ? Pics.Count - 1 : index + 4;
-                        //    arr[1] = Pics[i];
-                        //    i = index + 5 > Pics.Count - 1 ? Pics.Count - 1 : index + 5;
-                        //    arr[2] = Pics[i];
-                        //    Clear(arr);
-                        //}
                     }
                 }
 

+ 13 - 0
PicView/PicVIew.csproj

@@ -107,8 +107,21 @@
       <HintPath>..\packages\Microsoft-WindowsAPICodePack-ShellExtensions.1.1.3.3\lib\net452\Microsoft.WindowsAPICodePack.ShellExtensions.dll</HintPath>
     </Reference>
     <Reference Include="System" />
+    <Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
+      <HintPath>..\packages\System.Buffers.4.5.0\lib\netstandard2.0\System.Buffers.dll</HintPath>
+    </Reference>
     <Reference Include="System.Data" />
     <Reference Include="System.Drawing" />
+    <Reference Include="System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
+      <HintPath>..\packages\System.Memory.4.5.3\lib\netstandard2.0\System.Memory.dll</HintPath>
+    </Reference>
+    <Reference Include="System.Numerics" />
+    <Reference Include="System.Numerics.Vectors, Version=4.1.5.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
+      <HintPath>..\packages\System.Numerics.Vectors.4.6.0-preview5.19224.8\lib\net46\System.Numerics.Vectors.dll</HintPath>
+    </Reference>
+    <Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.5.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
+      <HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.6.0-preview8.19405.3\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
+    </Reference>
     <Reference Include="System.Windows.Forms" />
     <Reference Include="System.Xml" />
     <Reference Include="Microsoft.CSharp" />

+ 1 - 1
PicView/Properties/AssemblyInfo.cs

@@ -52,6 +52,6 @@ using System.Windows;
 // by using the '*' as shown below:
 // [assembly: AssemblyVersion("1.0.*")]
 [assembly: AssemblyVersion("1.0.0.0")]
-[assembly: AssemblyFileVersion("0.9.1.0")]
+[assembly: AssemblyFileVersion("0.9.2.0")]
 [assembly: NeutralResourcesLanguage("en")]
 

+ 4 - 0
PicView/packages.config

@@ -4,4 +4,8 @@
   <package id="Microsoft-WindowsAPICodePack-Core" version="1.1.3.3" targetFramework="net472" />
   <package id="Microsoft-WindowsAPICodePack-Shell" version="1.1.3.3" targetFramework="net472" />
   <package id="Microsoft-WindowsAPICodePack-ShellExtensions" version="1.1.3.3" targetFramework="net472" />
+  <package id="System.Buffers" version="4.5.0" targetFramework="net48" />
+  <package id="System.Memory" version="4.5.3" targetFramework="net48" />
+  <package id="System.Numerics.Vectors" version="4.6.0-preview5.19224.8" targetFramework="net48" />
+  <package id="System.Runtime.CompilerServices.Unsafe" version="4.6.0-preview8.19405.3" targetFramework="net48" />
 </packages>