jellyfin/MediaBrowser.Server.Startup.Common/ApplicationPathHelper.cs

52 lines
1.6 KiB
C#
Raw Normal View History

2014-11-26 04:12:29 +00:00
using System;
using System.Configuration;
using System.IO;
namespace MediaBrowser.Server.Startup.Common
{
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 17:58:17 +00:00
var programDataPath = useDebugPath ?
ConfigurationManager.AppSettings["DebugProgramDataPath"] :
ConfigurationManager.AppSettings["ReleaseProgramDataPath"];
2014-11-26 04:12:29 +00:00
programDataPath = programDataPath.Replace("%ApplicationData%", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData));
2016-09-24 17:58:17 +00:00
programDataPath = programDataPath
.Replace('/', Path.DirectorySeparatorChar)
.Replace('\\', Path.DirectorySeparatorChar);
2014-11-26 04:12:29 +00: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;
}
}
}