Field.FSLookupService.cs 2.2 KB

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