From 65197483762bc41a974f05950b56ceb7a8e5c6e7 Mon Sep 17 00:00:00 2001 From: Stamatios Psarras Date: Mon, 2 Dec 2024 13:26:28 +0000 Subject: [PATCH] GSAGH-567: Cannot Open File with Whitespaces (#734) Co-authored-by: DominikaLos <83698580+DominikaLos@users.noreply.github.com> --- GsaGH/Components/0_Model/SaveGsaModel.cs | 3 ++- .../3_Components/0_Model/SaveGsaModelTests.cs | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/GsaGH/Components/0_Model/SaveGsaModel.cs b/GsaGH/Components/0_Model/SaveGsaModel.cs index e3a6ab94e..5d54d7281 100644 --- a/GsaGH/Components/0_Model/SaveGsaModel.cs +++ b/GsaGH/Components/0_Model/SaveGsaModel.cs @@ -34,6 +34,7 @@ public class SaveGsaModel : GH_OasysDropDownComponent { public override OasysPluginInfo PluginInfo => GsaGH.PluginInfo.Instance; protected override Bitmap Icon => Resources.SaveGsaModel; private string _fileNameLastSaved; + internal string FileNameLastSavedFullPath => $"\"{Path.GetFullPath(_fileNameLastSaved)}\""; private bool _saveInputOverride = false; public SaveGsaModel() : base("Save GSA Model", "Save", @@ -181,7 +182,7 @@ internal void OpenGsaExe() { internal Process RunGsa() { string programFiles = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles); string fullPath = Path.Combine(programFiles, @"Oasys\GSA 10.2\GSA.exe"); - return Process.Start(fullPath, Path.GetFullPath(_fileNameLastSaved)); + return Process.Start(fullPath, FileNameLastSavedFullPath); } } } diff --git a/GsaGHTests/3_Components/0_Model/SaveGsaModelTests.cs b/GsaGHTests/3_Components/0_Model/SaveGsaModelTests.cs index 140cb1c4f..cfaf41ace 100644 --- a/GsaGHTests/3_Components/0_Model/SaveGsaModelTests.cs +++ b/GsaGHTests/3_Components/0_Model/SaveGsaModelTests.cs @@ -1,6 +1,5 @@ -using System; -using System.Diagnostics; -using System.IO; +using System.IO; +using System.Linq; using GsaGH.Components; using GsaGH.Parameters; @@ -66,5 +65,15 @@ public void StartGsaShouldTargetGsa() { process.Kill(); } } + + [Fact] + public void StartGsaShouldWorkWhenFilenameHasGaps() { + SaveGsaModel comp = new SaveGsaModel(); + ComponentTestHelper.SetInput(comp, GsaModelGooMother); + ComponentTestHelper.SetInput(comp, true, 1); + ComponentTestHelper.SetInput(comp, Path.Combine(Path.GetTempPath(), "dummyPath with spaces.gwb"), 2); + _ = (GsaModelGoo)ComponentTestHelper.GetOutput(comp); + Assert.Equal(2, comp.FileNameLastSavedFullPath.Count(x => x == '\"')); + } } }