diff options
Diffstat (limited to 'MediaBrowser.Server.Mono')
| -rw-r--r-- | MediaBrowser.Server.Mono/ApplicationPathHelper.cs | 51 | ||||
| -rw-r--r-- | MediaBrowser.Server.Mono/MediaBrowser.Server.Mono.csproj | 5 |
2 files changed, 52 insertions, 4 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; + } + } +} diff --git a/MediaBrowser.Server.Mono/MediaBrowser.Server.Mono.csproj b/MediaBrowser.Server.Mono/MediaBrowser.Server.Mono.csproj index a0b1d526a..7ddafb636 100644 --- a/MediaBrowser.Server.Mono/MediaBrowser.Server.Mono.csproj +++ b/MediaBrowser.Server.Mono/MediaBrowser.Server.Mono.csproj @@ -86,6 +86,7 @@ <Compile Include="..\SharedVersion.cs"> <Link>Properties\SharedVersion.cs</Link> </Compile> + <Compile Include="ApplicationPathHelper.cs" /> <Compile Include="ImageEncoderHelper.cs" /> <Compile Include="MonoAppHost.cs" /> <Compile Include="Native\MonoFileSystem.cs" /> @@ -131,10 +132,6 @@ <Project>{5624B7B5-B5A7-41D8-9F10-CC5611109619}</Project> <Name>MediaBrowser.WebDashboard</Name> </ProjectReference> - <ProjectReference Include="..\MediaBrowser.Server.Implementations\MediaBrowser.Server.Implementations.csproj"> - <Project>{2E781478-814D-4A48-9D80-BFF206441A65}</Project> - <Name>MediaBrowser.Server.Implementations</Name> - </ProjectReference> <ProjectReference Include="..\MediaBrowser.Providers\MediaBrowser.Providers.csproj"> <Project>{442B5058-DCAF-4263-BB6A-F21E31120A1B}</Project> <Name>MediaBrowser.Providers</Name> |
