ConfigFile for NzbDrone.exe is now stored under App_Data for NzbDrone.Web. - This will be to provide the users a way to edit Port and set whether they want their default browser to open on startup, all form the WebUI (and not be overwritten on upgrades).
This commit is contained in:
parent
79472964ed
commit
f0f706b32c
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
|
||||
<Config>
|
||||
<Port>8989</Port>
|
||||
<LaunchBrowser>true</LaunchBrowser>
|
||||
</Config>
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
|
||||
<Config>
|
||||
<Port>8989</Port>
|
||||
<LaunchBrowser>true</LaunchBrowser>
|
||||
</Config>
|
|
@ -0,0 +1,84 @@
|
|||
using AutoMoq;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Providers.Core;
|
||||
using NzbDrone.Core.Repository;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test
|
||||
{
|
||||
[TestFixture]
|
||||
// ReSharper disable InconsistentNaming
|
||||
public class ConfigFileProviderTest : TestBase
|
||||
{
|
||||
[Test]
|
||||
public void GetValue_Success()
|
||||
{
|
||||
const string key = "Port";
|
||||
const string value = "8989";
|
||||
|
||||
var mocker = new AutoMoqer();
|
||||
|
||||
//Act
|
||||
var result = mocker.Resolve<ConfigFileProvider>().GetValue(key);
|
||||
|
||||
//Assert
|
||||
result.Should().Be(value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetInt_Success()
|
||||
{
|
||||
const string key = "Port";
|
||||
const int value = 8989;
|
||||
|
||||
var mocker = new AutoMoqer();
|
||||
|
||||
//Act
|
||||
var result = mocker.Resolve<ConfigFileProvider>().GetValueInt(key);
|
||||
|
||||
//Assert
|
||||
result.Should().Be(value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetBool_Success()
|
||||
{
|
||||
const string key = "LaunchBrowser";
|
||||
|
||||
var mocker = new AutoMoqer();
|
||||
|
||||
//Act
|
||||
var result = mocker.Resolve<ConfigFileProvider>().GetValueBoolean(key);
|
||||
|
||||
//Assert
|
||||
result.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetLaunchBrowser_Success()
|
||||
{
|
||||
var mocker = new AutoMoqer();
|
||||
|
||||
//Act
|
||||
var result = mocker.Resolve<ConfigFileProvider>().LaunchBrowser;
|
||||
|
||||
//Assert
|
||||
result.Should().Be(true);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetPort_Success()
|
||||
{
|
||||
const int value = 8989;
|
||||
|
||||
var mocker = new AutoMoqer();
|
||||
|
||||
//Act
|
||||
var result = mocker.Resolve<ConfigFileProvider>().Port;
|
||||
|
||||
//Assert
|
||||
result.Should().Be(value);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -90,6 +90,7 @@
|
|||
<ItemGroup>
|
||||
<Compile Include="BacklogSearchJobTest.cs" />
|
||||
<Compile Include="BannerDownloadJobTest.cs" />
|
||||
<Compile Include="ConfigFileProviderTest.cs" />
|
||||
<Compile Include="EpisodeProviderTest_DeleteInvalidEpisodes.cs" />
|
||||
<Compile Include="InventoryProvider_IsAcceptableSizeTest.cs" />
|
||||
<Compile Include="QualityTypeProviderTest.cs" />
|
||||
|
@ -153,6 +154,10 @@
|
|||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="App_Data\Config.xml">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Files\History.xml" />
|
||||
<Content Include="Files\RSS\newbin_none_english.xml">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
|
|
|
@ -203,6 +203,7 @@
|
|||
<Compile Include="Model\Xbmc\ActivePlayersResult.cs" />
|
||||
<Compile Include="Model\Xbmc\ErrorResult.cs" />
|
||||
<Compile Include="Model\Xbmc\IconType.cs" />
|
||||
<Compile Include="Providers\Core\ConfigFileProvider.cs" />
|
||||
<Compile Include="Providers\Core\UdpProvider.cs" />
|
||||
<Compile Include="Providers\Jobs\BacklogSearchJob.cs" />
|
||||
<Compile Include="Providers\Jobs\BannerDownloadJob.cs" />
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace NzbDrone.Core.Providers.Core
|
||||
{
|
||||
public class ConfigFileProvider
|
||||
{
|
||||
public string ConfigFile
|
||||
{
|
||||
get { return Path.Combine(CentralDispatch.AppPath, "App_Data", "Config.xml"); }
|
||||
}
|
||||
|
||||
public virtual int Port
|
||||
{
|
||||
get { return GetValueInt("Port"); }
|
||||
}
|
||||
|
||||
public virtual bool LaunchBrowser
|
||||
{
|
||||
get { return GetValueBoolean("LaunchBrowser"); }
|
||||
}
|
||||
|
||||
public virtual string GetValue(string key, string parent = null)
|
||||
{
|
||||
var xDoc = XDocument.Load(ConfigFile);
|
||||
var config = xDoc.Descendants("Config").Single();
|
||||
|
||||
var parentContainer = config;
|
||||
|
||||
if (parent != null)
|
||||
parentContainer = config.Descendants(parent).Single();
|
||||
|
||||
var value = parentContainer.Descendants(key).Single().Value;
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public virtual int GetValueInt(string key, string parent = null)
|
||||
{
|
||||
return Convert.ToInt32(GetValue(key, parent));
|
||||
}
|
||||
|
||||
public virtual bool GetValueBoolean(string key, string parent = null)
|
||||
{
|
||||
return Convert.ToBoolean(GetValue(key, parent));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,7 +1,9 @@
|
|||
using System;
|
||||
using System.Configuration;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Xml.Linq;
|
||||
using NLog;
|
||||
using NLog.Config;
|
||||
|
||||
|
@ -34,13 +36,77 @@ namespace NzbDrone
|
|||
|
||||
internal static int Port
|
||||
{
|
||||
get { return Convert.ToInt32(ConfigurationManager.AppSettings.Get("port")); }
|
||||
get { return GetValueInt("Port"); }
|
||||
}
|
||||
|
||||
internal static bool LaunchBrowser
|
||||
{
|
||||
get { return GetValueBoolean("LaunchBrowser"); }
|
||||
}
|
||||
|
||||
internal static string AppDataDirectory
|
||||
{
|
||||
get { return Path.Combine(ProjectRoot, "NzbDrone.Web", "App_Data"); }
|
||||
}
|
||||
|
||||
internal static string ConfigFile
|
||||
{
|
||||
get { return Path.Combine(AppDataDirectory, "Config.xml"); }
|
||||
}
|
||||
|
||||
internal static void ConfigureNlog()
|
||||
{
|
||||
LogManager.Configuration = new XmlLoggingConfiguration(
|
||||
Path.Combine(ProjectRoot, "NZBDrone.Web\\log.config"), false);
|
||||
Path.Combine(ProjectRoot, "NzbDrone.Web\\log.config"), false);
|
||||
}
|
||||
|
||||
internal static void CreateDefaultConfigFile()
|
||||
{
|
||||
//Create the config file here
|
||||
Directory.CreateDirectory(AppDataDirectory);
|
||||
|
||||
if (!File.Exists(ConfigFile))
|
||||
{
|
||||
WriteDefaultConfig();
|
||||
}
|
||||
}
|
||||
|
||||
internal static void WriteDefaultConfig()
|
||||
{
|
||||
var xDoc = new XDocument(new XDeclaration("1.0", "utf-8", "yes"));
|
||||
|
||||
xDoc.Add(new XElement("Config",
|
||||
new XElement("Port", 8989),
|
||||
new XElement("LaunchBrowser", true)
|
||||
)
|
||||
);
|
||||
|
||||
xDoc.Save(ConfigFile);
|
||||
}
|
||||
|
||||
private static string GetValue(string key, string parent = null)
|
||||
{
|
||||
var xDoc = XDocument.Load(ConfigFile);
|
||||
var config = xDoc.Descendants("Config").Single();
|
||||
|
||||
var parentContainer = config;
|
||||
|
||||
if (parent != null)
|
||||
parentContainer = config.Descendants(parent).Single();
|
||||
|
||||
var value = parentContainer.Descendants(key).Single().Value;
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
private static int GetValueInt(string key, string parent = null)
|
||||
{
|
||||
return Convert.ToInt32(GetValue(key, parent));
|
||||
}
|
||||
|
||||
private static bool GetValueBoolean(string key, string parent = null)
|
||||
{
|
||||
return Convert.ToBoolean(GetValue(key, parent));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -16,6 +16,7 @@ namespace NzbDrone
|
|||
try
|
||||
{
|
||||
Config.ConfigureNlog();
|
||||
Config.CreateDefaultConfigFile();
|
||||
Logger.Info("Starting NZBDrone. Start-up Path:'{0}'", Config.ProjectRoot);
|
||||
Thread.CurrentThread.Name = "Host";
|
||||
|
||||
|
@ -39,7 +40,7 @@ namespace NzbDrone
|
|||
Attach();
|
||||
#endif
|
||||
|
||||
if (!Environment.UserInteractive)
|
||||
if (!Environment.UserInteractive || !Config.LaunchBrowser)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
|
@ -3,7 +3,4 @@
|
|||
<startup useLegacyV2RuntimeActivationPolicy="true">
|
||||
<supportedRuntime version="v4.0" />
|
||||
</startup>
|
||||
<appSettings>
|
||||
<add key="port" value="8989" />
|
||||
</appSettings>
|
||||
</configuration>
|
Loading…
Reference in New Issue