mirror of
https://github.com/Sonarr/Sonarr.git
synced 2025-01-04 06:38:28 +02:00
Fixed application path detection.
This commit is contained in:
parent
508be34ebc
commit
5ea8fd22f7
@ -30,12 +30,24 @@ public void ApplicationPath_should_not_be_empty()
|
||||
|
||||
|
||||
[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 @@ public void Application_version_should_not_be_default(string 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 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 @@ public virtual string ApplicationPath
|
||||
{
|
||||
string applicationPath;
|
||||
|
||||
applicationPath = GetApplicationPath(Environment.CurrentDirectory);
|
||||
applicationPath = CrawlToRoot(StartUpPath);
|
||||
if (!string.IsNullOrWhiteSpace(applicationPath))
|
||||
return applicationPath;
|
||||
|
||||
applicationPath = GetApplicationPath(StartUpPath);
|
||||
|
||||
applicationPath = CrawlToRoot(Environment.CurrentDirectory);
|
||||
if (!string.IsNullOrWhiteSpace(applicationPath))
|
||||
return applicationPath;
|
||||
|
||||
applicationPath = GetApplicationPath(NzbDronePathFromEnviroment);
|
||||
applicationPath = CrawlToRoot(StartUpPath);
|
||||
if (!string.IsNullOrWhiteSpace(applicationPath))
|
||||
return applicationPath;
|
||||
|
||||
applicationPath = CrawlToRoot(NzbDronePathFromEnviroment);
|
||||
if (!string.IsNullOrWhiteSpace(applicationPath))
|
||||
return applicationPath;
|
||||
|
||||
@ -62,22 +66,22 @@ public virtual string ApplicationPath
|
||||
}
|
||||
}
|
||||
|
||||
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 @@ public virtual string NzbDronePathFromEnviroment
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -118,7 +118,7 @@ public virtual void StopServer()
|
||||
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);
|
||||
|
@ -7,7 +7,7 @@ public static class PathExtentions
|
||||
{
|
||||
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";
|
||||
|
||||
|
||||
|
@ -31,9 +31,9 @@ public static void Main(string[] args)
|
||||
Console.WriteLine("Starting NzbDrone Update Client");
|
||||
|
||||
InitLoggers();
|
||||
logger.Info("Initializing update application");
|
||||
|
||||
_kernel = new StandardKernel();
|
||||
|
||||
logger.Info("Updating NzbDrone to version {0}", _kernel.Get<EnviromentProvider>().Version);
|
||||
_kernel.Get<Program>().Start(args);
|
||||
}
|
||||
catch (Exception e)
|
||||
|
Loading…
Reference in New Issue
Block a user