Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Knossos.NET/Classes/KnUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Runtime.Intrinsics.X86;
using System.Text;
using System.Text.Json;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Security.Cryptography;
Expand Down Expand Up @@ -951,6 +952,20 @@ public static string EscapeUnderscores(string? text)
return text.Replace("_", "__");
}

/// <summary>
/// Gets rid of 'A', 'An', and 'The' at the beginning of a string, case-insensitively
/// </summary>
/// <param name="text">A string</param>
/// <returns>The string with any articles removed from the beginning</returns>
public static string RemoveArticles(string title)
{
var match = Regex.Match(title, "((A)|(An)|(The))\\s+", RegexOptions.IgnoreCase);
if (match.Index == 0 && match.Length > 0)
return title.Substring(match.Length);
else
return title;
}

/// <summary>
/// Checks if a file is currently in use
/// </summary>
Expand Down
16 changes: 13 additions & 3 deletions Knossos.NET/Models/Mod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -779,19 +779,18 @@ public async Task LoadFulLNebulaData()

/// <summary>
/// To use with the List .Sort()
/// Retuns a list that is sort from older to newer
/// Orders the two mods from older to newer
/// </summary>
/// <param name="mod1"></param>
/// <param name="mod2"></param>
public static int CompareVersion(Mod mod1, Mod mod2)
{
//inverted
return SemanticVersion.Compare(mod1.version, mod2.version);
}

/// <summary>
/// To use with the List .Sort()
/// Retuns a list that is sort from newer to older
/// Orders the two mods from newer to older
/// </summary>
/// <param name="mod1"></param>
/// <param name="mod2"></param>
Expand All @@ -801,6 +800,17 @@ public static int CompareVersionNewerToOlder(Mod mod1, Mod mod2)
return SemanticVersion.Compare(mod2.version, mod1.version);
}

/// <summary>
/// To use with the List .Sort()
/// Orders the two titles using a regular case-insensitive string comparison, but ignoring any leading 'A', 'An', or 'The' articles
/// </summary>
/// <param name="title1"></param>
/// <param name="title2"></param>
public static int CompareTitles(string title1, string title2)
{
return String.Compare(KnUtils.RemoveArticles(title1), KnUtils.RemoveArticles(title2), StringComparison.CurrentCultureIgnoreCase);
}

/// <summary>
/// Compares two mods and determines if the metadata is different
/// Full data must be loaded on both mods for this to work properly
Expand Down
2 changes: 1 addition & 1 deletion Knossos.NET/ViewModels/ModListViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ private int CompareMods(Mod modA,Mod modB)
switch (sortType)
{
case MainWindowViewModel.SortType.name:
return String.Compare(modA.title, modB.title);
return Mod.CompareTitles(modA.title, modB.title);
case MainWindowViewModel.SortType.release:
if (modA.firstRelease == modB.firstRelease)
return 0;
Expand Down
4 changes: 2 additions & 2 deletions Knossos.NET/ViewModels/NebulaModListViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ private int CompareMods(Mod modA,Mod modB)
switch (sortType)
{
case MainWindowViewModel.SortType.name:
return String.Compare(modA.title, modB.title);
return Mod.CompareTitles(modA.title, modB.title);
case MainWindowViewModel.SortType.release:
if (modA.firstRelease == modB.firstRelease)
return 0;
Expand Down Expand Up @@ -370,7 +370,7 @@ private int CompareMods(Mod modA,Mod modB)
return 0;
}
}

/// <summary>
/// Changes a modcard to "installing" mode
/// </summary>
Expand Down