using Microsoft.Win32;
using System.IO;
namespace OpenVIII
{
public sealed class WindowsGameLocationProvider : IGameLocationProvider
{
///
/// Steam 2013
///
private const string SteamRegistyPath = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Steam App 39150";
///
/// Steam 2013
///
private const string SteamGamePathTag = @"InstallLocation";
///
/// Supplied from LordUrQuan
///
private const string CD2000RegistyPath = @"SOFTWARE\Wow6432Node\Square Soft, Inc\FINAL FANTASY VIII\1.00";
///
/// Supplied from LordUrQuan
///
private const string CD2000GamePathTag = @"AppPath";
///
/// ReMaster
///
private const string SteamRERegistyPath = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Steam App 1026680";
///
/// ReMaster
///
private const string SteamREGamePathTag = @"InstallLocation";
public GameLocation GetGameLocation()
{
if (_hardcoded.FindGameLocation(out var gameLocation))
return gameLocation;
foreach (var registryView in new RegistryView[] { RegistryView.Registry32, RegistryView.Registry64 })
{
GameLocation r;
if ((r = Check(SteamRegistyPath, SteamGamePathTag)) == null &&
(r = Check(CD2000RegistyPath, CD2000RegistyPath)) == null &&
(r = Check(SteamRERegistyPath, SteamREGamePathTag)) == null)
continue;
else
return r;
GameLocation Check(string path, string tag)
{
using (var localMachine = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, registryView))
using (var registryKey = localMachine.OpenSubKey(path))
{
if (registryKey != null)
{
var installLocation = (string)registryKey.GetValue(tag);
var dataPath = installLocation;
if (Directory.Exists(dataPath))
return new GameLocation(dataPath);
}
}
return null;
}
}
throw new DirectoryNotFoundException($"Cannot find game directory." +
$"Add your own path to the {nameof(WindowsGameLocationProvider)} type or fix a registration in the registry:" +
$"{SteamRegistyPath}.{SteamGamePathTag}");
}
private readonly HardcodedGameLocationProvider _hardcoded = new HardcodedGameLocationProvider(new[]
{
@"C:\Program Files (x86)\Steam\steamapps\common\FINAL FANTASY VIII",//Data\lang-en
@"D:\SteamLibrary\steamapps\common\FINAL FANTASY VIII",
@"D:\Steam\steamapps\common\FINAL FANTASY VIII",
});
}
}