HardcodedGameLocationProvider.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System;
  2. using System.IO;
  3. namespace FF8
  4. {
  5. public sealed class HardcodedGameLocationProvider
  6. {
  7. private readonly String[] _knownPaths;
  8. public HardcodedGameLocationProvider(String[] knownPaths)
  9. {
  10. _knownPaths = knownPaths ?? throw new ArgumentNullException(nameof(knownPaths));
  11. }
  12. public Boolean FindGameLocation(out GameLocation gameLocation)
  13. {
  14. using (var errors = new ExceptionList())
  15. {
  16. foreach (var path in _knownPaths)
  17. {
  18. try
  19. {
  20. if (!Directory.Exists(path))
  21. continue;
  22. gameLocation = new GameLocation(path);
  23. errors.Clear();
  24. return true;
  25. }
  26. catch (Exception ex)
  27. {
  28. errors.Add(ex);
  29. }
  30. }
  31. }
  32. gameLocation = null;
  33. return false;
  34. }
  35. }
  36. }