/********* ** Public methods *********/ /// <summary>Construct an instance.</summary> /// <param name="path">The path to the patch from the root content file.</param> /// <param name="assetName">The normalized asset name to intercept.</param> /// <param name="conditions">The conditions which determine whether this patch should be applied.</param> /// <param name="fromFile">The normalized asset key from which to load entries (if applicable), including tokens.</param> /// <param name="updateRate">When the patch should be updated.</param> /// <param name="contentPack">The content pack which requested the patch.</param> /// <param name="parentPatch">The parent patch for which this patch was loaded, if any.</param> /// <param name="normalizeAssetName">Normalize an asset name.</param> /// <param name="monitor">Encapsulates monitoring and logging.</param> /// <param name="patchLoader">Handles loading and unloading patches for content packs.</param> public IncludePatch(LogPathBuilder path, IManagedTokenString assetName, IEnumerable <Condition> conditions, IManagedTokenString fromFile, UpdateRate updateRate, RawContentPack contentPack, IPatch parentPatch, Func <string, string> normalizeAssetName, IMonitor monitor, PatchLoader patchLoader) : base( path: path, type: PatchType.Include, assetName: assetName, conditions: conditions, fromAsset: fromFile, updateRate: updateRate, parentPatch: parentPatch, contentPack: contentPack.ContentPack, normalizeAssetName: normalizeAssetName ) { this.RawContentPack = contentPack; this.Monitor = monitor; this.PatchLoader = patchLoader; }
/// <inheritdoc /> public override void Handle(string[] args) { var patchLoader = this.GetPatchLoader(); // get pack ID if (args.Length != 1) { this.Monitor.Log("The 'patch reload' command expects a single arguments containing the target content pack ID. See 'patch help' for more info.", LogLevel.Error); return; } string packId = args[0]; // get pack RawContentPack pack = this.ContentPacks.SingleOrDefault(p => p.Manifest.UniqueID == packId); if (pack == null) { this.Monitor.Log($"No Content Patcher content pack with the unique ID \"{packId}\".", LogLevel.Error); return; } // unload patches patchLoader.UnloadPatchesLoadedBy(pack, false); // load pack patches if (!pack.TryReloadContent(out string loadContentError)) { this.Monitor.Log($"Failed to reload content pack '{pack.Manifest.Name}' for configuration changes: {loadContentError}. The content pack may not be in a valid state.", LogLevel.Error); // should never happen return; } // reload patches patchLoader.LoadPatches( contentPack: pack, rawPatches: pack.Content.Changes, rootIndexPath: new[] { pack.Index }, path: new LogPathBuilder(pack.Manifest.Name), reindex: true, parentPatch: null ); // make the changes apply this.UpdateContext(); this.Monitor.Log("Content pack reloaded.", LogLevel.Info); }
/// <summary>Handle the 'patch reload' command.</summary> /// <param name="args">The subcommand arguments.</param> /// <returns>Returns whether the command was handled.</returns> private bool HandleReload(string[] args) { // get pack ID if (args.Length != 1) { this.Monitor.Log("The 'patch reload' command expects a single arguments containing the target content pack ID. See 'patch help' for more info.", LogLevel.Error); return(true); } string packId = args[0]; // get pack RawContentPack pack = this.ContentPacks.SingleOrDefault(p => p.Manifest.UniqueID == packId); if (pack == null) { this.Monitor.Log($"No Content Patcher content pack with the unique ID \"{packId}\".", LogLevel.Error); return(true); } // unload patches this.PatchLoader.UnloadPatchesLoadedBy(pack, false); // load pack patches var changes = pack.ContentPack.ReadJsonFile <ContentConfig>("content.json").Changes; pack.Content.Changes = changes; // reload patches this.PatchLoader.LoadPatches( contentPack: pack, rawPatches: pack.Content.Changes, rootIndexPath: new[] { pack.Index }, path: new LogPathBuilder(pack.Manifest.Name), reindex: true, parentPatch: null ); // make the changes apply this.UpdateContext(); this.Monitor.Log("Content pack reloaded.", LogLevel.Info); return(true); }
private IEnumerable <RawContentPack> GetContentPacks(IMigration[] migrations) { this.Monitor.VerboseLog("Preloading content packs..."); foreach (IContentPack contentPack in this.Helper.ContentPacks.GetOwned()) { RawContentPack rawContentPack; try { // validate content.json has required fields ContentConfig content = contentPack.ReadJsonFile <ContentConfig>(this.PatchFileName); if (content == null) { this.Monitor.Log($"Ignored content pack '{contentPack.Manifest.Name}' because it has no {this.PatchFileName} file.", LogLevel.Error); continue; } if (content.Format == null || content.Changes == null) { this.Monitor.Log($"Ignored content pack '{contentPack.Manifest.Name}' because it doesn't specify the required {nameof(ContentConfig.Format)} or {nameof(ContentConfig.Changes)} fields.", LogLevel.Error); continue; } // apply migrations IMigration migrator = new AggregateMigration(content.Format, this.SupportedFormatVersions, migrations); if (!migrator.TryMigrate(content, out string error)) { this.Monitor.Log($"Loading content pack '{contentPack.Manifest.Name}' failed: {error}.", LogLevel.Error); continue; } // init rawContentPack = new RawContentPack(new ManagedContentPack(contentPack), content, migrator); } catch (Exception ex) { this.Monitor.Log($"Error preloading content pack '{contentPack.Manifest.Name}'. Technical details:\n{ex}", LogLevel.Error); continue; } yield return(rawContentPack); } }