mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-09 03:04:24 -04:00
Merge pull request #5005 from jellyfin/bytes
JsonSerializer deserialize from bytes where possible
This commit is contained in:
commit
54a3ab15a3
@ -336,19 +336,19 @@ namespace Emby.Server.Implementations.Channels
|
|||||||
return GetChannel(GetInternalChannelId(channel.Name)) ?? GetChannel(channel, CancellationToken.None).Result;
|
return GetChannel(GetInternalChannelId(channel.Name)) ?? GetChannel(channel, CancellationToken.None).Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<MediaSourceInfo> GetSavedMediaSources(BaseItem item)
|
private MediaSourceInfo[] GetSavedMediaSources(BaseItem item)
|
||||||
{
|
{
|
||||||
var path = Path.Combine(item.GetInternalMetadataPath(), "channelmediasourceinfos.json");
|
var path = Path.Combine(item.GetInternalMetadataPath(), "channelmediasourceinfos.json");
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var jsonString = File.ReadAllText(path, Encoding.UTF8);
|
var bytes = File.ReadAllBytes(path);
|
||||||
return JsonSerializer.Deserialize<List<MediaSourceInfo>>(jsonString, _jsonOptions)
|
return JsonSerializer.Deserialize<MediaSourceInfo[]>(bytes, _jsonOptions)
|
||||||
?? new List<MediaSourceInfo>();
|
?? Array.Empty<MediaSourceInfo>();
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
return new List<MediaSourceInfo>();
|
return Array.Empty<MediaSourceInfo>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,11 +47,11 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var jsonString = File.ReadAllText(_dataPath, Encoding.UTF8);
|
var bytes = File.ReadAllBytes(_dataPath);
|
||||||
_items = JsonSerializer.Deserialize<T[]>(jsonString, _jsonOptions);
|
_items = JsonSerializer.Deserialize<T[]>(bytes, _jsonOptions);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (JsonException ex)
|
||||||
{
|
{
|
||||||
Logger.LogError(ex, "Error deserializing {Path}", _dataPath);
|
Logger.LogError(ex, "Error deserializing {Path}", _dataPath);
|
||||||
}
|
}
|
||||||
|
@ -526,32 +526,36 @@ namespace Emby.Server.Implementations.Plugins
|
|||||||
var metafile = Path.Combine(dir, "meta.json");
|
var metafile = Path.Combine(dir, "meta.json");
|
||||||
if (File.Exists(metafile))
|
if (File.Exists(metafile))
|
||||||
{
|
{
|
||||||
|
// Only path where this stays null is when File.ReadAllBytes throws an IOException
|
||||||
|
byte[] data = null!;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var data = File.ReadAllText(metafile, Encoding.UTF8);
|
data = File.ReadAllBytes(metafile);
|
||||||
manifest = JsonSerializer.Deserialize<PluginManifest>(data, _jsonOptions);
|
manifest = JsonSerializer.Deserialize<PluginManifest>(data, _jsonOptions);
|
||||||
}
|
}
|
||||||
#pragma warning disable CA1031 // Do not catch general exception types
|
catch (IOException ex)
|
||||||
catch (Exception ex)
|
|
||||||
#pragma warning restore CA1031 // Do not catch general exception types
|
|
||||||
{
|
{
|
||||||
_logger.LogError(ex, "Error deserializing {Path}.", dir);
|
_logger.LogError(ex, "Error reading file {Path}.", dir);
|
||||||
}
|
}
|
||||||
}
|
catch (JsonException ex)
|
||||||
|
|
||||||
if (manifest != null)
|
|
||||||
{
|
|
||||||
if (!Version.TryParse(manifest.TargetAbi, out var targetAbi))
|
|
||||||
{
|
{
|
||||||
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;
|
||||||
|
}
|
||||||
|
|
||||||
return new LocalPlugin(dir, _appVersion >= targetAbi, manifest);
|
if (!Version.TryParse(manifest.Version, out version))
|
||||||
|
{
|
||||||
|
manifest.Version = _minimumVersion.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
return new LocalPlugin(dir, _appVersion >= targetAbi, manifest);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// No metafile, so lets see if the folder is versioned.
|
// No metafile, so lets see if the folder is versioned.
|
||||||
|
@ -143,21 +143,21 @@ namespace Emby.Server.Implementations.ScheduledTasks
|
|||||||
{
|
{
|
||||||
if (File.Exists(path))
|
if (File.Exists(path))
|
||||||
{
|
{
|
||||||
try
|
var bytes = File.ReadAllBytes(path);
|
||||||
|
if (bytes.Length > 0)
|
||||||
{
|
{
|
||||||
var jsonString = File.ReadAllText(path, Encoding.UTF8);
|
try
|
||||||
if (!string.IsNullOrWhiteSpace(jsonString))
|
|
||||||
{
|
{
|
||||||
_lastExecutionResult = JsonSerializer.Deserialize<TaskResult>(jsonString, _jsonOptions);
|
_lastExecutionResult = JsonSerializer.Deserialize<TaskResult>(bytes, _jsonOptions);
|
||||||
}
|
}
|
||||||
else
|
catch (JsonException ex)
|
||||||
{
|
{
|
||||||
_logger.LogDebug("Scheduled Task history file {Path} is empty. Skipping deserialization.", path);
|
_logger.LogError(ex, "Error deserializing {File}", path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
else
|
||||||
{
|
{
|
||||||
_logger.LogError(ex, "Error deserializing {File}", path);
|
_logger.LogDebug("Scheduled Task history file {Path} is empty. Skipping deserialization.", path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -541,8 +541,8 @@ namespace Emby.Server.Implementations.ScheduledTasks
|
|||||||
TaskTriggerInfo[] list = null;
|
TaskTriggerInfo[] list = null;
|
||||||
if (File.Exists(path))
|
if (File.Exists(path))
|
||||||
{
|
{
|
||||||
var jsonString = File.ReadAllText(path, Encoding.UTF8);
|
var bytes = File.ReadAllBytes(path);
|
||||||
list = JsonSerializer.Deserialize<TaskTriggerInfo[]>(jsonString, _jsonOptions);
|
list = JsonSerializer.Deserialize<TaskTriggerInfo[]>(bytes, _jsonOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return defaults if file doesn't exist.
|
// Return defaults if file doesn't exist.
|
||||||
|
@ -90,7 +90,7 @@ namespace Jellyfin.Server.Migrations.Routines
|
|||||||
var results = connection.Query("SELECT * FROM userdisplaypreferences");
|
var results = connection.Query("SELECT * FROM userdisplaypreferences");
|
||||||
foreach (var result in results)
|
foreach (var result in results)
|
||||||
{
|
{
|
||||||
var dto = JsonSerializer.Deserialize<DisplayPreferencesDto>(result[3].ToString(), _jsonOptions);
|
var dto = JsonSerializer.Deserialize<DisplayPreferencesDto>(result[3].ToBlob(), _jsonOptions);
|
||||||
if (dto == null)
|
if (dto == null)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user