diff options
| author | dkanada <dkanada@users.noreply.github.com> | 2021-02-05 11:47:06 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-05 11:47:06 +0900 |
| commit | 54a3ab15a38ff0f10a55398357538376958000e4 (patch) | |
| tree | 1830eb490de1fc8d6589f920f4c8ffdbb68a4931 /Emby.Server.Implementations/Plugins/PluginManager.cs | |
| parent | 2e9661c415c362c694b6d63921ed71cf63b80b6f (diff) | |
| parent | 1fdd2d6e0527a7b112ed6d79d8854f6fbe6fdaca (diff) | |
Merge pull request #5005 from jellyfin/bytes
JsonSerializer deserialize from bytes where possible
Diffstat (limited to 'Emby.Server.Implementations/Plugins/PluginManager.cs')
| -rw-r--r-- | Emby.Server.Implementations/Plugins/PluginManager.cs | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/Emby.Server.Implementations/Plugins/PluginManager.cs b/Emby.Server.Implementations/Plugins/PluginManager.cs index adf62124a..8e5987026 100644 --- a/Emby.Server.Implementations/Plugins/PluginManager.cs +++ b/Emby.Server.Implementations/Plugins/PluginManager.cs @@ -526,32 +526,36 @@ namespace Emby.Server.Implementations.Plugins var metafile = Path.Combine(dir, "meta.json"); if (File.Exists(metafile)) { + // Only path where this stays null is when File.ReadAllBytes throws an IOException + byte[] data = null!; try { - var data = File.ReadAllText(metafile, Encoding.UTF8); + data = File.ReadAllBytes(metafile); manifest = JsonSerializer.Deserialize<PluginManifest>(data, _jsonOptions); } -#pragma warning disable CA1031 // Do not catch general exception types - catch (Exception ex) -#pragma warning restore CA1031 // Do not catch general exception types + catch (IOException ex) { - _logger.LogError(ex, "Error deserializing {Path}.", dir); + _logger.LogError(ex, "Error reading file {Path}.", dir); } - } - - if (manifest != null) - { - if (!Version.TryParse(manifest.TargetAbi, out var targetAbi)) + catch (JsonException ex) { - targetAbi = _minimumVersion; + _logger.LogError(ex, "Error deserializing {Json}.", Encoding.UTF8.GetString(data!)); } - if (!Version.TryParse(manifest.Version, out version)) + if (manifest != null) { - manifest.Version = _minimumVersion.ToString(); - } + if (!Version.TryParse(manifest.TargetAbi, out var targetAbi)) + { + targetAbi = _minimumVersion; + } + + if (!Version.TryParse(manifest.Version, out version)) + { + manifest.Version = _minimumVersion.ToString(); + } - return new LocalPlugin(dir, _appVersion >= targetAbi, manifest); + return new LocalPlugin(dir, _appVersion >= targetAbi, manifest); + } } // No metafile, so lets see if the folder is versioned. |
