WindowsGameLocationProvider.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System;
  2. using System.IO;
  3. using Microsoft.Win32;
  4. namespace FF8
  5. {
  6. public sealed class WindowsGameLocationProvider : IGameLocationProvider
  7. {
  8. private const String SteamRegistyPath = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Steam App 39150";
  9. private const String SteamGamePathTag = @"InstallLocation";
  10. /// <summary>
  11. /// Supplied from LordUrQuan
  12. /// </summary>
  13. private const String CD2000RegistyPath = @"SOFTWARE\Wow6432Node\Square Soft, Inc\FINAL FANTASY VIII\1.00";
  14. private const String CD2000GamePathTag = @"AppPath";
  15. public GameLocation GetGameLocation()
  16. {
  17. if (_hardcoded.FindGameLocation(out var gameLocation))
  18. return gameLocation;
  19. using (RegistryKey localMachine = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32))
  20. using (RegistryKey registryKey = localMachine.OpenSubKey(SteamRegistyPath))
  21. {
  22. if (registryKey != null)
  23. {
  24. String installLocation = (String)registryKey.GetValue(SteamGamePathTag);
  25. String dataPath = installLocation;//Path.Combine(installLocation, "Data", "lang-en");
  26. if (Directory.Exists(dataPath))
  27. return new GameLocation(dataPath);
  28. }
  29. }
  30. using (RegistryKey localMachine = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32))
  31. using (RegistryKey registryKey = localMachine.OpenSubKey(CD2000RegistyPath))
  32. {
  33. String installLocation = (String)registryKey.GetValue(CD2000GamePathTag);
  34. String dataPath = installLocation; //Path.Combine(installLocation, "Data"); //no lang-en on cd version.
  35. if (Directory.Exists(dataPath))
  36. return new GameLocation(dataPath);
  37. }
  38. throw new DirectoryNotFoundException($"Cannot find game directory." +
  39. $"Add your own path to the {nameof(WindowsGameLocationProvider)} type or fix a registration in the registry:" +
  40. $"{SteamRegistyPath}.{SteamGamePathTag}");
  41. }
  42. private readonly HardcodedGameLocationProvider _hardcoded = new HardcodedGameLocationProvider(new[]
  43. {
  44. @"C:\Program Files (x86)\Steam\steamapps\common\FINAL FANTASY VIII",//Data\lang-en
  45. @"D:\SteamLibrary\steamapps\common\FINAL FANTASY VIII",
  46. @"D:\Steam\steamapps\common\FINAL FANTASY VIII",
  47. });
  48. }
  49. }