Skip to content

Commit

Permalink
Ensure upgrading does not re-enable disabled nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
glopesdev committed Nov 14, 2022
1 parent e6b06e9 commit 7201015
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Bonsai.Editor/GraphModel/UpgradeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ static Stream GetWorkflowStream(string path)
else return File.Exists(path) ? File.OpenRead(path) : null;
}

static ExpressionBuilder ConvertBuilder(ExpressionBuilder builder, Func<ExpressionBuilder, ExpressionBuilder> selector)
{
//TODO: Remove this workaround for ensuring workflow node order (refactor core conversion API)
var set = new[] { new Node<ExpressionBuilder, ExpressionBuilderArgument>(builder) };
var result = set.Convert(selector, recurse: false);
return result.First().Value;
}

internal static bool TryUpgradeWorkflow(ExpressionBuilderGraph workflow, string fileName, out ExpressionBuilderGraph upgradedWorkflow)
{
Stream workflowStream;
Expand Down Expand Up @@ -113,6 +121,18 @@ static bool TryUpgradeBuilderNodes(ExpressionBuilderGraph workflow, SemanticVers
GetArgumentCount(workflow, argumentCount);
ExpressionBuilder UpgradeBuilder(ExpressionBuilder builder)
{
if (builder is DisableBuilder disableBuilder)
{
var upgradedBuilder = UpgradeBuilder(disableBuilder.Builder);
if (upgradedBuilder != disableBuilder.Builder)
{
upgradedBuilder = ConvertBuilder(disableBuilder, builder => upgradedBuilder);
return new DisableBuilder(upgradedBuilder);
}

return builder;
}

#pragma warning disable CS0612 // Type or member is obsolete
if (builder is SourceBuilder sourceBuilder)
{
Expand Down

0 comments on commit 7201015

Please sign in to comment.