Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Commit

Permalink
ExtensionUpdater will check multiple install directories
Browse files Browse the repository at this point in the history
  • Loading branch information
erri120 committed Oct 26, 2020
1 parent c27f006 commit b6485db
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 32 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
63 changes: 31 additions & 32 deletions ExtensionUpdater/ExtensionUpdaterPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class ExtensionUpdaterPlugin : Plugin
{
private readonly IPlayniteAPI _playniteAPI;
private readonly ILogger _logger;
private readonly string _extensionsDirectory;
private readonly List<string> _extensionsDirectories;
private readonly CancellationTokenSource _source;
private readonly CancellationToken _token;

Expand All @@ -43,16 +43,15 @@ public ExtensionUpdaterPlugin(IPlayniteAPI playniteAPI) : base(playniteAPI)
_playniteAPI = playniteAPI;
_logger = playniteAPI.CreateLogger();

_extensionsDirectories = new List<string>();

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;
Expand All @@ -75,37 +74,37 @@ public override void OnApplicationStarted()
{
Task.Run(() =>
{
if (_extensionsDirectory == null)
{
if (_extensionsDirectories.Count == 0)
return;
}

if (_playniteAPI.ApplicationInfo.InOfflineMode)
{
_logger.Info("Application is in offline mode, skipping extension update check");
return;
}

IEnumerable<IGrouping<string, PlayniteExtensionConfig>> configs = Directory
.EnumerateFiles(_extensionsDirectory, "*.yaml", SearchOption.AllDirectories)
.Select(file =>
{
try
{
var config = YamlUtils.FromYaml<PlayniteExtensionConfig>(file);
return config?.UpdaterConfig == null ? null : config;
}
catch (Exception e)
{
_logger.Error(e, $"Exception while trying to deserialize {file}!\n");
}
IEnumerable<IGrouping<string, PlayniteExtensionConfig>> configs = _extensionsDirectories
.Where(Directory.Exists)
.SelectMany(extensionsDirectory =>
Directory.EnumerateFiles(extensionsDirectory, "*.yaml", SearchOption.AllDirectories)
.Select(file =>
{
try
{
var config = YamlUtils.FromYaml<PlayniteExtensionConfig>(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 =>
{
Expand Down

0 comments on commit b6485db

Please sign in to comment.