1
0
Fork 0
mirror of https://github.com/Jackett/Jackett synced 2025-01-31 20:02:08 +00:00

BitMeTV saving and loading cookies working

This commit is contained in:
zone117x 2015-04-14 22:57:55 -06:00
parent e27b696c61
commit 213e8c062c
4 changed files with 30 additions and 8 deletions

View file

@ -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<JToken> OnSaveConfigurationRequested;
event Action<IndexerInterface, JToken> OnSaveConfigurationRequested;
// Whether this indexer has been configured, verified and saved in the past and has the settings required for functioning
bool IsConfigured { get; }

View file

@ -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<string, IndexerInterface> 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;

View file

@ -43,7 +43,7 @@ namespace Jackett
HttpClientHandler handler;
HttpClient client;
public event Action<JToken> OnSaveConfigurationRequested;
public event Action<IndexerInterface, JToken> 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;
}
}

View file

@ -41,7 +41,7 @@ namespace Jackett
throw new NotImplementedException();
}
public event Action<JToken> OnSaveConfigurationRequested;
public event Action<IndexerInterface, JToken> OnSaveConfigurationRequested;
public bool IsConfigured
{