diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c0fadc..0824851 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## 1.7.2 - Updated ExtensionUpdater notifications to be more helpful +- ExtensionUpdater can now find Extensions in `%appdata%\Playnite\Extensions` ## 1.7.1 diff --git a/ExtensionUpdater/ExtensionUpdaterPlugin.cs b/ExtensionUpdater/ExtensionUpdaterPlugin.cs index b822339..2a83a5a 100644 --- a/ExtensionUpdater/ExtensionUpdaterPlugin.cs +++ b/ExtensionUpdater/ExtensionUpdaterPlugin.cs @@ -34,7 +34,7 @@ public class ExtensionUpdaterPlugin : Plugin { private readonly IPlayniteAPI _playniteAPI; private readonly ILogger _logger; - private readonly string _extensionsDirectory; + private readonly List _extensionsDirectories; private readonly CancellationTokenSource _source; private readonly CancellationToken _token; @@ -43,16 +43,15 @@ public ExtensionUpdaterPlugin(IPlayniteAPI playniteAPI) : base(playniteAPI) _playniteAPI = playniteAPI; _logger = playniteAPI.CreateLogger(); + _extensionsDirectories = new List(); + var applicationPath = _playniteAPI.Paths.ApplicationPath; - var extensionsPath = Path.Combine(applicationPath, "Extensions"); - if (!Directory.Exists(extensionsPath)) - { - _logger.Error($"Directory {extensionsPath} does not exist!"); - } - else - { - _extensionsDirectory = extensionsPath; - } + var applicationExtensionsPath = Path.Combine(applicationPath, "Extensions"); + _extensionsDirectories.Add(applicationExtensionsPath); + + var configurationPath = _playniteAPI.Paths.ConfigurationPath; + var configurationExtensionsPath = Path.Combine(configurationPath, "Extensions"); + _extensionsDirectories.Add(configurationExtensionsPath); _source = new CancellationTokenSource(); _token = _source.Token; @@ -75,10 +74,8 @@ public override void OnApplicationStarted() { Task.Run(() => { - if (_extensionsDirectory == null) - { + if (_extensionsDirectories.Count == 0) return; - } if (_playniteAPI.ApplicationInfo.InOfflineMode) { @@ -86,26 +83,28 @@ public override void OnApplicationStarted() return; } - IEnumerable> configs = Directory - .EnumerateFiles(_extensionsDirectory, "*.yaml", SearchOption.AllDirectories) - .Select(file => - { - try - { - var config = YamlUtils.FromYaml(file); - return config?.UpdaterConfig == null ? null : config; - } - catch (Exception e) - { - _logger.Error(e, $"Exception while trying to deserialize {file}!\n"); - } + IEnumerable> configs = _extensionsDirectories + .Where(Directory.Exists) + .SelectMany(extensionsDirectory => + Directory.EnumerateFiles(extensionsDirectory, "*.yaml", SearchOption.AllDirectories) + .Select(file => + { + try + { + var config = YamlUtils.FromYaml(file); + return config?.UpdaterConfig == null ? null : config; + } + catch (Exception e) + { + _logger.Error(e, $"Exception while trying to deserialize {file}!\n"); + } - return null; - }).NotNull().GroupBy(config => - { - var repo = $"{config.UpdaterConfig.GitHubUser}/{config.UpdaterConfig.GitHubRepo}"; - return repo; - }); + return null; + }).NotNull().GroupBy(config => + { + var repo = $"{config.UpdaterConfig.GitHubUser}/{config.UpdaterConfig.GitHubRepo}"; + return repo; + })); configs.Do(async group => {