diff --git a/src/Jackett/IndexerInterface.cs b/src/Jackett/IndexerInterface.cs index cf3254b7e..644aad426 100644 --- a/src/Jackett/IndexerInterface.cs +++ b/src/Jackett/IndexerInterface.cs @@ -24,7 +24,7 @@ namespace Jackett Task VerifyConnection(); // Invoked when the indexer configuration has been applied and verified so the cookie needs to be saved - event Action OnSaveConfigurationRequested; + event Action OnSaveConfigurationRequested; // Whether this indexer has been configured, verified and saved in the past and has the settings required for functioning bool IsConfigured { get; } diff --git a/src/Jackett/IndexerManager.cs b/src/Jackett/IndexerManager.cs index fb22b9c2e..1abea0092 100644 --- a/src/Jackett/IndexerManager.cs +++ b/src/Jackett/IndexerManager.cs @@ -10,7 +10,8 @@ namespace Jackett { public class IndexerManager { - static string AppConfigDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); + + static string AppConfigDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Jackett"); static string IndexerConfigDirectory = Path.Combine(AppConfigDirectory, "Indexers"); public Dictionary Indexers { get; private set; } @@ -35,11 +36,12 @@ namespace Jackett var name = indexerType.Name.Trim().ToLower(); IndexerInterface newIndexer = (IndexerInterface)Activator.CreateInstance(indexerType); + newIndexer.OnSaveConfigurationRequested += newIndexer_OnSaveConfigurationRequested; - var configFilePath = Path.Combine(IndexerConfigDirectory, name.ToString().ToLower()); + var configFilePath = GetIndexerConfigFilePath(newIndexer); if (File.Exists(configFilePath)) { - string jsonString = File.ReadAllText(configFilePath); + var jsonString = JObject.Parse(File.ReadAllText(configFilePath)); newIndexer.LoadFromSavedConfiguration(jsonString); } @@ -47,6 +49,20 @@ namespace Jackett return newIndexer; } + string GetIndexerConfigFilePath(IndexerInterface indexer) + { + return Path.Combine(IndexerConfigDirectory, indexer.GetType().Name.ToLower() + ".json"); + } + + void newIndexer_OnSaveConfigurationRequested(IndexerInterface indexer, JToken obj) + { + var name = indexer.GetType().Name.Trim().ToLower(); + var configFilePath = GetIndexerConfigFilePath(indexer); + if (!Directory.Exists(IndexerConfigDirectory)) + Directory.CreateDirectory(IndexerConfigDirectory); + File.WriteAllText(configFilePath, obj.ToString()); + } + public IndexerInterface GetIndexer(string name) { IndexerInterface indexer; diff --git a/src/Jackett/Indexers/BitMeTV.cs b/src/Jackett/Indexers/BitMeTV.cs index 611eab408..abe7212a3 100644 --- a/src/Jackett/Indexers/BitMeTV.cs +++ b/src/Jackett/Indexers/BitMeTV.cs @@ -43,7 +43,7 @@ namespace Jackett HttpClientHandler handler; HttpClient client; - public event Action OnSaveConfigurationRequested; + public event Action OnSaveConfigurationRequested; public BitMeTV() { @@ -114,7 +114,7 @@ namespace Jackett ).ToArray()); if (OnSaveConfigurationRequested != null) - OnSaveConfigurationRequested(configSaveData); + OnSaveConfigurationRequested(this, configSaveData); IsConfigured = true; } @@ -133,7 +133,13 @@ namespace Jackett public void LoadFromSavedConfiguration(JToken jsonConfig) { - // todo: set cookie data... + + foreach (var cookie in jsonConfig["cookies"]) + { + var w = ((string)cookie).Split(':'); + cookies.Add(new Uri(BaseUrl), new Cookie(w[0], w[1])); + } + IsConfigured = true; } } diff --git a/src/Jackett/Indexers/Freshon.cs b/src/Jackett/Indexers/Freshon.cs index 3f166d131..a95b61a52 100644 --- a/src/Jackett/Indexers/Freshon.cs +++ b/src/Jackett/Indexers/Freshon.cs @@ -41,7 +41,7 @@ namespace Jackett throw new NotImplementedException(); } - public event Action OnSaveConfigurationRequested; + public event Action OnSaveConfigurationRequested; public bool IsConfigured {