add function to open a file
This commit is contained in:
parent
f2322b5fee
commit
787d1e3508
2 changed files with 45 additions and 26 deletions
|
|
@ -27,7 +27,6 @@ of the authors and should not be interpreted as representing official policies,
|
||||||
either expressed or implied, of the FreeBSD Project.
|
either expressed or implied, of the FreeBSD Project.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using Lucene.Net.Support;
|
|
||||||
using MatterHackers.Agg.Platform;
|
using MatterHackers.Agg.Platform;
|
||||||
using MatterHackers.Agg.UI;
|
using MatterHackers.Agg.UI;
|
||||||
using MatterHackers.DataConverters3D;
|
using MatterHackers.DataConverters3D;
|
||||||
|
|
@ -42,14 +41,37 @@ using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace MatterControlLib.Library.OpenInto
|
namespace MatterControlLib.Library.OpenInto
|
||||||
{
|
{
|
||||||
public abstract class OpenIntoExecutable
|
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;
|
public int Priority => 2;
|
||||||
|
|
||||||
|
|
@ -119,22 +141,7 @@ namespace MatterControlLib.Library.OpenInto
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
// get data from the registry for: Computer\HKEY_CLASSES_ROOT\ Bambu.Studio.1\Shell\Open\Command
|
return !string.IsNullOrEmpty(PathToExe);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -155,12 +162,7 @@ namespace MatterControlLib.Library.OpenInto
|
||||||
|
|
||||||
if (bedExports.Count == 0)
|
if (bedExports.Count == 0)
|
||||||
{
|
{
|
||||||
// open the file with the specified exe
|
ExportToExe(exportFilename);
|
||||||
ProcessStartInfo startInfo = new ProcessStartInfo();
|
|
||||||
startInfo.FileName = $"\"{pathToExe}\"";
|
|
||||||
startInfo.Arguments = $"\"{exportFilename}\"";
|
|
||||||
|
|
||||||
Process.Start(startInfo);
|
|
||||||
|
|
||||||
return null;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1 +1 @@
|
||||||
Subproject commit 370c3bd1ce6eb0f7c8e515249425ada033264b83
|
Subproject commit 04f575a31a6d6d90b6c99aca7470292668a4b8fe
|
||||||
Loading…
Add table
Add a link
Reference in a new issue