using System; using System.IO; using System.Linq; using System.Reflection; using StardewValley; namespace StardewModdingAPI { /// Contains SMAPI's constants and assumptions. public static class Constants { /********* ** Properties *********/ /// The directory name containing the current save's data (if a save is loaded). private static string RawSaveFolderName => Constants.PlayerNull ? string.Empty : Constants.GetSaveFolderName(); /// The directory path containing the current save's data (if a save is loaded). private static string RawSavePath => Constants.PlayerNull ? string.Empty : Path.Combine(Constants.SavesPath, Constants.RawSaveFolderName); /********* ** Accessors *********/ /// SMAPI's current semantic version. public static readonly Version Version = new Version(1, 0, 0, null); /// The minimum supported version of Stardew Valley. public const string MinimumGameVersion = "1.1"; /// The GitHub repository to check for updates. public const string GitHubRepository = "Pathoschild/SMAPI"; /// The directory path containing Stardew Valley's app data. public static string DataPath => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StardewValley"); /// The directory path where all saves are stored. public static string SavesPath => Path.Combine(Constants.DataPath, "Saves"); /// Whether the directory containing the current save's data exists on disk. public static bool CurrentSavePathExists => Directory.Exists(Constants.RawSavePath); /// The directory name containing the current save's data (if a save is loaded and the directory exists). public static string SaveFolderName => Constants.CurrentSavePathExists ? Constants.RawSaveFolderName : ""; /// The directory path containing the current save's data (if a save is loaded and the directory exists). public static string CurrentSavePath => Constants.CurrentSavePathExists ? Constants.RawSavePath : ""; /// Whether a player save has been loaded. public static bool PlayerNull => !Game1.hasLoadedGame || Game1.player == null || string.IsNullOrEmpty(Game1.player.name); /// The path to the current assembly being executing. public static string ExecutionPath => Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); /// The title of the SMAPI console window. public static string ConsoleTitle => $"Stardew Modding API Console - Version {Constants.Version} - Mods Loaded: {Program.ModsLoaded}"; /// The directory path in which error logs should be stored. public static string LogDir => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StardewValley", "ErrorLogs"); /// The file path to the error log where the latest output should be saved. public static string LogPath => Path.Combine(Constants.LogDir, "MODDED_ProgramLog.Log_LATEST.txt"); /********* ** Private field *********/ /// Get the name of a save directory for the current player. private static string GetSaveFolderName() { string prefix = new string(Game1.player.name.Where(char.IsLetterOrDigit).ToArray()); return $"{prefix}_{Game1.uniqueIDForThisGame}"; } } }