diff --git a/Mk0.Software.ImageSorter/Cropper.Designer.cs b/Mk0.Software.ImageSorter/Cropper.Designer.cs index 6f6c813..639e103 100644 --- a/Mk0.Software.ImageSorter/Cropper.Designer.cs +++ b/Mk0.Software.ImageSorter/Cropper.Designer.cs @@ -65,7 +65,7 @@ this.ClientSize = new System.Drawing.Size(800, 564); this.Controls.Add(this.label1); this.Controls.Add(this.rubberBand1); - this.Cursor = System.Windows.Forms.Cursors.Cross; + this.Cursor = System.Windows.Forms.Cursors.Default; this.MaximizeBox = false; this.MinimizeBox = false; this.MinimumSize = new System.Drawing.Size(816, 603); diff --git a/Mk0.Software.ImageSorter/FileAssociation.cs b/Mk0.Software.ImageSorter/FileAssociation.cs new file mode 100644 index 0000000..72e0789 --- /dev/null +++ b/Mk0.Software.ImageSorter/FileAssociation.cs @@ -0,0 +1,66 @@ +using Microsoft.Win32; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Mk0.Tools.FileAssociaton +{ + class FileAssociation + { + [System.Runtime.InteropServices.DllImport("Shell32.dll")] + private static extern int SHChangeNotify(int eventId, int flags, IntPtr item1, IntPtr item2); + + private const int SHCNE_ASSOCCHANGED = 0x8000000; + private const int SHCNF_FLUSH = 0x1000; + + public static void Add(string progId, string extension, string applicationFilePath, string fileTypeDescription, string iconPath) + { + bool madeChanges = false; + madeChanges |= SetAssociation( + extension, + progId, + fileTypeDescription, + applicationFilePath); + + if (madeChanges) + { + SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_FLUSH, IntPtr.Zero, IntPtr.Zero); + } + } + + public static void Remove(string progId, string extension, string applicationFilePath, string fileTypeDescription, string iconPath) + { + //remove reg + } + + public static void Check(string progId, string extension, string applicationFilePath, string fileTypeDescription, string iconPath) + { + //add or update reg + } + + private static bool SetAssociation(string extension, string progId, string fileTypeDescription, string applicationFilePath) + { + bool madeChanges = false; + madeChanges |= SetKeyDefaultValue(@"Software\Classes\" + extension, progId); + madeChanges |= SetKeyDefaultValue(@"Software\Classes\" + progId, fileTypeDescription); + madeChanges |= SetKeyDefaultValue($@"Software\Classes\{progId}\shell\open\command", "\"" + applicationFilePath + "\" \"%1\""); + return madeChanges; + } + + private static bool SetKeyDefaultValue(string keyPath, string value) + { + using (var key = Registry.CurrentUser.CreateSubKey(keyPath)) + { + if (key.GetValue(null) as string != value) + { + key.SetValue(null, value); + return true; + } + } + + return false; + } + } +} diff --git a/Mk0.Software.ImageSorter/Main.Designer.cs b/Mk0.Software.ImageSorter/Main.Designer.cs index 29c210d..c4b2a3b 100644 --- a/Mk0.Software.ImageSorter/Main.Designer.cs +++ b/Mk0.Software.ImageSorter/Main.Designer.cs @@ -471,6 +471,7 @@ this.KeyPreview = true; this.MinimumSize = new System.Drawing.Size(983, 605); this.Name = "Main"; + this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Show; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "Image Sorter v1.27 | © 2015-2019 by manuelkamper.com"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Main_FormClosing); diff --git a/Mk0.Software.ImageSorter/Main.cs b/Mk0.Software.ImageSorter/Main.cs index da8e2eb..ea23175 100644 --- a/Mk0.Software.ImageSorter/Main.cs +++ b/Mk0.Software.ImageSorter/Main.cs @@ -1,12 +1,13 @@ using Microsoft.VisualBasic.FileIO; using Mk0.GUI.Banner; +using Mk0.Software.ImageSorter.Properties; using Mk0.Tools.Calculation; +using Mk0.Tools.FileAssociaton; using Mk0.Tools.Images; using Mk0.Tools.Randomization; using System; using System.Collections.Generic; using System.ComponentModel; -using System.Data; using System.Diagnostics; using System.Drawing; using System.Drawing.Imaging; @@ -54,6 +55,47 @@ namespace Mk0.Software.ImageSorter startupimage = Path.GetFileName(startuppath); } SetDefaultPath(); + + if (Properties.Settings.Default.fileAssociation) + { + ExtractAssocIcons(); + + FileAssociation.Check("Image_Sorter", ".jpg", Application.StartupPath, "JPG Bild", $@"{Application.StartupPath}\AssocIcons\jpg.ico"); + FileAssociation.Check("Image_Sorter", ".png", Application.StartupPath, "PNG Bild", $@"{Application.StartupPath}\AssocIcons\png.ico"); + FileAssociation.Check("Image_Sorter", ".gif", Application.StartupPath, "GIF Bild", $@"{Application.StartupPath}\AssocIcons\gif.ico"); + FileAssociation.Check("Image_Sorter", ".jpeg", Application.StartupPath, "JPEG Bild", $@"{Application.StartupPath}\AssocIcons\jpeg.ico"); + FileAssociation.Check("Image_Sorter", ".bmp", Application.StartupPath, "BMP Bild", $@"{Application.StartupPath}\AssocIcons\bmp.ico"); + FileAssociation.Check("Image_Sorter", ".tif", Application.StartupPath, "TIF Bild", $@"{Application.StartupPath}\AssocIcons\tif.ico"); + FileAssociation.Check("Image_Sorter", ".tiff", Application.StartupPath, "TIFF Bild", $@"{Application.StartupPath}\AssocIcons\tiff.ico"); + } + } + + /// + /// Extrahiert die Icons für die Fileassociation + /// + private void ExtractAssocIcons() + { + Directory.CreateDirectory($@"{Application.StartupPath}\AssocIcons"); + WriteResource($@"{Application.StartupPath}\AssocIcons\jpg.ico", Resources.jpg); + WriteResource($@"{Application.StartupPath}\AssocIcons\png.ico", Resources.png); + WriteResource($@"{Application.StartupPath}\AssocIcons\gif.ico", Resources.gif); + WriteResource($@"{Application.StartupPath}\AssocIcons\jpeg.ico", Resources.jpeg); + WriteResource($@"{Application.StartupPath}\AssocIcons\bmp.ico", Resources.bmp); + WriteResource($@"{Application.StartupPath}\AssocIcons\tif.ico", Resources.tif); + WriteResource($@"{Application.StartupPath}\AssocIcons\tiff.ico", Resources.tiff); + } + + /// + /// Helfer um Resources auf die Platte zu schreiben + /// + /// Zielpfad + /// Resource + private void WriteResource(string path, Icon icon) + { + using (var fileStream = new FileStream(path, FileMode.Create)) + { + icon.Save(fileStream); + } } /// @@ -258,9 +300,32 @@ namespace Mk0.Software.ImageSorter s.ShowDialog(); zielPath = Properties.Settings.Default.targetPath; - labelZielPath.Text = this.zielPath; + labelZielPath.Text = zielPath; imageIndex = 0; + if (Properties.Settings.Default.fileAssociation) + { + ExtractAssocIcons(); + FileAssociation.Add("Image_Sorter", ".jpg", Application.ExecutablePath, "JPG Bild", $@"{Application.StartupPath}\AssocIcons\jpg.ico"); + FileAssociation.Add("Image_Sorter", ".png", Application.ExecutablePath, "PNG Bild", $@"{Application.StartupPath}\AssocIcons\png.ico"); + FileAssociation.Add("Image_Sorter", ".gif", Application.ExecutablePath, "GIF Bild", $@"{Application.StartupPath}\AssocIcons\gif.ico"); + FileAssociation.Add("Image_Sorter", ".jpeg", Application.ExecutablePath, "JPEG Bild", $@"{Application.StartupPath}\AssocIcons\jpeg.ico"); + FileAssociation.Add("Image_Sorter", ".bmp", Application.ExecutablePath, "BMP Bild", $@"{Application.StartupPath}\AssocIcons\bmp.ico"); + FileAssociation.Add("Image_Sorter", ".tif", Application.ExecutablePath, "TIF Bild", $@"{Application.StartupPath}\AssocIcons\tif.ico"); + FileAssociation.Add("Image_Sorter", ".tiff", Application.ExecutablePath, "TIFF Bild", $@"{Application.StartupPath}\AssocIcons\tiff.ico"); + } + else + { + Directory.Delete($@"{Application.StartupPath}\AssocIcons", true); + FileAssociation.Remove("Image_Sorter", ".jpg", Application.ExecutablePath, "JPG Bild", $@"{Application.StartupPath}\AssocIcons\jpg.ico"); + FileAssociation.Remove("Image_Sorter", ".png", Application.ExecutablePath, "PNG Bild", $@"{Application.StartupPath}\AssocIcons\png.ico"); + FileAssociation.Remove("Image_Sorter", ".gif", Application.ExecutablePath, "GIF Bild", $@"{Application.StartupPath}\AssocIcons\gif.ico"); + FileAssociation.Remove("Image_Sorter", ".jpeg", Application.ExecutablePath, "JPEG Bild", $@"{Application.StartupPath}\AssocIcons\jpeg.ico"); + FileAssociation.Remove("Image_Sorter", ".bmp", Application.ExecutablePath, "BMP Bild", $@"{Application.StartupPath}\AssocIcons\bmp.ico"); + FileAssociation.Remove("Image_Sorter", ".tif", Application.ExecutablePath, "TIF Bild", $@"{Application.StartupPath}\AssocIcons\tif.ico"); + FileAssociation.Remove("Image_Sorter", ".tiff", Application.ExecutablePath, "TIFF Bild", $@"{Application.StartupPath}\AssocIcons\tiff.ico"); + } + CheckSubfolders(); SearchImages(); CountPicsInPath(); diff --git a/Mk0.Software.ImageSorter/Mk0.Software.ImageSorter.csproj b/Mk0.Software.ImageSorter/Mk0.Software.ImageSorter.csproj index 89e6b0e..962b988 100644 --- a/Mk0.Software.ImageSorter/Mk0.Software.ImageSorter.csproj +++ b/Mk0.Software.ImageSorter/Mk0.Software.ImageSorter.csproj @@ -114,6 +114,7 @@ Cropper.cs + Form diff --git a/Mk0.Software.ImageSorter/Properties/Resources.Designer.cs b/Mk0.Software.ImageSorter/Properties/Resources.Designer.cs index c02786f..9f8c8cb 100644 --- a/Mk0.Software.ImageSorter/Properties/Resources.Designer.cs +++ b/Mk0.Software.ImageSorter/Properties/Resources.Designer.cs @@ -60,6 +60,16 @@ namespace Mk0.Software.ImageSorter.Properties { } } + /// + /// Sucht eine lokalisierte Ressource vom Typ System.Drawing.Icon ähnlich wie (Symbol). + /// + internal static System.Drawing.Icon bmp { + get { + object obj = ResourceManager.GetObject("bmp", resourceCulture); + return ((System.Drawing.Icon)(obj)); + } + } + /// /// Sucht eine lokalisierte Ressource vom Typ System.Drawing.Bitmap. /// @@ -80,6 +90,16 @@ namespace Mk0.Software.ImageSorter.Properties { } } + /// + /// Sucht eine lokalisierte Ressource vom Typ System.Drawing.Icon ähnlich wie (Symbol). + /// + internal static System.Drawing.Icon gif { + get { + object obj = ResourceManager.GetObject("gif", resourceCulture); + return ((System.Drawing.Icon)(obj)); + } + } + /// /// Sucht eine lokalisierte Ressource vom Typ System.Byte[]. /// @@ -100,6 +120,26 @@ namespace Mk0.Software.ImageSorter.Properties { } } + /// + /// Sucht eine lokalisierte Ressource vom Typ System.Drawing.Icon ähnlich wie (Symbol). + /// + internal static System.Drawing.Icon jpeg { + get { + object obj = ResourceManager.GetObject("jpeg", resourceCulture); + return ((System.Drawing.Icon)(obj)); + } + } + + /// + /// Sucht eine lokalisierte Ressource vom Typ System.Drawing.Icon ähnlich wie (Symbol). + /// + internal static System.Drawing.Icon jpg { + get { + object obj = ResourceManager.GetObject("jpg", resourceCulture); + return ((System.Drawing.Icon)(obj)); + } + } + /// /// Sucht eine lokalisierte Ressource vom Typ System.Drawing.Bitmap. /// @@ -110,6 +150,36 @@ namespace Mk0.Software.ImageSorter.Properties { } } + /// + /// Sucht eine lokalisierte Ressource vom Typ System.Drawing.Icon ähnlich wie (Symbol). + /// + internal static System.Drawing.Icon png { + get { + object obj = ResourceManager.GetObject("png", resourceCulture); + return ((System.Drawing.Icon)(obj)); + } + } + + /// + /// Sucht eine lokalisierte Ressource vom Typ System.Drawing.Icon ähnlich wie (Symbol). + /// + internal static System.Drawing.Icon tif { + get { + object obj = ResourceManager.GetObject("tif", resourceCulture); + return ((System.Drawing.Icon)(obj)); + } + } + + /// + /// Sucht eine lokalisierte Ressource vom Typ System.Drawing.Icon ähnlich wie (Symbol). + /// + internal static System.Drawing.Icon tiff { + get { + object obj = ResourceManager.GetObject("tiff", resourceCulture); + return ((System.Drawing.Icon)(obj)); + } + } + /// /// Sucht eine lokalisierte Ressource vom Typ System.Drawing.Bitmap. /// diff --git a/Mk0.Software.ImageSorter/Properties/Resources.resx b/Mk0.Software.ImageSorter/Properties/Resources.resx index c2fe0a4..99f7c4a 100644 --- a/Mk0.Software.ImageSorter/Properties/Resources.resx +++ b/Mk0.Software.ImageSorter/Properties/Resources.resx @@ -118,21 +118,42 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + ..\Resources\bmp.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + ..\Resources\crop.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a ..\Resources\delete.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\gif.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + ..\Cursors\grab.cur;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ..\Cursors\grabbing.cur;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + ..\Resources\jpeg.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\jpg.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + ..\Resources\move.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\png.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\tif.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\tiff.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + ..\Resources\undo.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a diff --git a/Mk0.Software.ImageSorter/Settings.cs b/Mk0.Software.ImageSorter/Settings.cs index 6c612be..9732cf3 100644 --- a/Mk0.Software.ImageSorter/Settings.cs +++ b/Mk0.Software.ImageSorter/Settings.cs @@ -23,6 +23,7 @@ namespace Mk0.Software.ImageSorter Properties.Settings.Default.Save(); } checkBoxSingleInstance.Checked = Properties.Settings.Default.singleInstance; + checkBoxFileAssociation.Checked = Properties.Settings.Default.fileAssociation; } private void ButtonChangeTargetPath_Click(object sender, EventArgs e)