diff options
Diffstat (limited to 'MediaBrowser.Server.Startup.Common')
| -rw-r--r-- | MediaBrowser.Server.Startup.Common/ApplicationPathHelper.cs | 45 | ||||
| -rw-r--r-- | MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj | 2 |
2 files changed, 47 insertions, 0 deletions
diff --git a/MediaBrowser.Server.Startup.Common/ApplicationPathHelper.cs b/MediaBrowser.Server.Startup.Common/ApplicationPathHelper.cs new file mode 100644 index 000000000..285806791 --- /dev/null +++ b/MediaBrowser.Server.Startup.Common/ApplicationPathHelper.cs @@ -0,0 +1,45 @@ +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 + + var programDataPath = useDebugPath ? ConfigurationManager.AppSettings["DebugProgramDataPath"] : ConfigurationManager.AppSettings["ReleaseProgramDataPath"]; + + programDataPath = programDataPath.Replace("%ApplicationData%", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)); + + // 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; + } + } +} diff --git a/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj b/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj index 46a771027..db525e8e4 100644 --- a/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj +++ b/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj @@ -41,6 +41,7 @@ <HintPath>..\ThirdParty\ServiceStack\ServiceStack.Interfaces.dll</HintPath> </Reference> <Reference Include="System" /> + <Reference Include="System.Configuration" /> <Reference Include="System.Core" /> <Reference Include="System.Xml.Linq" /> <Reference Include="System.Data.DataSetExtensions" /> @@ -53,6 +54,7 @@ <Link>Properties\SharedVersion.cs</Link> </Compile> <Compile Include="ApplicationHost.cs" /> + <Compile Include="ApplicationPathHelper.cs" /> <Compile Include="Browser\BrowserLauncher.cs" /> <Compile Include="EntryPoints\KeepServerAwake.cs" /> <Compile Include="EntryPoints\StartupWizard.cs" /> |
