예제 #1
0
        /// <inheritdoc/>
        public override TestResult OnTest(ConfigNode node, LoadContext loadContext, ref string nodeName)
        {
            if (node.GetValue("$$failed") != null)
            {
                return(TestResult.Failed);
            }
            var partName = PartNodePatcher.GetPartNameFromUpgradeNode(node, loadContext);

            if (partName == null)
            {
                return(TestResult.Pass); // Part was dropped during the upgrade.
            }
            List <ConfigNodePatch> patches;
            var hasMatches = false;

            if (_partPatches.TryGetValue(partName, out patches))
            {
                for (var i = patches.Count - 1; i >= 0; --i)
                {
                    var patch = patches[i];
                    try {
                        hasMatches |= PartNodePatcher.TestPatch(node, patch, loadContext);
                    } catch (Exception ex) {
                        DebugEx.Error("Cannot handle test condition: {0}", ex);
                        DebugEx.Warning("Disabling patch: {0}", patch);
                        patches.RemoveAt(i);
                    }
                }
            }
            return(hasMatches ? TestResult.Upgradeable : TestResult.Pass);
        }
예제 #2
0
        /// <inheritdoc/>
        public override void OnUpgrade(ConfigNode node, LoadContext loadContext, ConfigNode parentNode)
        {
            var partName = PartNodePatcher.GetPartNameFromUpgradeNode(node, loadContext);

            DebugEx.Warning("Patch saved game state for part: {0}", partName);
            var badPatches   = new List <ConfigNodePatch>();
            var applyPatches = _partPatches[partName];

            foreach (var patch in applyPatches)
            {
                try {
                    PartNodePatcher.PatchNode(node, patch, loadContext);
                } catch (Exception ex) {
                    DebugEx.Error("Cannot apply patch '" + patch + "': " + ex);
                    node.SetValue("$$failed", true, createIfNotFound: true);
                }
                // Ensure that the patch worked and won't trigger another patching round.
                if (PartNodePatcher.TestPatch(node, patch, loadContext, quietMode: true))
                {
                    badPatches.Add(patch);
                    node.SetValue("$$failed", true, createIfNotFound: true);
                }
            }
            foreach (var badPatch in badPatches)
            {
                applyPatches.Remove(badPatch);
                DebugEx.Error("Patch hasn't fixed the part, disabling it: {0}", badPatch);
            }
        }
예제 #3
0
 /// <inheritdoc/>
 protected override void OnInit()
 {
     _partPatches = PartNodePatcher.GetPatches("KAS")
                    .GroupBy(x => x.testSection.partTests.GetValue("name"))
                    .ToDictionary(
         x => x.Key,
         x => x.OrderBy(n => n.patchCreationTimestamp)
         .ThenBy(n => n.modName)
         .ToList());
     DebugEx.Fine("Loaded {0} part patch nodes", _partPatches.Count);
 }