Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

0004143: Numeric String sorting uses alphanumerical algorithm

  • Loading branch information...
commit d4447075cdb09a07140232d08da1a657e05212fb 1 parent d5f87ef
@dedahr dedahr authored
View
8 TvEngine3/TVLibrary/SetupControls/UserInterfaceControls/ImageTextComparer.cs
@@ -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;
}
View
6 TvEngine3/TVLibrary/SetupControls/UserInterfaceControls/ListViewItemComparer.cs
@@ -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);
}
}
View
8 TvEngine3/TVLibrary/SetupControls/UserInterfaceControls/MPListViewStringColumnSorter.cs
@@ -19,6 +19,7 @@
#endregion
using System;
+using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Collections;
@@ -26,6 +27,9 @@ 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;
View
37 mediaportal/Core/Util/Util.cs
@@ -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);
+ }
+ }
}
View
40 mediaportal/WindowPlugins/GUIMusic/MusicSort.cs
@@ -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:
View
6 mediaportal/WindowPlugins/GUIPictures/GUIPictures.cs
@@ -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);
}
View
50 mediaportal/WindowPlugins/GUIPictures/PictureSort.cs
@@ -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);
}
}
}
View
41 mediaportal/WindowPlugins/GUIVideoFiles/GUIVideoFiles.cs
@@ -3319,6 +3319,12 @@ private void OnPlayAll(string path)
// Get all video files in selected folder and it's subfolders
ArrayList playFiles = new ArrayList();
AddVideoFiles(path, ref playFiles);
+
+ if(playFiles.Count == 0)
+ {
+ return;
+ }
+
int selectedOption = 0;
GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_MENU);
@@ -3364,21 +3370,28 @@ private void OnPlayAll(string path)
//
case 0: // By name == 103
case 103:
- IOrderedEnumerable<object> sortedPlayList = GetSortedPlayListbyName(playFiles);
- // Add all files in temporary playlist
- AddToPlayList(tmpPlayList, sortedPlayList);
+ AddToPlayList(tmpPlayList, playFiles.ToArray());
+ List<PlayListItem> sortedPlayListItems = new List<PlayListItem>();
+ sortedPlayListItems.AddRange(tmpPlayList);
+ sortedPlayListItems.Sort((item1, item2) => StringLogicalComparer.Compare(item1.Description, item2.Description));
+ tmpPlayList.Clear();
+
+ foreach (PlayListItem playListItem in sortedPlayListItems)
+ {
+ tmpPlayList.Add(playListItem);
+ }
+
break;
case 1: // By date (date modified) == 104
case 104:
- sortedPlayList = GetSortedPlayListbyDate(playFiles);
+ IOrderedEnumerable<object> sortedPlayList = playFiles.ToArray().OrderBy(fn => new FileInfo((string)fn).LastWriteTime);
AddToPlayList(tmpPlayList, sortedPlayList);
break;
case 2: // Shuffle == 191
case 191:
- sortedPlayList = GetSortedPlayListbyName(playFiles);
- AddToPlayList(tmpPlayList, sortedPlayList);
+ AddToPlayList(tmpPlayList, playFiles.ToArray());
tmpPlayList.Shuffle();
break;
}
@@ -3386,7 +3399,7 @@ private void OnPlayAll(string path)
PlayMovieFromPlayList(false, true);
}
- private void AddToPlayList(PlayList tmpPlayList, IOrderedEnumerable<object> sortedPlayList)
+ private void AddToPlayList(PlayList tmpPlayList, IEnumerable<object> sortedPlayList)
{
foreach (string file in sortedPlayList)
{
@@ -3424,19 +3437,7 @@ private void AddToPlayList(PlayList tmpPlayList, IOrderedEnumerable<object> sort
tmpPlayList.Add(newItem);
}
}
-
- // Sort by item description (Filename or DVD folder)
- private IOrderedEnumerable<object> GetSortedPlayListbyName(ArrayList playFiles)
- {
- return playFiles.ToArray().OrderBy(fn => new PlayListItem().Description);
- }
-
- // Sort by modified date without path
- private IOrderedEnumerable<object> GetSortedPlayListbyDate(ArrayList playFiles)
- {
- return playFiles.ToArray().OrderBy(fn => new FileInfo((string)fn).LastWriteTime);
- }
-
+
/// <summary>
/// Adds file (full path) and it's stacked parts (method will search
/// for them inside strFile folder) into videodatabase (movie table)
View
40 mediaportal/WindowPlugins/GUIVideoFiles/VideoSort.cs
@@ -21,8 +21,10 @@
using System;
using System.Collections.Generic;
using System.Globalization;
+using System.Runtime.InteropServices;
using MediaPortal.GUI.Library;
using MediaPortal.Profile;
+using MediaPortal.Util;
using MediaPortal.Video.Database;
namespace MediaPortal.GUI.Video
@@ -59,7 +61,15 @@ public VideoSort(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;
+ }
}
}
@@ -178,17 +188,17 @@ public int Compare(GUIListItem item1, GUIListItem item2)
{
if (!UseSortTitle)
{
- return String.Compare(item1.Label, item2.Label, true);
+ return Util.StringLogicalComparer.Compare(item1.Label, item2.Label);
}
else
{
if (movie1 != null && movie2 != null && movie1.ID > 0 && movie2.ID > 0)
{
- return String.Compare(movie1.SortTitle, movie2.SortTitle, true);
+ return Util.StringLogicalComparer.Compare(movie1.SortTitle, movie2.SortTitle);
}
else
{
- return String.Compare(item1.Label, item2.Label, true);
+ return Util.StringLogicalComparer.Compare(item1.Label, item2.Label);
}
}
}
@@ -196,17 +206,17 @@ public int Compare(GUIListItem item1, GUIListItem item2)
{
if (!UseSortTitle)
{
- return String.Compare(item2.Label, item1.Label, true);
+ return Util.StringLogicalComparer.Compare(item2.Label, item1.Label);
}
else
{
if (movie1 != null && movie2 != null && movie1.ID > 0 && movie2.ID > 0)
{
- return String.Compare(movie2.SortTitle, movie1.SortTitle, true);
+ return Util.StringLogicalComparer.Compare(movie2.SortTitle, movie1.SortTitle);
}
else
{
- return String.Compare(item2.Label, item1.Label, true);
+ return Util.StringLogicalComparer.Compare(item2.Label, item1.Label);
}
}
}
@@ -251,11 +261,11 @@ 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)
@@ -370,17 +380,17 @@ public int Compare(GUIListItem item1, GUIListItem item2)
{
if (!UseSortTitle)
{
- return String.Compare(item1.Label, item2.Label, true);
+ return Util.StringLogicalComparer.Compare(item1.Label, item2.Label);
}
else
{
if (movie1 != null && movie2 != null && movie1.ID > 0 && movie2.ID > 0)
{
- return String.Compare(movie1.SortTitle, movie2.SortTitle, true);
+ return Util.StringLogicalComparer.Compare(movie1.SortTitle, movie2.SortTitle);
}
else
{
- return String.Compare(item1.Label, item2.Label, true);
+ return Util.StringLogicalComparer.Compare(item1.Label, item2.Label);
}
}
}
@@ -388,17 +398,17 @@ public int Compare(GUIListItem item1, GUIListItem item2)
{
if (!UseSortTitle)
{
- return String.Compare(item2.Label, item1.Label, true);
+ return Util.StringLogicalComparer.Compare(item2.Label, item1.Label);
}
else
{
if (movie1 != null && movie2 != null && movie1.ID > 0 && movie2.ID > 0)
{
- return String.Compare(movie2.SortTitle, movie1.SortTitle, true);
+ return Util.StringLogicalComparer.Compare(movie2.SortTitle, movie1.SortTitle);
}
else
{
- return String.Compare(item2.Label, item1.Label, true);
+ return Util.StringLogicalComparer.Compare(item2.Label, item1.Label);
}
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.