Skip to content

Commit

Permalink
Merge branch 'master' into l10n_master
Browse files Browse the repository at this point in the history
  • Loading branch information
HerrKnarz authored Feb 7, 2024
2 parents 53371cc + 1b6fa61 commit 0f364d7
Show file tree
Hide file tree
Showing 15 changed files with 636 additions and 244 deletions.
1 change: 1 addition & 0 deletions Generic/MetadataUtilities/Localization/LocSource.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<sys:String x:Key="LOCMetadataUtilitiesEditorChangeType">Change type</sys:String>
<sys:String x:Key="LOCMetadataUtilitiesEditorFilterSelected">Only selected</sys:String>
<sys:String x:Key="LOCMetadataUtilitiesEditorGameCount">Game Count</sys:String>
<sys:String x:Key="LOCMetadataUtilitiesEditorGroupMatches">Group matches</sys:String>
<sys:String x:Key="LOCMetadataUtilitiesEditorMerge">Merge</sys:String>
<sys:String x:Key="LOCMetadataUtilitiesEditorRelatedGames">Related games</sys:String>
<sys:String x:Key="LOCMetadataUtilitiesEditorRemoveUnused">Remove unused</sys:String>
Expand Down
2 changes: 1 addition & 1 deletion Generic/MetadataUtilities/Localization/en_US.xaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0"?>
<?xml version="1.0"?>
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:sys="clr-namespace:System;assembly=mscorlib">
<sys:String x:Key="LOCMetadataUtilitiesDialogAddNewObject">Add new object</sys:String>
<sys:String x:Key="LOCMetadataUtilitiesDialogAddedDefaultsMessage">Added default categories/tags to {0} games!</sys:String>
Expand Down
28 changes: 27 additions & 1 deletion Generic/MetadataUtilities/MetadataUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Forms;
using System.Windows.Media;
using MergeAction = MetadataUtilities.Actions.MergeAction;
using UserControl = System.Windows.Controls.UserControl;

namespace MetadataUtilities
{
Expand Down Expand Up @@ -60,13 +63,22 @@ public override void OnLibraryUpdated(OnLibraryUpdatedEventArgs args)
SavePluginSettings(Settings.Settings);
}


public override void OnApplicationStarted(OnApplicationStartedEventArgs args)
{
base.OnApplicationStarted(args);

if (Settings.Settings.RemoveUnusedOnStartup)
{
MetadataListObjects.RemoveUnusedMetadata(true, Settings.Settings.IgnoreHiddenGamesInRemoveUnused);
Cursor.Current = Cursors.WaitCursor;
try
{
MetadataListObjects.RemoveUnusedMetadata(true, Settings.Settings.IgnoreHiddenGamesInRemoveUnused);
}
finally
{
Cursor.Current = Cursors.Default;
}
}
}

Expand Down Expand Up @@ -111,6 +123,7 @@ private void DoForAll(List<Game> games, BaseAction action, bool showDialog = fal
{
IsUpdating = true;

Cursor.Current = Cursors.WaitCursor;
try
{
if (games.Count == 1)
Expand Down Expand Up @@ -171,18 +184,24 @@ private void DoForAll(List<Game> games, BaseAction action, bool showDialog = fal
// Shows a dialog with the number of games actually affected.
if (showDialog)
{
Cursor.Current = Cursors.Default;
PlayniteApi.Dialogs.ShowMessage(string.Format(ResourceProvider.GetString(action.ResultMessage), gamesAffected));
}
}
}
finally
{
IsUpdating = false;
Cursor.Current = Cursors.Default;
}
}

private void ShowEditor()
{
Log.Debug("=== ShowEditor: Start ===");
DateTime ts = DateTime.Now;

Cursor.Current = Cursors.WaitCursor;
try
{
MetadataListObjects metadataListObjects = new MetadataListObjects(Settings.Settings);
Expand All @@ -195,12 +214,19 @@ private void ShowEditor()
Window window = WindowHelper.CreateSizedWindow(ResourceProvider.GetString("LOCMetadataUtilitiesEditor"), Settings.Settings.EditorWindowWidth, Settings.Settings.EditorWindowHeight);
window.Content = editorView;
window.DataContext = viewModel;

Log.Debug($"=== ShowEditor: Show Dialog ({(DateTime.Now - ts).TotalMilliseconds} ms) ===");

window.ShowDialog();
}
catch (Exception exception)
{
Log.Error(exception, "Error during initializing Metadata Editor", true);
}
finally
{
Cursor.Current = Cursors.Default;
}
}

public override IEnumerable<TopPanelItem> GetTopPanelItems()
Expand Down
24 changes: 24 additions & 0 deletions Generic/MetadataUtilities/Models/MetadataListObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
using Playnite.SDK.Data;
using Playnite.SDK.Models;
using System;
using System.Collections.Generic;
using System.Linq;

namespace MetadataUtilities.Models
{
public class MetadataListObject : DatabaseObject
{
private string _cleanedUpName;
private string _editName;
private int _gameCount;
private bool _selected;
private bool _showGrouped;
private FieldType _type;

[DontSerialize]
Expand All @@ -37,6 +40,13 @@ public FieldType Type
set => SetValue(ref _type, value);
}

[DontSerialize]
public string CleanedUpName
{
get => _cleanedUpName;
set => SetValue(ref _cleanedUpName, value);
}

[DontSerialize]
public string EditName
{
Expand Down Expand Up @@ -67,6 +77,8 @@ public string EditName
Name = value;
}

CleanedUpName = Name.RemoveDiacritics().RemoveSpecialChars().ToLower().Replace("-", "").Replace(" ", "");

OnPropertyChanged();
}
}
Expand All @@ -77,6 +89,13 @@ public string EditName
[DontSerialize]
public string TypeLabel => Type.GetEnumDisplayName("MetadataUtilities");

[DontSerialize]
public bool ShowGrouped
{
get => _showGrouped;
set => SetValue(ref _showGrouped, value);
}

public void GetGameCount(bool ignoreHiddenGames = false)
{
switch (Type)
Expand All @@ -100,5 +119,10 @@ public void GetGameCount(bool ignoreHiddenGames = false)
throw new ArgumentOutOfRangeException();
}
}

public void CheckGroup(List<MetadataListObject> metadataList)
{
ShowGrouped = metadataList.Any(x => x.CleanedUpName == CleanedUpName && x != this);
}
}
}
26 changes: 21 additions & 5 deletions Generic/MetadataUtilities/Models/MetadataListObjects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public class MetadataListObjects : ObservableCollection<MetadataListObject>

public void LoadMetadata(bool showGameNumber = true, FieldType? type = null)
{
Log.Debug("=== LoadMetadata: Start ===");
DateTime ts = DateTime.Now;

List<MetadataListObject> temporaryList = new List<MetadataListObject>();

GlobalProgressOptions globalProgressOptions = new GlobalProgressOptions(
Expand All @@ -38,7 +41,6 @@ public void LoadMetadata(bool showGameNumber = true, FieldType? type = null)
=> new MetadataListObject
{
Id = category.Id,
Name = category.Name,
EditName = category.Name,
Type = FieldType.Category
}));
Expand All @@ -50,7 +52,6 @@ public void LoadMetadata(bool showGameNumber = true, FieldType? type = null)
=> new MetadataListObject
{
Id = feature.Id,
Name = feature.Name,
EditName = feature.Name,
Type = FieldType.Feature
}));
Expand All @@ -62,7 +63,6 @@ public void LoadMetadata(bool showGameNumber = true, FieldType? type = null)
=> new MetadataListObject
{
Id = genre.Id,
Name = genre.Name,
EditName = genre.Name,
Type = FieldType.Genre
}));
Expand All @@ -74,7 +74,6 @@ public void LoadMetadata(bool showGameNumber = true, FieldType? type = null)
=> new MetadataListObject
{
Id = series.Id,
Name = series.Name,
EditName = series.Name,
Type = FieldType.Series
}));
Expand All @@ -86,7 +85,6 @@ public void LoadMetadata(bool showGameNumber = true, FieldType? type = null)
=> new MetadataListObject
{
Id = tag.Id,
Name = tag.Name,
EditName = tag.Name,
Type = FieldType.Tag
}));
Expand All @@ -105,6 +103,7 @@ public void LoadMetadata(bool showGameNumber = true, FieldType? type = null)

Clear();
this.AddMissing(temporaryList.OrderBy(x => x.TypeLabel).ThenBy(x => x.Name));
Log.Debug($"=== LoadMetadata: End ({(DateTime.Now - ts).TotalMilliseconds} ms) ===");
}

public static List<MetadataListObject> RemoveUnusedMetadata(bool AutoMode = false, bool ignoreHiddenGames = false)
Expand Down Expand Up @@ -212,6 +211,9 @@ public static List<MetadataListObject> RemoveUnusedMetadata(bool AutoMode = fals

public static void UpdateGameCounts(List<MetadataListObject> itemList, bool ignoreHiddenGames)
{
Log.Debug("=== UpdateGameCounts: Start ===");
DateTime ts = DateTime.Now;

ConcurrentQueue<Guid> items = new ConcurrentQueue<Guid>();

ParallelOptions opts = new ParallelOptions { MaxDegreeOfParallelism = Convert.ToInt32(Math.Ceiling(Environment.ProcessorCount * 0.75 * 2.0)) };
Expand Down Expand Up @@ -256,6 +258,20 @@ public static void UpdateGameCounts(List<MetadataListObject> itemList, bool igno

item.GameCount = count;
});

Log.Debug($"=== UpdateGameCounts: End ({(DateTime.Now - ts).TotalMilliseconds} ms) ===");
}

public static void UpdateGroupDisplay(List<MetadataListObject> itemList)
{
Log.Debug("=== UpdateGroupDisplay: Start ===");
DateTime ts = DateTime.Now;

ParallelOptions opts = new ParallelOptions { MaxDegreeOfParallelism = Convert.ToInt32(Math.Ceiling(Environment.ProcessorCount * 0.75 * 2.0)) };

Parallel.ForEach(itemList, opts, item => item.CheckGroup(itemList));

Log.Debug($"=== UpdateGroupDisplay: End ({(DateTime.Now - ts).TotalMilliseconds} ms) ===");
}

public bool MergeItems(FieldType type, Guid id)
Expand Down
2 changes: 1 addition & 1 deletion Generic/MetadataUtilities/Models/MyGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ public class MyGame

public int? ReleaseYear { get; set; }

public string RealSortingName => string.IsNullOrWhiteSpace(SortingName) ? Name : SortingName;
public string RealSortingName => string.IsNullOrEmpty(SortingName) ? Name : SortingName;
}
}
4 changes: 2 additions & 2 deletions Generic/MetadataUtilities/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.4.0.0")]
[assembly: AssemblyFileVersion("0.4.0.0")]
[assembly: AssemblyVersion("0.4.1.0")]
[assembly: AssemblyFileVersion("0.4.1.0")]
74 changes: 40 additions & 34 deletions Generic/MetadataUtilities/ViewModels/ChangeTypeViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Forms;

namespace MetadataUtilities
{
Expand Down Expand Up @@ -57,52 +58,57 @@ public bool SaveAsRule

public RelayCommand<Window> OkCommand => new RelayCommand<Window>(win =>
{
foreach (MetadataListObject item in _metadataListObjects)
Cursor.Current = Cursors.WaitCursor;
try
{
if (item.Type == NewType)
foreach (MetadataListObject item in _metadataListObjects)
{
continue;
}
if (item.Type == NewType)
{
continue;
}

Guid newId = DatabaseObjectHelper.AddDbObject(NewType, item.Name);
Guid newId = DatabaseObjectHelper.AddDbObject(NewType, item.Name);

DatabaseObjectHelper.ReplaceDbObject(item.Type, item.Id, NewType, newId);
DatabaseObjectHelper.ReplaceDbObject(item.Type, item.Id, NewType, newId);

NewObjects.Add(new MetadataListObject
{
Type = NewType,
Name = item.Name,
EditName = item.EditName,
Id = newId
});
NewObjects.Add(new MetadataListObject
{
Type = NewType,
EditName = item.EditName,
Id = newId
});

if (!SaveAsRule)
{
continue;
}
if (!SaveAsRule)
{
continue;
}

MergeRule rule = new MergeRule
{
Type = NewType,
Name = item.Name,
EditName = item.EditName,
Id = newId,
SourceObjects = new ObservableCollection<MetadataListObject>
MergeRule rule = new MergeRule
{
new MetadataListObject
Type = NewType,
EditName = item.EditName,
Id = newId,
SourceObjects = new ObservableCollection<MetadataListObject>
{
Type = item.Type,
Name = item.Name,
EditName = item.EditName,
Id = item.Id
new MetadataListObject
{
Type = item.Type,
EditName = item.EditName,
Id = item.Id
}
}
}
};
};

_plugin.Settings.Settings.MergeRules.AddRule(rule);
}
_plugin.Settings.Settings.MergeRules.AddRule(rule);
}

_plugin.SavePluginSettings(_plugin.Settings.Settings);
_plugin.SavePluginSettings(_plugin.Settings.Settings);
}
finally
{
Cursor.Current = Cursors.Default;
}

win.DialogResult = true;
win.Close();
Expand Down
Loading

0 comments on commit 0f364d7

Please sign in to comment.