Automatically load the backup config if the primary one is corrupted

This commit is contained in:
kaso17
2017-01-05 18:05:14 +01:00
parent 33cbc71817
commit 175bea9269
3 changed files with 23 additions and 2 deletions

View File

@@ -161,7 +161,7 @@ namespace Jackett.Indexers
IsConfigured = false; IsConfigured = false;
} }
protected virtual void SaveConfig() public virtual void SaveConfig()
{ {
indexerService.SaveConfig(this as IIndexer, configData.ToJson(protectionService, forDisplay: false)); indexerService.SaveConfig(this as IIndexer, configData.ToJson(protectionService, forDisplay: false));
} }

View File

@@ -34,6 +34,7 @@ namespace Jackett.Indexers
// Called on startup when initializing indexers from saved configuration // Called on startup when initializing indexers from saved configuration
void LoadFromSavedConfiguration(JToken jsonConfig); void LoadFromSavedConfiguration(JToken jsonConfig);
void SaveConfig();
Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuery query); Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuery query);

View File

@@ -55,7 +55,27 @@ namespace Jackett.Services
} }
catch (Exception ex) catch (Exception ex)
{ {
logger.Error(ex, "Failed loading configuration for {0}, you must reconfigure this indexer", idx.DisplayName); logger.Error(ex, "Failed loading configuration for {0}, trying backup", idx.DisplayName);
var configFilePathBak = configFilePath + ".bak";
if (File.Exists(configFilePathBak))
{
try
{
var fileStrBak = File.ReadAllText(configFilePathBak);
var jsonStringBak = JToken.Parse(fileStrBak);
idx.LoadFromSavedConfiguration(jsonStringBak);
logger.Info("Successfully loaded backup config for {0}", idx.DisplayName);
idx.SaveConfig();
}
catch (Exception exbak)
{
logger.Error(exbak, "Failed loading backup configuration for {0}, you must reconfigure this indexer", idx.DisplayName);
}
}
else
{
logger.Error(ex, "Failed loading backup configuration for {0} (no backup available), you must reconfigure this indexer", idx.DisplayName);
}
} }
} }
} }