Fixed application path detection.

pull/4/head
kay.one 13 years ago
parent 508be34ebc
commit 5ea8fd22f7

@ -30,12 +30,24 @@ namespace NzbDrone.Common.Test
[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()); 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] [Test]
public void IsProduction_should_return_false_when_run_within_nunit() 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)); enviromentProvider.Version.Should().NotBe(new Version(version));
} }
[TearDown]
public void TearDown()
{
if (Directory.Exists(EnviromentProvider.ROOT_MARKER))
Directory.Delete(EnviromentProvider.ROOT_MARKER);
}
} }
} }

@ -7,10 +7,9 @@ namespace NzbDrone.Common
{ {
public class EnviromentProvider public class EnviromentProvider
{ {
public const string IIS_FOLDER_NAME = "iisexpress";
public const string NZBDRONE_PATH = "NZBDRONE_PATH"; public const string NZBDRONE_PATH = "NZBDRONE_PATH";
public const string NZBDRONE_PID = "NZBDRONE_PID"; public const string NZBDRONE_PID = "NZBDRONE_PID";
public const string ROOT_MARKER = "NzbDrone.Web";
#if DEBUG #if DEBUG
private static readonly bool isInDebug = true; private static readonly bool isInDebug = true;
@ -46,15 +45,20 @@ namespace NzbDrone.Common
{ {
string applicationPath; string applicationPath;
applicationPath = GetApplicationPath(Environment.CurrentDirectory); applicationPath = CrawlToRoot(StartUpPath);
if (!string.IsNullOrWhiteSpace(applicationPath))
return applicationPath;
applicationPath = CrawlToRoot(Environment.CurrentDirectory);
if (!string.IsNullOrWhiteSpace(applicationPath)) if (!string.IsNullOrWhiteSpace(applicationPath))
return applicationPath; return applicationPath;
applicationPath = GetApplicationPath(StartUpPath); applicationPath = CrawlToRoot(StartUpPath);
if (!string.IsNullOrWhiteSpace(applicationPath)) if (!string.IsNullOrWhiteSpace(applicationPath))
return applicationPath; return applicationPath;
applicationPath = GetApplicationPath(NzbDronePathFromEnviroment); applicationPath = CrawlToRoot(NzbDronePathFromEnviroment);
if (!string.IsNullOrWhiteSpace(applicationPath)) if (!string.IsNullOrWhiteSpace(applicationPath))
return 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); 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; directoryInfo = directoryInfo.Parent;
} }
return directoryInfo.FullName; 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
} }
} }
} }
} }

@ -118,7 +118,7 @@ namespace NzbDrone.Common
private void OnOutputDataReceived(object s, DataReceivedEventArgs e) private void OnOutputDataReceived(object s, DataReceivedEventArgs e)
{ {
if (e == null || String.IsNullOrWhiteSpace(e.Data) || e.Data.StartsWith("Request started:") || 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; return;
Console.WriteLine(e.Data); Console.WriteLine(e.Data);

@ -7,7 +7,7 @@ namespace NzbDrone.Common
{ {
private const string WEB_FOLDER = "NzbDrone.Web\\"; private const string WEB_FOLDER = "NzbDrone.Web\\";
private const string APP_DATA = "App_Data\\"; 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"; public const string IIS_EXE = "iisexpress.exe";

@ -31,9 +31,9 @@ namespace NzbDrone.Update
Console.WriteLine("Starting NzbDrone Update Client"); Console.WriteLine("Starting NzbDrone Update Client");
InitLoggers(); InitLoggers();
logger.Info("Initializing update application");
_kernel = new StandardKernel(); _kernel = new StandardKernel();
logger.Info("Updating NzbDrone to version {0}", _kernel.Get<EnviromentProvider>().Version);
_kernel.Get<Program>().Start(args); _kernel.Get<Program>().Start(args);
} }
catch (Exception e) catch (Exception e)

Loading…
Cancel
Save