aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Server.Mono/ApplicationPathHelper.cs
diff options
context:
space:
mode:
authorLuke <luke.pulverenti@gmail.com>2017-08-19 16:06:14 -0400
committerGitHub <noreply@github.com>2017-08-19 16:06:14 -0400
commitff2f3108ee62fc8c943b1d83ec6312d6696990d8 (patch)
tree80f1823f901bdadad6af4fce8d36d9b73f79c0fb /MediaBrowser.Server.Mono/ApplicationPathHelper.cs
parent6b077f3f8467caa26388a25e6acd1990d286b5d0 (diff)
parentc58db90c950c766321615eca236557d87b8d1b74 (diff)
Merge pull request #2832 from MediaBrowser/beta
Beta
Diffstat (limited to 'MediaBrowser.Server.Mono/ApplicationPathHelper.cs')
-rw-r--r--MediaBrowser.Server.Mono/ApplicationPathHelper.cs51
1 files changed, 51 insertions, 0 deletions
diff --git a/MediaBrowser.Server.Mono/ApplicationPathHelper.cs b/MediaBrowser.Server.Mono/ApplicationPathHelper.cs
new file mode 100644
index 000000000..c8cca40ff
--- /dev/null
+++ b/MediaBrowser.Server.Mono/ApplicationPathHelper.cs
@@ -0,0 +1,51 @@
+using System;
+using System.Configuration;
+using System.IO;
+
+namespace MediaBrowser.Server.Mono
+{
+ 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
+
+ var programDataPath = useDebugPath ?
+ ConfigurationManager.AppSettings["DebugProgramDataPath"] :
+ ConfigurationManager.AppSettings["ReleaseProgramDataPath"];
+
+ programDataPath = programDataPath.Replace("%ApplicationData%", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData));
+
+ programDataPath = programDataPath
+ .Replace('/', Path.DirectorySeparatorChar)
+ .Replace('\\', Path.DirectorySeparatorChar);
+
+ // 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;
+ }
+ }
+}