Starting path clean up. (All paths should go through EnvironmentProvider)

pull/4/head
kay.one 13 years ago
parent 5b3f0bdffe
commit cd32a70179

@ -67,6 +67,26 @@ namespace NzbDrone.Common
}
}
public virtual string WebRoot
{
get
{
return Path.Combine(ApplicationPath, "NzbDrone.Web");
}
}
public virtual string AppDataPath
{
get
{
var path = Path.Combine(WebRoot, "App_data");
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
return path;
}
}
public virtual string StartUpPath
{
get
@ -75,6 +95,30 @@ namespace NzbDrone.Common
}
}
public virtual Version Version
{
get { return Assembly.GetExecutingAssembly().GetName().Version; }
}
public virtual DateTime BuildDateTime
{
get
{
var fileLocation = Assembly.GetCallingAssembly().Location;
return new FileInfo(fileLocation).CreationTime;
}
}
public virtual String TempPath
{
get
{
return Path.GetTempPath();
}
}
private static bool ContainsIIS(DirectoryInfo dir)
{
return dir.GetDirectories("iisexpress").Length != 0;

@ -4,12 +4,14 @@ using AutoMoq;
using FizzWare.NBuilder;
using Moq;
using NUnit.Framework;
using NzbDrone.Common;
using NzbDrone.Core.Model.Notification;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Providers.Jobs;
using NzbDrone.Core.Repository;
using NzbDrone.Core.Test.Framework;
using DiskProvider = NzbDrone.Core.Providers.Core.DiskProvider;
namespace NzbDrone.Core.Test.JobTests
{
@ -90,7 +92,7 @@ namespace NzbDrone.Core.Test.JobTests
var fakeSeries = Builder<Series>.CreateListOfSize(10)
.Build();
var path = Path.Combine(new EnviromentProvider().AppPath, "Content", "Images", "Banners");
var path = Path.Combine(new EnviromentProvider().WebRoot, "Content", "Images", "Banners");
var mocker = new AutoMoqer(MockBehavior.Strict);
mocker.Resolve<EnviromentProvider>();

@ -5,6 +5,7 @@ using System.Collections.Generic;
using System.Linq;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Common;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Test.Framework;
using TvdbLib.Data;

@ -3,6 +3,7 @@ using AutoMoq;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Common;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Test.Framework;

@ -4,10 +4,12 @@ using AutoMoq;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Common;
using NzbDrone.Core.Model;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Test.Framework;
using DiskProvider = NzbDrone.Core.Providers.Core.DiskProvider;
namespace NzbDrone.Core.Test.ProviderTests.UpdateProviderTests
{

@ -4,6 +4,7 @@ using System.Data.Common;
using System.Data.SqlServerCe;
using System.IO;
using MvcMiniProfiler.Data;
using NzbDrone.Common;
using NzbDrone.Core.Providers;
using PetaPoco;
@ -11,11 +12,10 @@ namespace NzbDrone.Core.Datastore
{
public static class Connection
{
private static readonly DirectoryInfo AppDataPath = new DirectoryInfo(Path.Combine(new EnviromentProvider().AppPath, "App_Data"));
private static EnviromentProvider _enviromentProvider = new EnviromentProvider();
static Connection()
{
if (!AppDataPath.Exists) AppDataPath.Create();
Database.Mapper = new CustomeMapper();
}
@ -30,7 +30,7 @@ namespace NzbDrone.Core.Datastore
{
get
{
return GetConnectionString(Path.Combine(AppDataPath.FullName, "nzbdrone.sdf"));
return GetConnectionString(Path.Combine(_enviromentProvider.AppDataPath, "nzbdrone.sdf"));
}
}
@ -38,7 +38,7 @@ namespace NzbDrone.Core.Datastore
{
get
{
return GetConnectionString(Path.Combine(AppDataPath.FullName, "log.sdf"));
return GetConnectionString(Path.Combine(_enviromentProvider.AppDataPath, "log.sdf"));
}
}

@ -2,6 +2,7 @@
using Ninject;
using NLog;
using NLog.Config;
using NzbDrone.Common;
using NzbDrone.Core.Providers;
namespace NzbDrone.Core.Instrumentation
@ -16,7 +17,7 @@ namespace NzbDrone.Core.Instrumentation
LogManager.ThrowExceptions = false;
}
LogManager.Configuration = new XmlLoggingConfiguration(Path.Combine(new EnviromentProvider().AppPath, "log.config"), false);
LogManager.Configuration = new XmlLoggingConfiguration(Path.Combine(new EnviromentProvider().WebRoot, "log.config"), false);
Common.LogConfiguration.RegisterConsoleLogger(LogLevel.Info, "NzbDrone.Web.MvcApplication");
Common.LogConfiguration.RegisterConsoleLogger(LogLevel.Info, "NzbDrone.Core.CentralDispatch");

@ -212,7 +212,6 @@
<Compile Include="Model\Xbmc\IconType.cs" />
<Compile Include="Providers\Converting\AtomicParsleyProvider.cs" />
<Compile Include="Providers\Converting\HandbrakeProvider.cs" />
<Compile Include="Providers\EnviromentProvider.cs" />
<Compile Include="Providers\Core\ConfigFileProvider.cs" />
<Compile Include="Providers\Core\UdpProvider.cs" />
<Compile Include="Providers\Jobs\BacklogSearchJob.cs" />

@ -1,17 +1,15 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Xml.Linq;
using NzbDrone.Common;
using NzbDrone.Core.Model;
namespace NzbDrone.Core.Providers.Core
{
public class ConfigFileProvider
{
private string _configFile = Path.Combine(new EnviromentProvider().AppPath, "App_Data", "Config.xml");
private string _configFile = Path.Combine(new EnviromentProvider().AppDataPath, "Config.xml");
public string ConfigFile
{
@ -112,22 +110,14 @@ namespace NzbDrone.Core.Providers.Core
public virtual void CreateDefaultConfigFile()
{
//Create the config file here
Directory.CreateDirectory(Path.Combine(new EnviromentProvider().AppPath, "App_Data"));
if (!File.Exists(ConfigFile))
{
WriteDefaultConfig();
}
}
var xDoc = new XDocument(new XDeclaration("1.0", "utf-8", "yes"));
public virtual void WriteDefaultConfig()
{
var xDoc = new XDocument(new XDeclaration("1.0", "utf-8", "yes"));
xDoc.Add(new XElement("Config"));
xDoc.Add(new XElement("Config"));
xDoc.Save(ConfigFile);
xDoc.Save(ConfigFile);
}
}
}
}

@ -1,55 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Web.Hosting;
using NLog;
using Ninject;
using NzbDrone.Core.Model;
using NzbDrone.Core.Providers.Core;
namespace NzbDrone.Core.Providers
{
public class EnviromentProvider
{
public virtual Version Version
{
get { return Assembly.GetExecutingAssembly().GetName().Version; }
}
public virtual DateTime BuildDateTime
{
get
{
var fileLocation = Assembly.GetCallingAssembly().Location;
return new FileInfo(fileLocation).CreationTime;
}
}
public virtual String AppPath
{
get
{
if (!String.IsNullOrWhiteSpace(HostingEnvironment.ApplicationPhysicalPath))
{
return HostingEnvironment.ApplicationPhysicalPath;
}
return Directory.GetCurrentDirectory();
}
}
public virtual String TempPath
{
get
{
return Path.GetTempPath();
}
}
}
}

@ -4,9 +4,11 @@ using System.IO;
using System.Linq;
using Ninject;
using NLog;
using NzbDrone.Common;
using NzbDrone.Core.Model.Notification;
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Repository;
using DiskProvider = NzbDrone.Core.Providers.Core.DiskProvider;
namespace NzbDrone.Core.Providers.Jobs
{
@ -49,7 +51,7 @@ namespace NzbDrone.Core.Providers.Jobs
{
Logger.Debug("Starting banner download job");
_bannerPath = Path.Combine(_enviromentProvider.AppPath, "Content", "Images", "Banners");
_bannerPath = Path.Combine(_enviromentProvider.WebRoot, "Content", "Images", "Banners");
_diskProvider.CreateDirectory(_bannerPath);
if (targetId > 0)

@ -4,6 +4,7 @@ using System.Linq;
using System.Text.RegularExpressions;
using NLog;
using Ninject;
using NzbDrone.Common;
using TvdbLib;
using TvdbLib.Cache;
using TvdbLib.Data;
@ -22,7 +23,7 @@ namespace NzbDrone.Core.Providers
public TvDbProvider(EnviromentProvider enviromentProvider)
{
_enviromentProvider = enviromentProvider;
_handler = new TvdbHandler(new XmlCacheProvider(_enviromentProvider.AppPath + @"\cache\tvdb"), TVDB_APIKEY);
_handler = new TvdbHandler(new XmlCacheProvider(_enviromentProvider.AppDataPath + @"\cache\tvdb"), TVDB_APIKEY);
}
public TvDbProvider()

@ -6,8 +6,10 @@ using System.Text;
using System.Text.RegularExpressions;
using NLog;
using Ninject;
using NzbDrone.Common;
using NzbDrone.Core.Model;
using NzbDrone.Core.Providers.Core;
using DiskProvider = NzbDrone.Core.Providers.Core.DiskProvider;
namespace NzbDrone.Core.Providers
{

@ -61,8 +61,8 @@ namespace NzbDrone.Update.Providers
//Copy update folder on top of the existing folder
//Happy: Start Service, Process?
//Happy: Cleanup
//Happy: Start Service, Process?
//Sad: delete fucked up folder
//Sad: restore backup

Loading…
Cancel
Save