mirror of
https://github.com/Jackett/Jackett.git
synced 2025-09-17 17:34:09 +02:00
Refactor
This commit is contained in:
84
src/Jackett/Services/ConfigurationService.cs
Normal file
84
src/Jackett/Services/ConfigurationService.cs
Normal file
@@ -0,0 +1,84 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Jackett.Services
|
||||
{
|
||||
public interface IConfigurationService
|
||||
{
|
||||
string GetContentFolder();
|
||||
string GetVersion();
|
||||
string GetIndexerConfigDir();
|
||||
string GetAppDataFolder();
|
||||
JObject ReadServerSettingsFile();
|
||||
string GetSonarrConfigFile();
|
||||
}
|
||||
|
||||
public class ConfigurationService: IConfigurationService
|
||||
{
|
||||
public string GetContentFolder()
|
||||
{
|
||||
var baseDir = Path.GetDirectoryName(Application.ExecutablePath);
|
||||
// If we are debugging we can use the non copied content.
|
||||
if (Debugger.IsAttached)
|
||||
{
|
||||
return Path.Combine(baseDir, "..\\..\\..\\Jackett\\WebContent");
|
||||
}
|
||||
else
|
||||
{
|
||||
return Path.Combine(baseDir, "WebContent");
|
||||
}
|
||||
}
|
||||
|
||||
public string GetVersion()
|
||||
{
|
||||
return Assembly.GetExecutingAssembly().GetName().Version.ToString();
|
||||
}
|
||||
|
||||
public string GetAppDataFolder()
|
||||
{
|
||||
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Jackett"); ;
|
||||
}
|
||||
|
||||
public string GetIndexerConfigDir()
|
||||
{
|
||||
return Path.Combine(GetAppDataFolder(), "Indexers");
|
||||
}
|
||||
|
||||
public string GetConfigFile()
|
||||
{
|
||||
return Path.Combine(GetAppDataFolder(), "config.json");
|
||||
}
|
||||
|
||||
public string GetSonarrConfigFile()
|
||||
{
|
||||
return Path.Combine(GetAppDataFolder(), "sonarr_api.json");
|
||||
}
|
||||
|
||||
|
||||
public JObject ReadServerSettingsFile()
|
||||
{
|
||||
var path = GetConfigFile();
|
||||
JObject jsonReply = new JObject();
|
||||
if (File.Exists(path))
|
||||
{
|
||||
jsonReply = JObject.Parse(File.ReadAllText(path));
|
||||
// Port = (int)jsonReply["port"];
|
||||
// ListenPublic = (bool)jsonReply["public"];
|
||||
}
|
||||
else
|
||||
{
|
||||
// jsonReply["port"] = Port;
|
||||
// jsonReply["public"] = ListenPublic;
|
||||
}
|
||||
return jsonReply;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user