From 71d6803ebafa6e79f6cc5626ab794e1bfe952c7c Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Mon, 29 Apr 2024 14:44:04 +0200 Subject: [PATCH] [msbuild] Refactor out function in CompileSceneKitAssets to make code reuse possible --- .../Tasks/CompileSceneKitAssets.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/msbuild/Xamarin.MacDev.Tasks/Tasks/CompileSceneKitAssets.cs b/msbuild/Xamarin.MacDev.Tasks/Tasks/CompileSceneKitAssets.cs index f7209f6a5a0a..63c2acb4346e 100644 --- a/msbuild/Xamarin.MacDev.Tasks/Tasks/CompileSceneKitAssets.cs +++ b/msbuild/Xamarin.MacDev.Tasks/Tasks/CompileSceneKitAssets.cs @@ -118,6 +118,14 @@ Task CopySceneKitAssets (string scnassets, string output, string intermediate) return ExecuteAsync (GetFullPathToTool (), args, sdkDevPath: SdkDevPath, environment: environment, showErrorIfFailure: true); } + static bool TryGetScnAssetsPath (string file, out string scnassets) + { + scnassets = file; + while (scnassets.Length > 0 && Path.GetExtension (scnassets).ToLowerInvariant () != ".scnassets") + scnassets = Path.GetDirectoryName (scnassets); + return scnassets.Length > 0; + } + public override bool Execute () { if (ShouldExecuteRemotely ()) { @@ -141,11 +149,7 @@ public override bool Execute () continue; // get the .scnassets directory path - var scnassets = Path.GetDirectoryName (asset.ItemSpec); - while (scnassets.Length > 0 && Path.GetExtension (scnassets).ToLowerInvariant () != ".scnassets") - scnassets = Path.GetDirectoryName (scnassets); - - if (scnassets.Length == 0) + if (!TryGetScnAssetsPath (asset.ItemSpec, out var scnassets)) continue; asset.RemoveMetadata ("LogicalName");