commit 74ff43464db17a1b3b0ac48fab6564acf64e6c9e Author: taynpg Date: Fri Mar 22 14:36:43 2024 +0800 Init Commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..674593b --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +obj/ +bin/ +.vs/ diff --git a/Demo/screenshot.png b/Demo/screenshot.png new file mode 100644 index 0000000..f898d1a Binary files /dev/null and b/Demo/screenshot.png differ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d169e66 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 Olivier Giniaux + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/OpenCmdHere.sln b/OpenCmdHere.sln new file mode 100644 index 0000000..52fb00a --- /dev/null +++ b/OpenCmdHere.sln @@ -0,0 +1,37 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.28010.2003 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenCmdHere", "OpenCmdHere\OpenCmdHere.csproj", "{31EFBD02-1FCC-4EC6-A7F3-5A04BE4AE806}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {31EFBD02-1FCC-4EC6-A7F3-5A04BE4AE806}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {31EFBD02-1FCC-4EC6-A7F3-5A04BE4AE806}.Debug|Any CPU.Build.0 = Debug|Any CPU + {31EFBD02-1FCC-4EC6-A7F3-5A04BE4AE806}.Debug|x64.ActiveCfg = Debug|Any CPU + {31EFBD02-1FCC-4EC6-A7F3-5A04BE4AE806}.Debug|x64.Build.0 = Debug|Any CPU + {31EFBD02-1FCC-4EC6-A7F3-5A04BE4AE806}.Debug|x86.ActiveCfg = Debug|Any CPU + {31EFBD02-1FCC-4EC6-A7F3-5A04BE4AE806}.Debug|x86.Build.0 = Debug|Any CPU + {31EFBD02-1FCC-4EC6-A7F3-5A04BE4AE806}.Release|Any CPU.ActiveCfg = Release|Any CPU + {31EFBD02-1FCC-4EC6-A7F3-5A04BE4AE806}.Release|Any CPU.Build.0 = Release|Any CPU + {31EFBD02-1FCC-4EC6-A7F3-5A04BE4AE806}.Release|x64.ActiveCfg = Release|Any CPU + {31EFBD02-1FCC-4EC6-A7F3-5A04BE4AE806}.Release|x64.Build.0 = Release|Any CPU + {31EFBD02-1FCC-4EC6-A7F3-5A04BE4AE806}.Release|x86.ActiveCfg = Release|Any CPU + {31EFBD02-1FCC-4EC6-A7F3-5A04BE4AE806}.Release|x86.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {8E12D7AF-41D3-4885-B0BB-2EA60909A541} + EndGlobalSection +EndGlobal diff --git a/OpenCmdHere/ContextMenu.cs b/OpenCmdHere/ContextMenu.cs new file mode 100644 index 0000000..1741e1e --- /dev/null +++ b/OpenCmdHere/ContextMenu.cs @@ -0,0 +1,61 @@ +using System.Runtime.InteropServices; +using System.Windows.Forms; +using SharpShell.Attributes; +using SharpShell.SharpContextMenu; +using System.Diagnostics; +using System.IO; +using System.Drawing; +using OpenCmdHere.Properties; + +namespace OpenCmdHere { + + [ComVisible(true)] + [COMServerAssociation(AssociationType.Class, @"Directory\Background")] + public class ContextMenu : SharpContextMenu { + + protected override bool CanShowMenu() { + return true; + } + + protected override ContextMenuStrip CreateMenu() { + + var contextMenu = new ContextMenuStrip(); + + var menuItem = new ToolStripMenuItem("Open Cmd Here", GetBitmap()); + menuItem.Click += (sender, args) => openCmdHere(); + contextMenu.Items.Add(menuItem); + + return contextMenu; + } + + private void openCmdHere() { + var pinfo = new ProcessStartInfo(); + pinfo.UseShellExecute = true; + pinfo.WorkingDirectory = FolderPath; + pinfo.FileName = "cmd.exe"; + Process process = Process.Start(pinfo); + } + + public static Bitmap GetBitmap() { + if (Extensions.Dpi > 0.96f * 250 - 1) { + return (Bitmap)Resources.ResourceManager.GetObject("Console40", Resources.Culture); + } + if (Extensions.Dpi > 0.96f * 225 - 1) { + return (Bitmap)Resources.ResourceManager.GetObject("Console36", Resources.Culture); + } + if (Extensions.Dpi > 0.96f * 200 - 1) { + return (Bitmap)Resources.ResourceManager.GetObject("Console32", Resources.Culture); + } + if (Extensions.Dpi > 0.96f * 175 - 1) { + return (Bitmap)Resources.ResourceManager.GetObject("Console28", Resources.Culture); + } + if (Extensions.Dpi > 0.96f * 150 - 1) { + return (Bitmap)Resources.ResourceManager.GetObject("Console24", Resources.Culture); + } + if (Extensions.Dpi > 0.96f * 125 - 1) { + return (Bitmap)Resources.ResourceManager.GetObject("Console20", Resources.Culture); + } + return (Bitmap)Resources.ResourceManager.GetObject("Console16", Resources.Culture); + } + } +} \ No newline at end of file diff --git a/OpenCmdHere/Extensions.cs b/OpenCmdHere/Extensions.cs new file mode 100644 index 0000000..219b210 --- /dev/null +++ b/OpenCmdHere/Extensions.cs @@ -0,0 +1,44 @@ +using System; +using System.Drawing; + +namespace OpenCmdHere { + + public static class Extensions { + + public static T[] Add(this T[] target, params T[] items) { + // Validate the parameters + if (target == null) { + target = new T[] { }; + } + if (items == null) { + items = new T[] { }; + } + + // Join the arrays + T[] result = new T[target.Length + items.Length]; + target.CopyTo(result, 0); + items.CopyTo(result, target.Length); + return result; + } + + + private static float _Dpi = -1; + public static float Dpi { + get { + if (_Dpi == -1) { + using (Graphics graphics = Graphics.FromHwnd(IntPtr.Zero)) { + _Dpi = graphics.DpiY; + } + } + return _Dpi; + } + } + + [System.Runtime.InteropServices.DllImport("Shell32.dll")] + private static extern int SHChangeNotify(int eventId, int flags, IntPtr item1, IntPtr item2); + + public static void RefreshExplorer() { + SHChangeNotify(0x8000000, 0x1000, IntPtr.Zero, IntPtr.Zero); + } + } +} diff --git a/OpenCmdHere/Key.snk b/OpenCmdHere/Key.snk new file mode 100644 index 0000000..f9b173d Binary files /dev/null and b/OpenCmdHere/Key.snk differ diff --git a/OpenCmdHere/OpenCmdHere.csproj b/OpenCmdHere/OpenCmdHere.csproj new file mode 100644 index 0000000..400d463 --- /dev/null +++ b/OpenCmdHere/OpenCmdHere.csproj @@ -0,0 +1,116 @@ + + + + Debug + AnyCPU + 8.0.30703 + 2.0 + {31EFBD02-1FCC-4EC6-A7F3-5A04BE4AE806} + Library + Properties + OpenCmdHere + OpenCmdHere + v4.0 + 512 + + + + + + + + + + + true + full + false + bin\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\ + TRACE + prompt + 4 + + + true + + + Key.snk + + + OnOutputUpdated + + + + False + ..\Tools\SharpShell.dll + + + + + + + + + + + + + + + + + True + True + Resources.resx + + + + + ResXFileCodeGenerator + Designer + Resources.Designer.cs + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OpenCmdHere/Properties/AssemblyInfo.cs b/OpenCmdHere/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..7aeb51a --- /dev/null +++ b/OpenCmdHere/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("OpenCmdHere")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("OpenCmdHere")] +[assembly: AssemblyCopyright("Copyright © 2013")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("b8ae651d-0143-420d-9b65-b356ab2c3d67")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// 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.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/OpenCmdHere/Properties/Resources.Designer.cs b/OpenCmdHere/Properties/Resources.Designer.cs new file mode 100644 index 0000000..d447c48 --- /dev/null +++ b/OpenCmdHere/Properties/Resources.Designer.cs @@ -0,0 +1,133 @@ +//------------------------------------------------------------------------------ +// +// Ce code a été généré par un outil. +// Version du runtime :4.0.30319.42000 +// +// Les modifications apportées à ce fichier peuvent provoquer un comportement incorrect et seront perdues si +// le code est régénéré. +// +//------------------------------------------------------------------------------ + +namespace OpenCmdHere.Properties { + using System; + + + /// + /// Une classe de ressource fortement typée destinée, entre autres, à la consultation des chaînes localisées. + /// + // Cette classe a été générée automatiquement par la classe StronglyTypedResourceBuilder + // à l'aide d'un outil, tel que ResGen ou Visual Studio. + // Pour ajouter ou supprimer un membre, modifiez votre fichier .ResX, puis réexécutez ResGen + // avec l'option /str ou régénérez votre projet VS. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Retourne l'instance ResourceManager mise en cache utilisée par cette classe. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("OpenCmdHere.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Remplace la propriété CurrentUICulture du thread actuel pour toutes + /// les recherches de ressources à l'aide de cette classe de ressource fortement typée. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Recherche une ressource localisée de type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap Console16 { + get { + object obj = ResourceManager.GetObject("Console16", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Recherche une ressource localisée de type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap Console20 { + get { + object obj = ResourceManager.GetObject("Console20", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Recherche une ressource localisée de type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap Console24 { + get { + object obj = ResourceManager.GetObject("Console24", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Recherche une ressource localisée de type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap Console28 { + get { + object obj = ResourceManager.GetObject("Console28", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Recherche une ressource localisée de type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap Console32 { + get { + object obj = ResourceManager.GetObject("Console32", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Recherche une ressource localisée de type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap Console36 { + get { + object obj = ResourceManager.GetObject("Console36", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Recherche une ressource localisée de type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap Console40 { + get { + object obj = ResourceManager.GetObject("Console40", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + } +} diff --git a/OpenCmdHere/Properties/Resources.resx b/OpenCmdHere/Properties/Resources.resx new file mode 100644 index 0000000..f5f48a0 --- /dev/null +++ b/OpenCmdHere/Properties/Resources.resx @@ -0,0 +1,142 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + ..\Resources\Console16.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\Console20.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\Console24.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\Console28.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\Console32.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\Console36.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\Console40.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + \ No newline at end of file diff --git a/OpenCmdHere/Resources/Console16.png b/OpenCmdHere/Resources/Console16.png new file mode 100644 index 0000000..e113520 Binary files /dev/null and b/OpenCmdHere/Resources/Console16.png differ diff --git a/OpenCmdHere/Resources/Console20.png b/OpenCmdHere/Resources/Console20.png new file mode 100644 index 0000000..ba4d259 Binary files /dev/null and b/OpenCmdHere/Resources/Console20.png differ diff --git a/OpenCmdHere/Resources/Console24.png b/OpenCmdHere/Resources/Console24.png new file mode 100644 index 0000000..54b53d9 Binary files /dev/null and b/OpenCmdHere/Resources/Console24.png differ diff --git a/OpenCmdHere/Resources/Console28.png b/OpenCmdHere/Resources/Console28.png new file mode 100644 index 0000000..d2cb8bf Binary files /dev/null and b/OpenCmdHere/Resources/Console28.png differ diff --git a/OpenCmdHere/Resources/Console32.png b/OpenCmdHere/Resources/Console32.png new file mode 100644 index 0000000..7639f79 Binary files /dev/null and b/OpenCmdHere/Resources/Console32.png differ diff --git a/OpenCmdHere/Resources/Console36.png b/OpenCmdHere/Resources/Console36.png new file mode 100644 index 0000000..f628716 Binary files /dev/null and b/OpenCmdHere/Resources/Console36.png differ diff --git a/OpenCmdHere/Resources/Console40.png b/OpenCmdHere/Resources/Console40.png new file mode 100644 index 0000000..208e007 Binary files /dev/null and b/OpenCmdHere/Resources/Console40.png differ diff --git a/README.md b/README.md new file mode 100644 index 0000000..b23b36d --- /dev/null +++ b/README.md @@ -0,0 +1,10 @@ +# Open Cmd Here +A Windows shell tool to open a new command line window at the current folder location (a.k.a. Cmd, DOS, batch, ...). + +This feature was natively available in Windows 10 until a few years ago when it got replaced with powershell. +This tool enables this open command window in the current directory again ! + +![Screenshot](https://gitee.com/sinxmiao/open-cmd-here/raw/main/Demo/screenshot.png) + +# Usage +Download and install the latest version in the release tab. diff --git a/Tools/ComRegTool.exe b/Tools/ComRegTool.exe new file mode 100644 index 0000000..1ceadff Binary files /dev/null and b/Tools/ComRegTool.exe differ diff --git a/Tools/SharpShell.dll b/Tools/SharpShell.dll new file mode 100644 index 0000000..ea6585f Binary files /dev/null and b/Tools/SharpShell.dll differ diff --git a/installer.nsi b/installer.nsi new file mode 100644 index 0000000..1be8951 --- /dev/null +++ b/installer.nsi @@ -0,0 +1,65 @@ +!define VERSION "1.0" + +; The name of the installer +Name "Open Cmd Here" + +; The file to write +OutFile "OpenCmdHere-${VERSION}-win64.exe" + +; The default installation directory +InstallDir "$PROGRAMFILES\Open Cmd Here" + +; Registry key to check for directory (so if you install again, it will +; overwrite the old one automatically) +InstallDirRegKey HKLM "SOFTWARE\Open Cmd Here" "Install_Dir" + +; Request application privileges for Windows Vista +RequestExecutionLevel admin + +Page components +Page directory +Page instfiles + +UninstPage uninstConfirm +UninstPage instfiles + +; The stuff to install +Section "Open Cmd Here(required)" + + SectionIn RO + + ; Set output path to the installation directory. + SetOutPath $INSTDIR + + File "Tools\ComRegTool.exe" + File "OpenCmdHere\bin\OpenCmdHere.dll" + File "OpenCmdHere\bin\SharpShell.dll" + + Exec '"$INSTDIR\ComRegTool.exe" install register "$INSTDIR\OpenCmdHere.dll"' + + ; Write the installation path into the registry + WriteRegStr HKLM "SOFTWARE\Open Cmd Here" "Install_Dir" "$INSTDIR" + + ; Write the uninstall keys for Windows + WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Open Cmd Here" "DisplayName" "Open Cmd Here" + WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Open Cmd Here" "UninstallString" '"$INSTDIR\uninstall.exe"' + WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Open Cmd Here" "NoModify" 1 + WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Open Cmd Here" "NoRepair" 1 + WriteUninstaller "$INSTDIR\uninstall.exe" + +SectionEnd + +Section "Uninstall" + + ; Remove registry keys + DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Open Cmd Here" + DeleteRegKey HKLM "SOFTWARE\Open Cmd Here" + + ; Unregister COM server + ExecWait '"$INSTDIR\ComRegTool.exe" uninstall unregister "$INSTDIR\OpenCmdHere.dll"' + + ; Remove directories used + RMDir "$SMPROGRAMS\Open Cmd Here" + RMDir /r "$INSTDIR" + +SectionEnd \ No newline at end of file diff --git a/register.cmd b/register.cmd new file mode 100644 index 0000000..45c1f9b --- /dev/null +++ b/register.cmd @@ -0,0 +1,2 @@ +set path=%~dp0 +"%path%Tools\ComRegTool.exe" install register "%path%OpenCmdHere\bin\OpenCmdHere.dll" \ No newline at end of file diff --git a/unregister.cmd b/unregister.cmd new file mode 100644 index 0000000..e903949 --- /dev/null +++ b/unregister.cmd @@ -0,0 +1,2 @@ +set path=%~dp0 +"%path%Tools\ComRegTool.exe" uninstall unregister "%path%OpenCmdHere\bin\OpenCmdHere.dll" \ No newline at end of file