ApplicationPathHelper.cs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Threading.Tasks;
  6. namespace Emby.Server
  7. {
  8. public class ApplicationPathHelper
  9. {
  10. public static string GetProgramDataPath(string appDirectory)
  11. {
  12. var useDebugPath = false;
  13. #if DEBUG
  14. useDebugPath = true;
  15. #endif
  16. var programDataPath = useDebugPath ?
  17. "programdata" :
  18. "programdata";
  19. programDataPath = programDataPath
  20. .Replace('/', Path.DirectorySeparatorChar)
  21. .Replace('\\', Path.DirectorySeparatorChar);
  22. // If it's a relative path, e.g. "..\"
  23. if (!Path.IsPathRooted(programDataPath))
  24. {
  25. programDataPath = Path.Combine(appDirectory, programDataPath);
  26. programDataPath = Path.GetFullPath(programDataPath);
  27. }
  28. Directory.CreateDirectory(programDataPath);
  29. return programDataPath;
  30. }
  31. }
  32. }