mirror of https://github.com/Radarr/Radarr
Cleaned up Environment.ApplicationPath
This commit is contained in:
parent
6778a6ed99
commit
115b06821e
|
@ -44,26 +44,40 @@ namespace NzbDrone.Common
|
|||
{
|
||||
get
|
||||
{
|
||||
var dir = new DirectoryInfo(Environment.CurrentDirectory);
|
||||
string applicationPath;
|
||||
|
||||
while (!ContainsIIS(dir))
|
||||
applicationPath = GetApplicationPath(Environment.CurrentDirectory);
|
||||
if (!string.IsNullOrWhiteSpace(applicationPath))
|
||||
return applicationPath;
|
||||
|
||||
applicationPath = GetApplicationPath(StartUpPath);
|
||||
if (!string.IsNullOrWhiteSpace(applicationPath))
|
||||
return applicationPath;
|
||||
|
||||
applicationPath = GetApplicationPath(NzbDronePathFromEnviroment);
|
||||
if (!string.IsNullOrWhiteSpace(applicationPath))
|
||||
return applicationPath;
|
||||
|
||||
throw new ApplicationException("Can't fine IISExpress folder.");
|
||||
}
|
||||
}
|
||||
|
||||
private string GetApplicationPath(string dir)
|
||||
{
|
||||
if (dir.Parent == null) break;
|
||||
dir = dir.Parent;
|
||||
}
|
||||
var directoryInfo = new DirectoryInfo(dir);
|
||||
|
||||
if (ContainsIIS(dir)) return dir.FullName;
|
||||
|
||||
dir = new FileInfo(Assembly.GetExecutingAssembly().Location).Directory;
|
||||
|
||||
while (!ContainsIIS(dir))
|
||||
while (!ContainsIIS(directoryInfo))
|
||||
{
|
||||
if (dir.Parent == null) throw new ApplicationException("Can't fine IISExpress folder.");
|
||||
dir = dir.Parent;
|
||||
if (directoryInfo.Parent == null) break;
|
||||
directoryInfo = directoryInfo.Parent;
|
||||
}
|
||||
|
||||
return dir.FullName;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -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
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue