Compare commits

...

11 Commits

Author SHA1 Message Date
kougyoku f10c14253c Update Program.cs
Replace / with \ to support unc on links that require /
If URL contains #, strip it out.
Add runtime configurable DEBUG property
2022-06-15 14:13:49 -07:00
kougyoku c40cefb363 Update to 2.1 2022-06-15 14:12:48 -07:00
kougyoku ea08721627 Strip ending \ from prefix. Add in DEBUG setting for on the fly debugging 2022-06-15 14:12:39 -07:00
kougyoku a24112162b Strip ending \ from prefix. Add in DEBUG setting for on the fly debugging toggle. 2022-06-15 14:12:08 -07:00
kougyoku 67e403bc23 add wav file to allowed extensions 2022-05-19 09:07:30 -07:00
kougyoku d3f49dc2b5 Ignore a private testing html file. 2022-05-18 09:13:51 -07:00
kougyoku 7f1084300c Update to new uri scheme 2022-05-18 09:13:36 -07:00
kougyoku bb91cdc95e 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.
2022-05-17 20:04:24 -07:00
kougyoku 1f63f2febd Update RegistryEntries.reg
change to uri scheme to SaoLocalExplorer
2022-05-17 20:03:33 -07:00
kougyoku 9470c8de53 Add mp4, mp3, and wmv to the allowed extensions 2022-05-17 20:03:18 -07:00
kougyoku 6ae4436119 v2.0
Allows opening of files with ALLOWED_EXTENSIONS from a fileserver with PREFIX eg, contoso.com\ . The PREFIX and ALLOWED_EXTENSIONS are configurable in App.config
2022-05-10 13:45:39 -07:00
9 changed files with 273 additions and 37 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@ bin/*
obj/*
.vs/*
test.html
privateTest.html

View File

@ -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>

View File

@ -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" />

View File

@ -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();
}
}
}

View File

@ -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")]

61
Properties/Settings.Designer.cs generated Normal file
View File

@ -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"]));
}
}
}
}

View File

@ -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)">&lt;?xml version="1.0" encoding="utf-16"?&gt;
&lt;ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
&lt;string&gt;.docx&lt;/string&gt;
&lt;string&gt;.pdf&lt;/string&gt;
&lt;string&gt;.mp4&lt;/string&gt;
&lt;string&gt;.mp3&lt;/string&gt;
&lt;string&gt;.wmv&lt;/string&gt;
&lt;string&gt;.wav&lt;/string&gt;
&lt;/ArrayOfString&gt;</Value>
</Setting>
<Setting Name="DEBUG" Type="System.Boolean" Scope="Application">
<Value Profile="(Default)">False</Value>
</Setting>
</Settings>
</SettingsFile>

View File

@ -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\""

View File

@ -1,6 +1,6 @@
<html>
<body>
<h4>klicken</h4>
<a href="localexplorer:\\server\sharname">sharename</a>
<a href="saolocalexplorer:\\server\sharname">sharename</a>
</body>
</html>