From d4ff9f3f5c108493452879938aa224adb556b7c3 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 7 May 2022 21:53:18 -0400 Subject: log fake content packs created by mods --- src/SMAPI/Framework/ModHelpers/ContentPackHelper.cs | 10 +++++++++- src/SMAPI/Framework/SCore.cs | 14 +++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/SMAPI/Framework/ModHelpers/ContentPackHelper.cs b/src/SMAPI/Framework/ModHelpers/ContentPackHelper.cs index 9f4a7ceb..6bc091fa 100644 --- a/src/SMAPI/Framework/ModHelpers/ContentPackHelper.cs +++ b/src/SMAPI/Framework/ModHelpers/ContentPackHelper.cs @@ -42,7 +42,15 @@ namespace StardewModdingAPI.Framework.ModHelpers public IContentPack CreateFake(string directoryPath) { string id = Guid.NewGuid().ToString("N"); - return this.CreateTemporary(directoryPath, id, id, id, id, new SemanticVersion(1, 0, 0)); + string relativePath = Path.GetRelativePath(Constants.ModsPath, directoryPath); + return this.CreateTemporary( + directoryPath: directoryPath, + id: id, + name: $"{this.Mod.DisplayName} (fake content pack: {relativePath})", + description: $"A temporary content pack created by the {this.Mod.DisplayName} mod.", + author: "???", + new SemanticVersion(1, 0, 0) + ); } /// diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index c8dcf747..0465b6f1 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -1846,7 +1846,7 @@ namespace StardewModdingAPI.Framework IContentPackHelper contentPackHelper = new ContentPackHelper( mod: mod, contentPacks: new Lazy(GetContentPacks), - createContentPack: (dirPath, manifest) => this.CreateFakeContentPack(dirPath, manifest, contentCore, mod) + createContentPack: (dirPath, fakeManifest) => this.CreateFakeContentPack(dirPath, fakeManifest, contentCore, mod) ); IDataHelper dataHelper = new DataHelper(mod, mod.DirectoryPath, jsonHelper); IReflectionHelper reflectionHelper = new ReflectionHelper(mod, mod.DisplayName, this.Reflection); @@ -1883,8 +1883,10 @@ namespace StardewModdingAPI.Framework /// The mod for which the content pack is being created. private IContentPack CreateFakeContentPack(string packDirPath, IManifest packManifest, ContentCoordinator contentCore, IModMetadata parentMod) { + // create fake mod info + string relativePath = Path.GetRelativePath(Constants.ModsPath, packDirPath); IModMetadata fakeMod = new ModMetadata( - displayName: $"{parentMod.DisplayName} (fake content pack: {Path.GetRelativePath(Constants.ModsPath, packDirPath)})", + displayName: packManifest.Name, directoryPath: packDirPath, rootPath: Constants.ModsPath, manifest: packManifest, @@ -1892,16 +1894,22 @@ namespace StardewModdingAPI.Framework isIgnored: false ); + // create mod helpers IMonitor packMonitor = this.LogManager.GetMonitor(packManifest.Name); IFilePathLookup relativePathCache = this.GetFilePathLookup(packDirPath); - GameContentHelper gameContentHelper = new(contentCore, fakeMod, packManifest.Name, packMonitor, this.Reflection); IModContentHelper packContentHelper = new ModContentHelper(contentCore, packDirPath, fakeMod, packManifest.Name, gameContentHelper.GetUnderlyingContentManager(), relativePathCache, this.Reflection); TranslationHelper packTranslationHelper = new(fakeMod, contentCore.GetLocale(), contentCore.Language); + // add content pack ContentPack contentPack = new(packDirPath, packManifest, packContentHelper, packTranslationHelper, this.Toolkit.JsonHelper, relativePathCache); this.ReloadTranslationsForTemporaryContentPack(parentMod, contentPack); parentMod.FakeContentPacks.Add(new WeakReference(contentPack)); + + // log change + string pathLabel = packDirPath.Contains("..") ? packDirPath : relativePath; + this.Monitor.Log($"{parentMod.DisplayName} created dynamic content pack '{packManifest.Name}' (unique ID: {packManifest.UniqueID}{(packManifest.Name.Contains(pathLabel) ? "" : $", path: {pathLabel}")})."); + return contentPack; } -- cgit