From b958622bebd978210ebc85c8b91fd5946cbdcca9 Mon Sep 17 00:00:00 2001 From: eltos Date: Mon, 24 Aug 2020 19:51:07 +0200 Subject: [PATCH 1/3] Add string as resources This is done to allow localisation --- PasteIntoFile/Program.cs | 13 +- .../Properties/Resources.Designer.cs | 176 +++++++++++++++++- PasteIntoFile/Properties/Resources.resx | 67 +++++++ PasteIntoFile/frmMain.Designer.cs | 16 +- PasteIntoFile/frmMain.cs | 22 +-- 5 files changed, 267 insertions(+), 27 deletions(-) diff --git a/PasteIntoFile/Program.cs b/PasteIntoFile/Program.cs index 202ab20..4edcc46 100644 --- a/PasteIntoFile/Program.cs +++ b/PasteIntoFile/Program.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Threading.Tasks; using System.Windows.Forms; +using PasteIntoFile.Properties; namespace PasteAsFile { @@ -54,12 +55,12 @@ public static void RegisterFilename(string filename) key = key.CreateSubKey("filename"); key.SetValue("", filename); - MessageBox.Show("Filename has been registered with your system", "Paste Into File", MessageBoxButtons.OK, MessageBoxIcon.Information); + MessageBox.Show(Resources.str_message_register_filename_success, Resources.window_title, 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); + MessageBox.Show(ex.Message + "\n" + Resources.str_message_run_as_admin, Resources.window_title, MessageBoxButtons.OK, MessageBoxIcon.Error); } } @@ -73,12 +74,12 @@ public static void UnRegisterApp() key = OpenDirectoryKey().OpenSubKey("shell", true); key.DeleteSubKeyTree("Paste Into File"); - MessageBox.Show("Application has been Unregistered from your system", "Paste Into File", MessageBoxButtons.OK, MessageBoxIcon.Information); + MessageBox.Show(Resources.str_message_unregister_context_menu_success, Resources.window_title, MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { - MessageBox.Show(ex.Message + "\nPlease run the application as Administrator !", "Paste Into File", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show(ex.Message + "\n" + Resources.str_message_run_as_admin, Resources.window_title, MessageBoxButtons.OK, MessageBoxIcon.Error); } } @@ -96,13 +97,13 @@ public static void RegisterApp() 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); + MessageBox.Show(Resources.str_message_register_context_menu_success, Resources.window_title, 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); + MessageBox.Show(ex.Message + "\n" + Resources.str_message_run_as_admin, Resources.window_title, MessageBoxButtons.OK, MessageBoxIcon.Error); } } diff --git a/PasteIntoFile/Properties/Resources.Designer.cs b/PasteIntoFile/Properties/Resources.Designer.cs index 8014b10..6dbd69c 100644 --- a/PasteIntoFile/Properties/Resources.Designer.cs +++ b/PasteIntoFile/Properties/Resources.Designer.cs @@ -19,7 +19,7 @@ namespace PasteIntoFile.Properties { // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Resources { @@ -59,5 +59,179 @@ internal Resources() { resourceCulture = value; } } + + /// + /// Looks up a localized string similar to Paste Into File. + /// + internal static string explorer_context_entry { + get { + return ResourceManager.GetString("explorer_context_entry", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to …. + /// + internal static string str_ellipsis { + get { + return ResourceManager.GetString("str_ellipsis", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Extension. + /// + internal static string str_extension { + get { + return ResourceManager.GetString("str_extension", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to File saved :). + /// + internal static string str_file_saved { + get { + return ResourceManager.GetString("str_file_saved", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Filename. + /// + internal static string str_filename { + get { + return ResourceManager.GetString("str_filename", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Current Location. + /// + internal static string str_location { + get { + return ResourceManager.GetString("str_location", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to It seems that you are running this application for the first time, + ///do you want to add an entry to the explorer context menu?. + /// + internal static string str_message_first_time { + get { + return ResourceManager.GetString("str_message_first_time", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Paste Into File helps you paste any text or images in your system clipboard into a file directly instead of creating new file yourself + /// + ///-------------------- + /// + ///To Register the application to your system context menu run the program as administrator with this argument : /reg + ///to Unregister the application use this argument : /unreg + ///To change the format of the default filename, use this argument: /filename yyyy-MM-dd_HHmm + /// + ///-------------------- + /// + ///https://github.com/EslaMx7/PasteIntoFile + ///Send [rest of string was truncated]";. + /// + internal static string str_message_help { + get { + return ResourceManager.GetString("str_message_help", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Explorer context menu entry has been added. + /// + internal static string str_message_register_context_menu_success { + get { + return ResourceManager.GetString("str_message_register_context_menu_success", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Filename-template has been registered. + /// + internal static string str_message_register_filename_success { + get { + return ResourceManager.GetString("str_message_register_filename_success", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Please run the application as Administrator!. + /// + internal static string str_message_run_as_admin { + get { + return ResourceManager.GetString("str_message_run_as_admin", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Explorer context menu entry has been removed. + /// + internal static string str_message_unregister_context_menu_success { + get { + return ResourceManager.GetString("str_message_unregister_context_menu_success", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Save. + /// + internal static string str_save { + get { + return ResourceManager.GetString("str_save", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Select a folder for saving this file . + /// + internal static string str_select_folder { + get { + return ResourceManager.GetString("str_select_folder", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Image file. + /// + internal static string str_type_img { + get { + return ResourceManager.GetString("str_type_img", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Text file. + /// + internal static string str_type_txt { + get { + return ResourceManager.GetString("str_type_txt", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Unknown file. + /// + internal static string str_type_unknown { + get { + return ResourceManager.GetString("str_type_unknown", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Paste Into File. + /// + internal static string window_title { + get { + return ResourceManager.GetString("window_title", resourceCulture); + } + } } } diff --git a/PasteIntoFile/Properties/Resources.resx b/PasteIntoFile/Properties/Resources.resx index af7dbeb..55ac749 100644 --- a/PasteIntoFile/Properties/Resources.resx +++ b/PasteIntoFile/Properties/Resources.resx @@ -114,4 +114,71 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + Filename-template has been registered + + + Save + + + Filename + + + Extension + + + Current Location + + + + + + Paste Into File + + + Explorer context menu entry has been removed + + + Please run the application as Administrator! + + + Explorer context menu entry has been added + + + Paste Into File + + + It seems that you are running this application for the first time, +do you want to add an entry to the explorer context menu? + + + Text file + + + Image file + + + Unknown file + + + File saved :) + + + Select a folder for saving this file + + + Paste Into File helps you paste any text or images in your system clipboard into a file directly instead of creating new file yourself + +-------------------- + +To Register the application to your system context menu run the program as administrator with this argument : /reg +to Unregister the application use this argument : /unreg +To change the format of the default filename, use this argument: /filename yyyy-MM-dd_HHmm + +-------------------- + +https://github.com/EslaMx7/PasteIntoFile +Send Feedback to: eslamx7@gmail.com +Thanks :) + \ No newline at end of file diff --git a/PasteIntoFile/frmMain.Designer.cs b/PasteIntoFile/frmMain.Designer.cs index a6636b4..272b46c 100644 --- a/PasteIntoFile/frmMain.Designer.cs +++ b/PasteIntoFile/frmMain.Designer.cs @@ -1,4 +1,6 @@ -namespace PasteAsFile +using PasteIntoFile.Properties; + +namespace PasteAsFile { partial class frmMain { @@ -83,7 +85,7 @@ private void InitializeComponent() this.lblFileName.Name = "lblFileName"; this.lblFileName.Size = new System.Drawing.Size(73, 17); this.lblFileName.TabIndex = 4; - this.lblFileName.Text = "Filename :"; + this.lblFileName.Text = Resources.str_filename; // // txtFilename // @@ -102,7 +104,7 @@ private void InitializeComponent() this.lblExt.Name = "lblExt"; this.lblExt.Size = new System.Drawing.Size(77, 17); this.lblExt.TabIndex = 6; - this.lblExt.Text = "Extension :"; + this.lblExt.Text = Resources.str_extension; // // comExt // @@ -137,7 +139,7 @@ private void InitializeComponent() this.btnSave.Name = "btnSave"; this.btnSave.Size = new System.Drawing.Size(180, 37); this.btnSave.TabIndex = 5; - this.btnSave.Text = "Save"; + this.btnSave.Text = Resources.str_save; this.btnSave.UseVisualStyleBackColor = true; this.btnSave.Click += new System.EventHandler(this.btnSave_Click); // @@ -158,7 +160,7 @@ private void InitializeComponent() this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(121, 17); this.label1.TabIndex = 9; - this.label1.Text = "Current Location :"; + this.label1.Text = Resources.str_location; // // btnBrowseForFolder // @@ -167,7 +169,7 @@ private void InitializeComponent() this.btnBrowseForFolder.Name = "btnBrowseForFolder"; this.btnBrowseForFolder.Size = new System.Drawing.Size(44, 28); this.btnBrowseForFolder.TabIndex = 4; - this.btnBrowseForFolder.Text = "..."; + this.btnBrowseForFolder.Text = Resources.str_ellipsis; this.btnBrowseForFolder.UseVisualStyleBackColor = true; this.btnBrowseForFolder.Click += new System.EventHandler(this.btnBrowseForFolder_Click); // @@ -233,7 +235,7 @@ private void InitializeComponent() this.MaximizeBox = false; this.Name = "frmMain"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; - this.Text = "Paste Into File"; + this.Text = Resources.window_title; this.Load += new System.EventHandler(this.frmMain_Load); ((System.ComponentModel.ISupportInitialize)(this.imgContent)).EndInit(); this.ResumeLayout(false); diff --git a/PasteIntoFile/frmMain.cs b/PasteIntoFile/frmMain.cs index bce6897..c9ef85b 100644 --- a/PasteIntoFile/frmMain.cs +++ b/PasteIntoFile/frmMain.cs @@ -12,6 +12,7 @@ using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; +using PasteIntoFile.Properties; namespace PasteAsFile { @@ -37,7 +38,7 @@ private void frmMain_Load(object sender, EventArgs e) 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) + if (MessageBox.Show(Resources.str_message_first_time, Resources.window_title, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { Program.RegisterApp(); } @@ -45,7 +46,7 @@ private void frmMain_Load(object sender, EventArgs e) if (Clipboard.ContainsText()) { - lblType.Text = "Text File"; + lblType.Text = Resources.str_type_txt; comExt.SelectedItem = "txt"; IsText = true; txtContent.Text = Clipboard.GetText(); @@ -54,13 +55,13 @@ private void frmMain_Load(object sender, EventArgs e) if (Clipboard.ContainsImage()) { - lblType.Text = "Image"; + lblType.Text = Resources.str_type_img; comExt.SelectedItem = "png"; imgContent.Image = Clipboard.GetImage(); return; } - lblType.Text = "Unknown File"; + lblType.Text = Resources.str_type_unknown; btnSave.Enabled = false; @@ -75,7 +76,6 @@ private void btnSave_Click(object sender, EventArgs e) { File.WriteAllText(location + filename, txtContent.Text, Encoding.UTF8); - this.Text += " : File Saved :)"; } else { @@ -101,8 +101,9 @@ private void btnSave_Click(object sender, EventArgs e) break; } - this.Text += " : Image Saved :)"; } + + this.btnSave.Text = Resources.str_file_saved; Task.Factory.StartNew(() => { @@ -114,7 +115,7 @@ private void btnSave_Click(object sender, EventArgs e) private void btnBrowseForFolder_Click(object sender, EventArgs e) { FolderBrowserDialog fbd = new FolderBrowserDialog(); - fbd.Description = "Select a folder for saving this file "; + fbd.Description = Resources.str_select_folder; if (fbd.ShowDialog() == DialogResult.OK) { txtCurrentLocation.Text = fbd.SelectedPath; @@ -133,12 +134,7 @@ 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 :)"; - MessageBox.Show(msg, "Paste As File Help", MessageBoxButtons.OK, MessageBoxIcon.Information); + MessageBox.Show(Resources.str_message_help, Resources.window_title, MessageBoxButtons.OK, MessageBoxIcon.Information); From 7a26d81d735f56cf030e2d872e86bbe274256996 Mon Sep 17 00:00:00 2001 From: eltos Date: Mon, 24 Aug 2020 19:52:11 +0200 Subject: [PATCH 2/3] Use resource string for registry key and text --- PasteIntoFile/Program.cs | 14 +++++++++----- PasteIntoFile/frmMain.cs | 4 ++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/PasteIntoFile/Program.cs b/PasteIntoFile/Program.cs index 4edcc46..3a655ef 100644 --- a/PasteIntoFile/Program.cs +++ b/PasteIntoFile/Program.cs @@ -11,6 +11,8 @@ namespace PasteAsFile { static class Program { + public static readonly string RegistrySubKey = "Paste Into File"; + /// /// The main entry point for the application. /// @@ -51,7 +53,7 @@ public static void RegisterFilename(string filename) { try { - var key = OpenDirectoryKey().CreateSubKey("shell").CreateSubKey("Paste Into File"); + var key = OpenDirectoryKey().CreateSubKey("shell").CreateSubKey(RegistrySubKey); key = key.CreateSubKey("filename"); key.SetValue("", filename); @@ -69,10 +71,10 @@ public static void UnRegisterApp() try { var key = OpenDirectoryKey().OpenSubKey(@"Background\shell", true); - key.DeleteSubKeyTree("Paste Into File"); + key.DeleteSubKeyTree(RegistrySubKey); key = OpenDirectoryKey().OpenSubKey("shell", true); - key.DeleteSubKeyTree("Paste Into File"); + key.DeleteSubKeyTree(RegistrySubKey); MessageBox.Show(Resources.str_message_unregister_context_menu_success, Resources.window_title, MessageBoxButtons.OK, MessageBoxIcon.Information); @@ -88,12 +90,14 @@ public static void RegisterApp() { try { - var key = OpenDirectoryKey().CreateSubKey(@"Background\shell").CreateSubKey("Paste Into File"); + var key = OpenDirectoryKey().CreateSubKey(@"Background\shell").CreateSubKey(RegistrySubKey); + key.SetValue("", Resources.explorer_context_entry); key.SetValue("Icon", "\"" + Application.ExecutablePath + "\",0"); key = key.CreateSubKey("command"); key.SetValue("" , "\"" + Application.ExecutablePath + "\" \"%V\""); - key = OpenDirectoryKey().CreateSubKey("shell").CreateSubKey("Paste Into File"); + key = OpenDirectoryKey().CreateSubKey("shell").CreateSubKey(RegistrySubKey); + key.SetValue("", Resources.explorer_context_entry); key.SetValue("Icon", "\"" + Application.ExecutablePath + "\",0"); key = key.CreateSubKey("command"); key.SetValue("" , "\"" + Application.ExecutablePath + "\" \"%1\""); diff --git a/PasteIntoFile/frmMain.cs b/PasteIntoFile/frmMain.cs index c9ef85b..c6ab3f6 100644 --- a/PasteIntoFile/frmMain.cs +++ b/PasteIntoFile/frmMain.cs @@ -32,11 +32,11 @@ 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; + string filename = (string)Registry.GetValue(@"HKEY_CURRENT_USER\Software\Classes\Directory\shell\"+Program.RegistrySubKey+@"\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) + if (Registry.GetValue(@"HKEY_CURRENT_USER\Software\Classes\Directory\Background\shell\"+Program.RegistrySubKey+@"\command", "", null) == null) { if (MessageBox.Show(Resources.str_message_first_time, Resources.window_title, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { From b819be14888e486b3d7631db5799db2e749e5d66 Mon Sep 17 00:00:00 2001 From: eltos Date: Mon, 24 Aug 2020 19:58:35 +0200 Subject: [PATCH 3/3] German localisation --- PasteIntoFile/PasteIntoFile.csproj | 1 + PasteIntoFile/Properties/Resources.de.resx | 83 ++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 PasteIntoFile/Properties/Resources.de.resx diff --git a/PasteIntoFile/PasteIntoFile.csproj b/PasteIntoFile/PasteIntoFile.csproj index fbf8af7..6812de0 100644 --- a/PasteIntoFile/PasteIntoFile.csproj +++ b/PasteIntoFile/PasteIntoFile.csproj @@ -64,6 +64,7 @@ frmMain.cs + ResXFileCodeGenerator Resources.Designer.cs diff --git a/PasteIntoFile/Properties/Resources.de.resx b/PasteIntoFile/Properties/Resources.de.resx new file mode 100644 index 0000000..66113ac --- /dev/null +++ b/PasteIntoFile/Properties/Resources.de.resx @@ -0,0 +1,83 @@ + + + + + + + + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Speichern + + + Dateiname-Vorlage wurde registriert + + + Dateiname + + + Erweiterung + + + Gespeichert :) + + + Es scheint als würdest du die Anwendung zum ersten Mal starten. Möchtest du einen Eintrag zum Kontextmenu des Explorers hinzufügen? + + + Speicherort + + + Speicherort auswählen + + + Bilddatei + + + Textdatei + + + Unbekannte Datei + + + Eintrag im Kontextmenu wurde hinzugefügt + + + Bitte die Anwendung als Administrator ausführen! + + + Eintrag im Kontextmenu wurde entfernt + + + Einfügen als Datei (Paste Into File) + + + Paste Into File speichert Texte und Bilder aus der Zwischenablage direkt als Datei. + +-------------------- + +Komandozeilen-Argumente: + /reg Fügt den Eintrag dem Kontextmenu hinzu + /unreg Entfernt den Eintrag aus dem Kontextmenu + /filename XXX Stellt den Standard Dateinamen ein, + z.B. yyyy-MM-dd_HHmm + +-------------------- + +https://github.com/EslaMx7/PasteIntoFile +Feedback an: eslamx7@gmail.com +Danke :) + + \ No newline at end of file