using System; using System.IO; namespace StardewModdingAPI { /// The base class for a mod. public class Mod { /********* ** Properties *********/ /// The backing field for . private string _pathOnDisk; /********* ** Accessors *********/ /// Provides methods for interacting with the mod directory, such as read/writing a config file or custom JSON files. public ModHelper Helper { get; internal set; } /// The mod's manifest. public Manifest Manifest { get; internal set; } /// The full path to the mod's directory on the disk. [Obsolete("Use " + nameof(Mod.Helper) + "." + nameof(ModHelper.DirectoryPath) + " instead")] public string PathOnDisk { get { Program.DeprecationManager.Warn($"{nameof(Mod)}.{nameof(PathOnDisk)}", "1.0"); return this._pathOnDisk; } internal set { this._pathOnDisk = value; } } /// The full path to the mod's config.json file on the disk. [Obsolete("Use " + nameof(Mod.Helper) + "." + nameof(ModHelper.ReadConfig) + " instead")] public string BaseConfigPath { get { Program.DeprecationManager.Warn($"{nameof(Mod)}.{nameof(BaseConfigPath)}", "1.0"); Program.DeprecationManager.MarkWarned($"{nameof(Mod)}.{nameof(PathOnDisk)}", "1.0"); // avoid redundant warnings return Path.Combine(this.PathOnDisk, "config.json"); } } /// The full path to the per-save configs folder (if is true). [Obsolete("Use " + nameof(Mod.Helper) + "." + nameof(ModHelper.ReadJsonFile) + " instead")] public string PerSaveConfigFolder => this.GetPerSaveConfigFolder(); /// The full path to the per-save configuration file for the current save (if is true). [Obsolete("Use " + nameof(Mod.Helper) + "." + nameof(ModHelper.ReadJsonFile) + " instead")] public string PerSaveConfigPath { get { Program.DeprecationManager.Warn($"{nameof(Mod)}.{nameof(PerSaveConfigPath)}", "1.0"); Program.DeprecationManager.MarkWarned($"{nameof(Mod)}.{nameof(PerSaveConfigFolder)}", "1.0"); // avoid redundant warnings return Constants.CurrentSavePathExists ? Path.Combine(this.PerSaveConfigFolder, Constants.SaveFolderName + ".json") : ""; } } /********* ** Public methods *********/ /// The entry point for your mod. It will always be called once when the mod loads. [Obsolete("This overload is obsolete since SMAPI 1.0.")] public virtual void Entry(params object[] objects) { } /// The entry point for your mod. It will always be called once when the mod loads. /// Provides methods for interacting with the mod directory, such as read/writing a config file or custom JSON files. public virtual void Entry(ModHelper helper) { } /********* ** Private methods *********/ /// Get the full path to the per-save configuration file for the current save (if is true). private string GetPerSaveConfigFolder() { Program.DeprecationManager.Warn($"{nameof(Mod)}.{nameof(PerSaveConfigFolder)}", "1.0"); Program.DeprecationManager.MarkWarned($"{nameof(Mod)}.{nameof(PathOnDisk)}", "1.0"); // avoid redundant warnings if (!this.Manifest.PerSaveConfigs) { Log.Error($"The mod [{this.Manifest.Name}] is not configured to use per-save configs."); return ""; } return Path.Combine(this.PathOnDisk, "psconfigs"); } } }