|
@@ -1,7 +1,10 @@
|
|
|
using NLog;
|
|
|
+using SyncTrayzor.Services.Config;
|
|
|
+using SyncTrayzor.Utils;
|
|
|
using System;
|
|
|
using System.Diagnostics;
|
|
|
using System.IO;
|
|
|
+using System.Linq;
|
|
|
|
|
|
namespace SyncTrayzor.Services
|
|
|
{
|
|
@@ -12,7 +15,8 @@ namespace SyncTrayzor.Services
|
|
|
void StartDetached(string filename);
|
|
|
void StartDetached(string filename, string arguments, string launchAfterFinished = null);
|
|
|
void StartElevatedDetached(string filename, string arguments, string launchAfterFinished = null);
|
|
|
- void ShowInExplorer(string filePath);
|
|
|
+ void ShowFolderInExplorer(string path);
|
|
|
+ void ShowFileInExplorer(string filePath);
|
|
|
}
|
|
|
|
|
|
public class ProcessStartProvider : IProcessStartProvider
|
|
@@ -21,9 +25,12 @@ namespace SyncTrayzor.Services
|
|
|
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
|
|
|
private readonly string processRunnerPath;
|
|
|
|
|
|
- public ProcessStartProvider(IAssemblyProvider assemblyProvider)
|
|
|
+ private readonly IConfigurationProvider configurationProvider;
|
|
|
+
|
|
|
+ public ProcessStartProvider(IAssemblyProvider assemblyProvider, IConfigurationProvider configurationProvider)
|
|
|
{
|
|
|
this.processRunnerPath = Path.Combine(Path.GetDirectoryName(assemblyProvider.Location), processRunner);
|
|
|
+ this.configurationProvider = configurationProvider;
|
|
|
}
|
|
|
|
|
|
public void Start(string filename)
|
|
@@ -84,6 +91,29 @@ namespace SyncTrayzor.Services
|
|
|
Process.Start(startInfo);
|
|
|
}
|
|
|
|
|
|
- public void ShowInExplorer(string filePath) => this.StartDetached("explorer.exe", $"/select, \"{filePath}\"");
|
|
|
+ public void ShowFolderInExplorer(string path)
|
|
|
+ {
|
|
|
+ var command = this.configurationProvider.Load().OpenFolderCommand;
|
|
|
+ this.StartExplorerHelper(command, path);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void ShowFileInExplorer(string filePath)
|
|
|
+ {
|
|
|
+ var command = this.configurationProvider.Load().ShowFileInFolderCommand;
|
|
|
+ this.StartExplorerHelper(command, filePath);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void StartExplorerHelper(string commandFromConfig, string path)
|
|
|
+ {
|
|
|
+ var parts = StringExtensions.SplitCommandLine(String.Format(commandFromConfig, path));
|
|
|
+ var executable = parts.FirstOrDefault();
|
|
|
+ if (executable == null)
|
|
|
+ {
|
|
|
+ logger.Error($"Command {commandFromConfig} is badly formed, and does not contain an executable");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ this.StartDetached(executable, StringExtensions.JoinCommandLine(parts.Skip(1)));
|
|
|
+ }
|
|
|
}
|
|
|
}
|