Skip to content

Commit

Permalink
never ending
Browse files Browse the repository at this point in the history
  • Loading branch information
spektor56 committed Jan 20, 2020
1 parent 5f1fcc3 commit 248d341
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 25 deletions.
39 changes: 39 additions & 0 deletions LBGDBMetadata/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace LBGDBMetadata.Extensions
{
public static class StringExtensions
{
public static string Sanitize(this string text)
{
/*
text = Regex.Replace(text, @"(^|\s+){1}II($|\s+){1}", "2", RegexOptions.IgnoreCase);
text = Regex.Replace(text, @"(^|\s+){1}III($|\s+){1}", "3", RegexOptions.IgnoreCase);
text = Regex.Replace(text, @"(^|\s+){1}IV($|\s+){1}", "4", RegexOptions.IgnoreCase);
text = Regex.Replace(text, @"(^|\s+){1}V($|\s+){1}", "5", RegexOptions.IgnoreCase);
text = Regex.Replace(text, @"(^|\s+){1}VI($|\s+){1}", "6", RegexOptions.IgnoreCase);
text = Regex.Replace(text, @"(^|\s+){1}VII($|\s+){1}", "7", RegexOptions.IgnoreCase);
text = Regex.Replace(text, @"(^|\s+){1}VIII($|\s+){1}", "8", RegexOptions.IgnoreCase);
*/

return Regex.Replace(text, @"(((^|\s+){1}|(,\s+){1})the($|\s+){1})|(((^|\s+){1}|(,\s+){1})an($|\s+){1})|(((^|\s+){1}|(,\s+){1})a($|\s+){1})|[^A-Za-z0-9]", "", RegexOptions.IgnoreCase).ToLower();
}

public static string ConvertRomans(this string text)
{
text = Regex.Replace(text, @"(^|\s+){1}II($|\s+){1}", "2", RegexOptions.IgnoreCase);
text = Regex.Replace(text, @"(^|\s+){1}III($|\s+){1}", "3", RegexOptions.IgnoreCase);
text = Regex.Replace(text, @"(^|\s+){1}IV($|\s+){1}", "4", RegexOptions.IgnoreCase);
text = Regex.Replace(text, @"(^|\s+){1}V($|\s+){1}", "5", RegexOptions.IgnoreCase);
text = Regex.Replace(text, @"(^|\s+){1}VI($|\s+){1}", "6", RegexOptions.IgnoreCase);
text = Regex.Replace(text, @"(^|\s+){1}VII($|\s+){1}", "7", RegexOptions.IgnoreCase);
return Regex.Replace(text, @"(^|\s+){1}VIII($|\s+){1}", "8", RegexOptions.IgnoreCase);
}

}
}
3 changes: 2 additions & 1 deletion LBGDBMetadata/LBGDBMetadata.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\..\AppData\Local\Playnite\Extensions\LBGDBMetadata\</OutputPath>
<OutputPath>..\..\..\..\..\AppData\Local\Playnite\Extensions\LBGDBMetadata\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
Expand Down Expand Up @@ -59,6 +59,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Extensions\StreamExtensions.cs" />
<Compile Include="Extensions\StringExtensions.cs" />
<Compile Include="LaunchBox\Api\LbgdbApi.cs" />
<Compile Include="LaunchBox\Api\Options.cs" />
<Compile Include="LaunchBox\Image\ImageType.cs" />
Expand Down
4 changes: 4 additions & 0 deletions LBGDBMetadata/LaunchBox/Regions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public static class Region
public const string SouthAmerica = "South America";
public const string HongKong = "Hong Kong";
public const string Greece = "Greece";
public const string Finland = "Finland";
public const string Holland = "Holland";
public const string Netherlands = "The Netherlands";
public const string Thailand = "Thailand";

}
}
5 changes: 3 additions & 2 deletions LBGDBMetadata/LbgdbLazyMetadataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
using LBGDBMetadata.Extensions;
using LBGDBMetadata.LaunchBox.Metadata;
using Microsoft.EntityFrameworkCore;
using Playnite.SDK.Metadata;
Expand Down Expand Up @@ -99,8 +100,8 @@ private LaunchBox.Metadata.Game GetGame()
{
using (var context = new MetaDataContext())
{
var gameSearchName = Regex.Replace(options.GameData.Name, "[^A-Za-z0-9]", "").ToLower();
var platformSearchName = Regex.Replace(options.GameData.Platform.Name, "[^A-Za-z0-9]", "").ToLower();
var gameSearchName = options.GameData.Name.Sanitize();
var platformSearchName = options.GameData.Platform.Name.Sanitize();
_game = context.Games.FirstOrDefault(game => game.PlatformSearch == platformSearchName && (game.NameSearch == gameSearchName || game.AlternateNames.Any(alternateName => alternateName.NameSearch == gameSearchName)));
return _game;
}
Expand Down
13 changes: 8 additions & 5 deletions LBGDBMetadata/LbgdbMetadataPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,15 @@ private async Task<bool> ImportXml<T>(Stream metaDataStream) where T : class
switch (deserializedObject)
{
case LaunchBox.Metadata.Game game:
game.NameSearch = Regex.Replace(game.Name, "[^A-Za-z0-9]", "").ToLower();
game.PlatformSearch = Regex.Replace(game.Platform, "[^A-Za-z0-9]", "").ToLower();
if(game.CommunityRating != null)
game.NameSearch = game.Name.Sanitize();
game.PlatformSearch = game.Platform.Sanitize();
if (game.CommunityRating != null)
{
game.CommunityRating = Math.Round(((decimal)game.CommunityRating / 5) * 100, 0);
}
break;
case GameAlternateName game:
game.NameSearch = Regex.Replace(game.AlternateName, "[^A-Za-z0-9]", "").ToLower();
game.NameSearch = game.AlternateName.Sanitize();
break;
}

Expand Down Expand Up @@ -196,6 +196,7 @@ public void UpdateMetadata(string filename)
entry.Name.Equals("MetaData.xml", StringComparison.OrdinalIgnoreCase));

if (metaData != null)
{
using (var metaDataStream = metaData.Open())
{
var games = metaDataStream.AsEnumerableXml("Game");
Expand All @@ -207,7 +208,8 @@ public void UpdateMetadata(string filename)

foreach (var xElement in games)
{
var gameMetaData = (LaunchBox.Metadata.Game)xmlSerializer.Deserialize(xElement.CreateReader());
var gameMetaData =
(LaunchBox.Metadata.Game) xmlSerializer.Deserialize(xElement.CreateReader());
i++;
if (i++ > 1000)
{
Expand All @@ -223,6 +225,7 @@ public void UpdateMetadata(string filename)

context.Dispose();
}
}
}
}

Expand Down
19 changes: 2 additions & 17 deletions LBGDBMetadata/LbgdbMetadataSettingsView.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO.Compression;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Xml;
using System.Xml.Serialization;
using LBGDBMetadata.LaunchBox.Metadata;


namespace LBGDBMetadata
Expand Down Expand Up @@ -54,8 +39,8 @@ private async void Button_Click(object sender, RoutedEventArgs e)

private async void UserControl_Loaded(object sender, RoutedEventArgs e)
{
btnRefresh.IsEnabled = true;
//btnRefresh.IsEnabled = await _plugin.NewMetadataAvailable();
//btnRefresh.IsEnabled = true;
btnRefresh.IsEnabled = await _plugin.NewMetadataAvailable();
}
}
}

0 comments on commit 248d341

Please sign in to comment.