using System.IO;
using StardewModdingAPI.Toolkit;
using StardewModdingAPI.Toolkit.Framework.GameScanning;
using StardewModdingAPI.Toolkit.Utilities;
namespace StardewModdingAPI.Installer.Framework
{
/// The installer context.
internal class InstallerContext
{
/*********
** Fields
*********/
/// The underlying toolkit game scanner.
private readonly GameScanner GameScanner = new();
/*********
** Accessors
*********/
/// The current OS.
public Platform Platform { get; }
/// The human-readable OS name and version.
public string PlatformName { get; }
/// Whether the installer is running on Windows.
public bool IsWindows => this.Platform == Platform.Windows;
/// Whether the installer is running on a Unix OS (including Linux or macOS).
public bool IsUnix => !this.IsWindows;
/*********
** Public methods
*********/
/// Construct an instance.
public InstallerContext()
{
this.Platform = EnvironmentUtility.DetectPlatform();
this.PlatformName = EnvironmentUtility.GetFriendlyPlatformName(this.Platform);
}
/// Get the installer's version number.
public ISemanticVersion GetInstallerVersion()
{
var raw = this.GetType().Assembly.GetName().Version;
return new SemanticVersion(raw);
}
/// Get whether a folder seems to contain the game files.
/// The folder to check.
public bool LooksLikeGameFolder(DirectoryInfo dir)
{
return this.GameScanner.LooksLikeGameFolder(dir);
}
/// Get whether a folder seems to contain the game, and which version it contains if so.
/// The folder to check.
public GameFolderType GetGameFolderType(DirectoryInfo dir)
{
return this.GameScanner.GetGameFolderType(dir);
}
}
}