From 115b06821ec2e55fd9bc8997784200f58cbf0a8e Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sun, 20 Nov 2011 16:52:40 -0800 Subject: [PATCH] Cleaned up Environment.ApplicationPath --- NzbDrone.Common/EnviromentProvider.cs | 51 ++++++++++++++++++--------- NzbDrone/Providers/IISProvider.cs | 2 -- 2 files changed, 35 insertions(+), 18 deletions(-) diff --git a/NzbDrone.Common/EnviromentProvider.cs b/NzbDrone.Common/EnviromentProvider.cs index 572d3460e..829781641 100644 --- a/NzbDrone.Common/EnviromentProvider.cs +++ b/NzbDrone.Common/EnviromentProvider.cs @@ -44,26 +44,40 @@ namespace NzbDrone.Common { get { - var dir = new DirectoryInfo(Environment.CurrentDirectory); + string applicationPath; - while (!ContainsIIS(dir)) - { - if (dir.Parent == null) break; - dir = dir.Parent; - } + applicationPath = GetApplicationPath(Environment.CurrentDirectory); + if (!string.IsNullOrWhiteSpace(applicationPath)) + return applicationPath; - if (ContainsIIS(dir)) return dir.FullName; + applicationPath = GetApplicationPath(StartUpPath); + if (!string.IsNullOrWhiteSpace(applicationPath)) + return applicationPath; - dir = new FileInfo(Assembly.GetExecutingAssembly().Location).Directory; + applicationPath = GetApplicationPath(NzbDronePathFromEnviroment); + if (!string.IsNullOrWhiteSpace(applicationPath)) + return applicationPath; - while (!ContainsIIS(dir)) - { - if (dir.Parent == null) throw new ApplicationException("Can't fine IISExpress folder."); - dir = dir.Parent; - } + throw new ApplicationException("Can't fine IISExpress folder."); + } + } - return dir.FullName; + private string GetApplicationPath(string dir) + { + var directoryInfo = new DirectoryInfo(dir); + + while (!ContainsIIS(directoryInfo)) + { + if (directoryInfo.Parent == null) break; + directoryInfo = directoryInfo.Parent; } + + return directoryInfo.FullName; + } + + private static bool ContainsIIS(DirectoryInfo dir) + { + return dir.GetDirectories(IIS_FOLDER_NAME).Length != 0; } @@ -110,9 +124,14 @@ namespace NzbDrone.Common } } - private static bool ContainsIIS(DirectoryInfo dir) + public virtual string NzbDronePathFromEnviroment { - return dir.GetDirectories(IIS_FOLDER_NAME).Length != 0; + get + { + return Environment.GetEnvironmentVariable(NZBDRONE_PATH); + } } + + } } \ No newline at end of file diff --git a/NzbDrone/Providers/IISProvider.cs b/NzbDrone/Providers/IISProvider.cs index 42e188ef4..04256fd66 100644 --- a/NzbDrone/Providers/IISProvider.cs +++ b/NzbDrone/Providers/IISProvider.cs @@ -1,10 +1,8 @@ using System; using System.Diagnostics; -using System.IO; using NLog; using Ninject; using NzbDrone.Common; -using NzbDrone.Common.Model; namespace NzbDrone.Providers {