Field.FSLookupService.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using System.Collections.Generic;
  2. using System.IO;
  3. // ReSharper disable StringLiteralTypo
  4. namespace OpenVIII.Fields
  5. {
  6. public static partial class Field
  7. {
  8. #region Classes
  9. public sealed class FSLookupService : ILookupService
  10. {
  11. #region Fields
  12. private readonly string _rootPath;
  13. #endregion Fields
  14. #region Constructors
  15. public FSLookupService(string rootPath)
  16. {
  17. if (!Directory.Exists(rootPath))
  18. throw new DirectoryNotFoundException(rootPath);
  19. _rootPath = rootPath;
  20. }
  21. #endregion Constructors
  22. #region Methods
  23. public IEnumerable<Info> Enumerate(string mask)
  24. {
  25. foreach (var filePath in Directory.EnumerateFiles(_rootPath, mask, SearchOption.AllDirectories))
  26. {
  27. var fieldName = Path.GetFileNameWithoutExtension(filePath);
  28. if (SkipInvalidFields(fieldName))
  29. continue;
  30. IDataProvider dataProvider = new FsDataProvider(filePath);
  31. yield return new Info(fieldName, dataProvider);
  32. }
  33. }
  34. public IEnumerable<Info> EnumerateAll() => Enumerate("*.mim");
  35. private static bool SkipInvalidFields(string fieldName)
  36. {
  37. switch (fieldName)
  38. {
  39. case "test":
  40. case "test1":
  41. case "test3":
  42. case "test10":
  43. case "test11":
  44. case "test12":
  45. case "bccent12":
  46. case "bccent15":
  47. case "bgroom_2":
  48. case "bg2f_1a":
  49. case "doani2_1":
  50. case "doani2_2":
  51. case "glclock2":
  52. case "glsta3":
  53. case "glsta4":
  54. case "glstage2":
  55. case "glwitch2":
  56. case "glyagu2":
  57. case "logo":
  58. // Corrupted JSM: Test data, invalid stack
  59. return true;
  60. default:
  61. return false;
  62. }
  63. }
  64. #endregion Methods
  65. }
  66. #endregion Classes
  67. }
  68. }