aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/LiveTv/EmbyTV/ItemDataProvider.cs
diff options
context:
space:
mode:
authorBond_009 <Bond.009@outlook.com>2019-02-24 15:47:59 +0100
committerBond-009 <bond.009@outlook.com>2019-03-07 21:42:56 +0100
commit37ea50a572e8bd00aad39c193087228a5d3a3433 (patch)
tree100ea9cb7986a15c50af8af57cb5d549000f206f /Emby.Server.Implementations/LiveTv/EmbyTV/ItemDataProvider.cs
parent10a0d6bdba821449abfb1d48e9708ba6f3fc6a62 (diff)
Reduce the amount of exceptions thrown
Diffstat (limited to 'Emby.Server.Implementations/LiveTv/EmbyTV/ItemDataProvider.cs')
-rw-r--r--Emby.Server.Implementations/LiveTv/EmbyTV/ItemDataProvider.cs26
1 files changed, 10 insertions, 16 deletions
diff --git a/Emby.Server.Implementations/LiveTv/EmbyTV/ItemDataProvider.cs b/Emby.Server.Implementations/LiveTv/EmbyTV/ItemDataProvider.cs
index a2ac60b31..9c45ee36a 100644
--- a/Emby.Server.Implementations/LiveTv/EmbyTV/ItemDataProvider.cs
+++ b/Emby.Server.Implementations/LiveTv/EmbyTV/ItemDataProvider.cs
@@ -2,7 +2,6 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
-using MediaBrowser.Model.IO;
using MediaBrowser.Model.Serialization;
using Microsoft.Extensions.Logging;
@@ -32,32 +31,28 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
{
if (_items == null)
{
+ if (!File.Exists(_dataPath))
+ {
+ return new List<T>();
+ }
+
Logger.LogInformation("Loading live tv data from {0}", _dataPath);
_items = GetItemsFromFile(_dataPath);
}
+
return _items.ToList();
}
}
private List<T> GetItemsFromFile(string path)
{
- var jsonFile = path + ".json";
-
- if (!File.Exists(jsonFile))
- {
- return new List<T>();
- }
-
try
{
- return _jsonSerializer.DeserializeFromFile<List<T>>(jsonFile) ?? new List<T>();
- }
- catch (IOException)
- {
+ return _jsonSerializer.DeserializeFromFile<List<T>>(path);
}
catch (Exception ex)
{
- Logger.LogError(ex, "Error deserializing {jsonFile}", jsonFile);
+ Logger.LogError(ex, "Error deserializing {Path}", path);
}
return new List<T>();
@@ -70,12 +65,11 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
throw new ArgumentNullException(nameof(newList));
}
- var file = _dataPath + ".json";
- Directory.CreateDirectory(Path.GetDirectoryName(file));
+ Directory.CreateDirectory(Path.GetDirectoryName(_dataPath));
lock (_fileDataLock)
{
- _jsonSerializer.SerializeToFile(newList, file);
+ _jsonSerializer.SerializeToFile(newList, _dataPath);
_items = newList;
}
}