Load definitions from multiple directories

This commit is contained in:
kaso17
2016-10-30 19:34:48 +01:00
committed by kaso17
parent 2f140fd2c0
commit 0f5e18492c
3 changed files with 25 additions and 4 deletions

View File

@@ -25,7 +25,7 @@ namespace Jackett.Services
T GetConfig<T>(); T GetConfig<T>();
void SaveConfig<T>(T config); void SaveConfig<T>(T config);
string ApplicationFolder(); string ApplicationFolder();
string GetCardigannDefinitionsFolder(); List<string> GetCardigannDefinitionsFolders();
void CreateOrMigrateSettings(); void CreateOrMigrateSettings();
void PerformMigration(); void PerformMigration();
} }
@@ -198,8 +198,21 @@ namespace Jackett.Services
return dir; return dir;
} }
public string GetCardigannDefinitionsFolder() public List<string> GetCardigannDefinitionsFolders()
{ {
List<string> dirs = new List<string>();
if (System.Environment.OSVersion.Platform == PlatformID.Unix)
{
dirs.Add(Path.Combine(Environment.GetEnvironmentVariable("HOME"), ".config/cardigann/definitions/"));
dirs.Add("/etc/xdg/cardigan/definitions/");
}
else
{
dirs.Add(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "cardigann\\definitions\\"));
dirs.Add(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "cardigann\\definitions\\"));
}
// If we are debugging we can use the non copied definitions. // If we are debugging we can use the non copied definitions.
string dir = Path.Combine(ApplicationFolder(), "Definitions"); ; string dir = Path.Combine(ApplicationFolder(), "Definitions"); ;
@@ -211,7 +224,8 @@ namespace Jackett.Services
dir = sourcePath; dir = sourcePath;
} }
#endif #endif
return dir; dirs.Add(dir);
return dirs;
} }
public string GetVersion() public string GetVersion()

View File

@@ -76,10 +76,14 @@ namespace Jackett.Services
try try
{ {
if (!Directory.Exists(path))
return;
DirectoryInfo d = new DirectoryInfo(path); DirectoryInfo d = new DirectoryInfo(path);
foreach (var file in d.GetFiles("*.yml")) foreach (var file in d.GetFiles("*.yml"))
{ {
logger.Info("Loading Cardigann definition " + file.FullName);
string DefinitionString = File.ReadAllText(file.FullName); string DefinitionString = File.ReadAllText(file.FullName);
CardigannIndexer idx = new CardigannIndexer(this, container.Resolve<IWebClient>(), logger, container.Resolve<IProtectionService>(), DefinitionString); CardigannIndexer idx = new CardigannIndexer(this, container.Resolve<IWebClient>(), logger, container.Resolve<IProtectionService>(), DefinitionString);
if (indexers.ContainsKey(idx.ID)) if (indexers.ContainsKey(idx.ID))

View File

@@ -150,7 +150,10 @@ namespace Jackett.Services
CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US"); CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US");
// Load indexers // Load indexers
indexerService.InitIndexers(); indexerService.InitIndexers();
indexerService.InitCardigannIndexers(configService.GetCardigannDefinitionsFolder()); foreach(string dir in configService.GetCardigannDefinitionsFolders())
{
indexerService.InitCardigannIndexers(dir);
}
client.Init(); client.Init();
} }