From 3e4a08d81c62ddcb7396f1fbeb67bfed97d0093f Mon Sep 17 00:00:00 2001 From: JustArchi Date: Thu, 4 Apr 2019 22:34:58 +0200 Subject: [PATCH] Misc --- ArchiSteamFarm/BotConfig.cs | 10 +++++++++- ArchiSteamFarm/BotDatabase.cs | 11 ++++++++++- ArchiSteamFarm/GlobalConfig.cs | 10 +++++++++- ArchiSteamFarm/GlobalDatabase.cs | 11 ++++++++++- 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/ArchiSteamFarm/BotConfig.cs b/ArchiSteamFarm/BotConfig.cs index 53c3449da..2aef50184 100644 --- a/ArchiSteamFarm/BotConfig.cs +++ b/ArchiSteamFarm/BotConfig.cs @@ -315,7 +315,15 @@ namespace ArchiSteamFarm { BotConfig botConfig; try { - botConfig = JsonConvert.DeserializeObject(await RuntimeCompatibility.File.ReadAllTextAsync(filePath).ConfigureAwait(false)); + string json = await RuntimeCompatibility.File.ReadAllTextAsync(filePath).ConfigureAwait(false); + + if (string.IsNullOrEmpty(json)) { + ASF.ArchiLogger.LogGenericError(string.Format(Strings.ErrorIsEmpty, nameof(json))); + + return null; + } + + botConfig = JsonConvert.DeserializeObject(json); } catch (Exception e) { ASF.ArchiLogger.LogGenericException(e); diff --git a/ArchiSteamFarm/BotDatabase.cs b/ArchiSteamFarm/BotDatabase.cs index 532f2f8df..773568320 100644 --- a/ArchiSteamFarm/BotDatabase.cs +++ b/ArchiSteamFarm/BotDatabase.cs @@ -27,6 +27,7 @@ using System.IO; using System.Threading; using System.Threading.Tasks; using ArchiSteamFarm.Collections; +using ArchiSteamFarm.Localization; using JetBrains.Annotations; using Newtonsoft.Json; using SteamKit2; @@ -156,7 +157,15 @@ namespace ArchiSteamFarm { BotDatabase botDatabase; try { - botDatabase = JsonConvert.DeserializeObject(await RuntimeCompatibility.File.ReadAllTextAsync(filePath).ConfigureAwait(false)); + string json = await RuntimeCompatibility.File.ReadAllTextAsync(filePath).ConfigureAwait(false); + + if (string.IsNullOrEmpty(json)) { + ASF.ArchiLogger.LogGenericError(string.Format(Strings.ErrorIsEmpty, nameof(json))); + + return null; + } + + botDatabase = JsonConvert.DeserializeObject(json); } catch (Exception e) { ASF.ArchiLogger.LogGenericException(e); diff --git a/ArchiSteamFarm/GlobalConfig.cs b/ArchiSteamFarm/GlobalConfig.cs index 7ee420fba..bc8ab4152 100644 --- a/ArchiSteamFarm/GlobalConfig.cs +++ b/ArchiSteamFarm/GlobalConfig.cs @@ -286,7 +286,15 @@ namespace ArchiSteamFarm { GlobalConfig globalConfig; try { - globalConfig = JsonConvert.DeserializeObject(await RuntimeCompatibility.File.ReadAllTextAsync(filePath).ConfigureAwait(false)); + string json = await RuntimeCompatibility.File.ReadAllTextAsync(filePath).ConfigureAwait(false); + + if (string.IsNullOrEmpty(json)) { + ASF.ArchiLogger.LogGenericError(string.Format(Strings.ErrorIsEmpty, nameof(json))); + + return null; + } + + globalConfig = JsonConvert.DeserializeObject(json); } catch (Exception e) { ASF.ArchiLogger.LogGenericException(e); diff --git a/ArchiSteamFarm/GlobalDatabase.cs b/ArchiSteamFarm/GlobalDatabase.cs index d78497299..687af28f6 100644 --- a/ArchiSteamFarm/GlobalDatabase.cs +++ b/ArchiSteamFarm/GlobalDatabase.cs @@ -26,6 +26,7 @@ using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; +using ArchiSteamFarm.Localization; using ArchiSteamFarm.SteamKit2; using JetBrains.Annotations; using Newtonsoft.Json; @@ -84,7 +85,15 @@ namespace ArchiSteamFarm { GlobalDatabase globalDatabase; try { - globalDatabase = JsonConvert.DeserializeObject(await RuntimeCompatibility.File.ReadAllTextAsync(filePath).ConfigureAwait(false)); + string json = await RuntimeCompatibility.File.ReadAllTextAsync(filePath).ConfigureAwait(false); + + if (string.IsNullOrEmpty(json)) { + ASF.ArchiLogger.LogGenericError(string.Format(Strings.ErrorIsEmpty, nameof(json))); + + return null; + } + + globalDatabase = JsonConvert.DeserializeObject(json); } catch (Exception e) { ASF.ArchiLogger.LogGenericException(e);