2014-11-25 23:12:29 -05:00
|
|
|
|
using System;
|
|
|
|
|
using System.Configuration;
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
2017-08-16 13:30:16 -04:00
|
|
|
|
namespace MediaBrowser.Server.Mono
|
2014-11-25 23:12:29 -05:00
|
|
|
|
{
|
|
|
|
|
public static class ApplicationPathHelper
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the path to the application's ProgramDataFolder
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>System.String.</returns>
|
|
|
|
|
public static string GetProgramDataPath(string applicationPath)
|
|
|
|
|
{
|
|
|
|
|
var useDebugPath = false;
|
|
|
|
|
|
|
|
|
|
#if DEBUG
|
|
|
|
|
useDebugPath = true;
|
|
|
|
|
#endif
|
|
|
|
|
|
2016-09-24 13:58:17 -04:00
|
|
|
|
var programDataPath = useDebugPath ?
|
|
|
|
|
ConfigurationManager.AppSettings["DebugProgramDataPath"] :
|
|
|
|
|
ConfigurationManager.AppSettings["ReleaseProgramDataPath"];
|
2014-11-25 23:12:29 -05:00
|
|
|
|
|
|
|
|
|
programDataPath = programDataPath.Replace("%ApplicationData%", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData));
|
|
|
|
|
|
2016-09-24 13:58:17 -04:00
|
|
|
|
programDataPath = programDataPath
|
|
|
|
|
.Replace('/', Path.DirectorySeparatorChar)
|
|
|
|
|
.Replace('\\', Path.DirectorySeparatorChar);
|
|
|
|
|
|
2014-11-25 23:12:29 -05:00
|
|
|
|
// If it's a relative path, e.g. "..\"
|
|
|
|
|
if (!Path.IsPathRooted(programDataPath))
|
|
|
|
|
{
|
|
|
|
|
var path = Path.GetDirectoryName(applicationPath);
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(path))
|
|
|
|
|
{
|
|
|
|
|
throw new ApplicationException("Unable to determine running assembly location");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
programDataPath = Path.Combine(path, programDataPath);
|
|
|
|
|
|
|
|
|
|
programDataPath = Path.GetFullPath(programDataPath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Directory.CreateDirectory(programDataPath);
|
|
|
|
|
|
|
|
|
|
return programDataPath;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|