From 5ea8fd22f7cc742c91c22b963b0f2a5295ed2ca7 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sun, 20 Nov 2011 19:42:45 -0800 Subject: [PATCH] Fixed application path detection. --- .../EnviromentProviderTest.cs | 23 ++++++++++++++-- NzbDrone.Common/EnviromentProvider.cs | 26 +++++++++++-------- NzbDrone.Common/IISProvider.cs | 2 +- NzbDrone.Common/PathExtentions.cs | 2 +- NzbDrone.Update/Program.cs | 4 +-- 5 files changed, 40 insertions(+), 17 deletions(-) diff --git a/NzbDrone.Common.Test/EnviromentProviderTest.cs b/NzbDrone.Common.Test/EnviromentProviderTest.cs index d5157062d..b7d253cf8 100644 --- a/NzbDrone.Common.Test/EnviromentProviderTest.cs +++ b/NzbDrone.Common.Test/EnviromentProviderTest.cs @@ -30,12 +30,24 @@ namespace NzbDrone.Common.Test [Test] - public void ApplicationPath_should_find_iis_in_current_folder() + public void ApplicationPath_should_find_root_in_current_folder() { - Directory.CreateDirectory(EnviromentProvider.IIS_FOLDER_NAME); + Directory.CreateDirectory(EnviromentProvider.ROOT_MARKER); enviromentProvider.ApplicationPath.Should().BeEquivalentTo(Directory.GetCurrentDirectory()); } + [Test] + public void crawl_should_return_null_if_cant_find_root() + { + enviromentProvider.CrawlToRoot("C:\\").Should().BeNullOrEmpty(); + } + + [Test] + public void should_go_up_the_tree_to_find_iis() + { + enviromentProvider.ApplicationPath.Should().NotBe(Environment.CurrentDirectory); + enviromentProvider.ApplicationPath.Should().NotBe(enviromentProvider.StartUpPath); + } [Test] public void IsProduction_should_return_false_when_run_within_nunit() { @@ -48,5 +60,12 @@ namespace NzbDrone.Common.Test { enviromentProvider.Version.Should().NotBe(new Version(version)); } + + [TearDown] + public void TearDown() + { + if (Directory.Exists(EnviromentProvider.ROOT_MARKER)) + Directory.Delete(EnviromentProvider.ROOT_MARKER); + } } } diff --git a/NzbDrone.Common/EnviromentProvider.cs b/NzbDrone.Common/EnviromentProvider.cs index 829781641..44826f96f 100644 --- a/NzbDrone.Common/EnviromentProvider.cs +++ b/NzbDrone.Common/EnviromentProvider.cs @@ -7,10 +7,9 @@ namespace NzbDrone.Common { public class EnviromentProvider { - public const string IIS_FOLDER_NAME = "iisexpress"; - public const string NZBDRONE_PATH = "NZBDRONE_PATH"; public const string NZBDRONE_PID = "NZBDRONE_PID"; + public const string ROOT_MARKER = "NzbDrone.Web"; #if DEBUG private static readonly bool isInDebug = true; @@ -46,15 +45,20 @@ namespace NzbDrone.Common { string applicationPath; - applicationPath = GetApplicationPath(Environment.CurrentDirectory); + applicationPath = CrawlToRoot(StartUpPath); + if (!string.IsNullOrWhiteSpace(applicationPath)) + return applicationPath; + + + applicationPath = CrawlToRoot(Environment.CurrentDirectory); if (!string.IsNullOrWhiteSpace(applicationPath)) return applicationPath; - applicationPath = GetApplicationPath(StartUpPath); + applicationPath = CrawlToRoot(StartUpPath); if (!string.IsNullOrWhiteSpace(applicationPath)) return applicationPath; - applicationPath = GetApplicationPath(NzbDronePathFromEnviroment); + applicationPath = CrawlToRoot(NzbDronePathFromEnviroment); if (!string.IsNullOrWhiteSpace(applicationPath)) return applicationPath; @@ -62,22 +66,22 @@ namespace NzbDrone.Common } } - private string GetApplicationPath(string dir) + public string CrawlToRoot(string dir) { var directoryInfo = new DirectoryInfo(dir); - while (!ContainsIIS(directoryInfo)) + while (!IsRoot(directoryInfo)) { - if (directoryInfo.Parent == null) break; + if (directoryInfo.Parent == null) return null; directoryInfo = directoryInfo.Parent; } return directoryInfo.FullName; } - private static bool ContainsIIS(DirectoryInfo dir) + private static bool IsRoot(DirectoryInfo dir) { - return dir.GetDirectories(IIS_FOLDER_NAME).Length != 0; + return dir.GetDirectories(ROOT_MARKER).Length != 0; } @@ -132,6 +136,6 @@ namespace NzbDrone.Common } } - + } } \ No newline at end of file diff --git a/NzbDrone.Common/IISProvider.cs b/NzbDrone.Common/IISProvider.cs index 86d6df842..c0c75b4c6 100644 --- a/NzbDrone.Common/IISProvider.cs +++ b/NzbDrone.Common/IISProvider.cs @@ -118,7 +118,7 @@ namespace NzbDrone.Common private void OnOutputDataReceived(object s, DataReceivedEventArgs e) { if (e == null || String.IsNullOrWhiteSpace(e.Data) || e.Data.StartsWith("Request started:") || - e.Data.StartsWith("Request ended:") || e.Data == ("IncrementMessages called") || e.Data == "iisexpress") + e.Data.StartsWith("Request ended:") || e.Data == ("IncrementMessages called") || e.Data == "iisexpress" || e.Data == "nzbdrone") return; Console.WriteLine(e.Data); diff --git a/NzbDrone.Common/PathExtentions.cs b/NzbDrone.Common/PathExtentions.cs index cc4ea2a19..d9fe4f070 100644 --- a/NzbDrone.Common/PathExtentions.cs +++ b/NzbDrone.Common/PathExtentions.cs @@ -7,7 +7,7 @@ namespace NzbDrone.Common { private const string WEB_FOLDER = "NzbDrone.Web\\"; private const string APP_DATA = "App_Data\\"; - public const string IIS_FOLDER = EnviromentProvider.IIS_FOLDER_NAME; + public const string IIS_FOLDER = "IISExpress"; public const string IIS_EXE = "iisexpress.exe"; diff --git a/NzbDrone.Update/Program.cs b/NzbDrone.Update/Program.cs index 8792aa85d..163268779 100644 --- a/NzbDrone.Update/Program.cs +++ b/NzbDrone.Update/Program.cs @@ -31,9 +31,9 @@ namespace NzbDrone.Update Console.WriteLine("Starting NzbDrone Update Client"); InitLoggers(); - logger.Info("Initializing update application"); - _kernel = new StandardKernel(); + + logger.Info("Updating NzbDrone to version {0}", _kernel.Get().Version); _kernel.Get().Start(args); } catch (Exception e)