From cd32a70179f3d9df198aa6b3b5d48ea5f79ac720 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Fri, 28 Oct 2011 21:54:33 -0700 Subject: [PATCH] Starting path clean up. (All paths should go through EnvironmentProvider) --- NzbDrone.Common/EnviromentProvider.cs | 44 +++++++++++++++ .../JobTests/BannerDownloadJobTest.cs | 4 +- .../ProviderTests/TvDbProviderTest.cs | 1 + .../GetAvilableUpdateFixture.cs | 1 + .../PreformUpdateFixture.cs | 2 + NzbDrone.Core/Datastore/Connection.cs | 8 +-- .../Instrumentation/LogConfiguration.cs | 3 +- NzbDrone.Core/NzbDrone.Core.csproj | 1 - .../Providers/Core/ConfigFileProvider.cs | 24 +++----- NzbDrone.Core/Providers/EnviromentProvider.cs | 55 ------------------- .../Providers/Jobs/BannerDownloadJob.cs | 4 +- NzbDrone.Core/Providers/TvDbProvider.cs | 3 +- NzbDrone.Core/Providers/UpdateProvider.cs | 2 + NzbDrone.Update/Providers/UpdateProvider.cs | 2 +- 14 files changed, 72 insertions(+), 82 deletions(-) delete mode 100644 NzbDrone.Core/Providers/EnviromentProvider.cs diff --git a/NzbDrone.Common/EnviromentProvider.cs b/NzbDrone.Common/EnviromentProvider.cs index f06208e8e..6b73c980d 100644 --- a/NzbDrone.Common/EnviromentProvider.cs +++ b/NzbDrone.Common/EnviromentProvider.cs @@ -67,6 +67,26 @@ public virtual string ApplicationPath } } + 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 @@ public virtual string StartUpPath } } + 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; diff --git a/NzbDrone.Core.Test/JobTests/BannerDownloadJobTest.cs b/NzbDrone.Core.Test/JobTests/BannerDownloadJobTest.cs index 4724f626c..58a678bdd 100644 --- a/NzbDrone.Core.Test/JobTests/BannerDownloadJobTest.cs +++ b/NzbDrone.Core.Test/JobTests/BannerDownloadJobTest.cs @@ -4,12 +4,14 @@ 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 @@ public void BannerDownload_some_failed_download() var fakeSeries = Builder.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(); diff --git a/NzbDrone.Core.Test/ProviderTests/TvDbProviderTest.cs b/NzbDrone.Core.Test/ProviderTests/TvDbProviderTest.cs index ebaa0752a..a7e570261 100644 --- a/NzbDrone.Core.Test/ProviderTests/TvDbProviderTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/TvDbProviderTest.cs @@ -5,6 +5,7 @@ using System.Linq; using FluentAssertions; using NUnit.Framework; +using NzbDrone.Common; using NzbDrone.Core.Providers; using NzbDrone.Core.Test.Framework; using TvdbLib.Data; diff --git a/NzbDrone.Core.Test/ProviderTests/UpdateProviderTests/GetAvilableUpdateFixture.cs b/NzbDrone.Core.Test/ProviderTests/UpdateProviderTests/GetAvilableUpdateFixture.cs index 0048c4bf1..5e30f3206 100644 --- a/NzbDrone.Core.Test/ProviderTests/UpdateProviderTests/GetAvilableUpdateFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/UpdateProviderTests/GetAvilableUpdateFixture.cs @@ -3,6 +3,7 @@ using FluentAssertions; using Moq; using NUnit.Framework; +using NzbDrone.Common; using NzbDrone.Core.Providers; using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Test.Framework; diff --git a/NzbDrone.Core.Test/ProviderTests/UpdateProviderTests/PreformUpdateFixture.cs b/NzbDrone.Core.Test/ProviderTests/UpdateProviderTests/PreformUpdateFixture.cs index 3ef354107..68e28f688 100644 --- a/NzbDrone.Core.Test/ProviderTests/UpdateProviderTests/PreformUpdateFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/UpdateProviderTests/PreformUpdateFixture.cs @@ -4,10 +4,12 @@ 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 { diff --git a/NzbDrone.Core/Datastore/Connection.cs b/NzbDrone.Core/Datastore/Connection.cs index 631f522cd..7c05d377f 100644 --- a/NzbDrone.Core/Datastore/Connection.cs +++ b/NzbDrone.Core/Datastore/Connection.cs @@ -4,6 +4,7 @@ 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 @@ public static String MainConnectionString { get { - return GetConnectionString(Path.Combine(AppDataPath.FullName, "nzbdrone.sdf")); + return GetConnectionString(Path.Combine(_enviromentProvider.AppDataPath, "nzbdrone.sdf")); } } @@ -38,7 +38,7 @@ public static String LogConnectionString { get { - return GetConnectionString(Path.Combine(AppDataPath.FullName, "log.sdf")); + return GetConnectionString(Path.Combine(_enviromentProvider.AppDataPath, "log.sdf")); } } diff --git a/NzbDrone.Core/Instrumentation/LogConfiguration.cs b/NzbDrone.Core/Instrumentation/LogConfiguration.cs index d21d8690a..d94c6d520 100644 --- a/NzbDrone.Core/Instrumentation/LogConfiguration.cs +++ b/NzbDrone.Core/Instrumentation/LogConfiguration.cs @@ -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 @@ public static void Setup() 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"); diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj index 3018c61d8..608076c01 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -212,7 +212,6 @@ - diff --git a/NzbDrone.Core/Providers/Core/ConfigFileProvider.cs b/NzbDrone.Core/Providers/Core/ConfigFileProvider.cs index 7ee204018..5047fec37 100644 --- a/NzbDrone.Core/Providers/Core/ConfigFileProvider.cs +++ b/NzbDrone.Core/Providers/Core/ConfigFileProvider.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 @@ public virtual void SetValue(string key, object value, string parent = null) 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")); + + xDoc.Add(new XElement("Config")); + + xDoc.Save(ConfigFile); } } - - public virtual void WriteDefaultConfig() - { - var xDoc = new XDocument(new XDeclaration("1.0", "utf-8", "yes")); - - xDoc.Add(new XElement("Config")); - - xDoc.Save(ConfigFile); - } } } diff --git a/NzbDrone.Core/Providers/EnviromentProvider.cs b/NzbDrone.Core/Providers/EnviromentProvider.cs deleted file mode 100644 index 85440060a..000000000 --- a/NzbDrone.Core/Providers/EnviromentProvider.cs +++ /dev/null @@ -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(); - } - } - - } -} diff --git a/NzbDrone.Core/Providers/Jobs/BannerDownloadJob.cs b/NzbDrone.Core/Providers/Jobs/BannerDownloadJob.cs index 83f5090ad..15e0ad431 100644 --- a/NzbDrone.Core/Providers/Jobs/BannerDownloadJob.cs +++ b/NzbDrone.Core/Providers/Jobs/BannerDownloadJob.cs @@ -4,9 +4,11 @@ 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 @@ public virtual void Start(ProgressNotification notification, int targetId, int s { 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) diff --git a/NzbDrone.Core/Providers/TvDbProvider.cs b/NzbDrone.Core/Providers/TvDbProvider.cs index efa59ee26..da8465070 100644 --- a/NzbDrone.Core/Providers/TvDbProvider.cs +++ b/NzbDrone.Core/Providers/TvDbProvider.cs @@ -4,6 +4,7 @@ using System.Text.RegularExpressions; using NLog; using Ninject; +using NzbDrone.Common; using TvdbLib; using TvdbLib.Cache; using TvdbLib.Data; @@ -22,7 +23,7 @@ public class TvDbProvider 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() diff --git a/NzbDrone.Core/Providers/UpdateProvider.cs b/NzbDrone.Core/Providers/UpdateProvider.cs index eb70e710f..bc682c026 100644 --- a/NzbDrone.Core/Providers/UpdateProvider.cs +++ b/NzbDrone.Core/Providers/UpdateProvider.cs @@ -6,8 +6,10 @@ 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 { diff --git a/NzbDrone.Update/Providers/UpdateProvider.cs b/NzbDrone.Update/Providers/UpdateProvider.cs index 1cc962ce9..b92f2d302 100644 --- a/NzbDrone.Update/Providers/UpdateProvider.cs +++ b/NzbDrone.Update/Providers/UpdateProvider.cs @@ -61,8 +61,8 @@ public void Start(string installationFolder) //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