mirror of
				https://github.com/Kareadita/Kavita.git
				synced 2025-10-31 10:37:04 -04:00 
			
		
		
		
	* Added a tooltip to inform user that format and collection filter selections do not only show for the selected library. * Refactored a lot of code around when we update chapter cover images. Applied an optimization for when we re-calculate volume/series covers, such that it only occurs when the first chapter's image updates. * Updated code to ensure only lastmodified gets refreshed in metadata since it always follows a scan * Optimized how metadata is populated on the series. Instead of re-reading the comicInfos, instead I read the data from the underlying chapter entities. This reduces N additional reads AND enables the ability in the future to show/edit chapter level metadata. * Spelling mistake * Fixed a concurency issue by not selecting Genres from DB. Added a test for long paths. * Fixed a bug in filter where collection tag wasn't populating on load * Cleaned up the logic for changelog to better compare against the installed verison. For nightly users, show the last stable as installed. * Removed some demo code * SplitQuery to allow loading tags much faster for series metadata load.
		
			
				
	
	
		
			112 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			112 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| using System;
 | |
| using System.Collections.Generic;
 | |
| using System.Text.RegularExpressions;
 | |
| using static System.GC;
 | |
| using static System.String;
 | |
| 
 | |
| namespace API.Comparators
 | |
| {
 | |
|     /// <summary>
 | |
|     /// Attempts to emulate Windows explorer sorting
 | |
|     /// </summary>
 | |
|     /// <remarks>This is not thread-safe</remarks>
 | |
|     public sealed class NaturalSortComparer : IComparer<string>, IDisposable
 | |
|     {
 | |
|         private readonly bool _isAscending;
 | |
|         private Dictionary<string, string[]> _table = new();
 | |
| 
 | |
|         private bool _disposed;
 | |
| 
 | |
| 
 | |
|         public NaturalSortComparer(bool inAscendingOrder = true)
 | |
|         {
 | |
|             _isAscending = inAscendingOrder;
 | |
|         }
 | |
| 
 | |
|         int IComparer<string>.Compare(string? x, string? y)
 | |
|         {
 | |
|             if (x == y) return 0;
 | |
| 
 | |
|             if (x != null && y == null) return -1;
 | |
|             if (x == null) return 1;
 | |
| 
 | |
| 
 | |
|             if (!_table.TryGetValue(x ?? Empty, out var x1))
 | |
|             {
 | |
|                 x1 = Regex.Split(x ?? Empty, "([0-9]+)");
 | |
|                 _table.Add(x ?? Empty, x1);
 | |
|             }
 | |
| 
 | |
|             if (!_table.TryGetValue(y ?? Empty, out var y1))
 | |
|             {
 | |
|                 y1 = Regex.Split(y ?? Empty, "([0-9]+)");
 | |
|                 _table.Add(y ?? Empty, y1);
 | |
|             }
 | |
| 
 | |
|             int returnVal;
 | |
| 
 | |
|             for (var i = 0; i < x1.Length && i < y1.Length; i++)
 | |
|             {
 | |
|                 if (x1[i] == y1[i]) continue;
 | |
|                 if (x1[i] == Empty || y1[i] == Empty) continue;
 | |
|                 returnVal = PartCompare(x1[i], y1[i]);
 | |
|                 return _isAscending ? returnVal : -returnVal;
 | |
|             }
 | |
| 
 | |
|             if (y1.Length > x1.Length)
 | |
|             {
 | |
|                 returnVal = -1;
 | |
|             }
 | |
|             else if (x1.Length > y1.Length)
 | |
|             {
 | |
|                 returnVal = 1;
 | |
|             }
 | |
|             else
 | |
|             {
 | |
|                 returnVal = 0;
 | |
|             }
 | |
| 
 | |
| 
 | |
|             return _isAscending ? returnVal : -returnVal;
 | |
|         }
 | |
| 
 | |
|         private static int PartCompare(string left, string right)
 | |
|         {
 | |
|             if (!int.TryParse(left, out var x))
 | |
|                 return Compare(left, right, StringComparison.Ordinal);
 | |
| 
 | |
|             if (!int.TryParse(right, out var y))
 | |
|                 return Compare(left, right, StringComparison.Ordinal);
 | |
| 
 | |
|             return x.CompareTo(y);
 | |
|         }
 | |
| 
 | |
|         private void Dispose(bool disposing)
 | |
|         {
 | |
|             if (!_disposed)
 | |
|             {
 | |
|                 if (disposing)
 | |
|                 {
 | |
|                     // called via myClass.Dispose().
 | |
|                     _table.Clear();
 | |
|                     _table = null;
 | |
|                 }
 | |
|                 // Release unmanaged resources.
 | |
|                 // Set large fields to null.
 | |
|                 _disposed = true;
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         public void Dispose()
 | |
|         {
 | |
|             Dispose(true);
 | |
|             SuppressFinalize(this);
 | |
|         }
 | |
| 
 | |
|         ~NaturalSortComparer() // the finalizer
 | |
|         {
 | |
|             Dispose(false);
 | |
|         }
 | |
|     }
 | |
| }
 |