Update Program.cs

Change uri scheme to SaoLocalExplorer
enable opening mp3, mp4, and wmv files by simply calling it in cmd.exe and letting system figure out executable to open rather than call shell32.
This commit is contained in:
kougyoku 2022-05-17 20:04:24 -07:00
parent 1f63f2febd
commit bb91cdc95e
1 changed files with 27 additions and 17 deletions

View File

@ -43,7 +43,7 @@ namespace LocalExplorer
//Collect up the path
//the replace function is here to trim out the arg as it
//comes in from the url protocol handler
string path = args[0].Replace("localexplorer:", "").Replace("%5C", "\\");
string path = args[0].Replace("saolocalexplorer:", "").Replace("%5C", "\\");
//If there is a space in the path as it comes from the URL
//protocol handler, replace it with an actual space.
@ -103,6 +103,7 @@ namespace LocalExplorer
{
string PATH_PREFIX = Properties.Settings.Default.PREFIX;
StringCollection ALLOWED_EXTENSIONS = Properties.Settings.Default.ALLOWED_EXTENSIONS;
string commandToRun;
//Perform sanity checks.
//Check for ssv.wa.lcl prefix.
@ -129,30 +130,39 @@ namespace LocalExplorer
using (StreamWriter sw = File.CreateText(path)) { }
}
if (!HasExecutable(path))
if (HasExecutable(path))
{
MessageBox.Show($"This file does not have an assigned executable: {pathToFile}");
return;
commandToRun = $"\"{FindExecutable(path)}\" \"{pathToFile}\"";
}
else
{
commandToRun = $"\"{pathToFile}\"";
WriteOutputFile($"This file does not have an assigned executable: {pathToFile}");
}
string commandToRun = $"\"{FindExecutable(path)}\" \"{pathToFile}\"";
WriteOutputFile($"opening file with command: {commandToRun}");
//LOOKS LIKE YOUR COMMAND LINE JUST GOT EXECUTED
Process cmd = new Process();
cmd.StartInfo.FileName = "cmd.exe";
cmd.StartInfo.RedirectStandardInput = true;
cmd.StartInfo.RedirectStandardOutput = true;
cmd.StartInfo.CreateNoWindow = true;
cmd.StartInfo.UseShellExecute = false;
cmd.Start();
cmd.StandardInput.WriteLine(commandToRun);
cmd.StandardInput.Flush();
cmd.StandardInput.Close();
try
{
Process cmd = new Process();
cmd.StartInfo.FileName = "cmd.exe";
cmd.StartInfo.RedirectStandardInput = true;
cmd.StartInfo.RedirectStandardOutput = true;
cmd.StartInfo.CreateNoWindow = true;
cmd.StartInfo.UseShellExecute = false;
cmd.Start();
cmd.StandardInput.WriteLine(commandToRun);
cmd.StandardInput.Flush();
cmd.StandardInput.Close();
}
catch
{
MessageBox.Show($"Unable to execute command: {commandToRun}");
return;
}
}
private static void WriteOutputFile(string debugLine)
{
// comment this out to debug the program