ConfigFile.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using Newtonsoft.Json;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. namespace FNZCM.Core
  6. {
  7. public interface IConfigFile
  8. {
  9. string ListenPrefix { get; }
  10. IReadOnlyCollection<string> AliasPrefix { get; }
  11. IReadOnlyCollection<string> AccessControlAllowOrigin { get; }
  12. string M3uPrefix { get; }
  13. string Title { get; }
  14. string AdminPassword { get; }
  15. bool LibraryPathFollowLink { get; }
  16. public string RealConfigFilePath { get; }
  17. IReadOnlyDictionary<string, string> Libraries { get; }
  18. string[] MediaFilePattern { get; }
  19. string[] BkFilePattern { get; }
  20. IReadOnlyDictionary<string, ModuleEntry> Modules { get; }
  21. }
  22. public class ConfigFile : IConfigFile
  23. {
  24. static string ConfigFilePath => Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config.json");
  25. public string RealConfigFilePath => new FileInfo(ConfigFilePath).LinkTarget ?? ConfigFilePath;
  26. static ConfigFile() => Reload();
  27. public static void Reload() => Instance = JsonConvert.DeserializeObject<ConfigFile>(File.ReadAllText(ConfigFilePath));
  28. public string ListenPrefix { get; set; }
  29. public IReadOnlyCollection<string> AliasPrefix { get; set; }
  30. public IReadOnlyCollection<string> AccessControlAllowOrigin { get; set; }
  31. public string M3uPrefix { get; set; }
  32. public string Title { get; set; }
  33. public string AdminPassword { get; set; }
  34. public bool LibraryPathFollowLink { get; set; }
  35. public IReadOnlyDictionary<string, string> Libraries { get; set; }
  36. public string[] MediaFilePattern { get; set; }
  37. public string[] BkFilePattern { get; set; }
  38. public static IConfigFile Instance { get; private set; }
  39. public IReadOnlyDictionary<string, ModuleEntry> Modules { get; set; }
  40. }
  41. public class ModuleEntry
  42. {
  43. public bool IsDefault { get; set; }
  44. public string DisplayText { get; set; }
  45. public string Path { get; set; }
  46. public bool EnableFallbackRoute { get; set; }
  47. public string DefaultDocument { get; set; }
  48. public string HtmlBaseReplace { get; set; }
  49. }
  50. }