Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure upgrading does not re-enable disabled nodes #1132

Merged
merged 1 commit into from
Nov 14, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Bonsai.Editor/GraphModel/UpgradeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ static bool IsEmbeddedResourcePath(string path)
return separatorIndex >= 0 && !Path.IsPathRooted(path);
}

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)
{
if (!IsEmbeddedResourcePath(fileName) && File.Exists(fileName))
Expand Down Expand Up @@ -95,6 +103,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