Permalink
Browse files

0004143: Numeric String sorting uses alphanumerical algorithm

  • Loading branch information...
1 parent d5f87ef commit d4447075cdb09a07140232d08da1a657e05212fb @dedahr dedahr committed Mar 27, 2013
@@ -18,6 +18,7 @@
#endregion
+using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using System.Collections;
@@ -26,8 +27,11 @@ namespace MediaPortal.UserInterface.Controls
{
public class ImageTextComparer : IComparer
{
+ [DllImport("shlwapi.dll", CharSet = CharSet.Unicode)]
+ private static extern int StrCmpLogicalW(string x, string y);
+
//private CaseInsensitiveComparer ObjectCompare;
- private readonly NumberCaseInsensitiveComparer ObjectCompare;
+ private readonly NumberCaseInsensitiveComparer ObjectCompare;
public ImageTextComparer()
{
@@ -49,7 +53,7 @@ public int Compare(object x, object y)
}
if (image1 == image2)
{
- return ObjectCompare.Compare(listviewX.Text, listviewY.Text);
+ return StrCmpLogicalW(listviewX.Text, listviewY.Text);
}
return 1;
}
@@ -20,6 +20,7 @@
using System;
using System.Collections;
+using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace MediaPortal.Configuration.Controls
@@ -29,6 +30,9 @@ namespace MediaPortal.Configuration.Controls
/// </summary>
public class ListViewItemComparer : IComparer
{
+ [DllImport("shlwapi.dll", CharSet = CharSet.Unicode)]
+ private static extern int StrCmpLogicalW(string x, string y);
+
private readonly int col;
public ListViewItemComparer()
@@ -48,7 +52,7 @@ public int Compare(object x, object y)
sortCol = 0;
if (sortCol >= ((ListViewItem)y).SubItems.Count)
sortCol = 0;
- return String.Compare(((ListViewItem)x).SubItems[sortCol].Text, ((ListViewItem)y).SubItems[sortCol].Text);
+ return StrCmpLogicalW(((ListViewItem)x).SubItems[sortCol].Text, ((ListViewItem)y).SubItems[sortCol].Text);
}
}
@@ -19,13 +19,17 @@
#endregion
using System;
+using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Collections;
namespace MediaPortal.UserInterface.Controls
{
public class MPListViewStringColumnSorter : IComparer
{
+ [DllImport("shlwapi.dll", CharSet = CharSet.Unicode)]
+ private static extern int StrCmpLogicalW(string x, string y);
+
public enum OrderTypes
{
AsString,
@@ -46,8 +50,8 @@ public int Compare(object x, object y)
{
case OrderTypes.AsString:
compareResult = SortColumn == 0
- ? String.Compare(listviewX.Text, listviewY.Text)
- : String.Compare(listviewX.SubItems[SortColumn].Text, listviewY.SubItems[SortColumn].Text);
+ ? StrCmpLogicalW(listviewX.Text, listviewY.Text)
+ : StrCmpLogicalW(listviewX.SubItems[SortColumn].Text, listviewY.SubItems[SortColumn].Text);
break;
case OrderTypes.AsValue:
string line1 = SortColumn == 0 ? listviewX.Text : listviewX.SubItems[SortColumn].Text;
@@ -4673,4 +4673,41 @@ public static IEnumerable<IAsyncResult> DoActionAsync<T>(this IEnumerable<T> sou
.ToArray();
}
}
+
+ public class StringLogicalComparer : IComparer, IComparer<string>
+ {
+ public static int Compare(string x, string y)
+ {
+ return CompareStrings(x, y);
+ }
+
+ [DllImport("shlwapi.dll", CharSet = CharSet.Unicode)]
+ private static extern int StrCmpLogicalW(string x, string y);
+
+ private static int CompareStrings(string x, string y)
+ {
+ return StrCmpLogicalW(x, y);
+ }
+
+ private static int CompareObjects(object x, object y)
+ {
+ return StrCmpLogicalW((string) x, (string) y);
+ }
+
+ int IComparer<string>.Compare(string x, string y)
+ {
+ if (null == x && null == y) return 0;
+ if (null == x) return -1;
+ if (null == y) return 1;
+ return Compare(x, y);
+ }
+
+ int IComparer.Compare(object x, object y)
+ {
+ if (null == x && null == y) return 0;
+ if (null == x) return -1;
+ if (null == y) return 1;
+ return CompareObjects(x, y);
+ }
+ }
}
@@ -129,11 +129,11 @@ public int Compare(GUIListItem item1, GUIListItem item2)
case SortMethod.Name:
if (bAscending)
{
- return String.Compare(item1.Label, item2.Label, true);
+ return Util.StringLogicalComparer.Compare(item1.Label, item2.Label);
}
else
{
- return String.Compare(item2.Label, item1.Label, true);
+ return Util.StringLogicalComparer.Compare(item2.Label, item1.Label);
}
@@ -183,18 +183,18 @@ public int Compare(GUIListItem item1, GUIListItem item2)
if (item1.Year == item2.Year)
{
// When the Year is equal just sort on the Label
- return String.Compare(item1.Label, item2.Label, true);
+ return Util.StringLogicalComparer.Compare(item1.Label, item2.Label);
}
- return String.Compare(compVal1, compVal2, true);
+ return Util.StringLogicalComparer.Compare(compVal1, compVal2);
}
else
{
if (item1.Year == item2.Year)
{
// When the Year is equal, sort on label ASCENDING, altough sorting on year is DESC
- return String.Compare(item1.Label, item2.Label, true);
+ return Util.StringLogicalComparer.Compare(item1.Label, item2.Label);
}
- return String.Compare(compVal2, compVal1, true);
+ return Util.StringLogicalComparer.Compare(compVal2, compVal1);
}
case SortMethod.Rating:
@@ -300,11 +300,11 @@ public int Compare(GUIListItem item1, GUIListItem item2)
}
if (bAscending)
{
- return String.Compare(strTitle1, strTitle2, true);
+ return Util.StringLogicalComparer.Compare(strTitle1, strTitle2);
}
else
{
- return String.Compare(strTitle2, strTitle1, true);
+ return Util.StringLogicalComparer.Compare(strTitle2, strTitle1);
}
case SortMethod.Artist:
@@ -318,11 +318,11 @@ public int Compare(GUIListItem item1, GUIListItem item2)
}
if (bAscending)
{
- return String.Compare(strArtist1, strArtist2, true);
+ return Util.StringLogicalComparer.Compare(strArtist1, strArtist2);
}
else
{
- return String.Compare(strArtist2, strArtist1, true);
+ return Util.StringLogicalComparer.Compare(strArtist2, strArtist1);
}
case SortMethod.AlbumArtist:
@@ -336,11 +336,11 @@ public int Compare(GUIListItem item1, GUIListItem item2)
}
if (bAscending)
{
- return String.Compare(strAlbumArtist1, strAlbumArtist2, true);
+ return Util.StringLogicalComparer.Compare(strAlbumArtist1, strAlbumArtist2);
}
else
{
- return String.Compare(strAlbumArtist2, strAlbumArtist1, true);
+ return Util.StringLogicalComparer.Compare(strAlbumArtist2, strAlbumArtist1);
}
case SortMethod.Album:
@@ -377,12 +377,12 @@ public int Compare(GUIListItem item1, GUIListItem item2)
}
else
{
- return String.Compare(strAlbumArtist1, strAlbumArtist2, true);
+ return Util.StringLogicalComparer.Compare(strAlbumArtist1, strAlbumArtist2);
}
}
else
{
- return String.Compare(strAlbum1, strAlbum2, true);
+ return Util.StringLogicalComparer.Compare(strAlbum1, strAlbum2);
}
}
else
@@ -402,12 +402,12 @@ public int Compare(GUIListItem item1, GUIListItem item2)
}
else
{
- return String.Compare(strAlbumArtist2, strAlbumArtist1, true);
+ return Util.StringLogicalComparer.Compare(strAlbumArtist2, strAlbumArtist1);
}
}
else
{
- return String.Compare(strAlbum2, strAlbum1, true);
+ return Util.StringLogicalComparer.Compare(strAlbum2, strAlbum1);
}
}
@@ -417,11 +417,11 @@ public int Compare(GUIListItem item1, GUIListItem item2)
string strFile2 = Util.Utils.GetFilename(item2.Path);
if (bAscending)
{
- return String.Compare(strFile1, strFile2, true);
+ return Util.StringLogicalComparer.Compare(strFile1, strFile2);
}
else
{
- return String.Compare(strFile2, strFile1, true);
+ return Util.StringLogicalComparer.Compare(strFile2, strFile1);
}
case SortMethod.Composer:
@@ -438,11 +438,11 @@ public int Compare(GUIListItem item1, GUIListItem item2)
if (bAscending)
{
- return String.Compare(strComposer1, strComposer2, true);
+ return Util.StringLogicalComparer.Compare(strComposer1, strComposer2);
}
else
{
- return String.Compare(strComposer2, strComposer1, true);
+ return Util.StringLogicalComparer.Compare(strComposer2, strComposer1);
}
case SortMethod.TimesPlayed:
@@ -1157,11 +1157,11 @@ public int Compare(GUIListItem item1, GUIListItem item2)
if (sortAsc)
{
- return String.Compare(item1.Label, item2.Label, true);
+ return Util.StringLogicalComparer.Compare(item1.Label, item2.Label);
}
else
- {
- return String.Compare(item2.Label, item1.Label, true);
+ {
+ return Util.StringLogicalComparer.Compare(item2.Label, item1.Label);
}
@@ -59,7 +59,15 @@ public PictureSort(SortMethod sortMethod, bool ascending)
using (Profile.Settings xmlreader = new MPSettings())
{
KeepFoldersTogether = xmlreader.GetValueAsBool("movies", "keepfolderstogether", false);
- UseSortTitle = xmlreader.GetValueAsBool("moviedatabase", "usesorttitle", false);
+
+ if (GUIWindowManager.ActiveWindow == (int)GUIWindow.Window.WINDOW_VIDEO_TITLE)
+ {
+ UseSortTitle = xmlreader.GetValueAsBool("moviedatabase", "usesorttitle", false);
+ }
+ else
+ {
+ UseSortTitle = false;
+ }
}
}
@@ -155,26 +163,26 @@ public int Compare(GUIListItem item1, GUIListItem item2)
if (SortAscending)
{
if (!UseSortTitle)
- {
- return String.Compare(item1.Label, item2.Label, true);
+ {
+ return Util.StringLogicalComparer.Compare(item1.Label, item2.Label);
}
else
{
- {
- return String.Compare(item1.Label, item2.Label, true);
+ {
+ return Util.StringLogicalComparer.Compare(item1.Label, item2.Label);
}
}
}
else
{
if (!UseSortTitle)
- {
- return String.Compare(item2.Label, item1.Label, true);
+ {
+ return Util.StringLogicalComparer.Compare(item2.Label, item1.Label);
}
else
{
- {
- return String.Compare(item2.Label, item1.Label, true);
+ {
+ return Util.StringLogicalComparer.Compare(item2.Label, item1.Label);
}
}
}
@@ -218,12 +226,12 @@ public int Compare(GUIListItem item1, GUIListItem item2)
case SortMethod.Label:
if (SortAscending)
- {
- return String.Compare(item1.DVDLabel, item2.DVDLabel, true);
+ {
+ return Util.StringLogicalComparer.Compare(item1.DVDLabel, item2.DVDLabel);
}
else
- {
- return String.Compare(item2.DVDLabel, item1.DVDLabel, true);
+ {
+ return Util.StringLogicalComparer.Compare(item2.DVDLabel, item1.DVDLabel);
}
case SortMethod.Size:
if (item1.FileInfo == null || item2.FileInfo == null)
@@ -334,26 +342,26 @@ public int Compare(GUIListItem item1, GUIListItem item2)
if (SortAscending)
{
if (!UseSortTitle)
- {
- return String.Compare(item1.Label, item2.Label, true);
+ {
+ return Util.StringLogicalComparer.Compare(item1.Label, item2.Label);
}
else
{
- {
- return String.Compare(item1.Label, item2.Label, true);
+ {
+ return Util.StringLogicalComparer.Compare(item1.Label, item2.Label);
}
}
}
else
{
if (!UseSortTitle)
- {
- return String.Compare(item2.Label, item1.Label, true);
+ {
+ return Util.StringLogicalComparer.Compare(item2.Label, item1.Label);
}
else
{
- {
- return String.Compare(item2.Label, item1.Label, true);
+ {
+ return Util.StringLogicalComparer.Compare(item2.Label, item1.Label);
}
}
}
Oops, something went wrong.

0 comments on commit d444707

Please sign in to comment.