diff --git a/Source/LinkActions/AddLibraryLinks.cs b/Source/LinkActions/AddLibraryLinks.cs
index a09889a27..cd753b6a1 100644
--- a/Source/LinkActions/AddLibraryLinks.cs
+++ b/Source/LinkActions/AddLibraryLinks.cs
@@ -6,25 +6,22 @@ namespace LinkUtilities.LinkActions
///
/// Adds a link to the game store page of the library (e.g. steam or gog) the game is part of.
///
- public class AddLibraryLinks : ILinkAction
+ public class AddLibraryLinks : LinkAction
{
///
/// contains all game libraries that have a link to a store page that can be added.
///
private readonly Libraries libraries;
- public string ProgressMessage { get; } = "LOCLinkUtilitiesProgressLibraryLink";
- public string ResultMessage { get; } = "LOCLinkUtilitiesDialogAddedMessage";
- public LinkUtilitiesSettings Settings { get; set; }
+ public override string ProgressMessage { get; } = "LOCLinkUtilitiesProgressLibraryLink";
+ public override string ResultMessage { get; } = "LOCLinkUtilitiesDialogAddedMessage";
- public AddLibraryLinks(LinkUtilitiesSettings settings)
+ public AddLibraryLinks(LinkUtilities plugin) : base(plugin)
{
- Settings = settings;
-
- libraries = new Libraries(Settings);
+ libraries = new Libraries(Plugin);
}
- public bool Execute(Game game, string actionModifier = "")
+ public override bool Execute(Game game, string actionModifier = "")
{
ILibraryLink library;
bool result = false;
diff --git a/Source/LinkActions/AddWebsiteLinks.cs b/Source/LinkActions/AddWebsiteLinks.cs
index b0f0c4830..b7fe8dc81 100644
--- a/Source/LinkActions/AddWebsiteLinks.cs
+++ b/Source/LinkActions/AddWebsiteLinks.cs
@@ -6,25 +6,22 @@ namespace LinkUtilities.LinkActions
///
/// Class to add a link to all available websites in the Links list, if a definitive link was found.
///
- public class AddWebsiteLinks : ILinkAction
+ public class AddWebsiteLinks : LinkAction
{
///
/// contains all website Links that can be added.
///
public readonly Links Links;
- public string ProgressMessage { get; } = "LOCLinkUtilitiesProgressWebsiteLink";
- public string ResultMessage { get; } = "LOCLinkUtilitiesDialogAddedMessage";
- public LinkUtilitiesSettings Settings { get; set; }
+ public override string ProgressMessage { get; } = "LOCLinkUtilitiesProgressWebsiteLink";
+ public override string ResultMessage { get; } = "LOCLinkUtilitiesDialogAddedMessage";
- public AddWebsiteLinks(LinkUtilitiesSettings settings)
+ public AddWebsiteLinks(LinkUtilities plugin) : base(plugin)
{
- Settings = settings;
-
- Links = new Links(Settings);
+ Links = new Links(Plugin);
}
- public bool Execute(Game game, string actionModifier = "")
+ public override bool Execute(Game game, string actionModifier = "")
{
bool result = false;
diff --git a/Source/LinkActions/ILinkAction.cs b/Source/LinkActions/ILinkAction.cs
index 2cf22cb19..016b7947b 100644
--- a/Source/LinkActions/ILinkAction.cs
+++ b/Source/LinkActions/ILinkAction.cs
@@ -17,9 +17,9 @@ public interface ILinkAction
///
string ResultMessage { get; }
///
- /// Settings to use for the action
+ /// instance of the extension to access settings etc.
///
- LinkUtilitiesSettings Settings { get; set; }
+ LinkUtilities Plugin { get; }
///
/// Executes the action on a game.
diff --git a/Source/LinkActions/LinkAction.cs b/Source/LinkActions/LinkAction.cs
new file mode 100644
index 000000000..2193fa819
--- /dev/null
+++ b/Source/LinkActions/LinkAction.cs
@@ -0,0 +1,21 @@
+using Playnite.SDK.Models;
+
+namespace LinkUtilities.LinkActions
+{
+ public abstract class LinkAction : ILinkAction
+ {
+ public abstract string ProgressMessage { get; }
+
+ public abstract string ResultMessage { get; }
+
+ private readonly LinkUtilities plugin;
+ public LinkUtilities Plugin { get { return plugin; } }
+
+ public abstract bool Execute(Game game, string actionModifier = "");
+
+ public LinkAction(LinkUtilities plugin)
+ {
+ this.plugin = plugin;
+ }
+ }
+}
diff --git a/Source/LinkActions/SortLinks.cs b/Source/LinkActions/SortLinks.cs
index 7e07946d4..85e51019c 100644
--- a/Source/LinkActions/SortLinks.cs
+++ b/Source/LinkActions/SortLinks.cs
@@ -5,18 +5,16 @@ namespace LinkUtilities.LinkActions
///
/// Sorts the Links of a game.
///
- public class SortLinks : ILinkAction
+ public class SortLinks : LinkAction
{
- public string ProgressMessage { get; } = "LOCLinkUtilitiesProgressSortLinks";
- public string ResultMessage { get; } = "LOCLinkUtilitiesDialogSortedMessage";
- public LinkUtilitiesSettings Settings { get; set; }
-
- public SortLinks(LinkUtilitiesSettings settings)
+ public SortLinks(LinkUtilities plugin) : base(plugin)
{
- Settings = settings;
}
- public bool Execute(Game game, string actionModifier = "")
+ public override string ProgressMessage { get; } = "LOCLinkUtilitiesProgressSortLinks";
+ public override string ResultMessage { get; } = "LOCLinkUtilitiesDialogSortedMessage";
+
+ public override bool Execute(Game game, string actionModifier = "")
{
return LinkHelper.SortLinks(game);
}
diff --git a/Source/LinkUtilities.cs b/Source/LinkUtilities.cs
index 308c74160..0564e35a1 100644
--- a/Source/LinkUtilities.cs
+++ b/Source/LinkUtilities.cs
@@ -24,9 +24,9 @@ public LinkUtilities(IPlayniteAPI api) : base(api)
HasSettings = true
};
- sortLinks = new SortLinks(Settings.Settings);
- addLibraryLinks = new AddLibraryLinks(Settings.Settings);
- addWebsiteLinks = new AddWebsiteLinks(Settings.Settings);
+ sortLinks = new SortLinks(this);
+ addLibraryLinks = new AddLibraryLinks(this);
+ addWebsiteLinks = new AddWebsiteLinks(this);
IsUpdating = false;
PlayniteApi.UriHandler.RegisterSource("LinkUtilities", (args) =>
@@ -53,6 +53,10 @@ public LinkUtilities(IPlayniteAPI api) : base(api)
/// Class to add a link to all available websites in the Links list, if a definitive link was found.
///
private readonly AddWebsiteLinks addWebsiteLinks;
+ ///
+ /// Class to add a link to all available websites in the Links list, if a definitive link was found.
+ ///
+ public AddWebsiteLinks AddWebsiteLinks { get; }
///
/// Is set to true, while the library is updated via the sortLinks function. Is used to avoid an endless loop in the function.
diff --git a/Source/LinkUtilities.csproj b/Source/LinkUtilities.csproj
index e426fea0c..239d34ff5 100644
--- a/Source/LinkUtilities.csproj
+++ b/Source/LinkUtilities.csproj
@@ -55,6 +55,7 @@
+
@@ -84,6 +85,7 @@
LinkUtilitiesSettingsView.xaml
+
diff --git a/Source/Linker/ILink.cs b/Source/Linker/ILink.cs
index 7e107baa6..c836ffd02 100644
--- a/Source/Linker/ILink.cs
+++ b/Source/Linker/ILink.cs
@@ -20,9 +20,9 @@ interface ILink
///
string LinkUrl { get; set; }
///
- /// Settings to be used
+ /// instance of the extension to access settings etc.
///
- LinkUtilitiesSettings Settings { get; set; }
+ LinkUtilities Plugin { get; }
///
/// Adds a link to the specific game page of the specified website.
diff --git a/Source/Linker/Libraries.cs b/Source/Linker/Libraries.cs
index 663f65a02..73b50cc7c 100644
--- a/Source/Linker/Libraries.cs
+++ b/Source/Linker/Libraries.cs
@@ -7,13 +7,13 @@ namespace LinkUtilities.Linker
///
class Libraries : List
{
- public Libraries(LinkUtilitiesSettings settings)
+ public Libraries(LinkUtilities plugin)
{
- Add(new LibraryLinkSteam(settings));
- Add(new LibraryLinkGog(settings));
- if (!string.IsNullOrWhiteSpace(settings.ItchApiKey))
+ Add(new LibraryLinkSteam(plugin));
+ Add(new LibraryLinkGog(plugin));
+ if (!string.IsNullOrWhiteSpace(plugin.Settings.Settings.ItchApiKey))
{
- Add(new LibraryLinkItch(settings));
+ Add(new LibraryLinkItch(plugin));
}
}
}
diff --git a/Source/Linker/Libraries/LibraryLinkGog.cs b/Source/Linker/Libraries/LibraryLinkGog.cs
index 5546f6643..2baf95b60 100644
--- a/Source/Linker/Libraries/LibraryLinkGog.cs
+++ b/Source/Linker/Libraries/LibraryLinkGog.cs
@@ -47,7 +47,7 @@ public override bool AddLibraryLink(Game game)
LinkUrl = $"{BaseUrl}{gogMetaData.Slug}";
- return LinkHelper.AddLink(game, LinkName, LinkUrl, Settings);
+ return LinkHelper.AddLink(game, LinkName, LinkUrl, Plugin.Settings.Settings);
}
catch (Exception ex)
{
@@ -110,7 +110,7 @@ public override List SearchLink(string searchTerm)
return base.SearchLink(searchTerm);
}
- public LibraryLinkGog(LinkUtilitiesSettings settings) : base(settings)
+ public LibraryLinkGog(LinkUtilities plugin) : base(plugin)
{
}
}
diff --git a/Source/Linker/Libraries/LibraryLinkItch.cs b/Source/Linker/Libraries/LibraryLinkItch.cs
index f11b61643..3b47c8a71 100644
--- a/Source/Linker/Libraries/LibraryLinkItch.cs
+++ b/Source/Linker/Libraries/LibraryLinkItch.cs
@@ -22,11 +22,11 @@ class LibraryLinkItch : LinkAndLibrary
public override bool AddLibraryLink(Game game)
{
// To get the link to a game on the itch website, you need an API key and request the game data from their api.
- if (!string.IsNullOrWhiteSpace(Settings.ItchApiKey) && !LinkHelper.LinkExists(game, LinkName))
+ if (!string.IsNullOrWhiteSpace(Plugin.Settings.Settings.ItchApiKey) && !LinkHelper.LinkExists(game, LinkName))
{
try
{
- string apiUrl = string.Format(LibraryUrl, Settings.ItchApiKey, game.GameId);
+ string apiUrl = string.Format(LibraryUrl, Plugin.Settings.Settings.ItchApiKey, game.GameId);
WebClient client = new WebClient();
@@ -36,7 +36,7 @@ public override bool AddLibraryLink(Game game)
LinkUrl = itchMetaData.Game.Url;
- return LinkHelper.AddLink(game, LinkName, LinkUrl, Settings);
+ return LinkHelper.AddLink(game, LinkName, LinkUrl, Plugin.Settings.Settings);
}
catch (Exception ex)
{
@@ -55,11 +55,11 @@ public override List SearchLink(string searchTerm)
{
SearchResults.Clear();
- if (!string.IsNullOrWhiteSpace(Settings.ItchApiKey))
+ if (!string.IsNullOrWhiteSpace(Plugin.Settings.Settings.ItchApiKey))
{
try
{
- string apiUrl = string.Format(SearchUrl, Settings.ItchApiKey, searchTerm.UrlEncode());
+ string apiUrl = string.Format(SearchUrl, Plugin.Settings.Settings.ItchApiKey, searchTerm.UrlEncode());
WebClient client = new WebClient();
@@ -94,7 +94,7 @@ public override List SearchLink(string searchTerm)
return base.SearchLink(searchTerm);
}
- public LibraryLinkItch(LinkUtilitiesSettings settings) : base(settings)
+ public LibraryLinkItch(LinkUtilities plugin) : base(plugin)
{
}
}
diff --git a/Source/Linker/Libraries/LibraryLinkSteam.cs b/Source/Linker/Libraries/LibraryLinkSteam.cs
index 788e561ee..f4f6d9e4c 100644
--- a/Source/Linker/Libraries/LibraryLinkSteam.cs
+++ b/Source/Linker/Libraries/LibraryLinkSteam.cs
@@ -23,7 +23,7 @@ public override bool AddLibraryLink(Game game)
{
// Adding a link to steam is extremely simple. You only have to add the GameId to the base URL.
LinkUrl = $"{LibraryUrl}{game.GameId}";
- return LinkHelper.AddLink(game, LinkName, LinkUrl, Settings);
+ return LinkHelper.AddLink(game, LinkName, LinkUrl, Plugin.Settings.Settings);
}
public override List SearchLink(string searchTerm)
@@ -72,7 +72,7 @@ public override List SearchLink(string searchTerm)
return base.SearchLink(searchTerm);
}
- public LibraryLinkSteam(LinkUtilitiesSettings settings) : base(settings)
+ public LibraryLinkSteam(LinkUtilities plugin) : base(plugin)
{
}
}
diff --git a/Source/Linker/LibraryLink.cs b/Source/Linker/LibraryLink.cs
index 74635fc6d..11dd53f38 100644
--- a/Source/Linker/LibraryLink.cs
+++ b/Source/Linker/LibraryLink.cs
@@ -12,15 +12,16 @@ public abstract class LibraryLink : ILibraryLink
public abstract string LinkName { get; }
public virtual string BaseUrl { get => string.Empty; }
public virtual string LinkUrl { get; set; } = string.Empty;
- public LinkUtilitiesSettings Settings { get; set; }
+ private readonly LinkUtilities plugin;
+ public LinkUtilities Plugin { get { return plugin; } }
public abstract bool AddLink(Game game);
public abstract bool AddLibraryLink(Game game);
- public LibraryLink(LinkUtilitiesSettings settings)
+ public LibraryLink(LinkUtilities plugin)
{
- Settings = settings;
+ this.plugin = plugin;
}
}
}
diff --git a/Source/Linker/Link.cs b/Source/Linker/Link.cs
index 465d9aacd..5fca5ab23 100644
--- a/Source/Linker/Link.cs
+++ b/Source/Linker/Link.cs
@@ -34,7 +34,9 @@ public abstract class Link : ILink, ILinkAction
public virtual string LinkUrl { get; set; } = string.Empty;
public string ProgressMessage { get; } = "LOCLinkUtilitiesProgressLink";
public string ResultMessage { get; } = "LOCLinkUtilitiesDialogAddedMessage";
- public LinkUtilitiesSettings Settings { get; set; }
+
+ private readonly LinkUtilities plugin;
+ public LinkUtilities Plugin { get { return plugin; } }
///
/// Results of the last search for the link. Is used to get the right link after closing the search dialog, because the dialog
@@ -57,7 +59,7 @@ public virtual bool AddSearchedLink(Game game)
if (result != null)
{
- return LinkHelper.AddLink(game, LinkName, SearchResults.Find(x => x.Name == result.Name).Url, Settings, false);
+ return LinkHelper.AddLink(game, LinkName, SearchResults.Find(x => x.Name == result.Name).Url, plugin.Settings.Settings, false);
}
else
{
@@ -84,7 +86,7 @@ public virtual bool AddLink(Game game)
if (LinkHelper.CheckUrl(LinkUrl, AllowRedirects))
{
- return LinkHelper.AddLink(game, LinkName, LinkUrl, Settings);
+ return LinkHelper.AddLink(game, LinkName, LinkUrl, plugin.Settings.Settings);
}
else
{
@@ -121,9 +123,9 @@ public virtual bool Execute(Game game, string actionModifier = "")
}
}
- public Link(LinkUtilitiesSettings settings)
+ public Link(LinkUtilities plugin)
{
- Settings = settings;
+ this.plugin = plugin;
}
}
}
diff --git a/Source/Linker/LinkAndLibrary.cs b/Source/Linker/LinkAndLibrary.cs
index 132ce88b3..ae363e4f5 100644
--- a/Source/Linker/LinkAndLibrary.cs
+++ b/Source/Linker/LinkAndLibrary.cs
@@ -7,7 +7,7 @@ namespace LinkUtilities.Linker
///
public abstract class LinkAndLibrary : Link, ILibraryLink
{
- protected LinkAndLibrary(LinkUtilitiesSettings settings) : base(settings)
+ protected LinkAndLibrary(LinkUtilities plugin) : base(plugin)
{
}
diff --git a/Source/Linker/LinkSources/LinkEpic.cs b/Source/Linker/LinkSources/LinkEpic.cs
index 345238511..5862baf74 100644
--- a/Source/Linker/LinkSources/LinkEpic.cs
+++ b/Source/Linker/LinkSources/LinkEpic.cs
@@ -43,7 +43,7 @@ public override bool AddLink(Game game)
{
string _ = client.DownloadString(url);
LinkUrl = $"{BaseUrl}{gameSlug}";
- return LinkHelper.AddLink(game, LinkName, LinkUrl, Settings);
+ return LinkHelper.AddLink(game, LinkName, LinkUrl, Plugin.Settings.Settings);
}
catch
{
@@ -97,7 +97,7 @@ public override List SearchLink(string searchTerm)
return base.SearchLink(searchTerm);
}
- public LinkEpic(LinkUtilitiesSettings settings) : base(settings)
+ public LinkEpic(LinkUtilities plugin) : base(plugin)
{
}
}
diff --git a/Source/Linker/LinkSources/LinkHG101.cs b/Source/Linker/LinkSources/LinkHG101.cs
index ae0baf5b6..253454ed4 100644
--- a/Source/Linker/LinkSources/LinkHG101.cs
+++ b/Source/Linker/LinkSources/LinkHG101.cs
@@ -62,7 +62,7 @@ public override List SearchLink(string searchTerm)
return base.SearchLink(searchTerm);
}
- public LinkHG101(LinkUtilitiesSettings settings) : base(settings)
+ public LinkHG101(LinkUtilities plugin) : base(plugin)
{
}
}
diff --git a/Source/Linker/LinkSources/LinkMetacritic.cs b/Source/Linker/LinkSources/LinkMetacritic.cs
index fc73e8d40..bcd38f55d 100644
--- a/Source/Linker/LinkSources/LinkMetacritic.cs
+++ b/Source/Linker/LinkSources/LinkMetacritic.cs
@@ -86,7 +86,7 @@ public override bool AddLink(Game game)
if (LinkHelper.CheckUrl(LinkUrl))
{
- result = LinkHelper.AddLink(game, linkName, LinkUrl, Settings) || result;
+ result = LinkHelper.AddLink(game, linkName, LinkUrl, Plugin.Settings.Settings) || result;
}
}
}
@@ -100,7 +100,7 @@ public override string GetGamePath(Game game)
return game.Name.RemoveSpecialChars().CollapseWhitespaces().Replace(" ", "-").ToLower();
}
- public LinkMetacritic(LinkUtilitiesSettings settings) : base(settings)
+ public LinkMetacritic(LinkUtilities plugin) : base(plugin)
{
}
}
diff --git a/Source/Linker/LinkSources/LinkMobyGames.cs b/Source/Linker/LinkSources/LinkMobyGames.cs
index 13d0d4981..84668ba63 100644
--- a/Source/Linker/LinkSources/LinkMobyGames.cs
+++ b/Source/Linker/LinkSources/LinkMobyGames.cs
@@ -58,7 +58,7 @@ public override List SearchLink(string searchTerm)
return base.SearchLink(searchTerm);
}
- public LinkMobyGames(LinkUtilitiesSettings settings) : base(settings)
+ public LinkMobyGames(LinkUtilities plugin) : base(plugin)
{
}
}
diff --git a/Source/Linker/LinkSources/LinkPCGamingWiki.cs b/Source/Linker/LinkSources/LinkPCGamingWiki.cs
index f6b08572a..f6e7e2d0c 100644
--- a/Source/Linker/LinkSources/LinkPCGamingWiki.cs
+++ b/Source/Linker/LinkSources/LinkPCGamingWiki.cs
@@ -70,7 +70,7 @@ public override List SearchLink(string searchTerm)
return base.SearchLink(searchTerm);
}
- public LinkPCGamingWiki(LinkUtilitiesSettings settings) : base(settings)
+ public LinkPCGamingWiki(LinkUtilities plugin) : base(plugin)
{
}
}
diff --git a/Source/Linker/LinkSources/LinkWikipedia.cs b/Source/Linker/LinkSources/LinkWikipedia.cs
index e7796fc96..5ee08f364 100644
--- a/Source/Linker/LinkSources/LinkWikipedia.cs
+++ b/Source/Linker/LinkSources/LinkWikipedia.cs
@@ -61,7 +61,7 @@ public override List SearchLink(string searchTerm)
return base.SearchLink(searchTerm);
}
- public LinkWikipedia(LinkUtilitiesSettings settings) : base(settings)
+ public LinkWikipedia(LinkUtilities plugin) : base(plugin)
{
}
}
diff --git a/Source/Linker/Links.cs b/Source/Linker/Links.cs
index 2c26e0e86..e9d0b6593 100644
--- a/Source/Linker/Links.cs
+++ b/Source/Linker/Links.cs
@@ -7,20 +7,20 @@ namespace LinkUtilities.Linker
///
public class Links : List
{
- public Links(LinkUtilitiesSettings settings)
+ public Links(LinkUtilities plugin)
{
- Add(new LinkEpic(settings));
- Add(new LibraryLinkGog(settings));
- Add(new LinkHG101(settings));
- if (!string.IsNullOrWhiteSpace(settings.ItchApiKey))
+ Add(new LinkEpic(plugin));
+ Add(new LibraryLinkGog(plugin));
+ Add(new LinkHG101(plugin));
+ if (!string.IsNullOrWhiteSpace(plugin.Settings.Settings.ItchApiKey))
{
- Add(new LibraryLinkItch(settings));
+ Add(new LibraryLinkItch(plugin));
}
- Add(new LinkMetacritic(settings));
- Add(new LinkMobyGames(settings));
- Add(new LinkPCGamingWiki(settings));
- Add(new LibraryLinkSteam(settings));
- Add(new LinkWikipedia(settings));
+ Add(new LinkMetacritic(plugin));
+ Add(new LinkMobyGames(plugin));
+ Add(new LinkPCGamingWiki(plugin));
+ Add(new LibraryLinkSteam(plugin));
+ Add(new LinkWikipedia(plugin));
}
}
}
diff --git a/Source/Models/LinkSourceSettings.cs b/Source/Models/LinkSourceSettings.cs
new file mode 100644
index 000000000..e3ca6fb9b
--- /dev/null
+++ b/Source/Models/LinkSourceSettings.cs
@@ -0,0 +1,30 @@
+using System.Collections.Generic;
+
+namespace LinkUtilities.Models
+{
+ public class LinkSourceSetting
+ {
+ ///
+ /// Name of the link source - corresponds to the LinkName property of Link objects.
+ ///
+ public string LinkName { get; set; }
+ public bool? IsAddable { get; set; }
+ public bool? IsSearchable { get; set; }
+ }
+
+ public class LinkSourceSettings : Dictionary
+ {
+ public LinkSourceSettings(LinkUtilities plugin)
+ {
+ foreach (Linker.Link link in plugin.AddWebsiteLinks.Links)
+ {
+ Add(link.LinkName, new LinkSourceSetting
+ {
+ LinkName = link.LinkName,
+ IsAddable = link.IsAddable ? true : (bool?)null,
+ IsSearchable = link.IsSearchable ? true : (bool?)null
+ });
+ }
+ }
+ }
+}