From 787d1e35081e1619bb8722055cde80b2577f5115 Mon Sep 17 00:00:00 2001 From: Lars Brubaker Date: Tue, 28 Mar 2023 09:44:10 -0700 Subject: [PATCH] add function to open a file --- .../Library/OpenInto/ExportStlToExecutable.cs | 69 ++++++++++++------- Submodules/agg-sharp | 2 +- 2 files changed, 45 insertions(+), 26 deletions(-) diff --git a/MatterControlLib/Library/OpenInto/ExportStlToExecutable.cs b/MatterControlLib/Library/OpenInto/ExportStlToExecutable.cs index 16d732e2c..e33b71c4a 100644 --- a/MatterControlLib/Library/OpenInto/ExportStlToExecutable.cs +++ b/MatterControlLib/Library/OpenInto/ExportStlToExecutable.cs @@ -27,7 +27,6 @@ of the authors and should not be interpreted as representing official policies, either expressed or implied, of the FreeBSD Project. */ -using Lucene.Net.Support; using MatterHackers.Agg.Platform; using MatterHackers.Agg.UI; using MatterHackers.DataConverters3D; @@ -42,14 +41,37 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; -using System.Threading; using System.Threading.Tasks; namespace MatterControlLib.Library.OpenInto { public abstract class OpenIntoExecutable { - private string pathToExe; + private string _pathToExe; + private string PathToExe + { + get + { + if (string.IsNullOrEmpty(_pathToExe)) + { + // get data from the registry for: Computer\HKEY_CLASSES_ROOT\ Bambu.Studio.1\Shell\Open\Command + RegistryKey key = Registry.ClassesRoot.OpenSubKey(regExKeyName); + + if (key != null) + { + _pathToExe = key.GetValue("").ToString(); + + var regex = "C:.+.exe"; + var match = System.Text.RegularExpressions.Regex.Match(_pathToExe, regex); + _pathToExe = match.Value; + + key.Close(); + } + } + + return _pathToExe; + } + } public int Priority => 2; @@ -119,22 +141,7 @@ namespace MatterControlLib.Library.OpenInto { get { - // get data from the registry for: Computer\HKEY_CLASSES_ROOT\ Bambu.Studio.1\Shell\Open\Command - RegistryKey key = Registry.ClassesRoot.OpenSubKey(regExKeyName); - - if (key != null) - { - pathToExe = key.GetValue("").ToString(); - - var regex = "C:.+.exe"; - var match = System.Text.RegularExpressions.Regex.Match(pathToExe, regex); - pathToExe = match.Value; - - key.Close(); - return true; - } - - return false; + return !string.IsNullOrEmpty(PathToExe); } } @@ -155,12 +162,7 @@ namespace MatterControlLib.Library.OpenInto if (bedExports.Count == 0) { - // open the file with the specified exe - ProcessStartInfo startInfo = new ProcessStartInfo(); - startInfo.FileName = $"\"{pathToExe}\""; - startInfo.Arguments = $"\"{exportFilename}\""; - - Process.Start(startInfo); + ExportToExe(exportFilename); return null; } @@ -174,5 +176,22 @@ namespace MatterControlLib.Library.OpenInto } }; } + + public bool ExportToExe(string exportFilename) + { + if (File.Exists(exportFilename) + && !string.IsNullOrEmpty(PathToExe)) + { + // open the file with the specified exe + ProcessStartInfo startInfo = new ProcessStartInfo(); + startInfo.FileName = $"\"{PathToExe}\""; + startInfo.Arguments = $"\"{exportFilename}\""; + + Process.Start(startInfo); + return true; + } + + return false; + } } } \ No newline at end of file diff --git a/Submodules/agg-sharp b/Submodules/agg-sharp index 370c3bd1c..04f575a31 160000 --- a/Submodules/agg-sharp +++ b/Submodules/agg-sharp @@ -1 +1 @@ -Subproject commit 370c3bd1ce6eb0f7c8e515249425ada033264b83 +Subproject commit 04f575a31a6d6d90b6c99aca7470292668a4b8fe