Skip to content

Commit

Permalink
parse no-intro regions
Browse files Browse the repository at this point in the history
  • Loading branch information
spektor56 committed Oct 3, 2020
1 parent 7e38693 commit f30a4ef
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
22 changes: 22 additions & 0 deletions LBGDBMetadata/LaunchBox/Region.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using LBGDBMetadata.Extensions;

namespace LBGDBMetadata.LaunchBox
Expand Down Expand Up @@ -35,6 +36,25 @@ public static class Region
public const string UnitedStates = "United States";
public const string World = "World";

private static readonly Regex NoIntroTags = new Regex(@"(?<=\()([\w\s]+,?)+(?=\))", RegexOptions.IgnoreCase | RegexOptions.Compiled);

public static string GetRegionNoIntro(this string text)
{
var tagGroups = NoIntroTags.Matches(text);
foreach (Match tagGroup in tagGroups)
{
var regionList = tagGroup.Value.Split(',').Select(region => region.Sanitize())
.Where(region => !string.IsNullOrWhiteSpace(region)).Distinct().ToList();

if (regionList.All(region => RegionList.ContainsKey(region)))
{
return string.Join(",",regionList);
}
}

return "";
}

public static List<string> GetRegions(this string region)
{
List<string> regionList = new List<string>();
Expand Down Expand Up @@ -94,6 +114,8 @@ private static void GetRegionPriority(string region, Dictionary<string, int> reg
}
}



private static readonly Dictionary<string, RegionInfo> RegionList = new Dictionary<string, RegionInfo>
{
//{"NA",new RegionInfo("Namibia","africa")},
Expand Down
17 changes: 14 additions & 3 deletions LBGDBMetadata/LbgdbMetadataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class LbgdbMetadataProvider : OnDemandMetadataProvider
private readonly LbgdbMetadataPlugin _plugin;
private Game _game;
private Dictionary<string, int> _regionPriority = new Dictionary<string, int>();

public LbgdbMetadataProvider(MetadataRequestOptions options, LbgdbMetadataPlugin plugin)
{
_options = options;
Expand Down Expand Up @@ -81,12 +81,23 @@ private Game GetGame()

if (!string.IsNullOrWhiteSpace(gameSearchName))
{
if (_options?.GameData?.Region != null && _regionPriority.Count < 1)
if (_options?.GameData != null && _regionPriority.Count < 1)
{
if (!string.IsNullOrWhiteSpace(_options.GameData.Region.Name))
if (_options.GameData.Region != null && !string.IsNullOrWhiteSpace(_options.GameData.Region.Name))
{
_regionPriority = _options.GameData.Region.Name.GetRegionPriorityList();
}
else
{
if (!string.IsNullOrWhiteSpace(_options.GameData.GameImagePath))
{
var noIntoRegion = _options.GameData.GameImagePath.GetRegionNoIntro();
if (!string.IsNullOrWhiteSpace(noIntoRegion))
{
_regionPriority = noIntoRegion.GetRegionPriorityList();
}
}
}
}

var platformSearchName = "";
Expand Down

0 comments on commit f30a4ef

Please sign in to comment.