diff --git a/PasteIntoFile/Program.cs b/PasteIntoFile/Program.cs index 202ab20..3523d7a 100644 --- a/PasteIntoFile/Program.cs +++ b/PasteIntoFile/Program.cs @@ -20,23 +20,50 @@ static void Main(string[] args) Application.SetCompatibleTextRenderingDefault(false); if (args.Length>0) { - if (args[0] == "/reg") + try { - RegisterApp(); - return; + if (string.Equals(args[0], "/reg", StringComparison.CurrentCultureIgnoreCase)) + { + RegisterApp(); + return; + } + else if (string.Equals(args[0], "/unreg", StringComparison.CurrentCultureIgnoreCase)) + { + UnRegisterApp(); + return; + } + else if (string.Equals(args[0], "/filename", StringComparison.CurrentCultureIgnoreCase) && args.Length > 1) + { + var key = OpenDirectoryKey().CreateSubKey("shell").CreateSubKey("Paste Into File"); + key = key.CreateSubKey("filename"); + key.SetValue("", args[1]); + + MessageBox.Show("Filename has been registered with your system", "Paste Into File", MessageBoxButtons.OK, MessageBoxIcon.Information); + return; + } + else if (string.Equals(args[0], "/TextDefaultDir", StringComparison.CurrentCultureIgnoreCase) && args.Length > 1) + { + var key = OpenDirectoryKey().CreateSubKey("shell").CreateSubKey("Paste Into File"); + key = key.CreateSubKey("TextDefaultDir"); + key.SetValue("", args[1]); + + MessageBox.Show("TextDefaultDir has been registered with your system", "Paste Into File", MessageBoxButtons.OK, MessageBoxIcon.Information); + return; + } + else if (string.Equals(args[0], "/ImageDefaultDir", StringComparison.CurrentCultureIgnoreCase) && args.Length > 1) + { + var key = OpenDirectoryKey().CreateSubKey("shell").CreateSubKey("Paste Into File"); + key = key.CreateSubKey("ImageDefaultDir"); + key.SetValue("", args[1]); + + MessageBox.Show("ImageDefaultDir has been registered with your system", "Paste Into File", MessageBoxButtons.OK, MessageBoxIcon.Information); + return; + } } - else if (args[0] == "/unreg") + catch (Exception ex) { - UnRegisterApp(); - return; + MessageBox.Show(ex.Message + "\nPlease run the application as Administrator !", "Paste As File", MessageBoxButtons.OK, MessageBoxIcon.Error); } - else if (args[0] == "/filename") - { - if (args.Length > 1) { - RegisterFilename(args[1]); - } - return; - } Application.Run(new frmMain(args[0])); } else @@ -46,64 +73,29 @@ static void Main(string[] args) } - public static void RegisterFilename(string filename) - { - try - { - var key = OpenDirectoryKey().CreateSubKey("shell").CreateSubKey("Paste Into File"); - key = key.CreateSubKey("filename"); - key.SetValue("", filename); - - MessageBox.Show("Filename has been registered with your system", "Paste Into File", MessageBoxButtons.OK, MessageBoxIcon.Information); - } - catch (Exception ex) - { - //throw; - MessageBox.Show(ex.Message + "\nPlease run the application as Administrator !", "Paste As File", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - public static void UnRegisterApp() { - try - { - var key = OpenDirectoryKey().OpenSubKey(@"Background\shell", true); - key.DeleteSubKeyTree("Paste Into File"); - - key = OpenDirectoryKey().OpenSubKey("shell", true); - key.DeleteSubKeyTree("Paste Into File"); + var key = OpenDirectoryKey().OpenSubKey(@"Background\shell", true); + key.DeleteSubKeyTree("Paste Into File"); - MessageBox.Show("Application has been Unregistered from your system", "Paste Into File", MessageBoxButtons.OK, MessageBoxIcon.Information); + key = OpenDirectoryKey().OpenSubKey("shell", true); + key.DeleteSubKeyTree("Paste Into File"); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message + "\nPlease run the application as Administrator !", "Paste Into File", MessageBoxButtons.OK, MessageBoxIcon.Error); - - } + MessageBox.Show("Application has been Unregistered from your system", "Paste Into File", MessageBoxButtons.OK, MessageBoxIcon.Information); } public static void RegisterApp() { - try - { - var key = OpenDirectoryKey().CreateSubKey(@"Background\shell").CreateSubKey("Paste Into File"); - key.SetValue("Icon", "\"" + Application.ExecutablePath + "\",0"); - key = key.CreateSubKey("command"); - key.SetValue("" , "\"" + Application.ExecutablePath + "\" \"%V\""); - - key = OpenDirectoryKey().CreateSubKey("shell").CreateSubKey("Paste Into File"); - key.SetValue("Icon", "\"" + Application.ExecutablePath + "\",0"); - key = key.CreateSubKey("command"); - key.SetValue("" , "\"" + Application.ExecutablePath + "\" \"%1\""); - MessageBox.Show("Application has been registered with your system", "Paste Into File", MessageBoxButtons.OK, MessageBoxIcon.Information); + var key = OpenDirectoryKey().CreateSubKey(@"Background\shell").CreateSubKey("Paste Into File"); + key.SetValue("Icon", "\"" + Application.ExecutablePath + "\",0"); + key = key.CreateSubKey("command"); + key.SetValue("", "\"" + Application.ExecutablePath + "\" \"%V\""); - } - catch (Exception ex) - { - //throw; - MessageBox.Show(ex.Message + "\nPlease run the application as Administrator !", "Paste As File", MessageBoxButtons.OK, MessageBoxIcon.Error); - } + key = OpenDirectoryKey().CreateSubKey("shell").CreateSubKey("Paste Into File"); + key.SetValue("Icon", "\"" + Application.ExecutablePath + "\",0"); + key = key.CreateSubKey("command"); + key.SetValue("", "\"" + Application.ExecutablePath + "\" \"%1\""); + MessageBox.Show("Application has been registered with your system", "Paste Into File", MessageBoxButtons.OK, MessageBoxIcon.Information); } public static void RestartApp() diff --git a/PasteIntoFile/Properties/AssemblyInfo.cs b/PasteIntoFile/Properties/AssemblyInfo.cs index c316d43..d9b9459 100644 --- a/PasteIntoFile/Properties/AssemblyInfo.cs +++ b/PasteIntoFile/Properties/AssemblyInfo.cs @@ -5,13 +5,13 @@ // 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("PasteIntoFile")] +[assembly: AssemblyTitle("Paste Clipboard Contents Into File")] [assembly: AssemblyDescription("Paste Clipboard Contents Into Files")] [assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("EslaMxSoft 2014")] -[assembly: AssemblyProduct("PasteIntoFile v1.4")] -[assembly: AssemblyCopyright("Copyright © EslaMxSoft 2014")] -[assembly: AssemblyTrademark("")] +[assembly: AssemblyCompany("EslaMxSoft 2022")] +[assembly: AssemblyProduct("PasteIntoFile")] +[assembly: AssemblyCopyright("Copyright © EslaMxSoft 2022")] +[assembly: AssemblyTrademark("EslaMxSoft 2022")] [assembly: AssemblyCulture("")] // Setting ComVisible to false makes the types in this assembly not visible @@ -32,5 +32,5 @@ // 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.4.0.1")] -[assembly: AssemblyFileVersion("1.4.0.1")] +[assembly: AssemblyVersion("1.6.2.0")] +[assembly: AssemblyFileVersion("1.6.2.0")] diff --git a/PasteIntoFile/frmMain.Designer.cs b/PasteIntoFile/frmMain.Designer.cs index a6636b4..01c98fe 100644 --- a/PasteIntoFile/frmMain.Designer.cs +++ b/PasteIntoFile/frmMain.Designer.cs @@ -107,22 +107,6 @@ private void InitializeComponent() // comExt // this.comExt.FormattingEnabled = true; - this.comExt.Items.AddRange(new object[] { - "txt", - "html", - "js", - "css", - "csv", - "json", - "cs", - "cpp", - "java", - "php", - "png", - "jpg", - "bmp", - "gif", - "ico"}); this.comExt.Location = new System.Drawing.Point(316, 37); this.comExt.Margin = new System.Windows.Forms.Padding(4); this.comExt.Name = "comExt"; @@ -257,6 +241,7 @@ private void InitializeComponent() private System.Windows.Forms.Label lblMe; private System.Windows.Forms.Label lblWebsite; private System.Windows.Forms.Label lblHelp; - } + } } + diff --git a/PasteIntoFile/frmMain.cs b/PasteIntoFile/frmMain.cs index bce6897..8a1927b 100644 --- a/PasteIntoFile/frmMain.cs +++ b/PasteIntoFile/frmMain.cs @@ -17,10 +17,10 @@ namespace PasteAsFile { public partial class frmMain : Form { - public const string DEFAULT_FILENAME_FORMAT = "yyyy-MM-dd HH.mm.ss"; - public string CurrentLocation { get; set; } - public bool IsText { get; set; } - public frmMain() + public const string DEFAULT_FILENAME_FORMAT = "yyyy-MM-dd HH.mm.ss"; + public string CurrentLocation { get; set; } + public bool IsText { get; set; } + public frmMain() { InitializeComponent(); } @@ -31,11 +31,20 @@ public frmMain(string location) } private void frmMain_Load(object sender, EventArgs e) { - string filename = (string)Registry.GetValue(@"HKEY_CURRENT_USER\Software\Classes\Directory\shell\Paste Into File\filename", "", null) ?? DEFAULT_FILENAME_FORMAT; - txtFilename.Text = DateTime.Now.ToString(filename); - txtCurrentLocation.Text = CurrentLocation ?? @"C:\"; - - if (Registry.GetValue(@"HKEY_CURRENT_USER\Software\Classes\Directory\Background\shell\Paste Into File\command", "", null) == null) + string filename = (string)Registry.GetValue(@"HKEY_CURRENT_USER\Software\Classes\Directory\shell\Paste Into File\filename", "", null) ?? DEFAULT_FILENAME_FORMAT; + txtFilename.Text = DateTime.Now.ToString(filename); + txtCurrentLocation.Text = CurrentLocation ?? @"C:\"; + const string DEFAULT_TEXT_SUBFOLDER = "Text"; + const string DEFAULT_IMAGE_SUBFOLDER = "Image"; + string TextDefaultDir = (string)Registry.GetValue(@"HKEY_CURRENT_USER\Software\Classes\Directory\shell\Paste Into File\TextDefaultDir", "", null) ?? DEFAULT_TEXT_SUBFOLDER; + string ImageDefaultDir = (string)Registry.GetValue(@"HKEY_CURRENT_USER\Software\Classes\Directory\shell\Paste Into File\ImageDefaultDir", "", null) ?? DEFAULT_IMAGE_SUBFOLDER; + if ((Control.ModifierKeys & Keys.Control) == Keys.Control) + { + string SubDir = (Clipboard.ContainsText()) ? TextDefaultDir : ImageDefaultDir; + txtCurrentLocation.Text = (SubDir.IndexOf(":") > 0) ? SubDir : txtCurrentLocation.Text + @"\" + SubDir; + } + + if (Registry.GetValue(@"HKEY_CURRENT_USER\Software\Classes\Directory\Background\shell\Paste Into File\command", "", null) == null) { if (MessageBox.Show("Seems that you are running this application for the first time,\nDo you want to Register it with your system Context Menu ?", "Paste Into File", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { @@ -46,30 +55,68 @@ private void frmMain_Load(object sender, EventArgs e) if (Clipboard.ContainsText()) { lblType.Text = "Text File"; + comExt.Items.AddRange(new object[] { + "ahk", // - AutoHotkey + "au3", // - AutoIt + "bat", // - DOS Batch + "cmd", // - DOS Batch (modern) + "cpp", // - C++ Language + "cs", // - C-Sharp Langauge + "css", // - Cascading Style Sheets - use to style an HTML document + "csv", // - Comma-Separated Value + "htm", // - Hypertext Markup Language + "html", // - Hypertext Markup Language + "ini", // - INI - Windows Configuration File + "java", // - Java Language + "js", // - JavaScript Language + "json", // - JavaScript Object Notation + "php", // - PHP Language + "pl", // - Perl Language + "ps1", // - PowerShell + "py", // - Python Language + "reg", // - Registry File + "swift", // - Switft Language + "txt", // - Text Files + "vb", // - Visual Basic Language + "vbs", // - Visual Basic Script Language + "xml" // - Extensible Markup Language + }); comExt.SelectedItem = "txt"; IsText = true; - txtContent.Text = Clipboard.GetText(); - return; + txtContent.Text = Clipboard.GetText(); + if ((Control.ModifierKeys & Keys.Shift) == Keys.Shift) + Save_Action(0); + return; } if (Clipboard.ContainsImage()) { lblType.Text = "Image"; + comExt.Items.AddRange(new object[] { + "png", + "jpg", + "bmp", + "gif", + "ico" + }); comExt.SelectedItem = "png"; - imgContent.Image = Clipboard.GetImage(); + imgContent.Image = Clipboard.GetImage(); + if ((Control.ModifierKeys & Keys.Shift) == Keys.Shift) + Save_Action(0); return; } lblType.Text = "Unknown File"; btnSave.Enabled = false; + } - } - - private void btnSave_Click(object sender, EventArgs e) + public void Save_Action(int millisecondsTimeout) { string location = txtCurrentLocation.Text; - location = location.EndsWith("\\") ? location : location + "\\"; + if (!Directory.Exists(location)) + Directory.CreateDirectory(location); + location = location.EndsWith("\\") ? location : location + "\\"; string filename = txtFilename.Text + "." + comExt.SelectedItem.ToString(); if (IsText) { @@ -106,10 +153,15 @@ private void btnSave_Click(object sender, EventArgs e) Task.Factory.StartNew(() => { - Thread.Sleep(1000); + if (millisecondsTimeout > 0) + Thread.Sleep(millisecondsTimeout); Environment.Exit(0); }); } + private void btnSave_Click(object sender, EventArgs e) + { + Save_Action(1000); + } private void btnBrowseForFolder_Click(object sender, EventArgs e) { @@ -133,11 +185,19 @@ private void lblMe_Click(object sender, EventArgs e) private void lblHelp_Click(object sender, EventArgs e) { - string msg = "Paste Into File helps you paste any text or images in your system clipboard into a file directly instead of creating new file yourself"; - msg += "\n--------------------\nTo Register the application to your system Context Menu run the program as Administrator with this argument : /reg"; - msg += "\nto Unregister the application use this argument : /unreg\n"; - msg += "\nTo change the format of the default filename, use this argument: /filename yyyy-MM-dd_HHmm\n"; - msg += "\n--------------------\nSend Feedback to : eslamx7@gmail.com\n\nThanks :)"; + string msg = "Paste Into File helps you paste any text or images in your system clipboard into a file directly instead of creating new file yourself\n"; + msg += "-----------------------------------------------------------------\n"; + msg += "To Register the application to your system Context Menu run the program as Administrator with argument: /reg\n"; + msg += "To Unregister the application use argument: /unreg\n"; + msg += "To change the format of the default filename, use argument:\n/filename yyyy-MM-dd_HHmm\n"; + msg += "-----------------------------------------------------------------\n"; + + msg += "To create a file automatically without a window prompt, hold shift key while selecting 'Paste Into File'\n"; + msg += "To add a default sub folder to 'Current Location', hold ctrl key while selecting 'Paste Into File'. "; + msg += "The default sub folder for a text file is Text, and the default sub folder for an image file is Image.\n\n"; + msg += "To change the default Text Sub Folder, use argument:\n/TextDefaultDir MyDefaultTextFolder\n"; + msg += "To change the default Image Sub Folder, use argument:\n/ImageDefaultDir MyImgDir\n"; + msg += "\n--------------------\nSend Feedback to : eslamx7@gmail.com\n\nThanks :)"; MessageBox.Show(msg, "Paste As File Help", MessageBoxButtons.OK, MessageBoxIcon.Information); diff --git a/README.md b/README.md index 3cdfd3c..4feb639 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -## 📢 New Version Released: [Info & Download](https://on.eslamx.com/2YcPKdt) 🔥 +## 📢 New Version Released: [Info & Download](https://github.com/David-Maisonave/PasteIntoFile/releases/latest) 🔥 --- # Paste Into File @@ -18,11 +18,11 @@ choco install pasteintofile 1. Make sure you have _.NET Framework 4.5+_ installed in your system. (_Included in Windows 10_) -2. Download the executable from [here](https://on.eslamx.com/2YcPKdt) and install it. +2. Download the executable from [here](https://github.com/David-Maisonave/PasteIntoFile/releases/latest) and install it. ## Usage -1. Right click in the folder where you want to create the file and choose the *Paste Into File* entry from the context menu: +1. Right click in the folder where you want to create the file and choose the **Paste Into File** entry from the context menu: ![Paste As File](PasteIntoFile/menu.png)
@@ -30,6 +30,13 @@ choco install pasteintofile 2. Choose the filename, extenstion and location, then press the *Save* button:
![Paste As File](PasteIntoFile/screenshot.png) +### Combination Key Usage +* To create a file automatically (without a windows prompt), hold **SHIFT** key while choosing **[Paste Into File]** in the context menu. +* To create the file in a default sub folder under the current directory, hold **CTRL** key while choosing **[Paste Into File]** in the context menu. +* Holding both keys (**CTRL+SHIFT**) while choosing **[Paste Into File]** will create the text file automatically in the default sub folder associated with the file type. + * The default sub folder for a text file is Text, and the default folder for an image file is Image. + * The default sub folders can be changed using command line options. See Configuration section for details. + ## Configuration Run the following commands in a terminal (Command Prompt or PowerShell). @@ -46,11 +53,33 @@ Run the following commands in a terminal (Command Prompt or PowerShell). PasteIntoFile /unreg ``` -- To change the default filename format: +- To change the default **filename** format: ```powershell PasteIntoFile /filename yyyyMMdd_HHmmss ``` + +- To change the default **Text** Sub Folder: + + ```powershell + PasteIntoFile /TextDefaultDir MyDefaultTextFolder + ``` + + +- To change the default **Image** Sub Folder: + + ```powershell + PasteIntoFile /ImageDefaultDir MyImgDir + ``` + + +- To change the default path to a specific folder use a fully qualified path having a **drive** letter: + ```powershell + PasteIntoFile /ImageDefaultDir C:\MyProject\Screenshots + PasteIntoFile /TextDefaultDir C:\MyProject\SourceCode + ``` + + For more information on the format specifiers, see [Custom date and time format strings](https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings).