63 lines
1.4 KiB
C#
63 lines
1.4 KiB
C#
using System.Diagnostics;
|
|
using Explorer.Application;
|
|
using Explorer.Domain;
|
|
|
|
namespace Explorer.Windows;
|
|
|
|
public sealed class WindowsWorkspaceLauncher : IWorkspaceLauncher
|
|
{
|
|
public void OpenTerminal(string directory)
|
|
{
|
|
var dir = PathRules.FromExtended(directory);
|
|
if (!Directory.Exists(dir))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (TryStart("wt.exe", "-d " + Quote(dir)))
|
|
{
|
|
return;
|
|
}
|
|
|
|
TryStart("cmd.exe", "/k cd /d " + Quote(dir));
|
|
}
|
|
|
|
public bool TryOpenInCursor(string path)
|
|
{
|
|
var target = PathRules.FromExtended(path);
|
|
if (!Directory.Exists(target) && !File.Exists(target))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
var cursor = CursorLocator.Find();
|
|
if (cursor is not null)
|
|
{
|
|
return TryStart(cursor, Quote(target));
|
|
}
|
|
|
|
return TryStart("cursor", Quote(target));
|
|
}
|
|
|
|
private static bool TryStart(string fileName, string arguments)
|
|
{
|
|
try
|
|
{
|
|
Process.Start(new ProcessStartInfo
|
|
{
|
|
FileName = fileName,
|
|
Arguments = arguments,
|
|
UseShellExecute = true
|
|
});
|
|
return true;
|
|
}
|
|
catch
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
private static string Quote(string path)
|
|
=> path.StartsWith('"') ? path : "\"" + path.Replace("\"", "\\\"") + "\"";
|
|
}
|