Compare commits
11 Commits
master
...
SaoOpenDef
Author | SHA1 | Date |
---|---|---|
kougyoku | f10c14253c | |
kougyoku | c40cefb363 | |
kougyoku | ea08721627 | |
kougyoku | a24112162b | |
kougyoku | 67e403bc23 | |
kougyoku | d3f49dc2b5 | |
kougyoku | 7f1084300c | |
kougyoku | bb91cdc95e | |
kougyoku | 1f63f2febd | |
kougyoku | 9470c8de53 | |
kougyoku | 6ae4436119 |
|
@ -2,3 +2,4 @@ bin/*
|
|||
obj/*
|
||||
.vs/*
|
||||
test.html
|
||||
privateTest.html
|
||||
|
|
28
App.config
28
App.config
|
@ -1,6 +1,34 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<configSections>
|
||||
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
|
||||
<section name="LocalExplorer.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
|
||||
</sectionGroup>
|
||||
</configSections>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
|
||||
</startup>
|
||||
<applicationSettings>
|
||||
<LocalExplorer.Properties.Settings>
|
||||
<setting name="PREFIX" serializeAs="String">
|
||||
<value>ssv.wa.lcl</value>
|
||||
</setting>
|
||||
<setting name="ALLOWED_EXTENSIONS" serializeAs="Xml">
|
||||
<value>
|
||||
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
||||
<string>.docx</string>
|
||||
<string>.pdf</string>
|
||||
<string>.mp4</string>
|
||||
<string>.mp3</string>
|
||||
<string>.wmv</string>
|
||||
<string>.wav</string>
|
||||
</ArrayOfString>
|
||||
</value>
|
||||
</setting>
|
||||
<setting name="DEBUG" serializeAs="String">
|
||||
<value>False</value>
|
||||
</setting>
|
||||
</LocalExplorer.Properties.Settings>
|
||||
</applicationSettings>
|
||||
</configuration>
|
|
@ -37,7 +37,9 @@
|
|||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
|
@ -48,9 +50,18 @@
|
|||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Properties\Settings.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
<DependentUpon>Settings.settings</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
<None Include="Properties\Settings.settings">
|
||||
<Generator>SettingsSingleFileGenerator</Generator>
|
||||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="LocalExplorer.ico" />
|
||||
|
|
166
Program.cs
166
Program.cs
|
@ -5,9 +5,12 @@
|
|||
*
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Specialized;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace LocalExplorer
|
||||
{
|
||||
|
@ -17,8 +20,14 @@ namespace LocalExplorer
|
|||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
private static extern bool ShowWindow([In] IntPtr hWnd, [In] int nCmdShow);
|
||||
|
||||
[DllImport("shell32.dll", EntryPoint = "FindExecutable")]
|
||||
private static extern long FindExecutable(string lpFile, string lpDirectory, StringBuilder lpResult);
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
bool bDirectoryExists = false;
|
||||
bool bFileExists = false;
|
||||
|
||||
//Start this process hidden
|
||||
IntPtr handle = Process.GetCurrentProcess().MainWindowHandle;
|
||||
ShowWindow(handle, 0);
|
||||
|
@ -34,51 +43,154 @@ 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.
|
||||
path = path.Replace("%20", " ");
|
||||
|
||||
//Replace / with \ to support proper unc
|
||||
path = path.Replace("/", "\\");
|
||||
|
||||
//If the URL contains a #,
|
||||
//Trim out everything after # including the #
|
||||
if(path.Contains("#"))
|
||||
{ path = path.Substring(0, path.IndexOf("#")); }
|
||||
|
||||
WriteOutputFile($"arg passed: {path}");
|
||||
|
||||
//Check to see if the directory exists.
|
||||
//if so, pop it open.
|
||||
if (Directory.Exists(path))
|
||||
{
|
||||
ProcessStartInfo startInfo = new ProcessStartInfo
|
||||
{
|
||||
Arguments = path,
|
||||
FileName = "explorer.exe"
|
||||
};
|
||||
//Determine if file or directory.
|
||||
|
||||
//put this inside try/catch block just in case
|
||||
//explorer.exe has a permission issue or something.
|
||||
try
|
||||
{
|
||||
Process.Start(startInfo);
|
||||
}
|
||||
catch
|
||||
{
|
||||
Console.WriteLine($"Could not proc explorer.exe to open {path}");
|
||||
WriteOutputFile($"Could not proc explorer.exe to open {path}");
|
||||
}
|
||||
}
|
||||
else
|
||||
//Check to see if the directory or file exists.
|
||||
if (Directory.Exists(path))
|
||||
{ bDirectoryExists = true; }
|
||||
|
||||
if (!bDirectoryExists && File.Exists(path))
|
||||
{ bFileExists = true; }
|
||||
|
||||
//if the directory exists pop it open.
|
||||
if (bDirectoryExists)
|
||||
{
|
||||
WriteOutputFile($"Directory does not exist: {path}");
|
||||
Console.WriteLine("Directory does not exist.");
|
||||
OpenDirectory(path);
|
||||
}
|
||||
else if (bFileExists)
|
||||
{
|
||||
OpenFile(path);
|
||||
}
|
||||
else //The directory or file does not exist.
|
||||
{
|
||||
MessageBox.Show($"Directory or File does not exist: {path}");
|
||||
|
||||
WriteOutputFile($"Directory or File does not exist: {path}");
|
||||
Console.WriteLine($"Directory or File does not exist: {path}");
|
||||
}
|
||||
} //end main
|
||||
|
||||
private static void OpenDirectory(string path)
|
||||
{
|
||||
ProcessStartInfo startInfo = new ProcessStartInfo
|
||||
{
|
||||
Arguments = path,
|
||||
FileName = "explorer.exe"
|
||||
};
|
||||
|
||||
//put this inside try/catch block just in case
|
||||
//explorer.exe has a permission issue or something.
|
||||
try
|
||||
{
|
||||
Process.Start(startInfo);
|
||||
}
|
||||
catch
|
||||
{
|
||||
Console.WriteLine($"Could not proc explorer.exe to open {path}");
|
||||
WriteOutputFile($"Could not proc explorer.exe to open {path}");
|
||||
}
|
||||
}
|
||||
|
||||
private static void OpenFile(string pathToFile)
|
||||
{
|
||||
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.
|
||||
if (!pathToFile.Contains(PATH_PREFIX))
|
||||
{
|
||||
MessageBox.Show($"Not permitted to open file because path does not contain {PATH_PREFIX} : {pathToFile}");
|
||||
return;
|
||||
}
|
||||
//Check for allowed file extensions. List of allowed extensions is above.
|
||||
//GetExtension returns .docx as example, strip out to match allowed extensions
|
||||
string extension = Path.GetExtension(pathToFile);
|
||||
|
||||
if (!ALLOWED_EXTENSIONS.Contains(extension))
|
||||
{
|
||||
MessageBox.Show($"Not an allowed extension: {pathToFile} ; extension: {extension}");
|
||||
return;
|
||||
}
|
||||
|
||||
string path = $"{Path.GetTempFileName()}{Path.GetExtension(pathToFile)}";
|
||||
|
||||
//Need to create the new temp file.
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
using (StreamWriter sw = File.CreateText(path)) { }
|
||||
}
|
||||
|
||||
if (HasExecutable(path))
|
||||
{
|
||||
commandToRun = $"\"{FindExecutable(path)}\" \"{pathToFile}\"";
|
||||
}
|
||||
else
|
||||
{
|
||||
commandToRun = $"\"{pathToFile}\"";
|
||||
WriteOutputFile($"This file does not have an assigned executable: {pathToFile}");
|
||||
}
|
||||
|
||||
WriteOutputFile($"opening file with command: {commandToRun}");
|
||||
|
||||
//LOOKS LIKE YOUR COMMAND LINE JUST GOT EXECUTED
|
||||
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
|
||||
return;
|
||||
if (!Properties.Settings.Default.DEBUG)
|
||||
{ return; }
|
||||
|
||||
StreamWriter outFile = new StreamWriter(@"C:\LocalExplorer\OUTPUT.txt", true);
|
||||
outFile.WriteLine(debugLine);
|
||||
outFile.Close();
|
||||
}
|
||||
|
||||
public static bool HasExecutable(string path)
|
||||
{
|
||||
var executable = FindExecutable(path);
|
||||
return !string.IsNullOrEmpty(executable);
|
||||
}
|
||||
private static string FindExecutable(string path)
|
||||
{
|
||||
var executable = new StringBuilder(1024);
|
||||
FindExecutable(path, string.Empty, executable);
|
||||
return executable.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
|||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.1.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.1.0.0")]
|
||||
[assembly: AssemblyVersion("2.1.0.0")]
|
||||
[assembly: AssemblyFileVersion("2.1.0.0")]
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.42000
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace LocalExplorer.Properties {
|
||||
|
||||
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.10.0.0")]
|
||||
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
|
||||
|
||||
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
||||
|
||||
public static Settings Default {
|
||||
get {
|
||||
return defaultInstance;
|
||||
}
|
||||
}
|
||||
|
||||
[global::System.Configuration.ApplicationScopedSettingAttribute()]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Configuration.DefaultSettingValueAttribute("ssv.wa.lcl")]
|
||||
public string PREFIX {
|
||||
get {
|
||||
return ((string)(this["PREFIX"]));
|
||||
}
|
||||
}
|
||||
|
||||
[global::System.Configuration.ApplicationScopedSettingAttribute()]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Configuration.DefaultSettingValueAttribute(@"<?xml version=""1.0"" encoding=""utf-16""?>
|
||||
<ArrayOfString xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
|
||||
<string>.docx</string>
|
||||
<string>.pdf</string>
|
||||
<string>.mp4</string>
|
||||
<string>.mp3</string>
|
||||
<string>.wmv</string>
|
||||
<string>.wav</string>
|
||||
</ArrayOfString>")]
|
||||
public global::System.Collections.Specialized.StringCollection ALLOWED_EXTENSIONS {
|
||||
get {
|
||||
return ((global::System.Collections.Specialized.StringCollection)(this["ALLOWED_EXTENSIONS"]));
|
||||
}
|
||||
}
|
||||
|
||||
[global::System.Configuration.ApplicationScopedSettingAttribute()]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Configuration.DefaultSettingValueAttribute("False")]
|
||||
public bool DEBUG {
|
||||
get {
|
||||
return ((bool)(this["DEBUG"]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="LocalExplorer.Properties" GeneratedClassName="Settings">
|
||||
<Profiles />
|
||||
<Settings>
|
||||
<Setting Name="PREFIX" Type="System.String" Scope="Application">
|
||||
<Value Profile="(Default)">ssv.wa.lcl</Value>
|
||||
</Setting>
|
||||
<Setting Name="ALLOWED_EXTENSIONS" Type="System.Collections.Specialized.StringCollection" Scope="Application">
|
||||
<Value Profile="(Default)"><?xml version="1.0" encoding="utf-16"?>
|
||||
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
||||
<string>.docx</string>
|
||||
<string>.pdf</string>
|
||||
<string>.mp4</string>
|
||||
<string>.mp3</string>
|
||||
<string>.wmv</string>
|
||||
<string>.wav</string>
|
||||
</ArrayOfString></Value>
|
||||
</Setting>
|
||||
<Setting Name="DEBUG" Type="System.Boolean" Scope="Application">
|
||||
<Value Profile="(Default)">False</Value>
|
||||
</Setting>
|
||||
</Settings>
|
||||
</SettingsFile>
|
|
@ -1,10 +1,10 @@
|
|||
Windows Registry Editor Version 5.00
|
||||
[HKEY_CLASSES_ROOT\LocalExplorer]
|
||||
@="URL:LocalExplorer Protocol"
|
||||
"URL Protocol"="LocalExplorer"
|
||||
[HKEY_CLASSES_ROOT\LocalExplorer\DefaultIcon]
|
||||
[HKEY_CLASSES_ROOT\SaoLocalExplorer]
|
||||
@="URL:SaoLocalExplorer Protocol"
|
||||
"URL Protocol"="SaoLocalExplorer"
|
||||
[HKEY_CLASSES_ROOT\SaoLocalExplorer\DefaultIcon]
|
||||
@="C:\\Windows\\ISD\\LocalExplorer.exe"
|
||||
[HKEY_CLASSES_ROOT\LocalExplorer\shell]
|
||||
[HKEY_CLASSES_ROOT\LocalExplorer\shell\open]
|
||||
[HKEY_CLASSES_ROOT\LocalExplorer\shell\open\command]
|
||||
[HKEY_CLASSES_ROOT\SaoLocalExplorer\shell]
|
||||
[HKEY_CLASSES_ROOT\SaoLocalExplorer\shell\open]
|
||||
[HKEY_CLASSES_ROOT\SaoLocalExplorer\shell\open\command]
|
||||
@="C:\\Windows\\ISD\\LocalExplorer.exe \"%1\""
|
Loading…
Reference in New Issue