This commit is contained in:
Manuel Kamper 2019-04-14 18:34:56 +02:00
commit d9e2bba577
10 changed files with 231 additions and 33 deletions

22
LICENSE
View File

@ -1,21 +1,9 @@
MIT License
Copyright 2000-2019 mk0.at and Manuel Kamper
Copyright (c) 2019
This is valid for all kind of software published via GitHub from "manuelkamp" and NuGet packages published via NuGet from "Manuel Kamper".
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:
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 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.
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.

View File

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

View File

@ -0,0 +1,64 @@
using Microsoft.Win32;
using System;
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,
iconPath);
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 todo
}
public static void Check(string progId, string extension, string applicationFilePath, string fileTypeDescription, string iconPath)
{
//add or update reg todo
}
private static bool SetAssociation(string extension, string progId, string fileTypeDescription, string applicationFilePath, string iconPath)
{
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\"");
madeChanges |= SetKeyDefaultValue($@"Software\Classes\{progId}\DefaultIcon", "\"" + iconPath + "\"");
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;
}
}
}

View File

@ -77,8 +77,8 @@
//
// pictureBox
//
this.pictureBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
this.pictureBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.pictureBox.BackColor = System.Drawing.SystemColors.Control;
this.pictureBox.ContextMenuStrip = this.contextMenuStrip;
@ -191,7 +191,7 @@
//
// groupBox2
//
this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Right)));
this.groupBox2.Controls.Add(this.labelZielPath);
this.groupBox2.Controls.Add(this.panel2);
@ -216,7 +216,7 @@
//
// panel2
//
this.panel2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
this.panel2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)));
this.panel2.AutoScroll = true;
this.panel2.Controls.Add(this.labelNoTargets);
@ -335,8 +335,8 @@
//
// panel1
//
this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.panel1.BackColor = System.Drawing.SystemColors.Control;
this.panel1.Controls.Add(this.labelNoImages);
@ -349,8 +349,8 @@
//
// labelNoImages
//
this.labelNoImages.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
this.labelNoImages.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.labelNoImages.Font = new System.Drawing.Font("Microsoft Sans Serif", 13.875F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.labelNoImages.ForeColor = System.Drawing.Color.Maroon;
@ -374,7 +374,7 @@
//
// panel3
//
this.panel3.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
this.panel3.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.panel3.BackColor = System.Drawing.SystemColors.Highlight;
this.panel3.Controls.Add(this.pictureBox2);
@ -473,7 +473,7 @@
this.MinimumSize = new System.Drawing.Size(983, 605);
this.Name = "Main";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Image Sorter v1.29 | © 2015-2019 by manuelkamper.com";
this.Text = "Image Sorter v1.31 | © 2015-2019 by manuelkamper.com";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Main_FormClosing);
this.Load += new System.EventHandler(this.Main_Load);
this.Shown += new System.EventHandler(this.Main_Shown);
@ -535,4 +535,3 @@
private System.Windows.Forms.Label label3;
}
}

View File

@ -1,6 +1,8 @@
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;
@ -29,15 +31,14 @@ namespace Mk0.Software.ImageSorter
private bool moving;
private bool moveable = false;
private Point startLocation; //verschieben
private Cursor grabCursor = new Cursor(new MemoryStream(Properties.Resources.grab));
private Cursor grabbingCursor = new Cursor(new MemoryStream(Properties.Resources.grabbing));
private Cursor grabCursor = new Cursor(new MemoryStream(Resources.grab));
private Cursor grabbingCursor = new Cursor(new MemoryStream(Resources.grabbing));
private double xFaktor = 0.0;
private double yFaktor = 0.0;
private static object locker = new object();
private Thread folderThread;
private bool threadIsRunning = false;
private Banner banner;
//private string zoomType = "auto";
private string startuppath;
private string startupimage;
public string[] Args;
@ -50,6 +51,8 @@ namespace Mk0.Software.ImageSorter
DoubleBuffered = true;
SetDefaultPath();
comboBoxZoom.SelectedIndex = Properties.Settings.Default.zoom;
//todo file assoc prüfen
}
private void Main_Load(object sender, EventArgs e)
@ -83,6 +86,34 @@ namespace Mk0.Software.ImageSorter
}
}
/// <summary>
/// Extrahiert die Icons für die Fileassociation
/// </summary>
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);
}
/// <summary>
/// Helfer um Resources auf die Platte zu schreiben
/// </summary>
/// <param name="path">Zielpfad</param>
/// <param name="icon">Resource</param>
private void WriteResource(string path, Icon icon)
{
using (var fileStream = new FileStream(path, FileMode.Create))
{
icon.Save(fileStream);
}
}
/// <summary>
/// Default: Lädt das erste Bild
/// </summary>
@ -285,9 +316,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", ".jpg", Application.ExecutablePath, "JPG Bild", $@"{Application.StartupPath}\AssocIcons\jpg.ico");
FileAssociation.Add("Image_Sorter_PNG", ".png", Application.ExecutablePath, "PNG Bild", $@"{Application.StartupPath}\AssocIcons\png.ico");
FileAssociation.Add("Image_Sorter_GIF", ".gif", Application.ExecutablePath, "GIF Bild", $@"{Application.StartupPath}\AssocIcons\gif.ico");
FileAssociation.Add("Image_Sorter_JPEG", ".jpeg", Application.ExecutablePath, "JPEG Bild", $@"{Application.StartupPath}\AssocIcons\jpeg.ico");
FileAssociation.Add("Image_Sorter_BMP", ".bmp", Application.ExecutablePath, "BMP Bild", $@"{Application.StartupPath}\AssocIcons\bmp.ico");
FileAssociation.Add("Image_Sorter_TIF", ".tif", Application.ExecutablePath, "TIF Bild", $@"{Application.StartupPath}\AssocIcons\tif.ico");
FileAssociation.Add("Image_Sorter_TIFF", ".tiff", Application.ExecutablePath, "TIFF Bild", $@"{Application.StartupPath}\AssocIcons\tiff.ico");
}
else
{
Directory.Delete($@"{Application.StartupPath}\AssocIcons", true);
FileAssociation.Remove("Image_Sorter_JPG", ".jpg", Application.ExecutablePath, "JPG Bild", $@"{Application.StartupPath}\AssocIcons\jpg.ico");
FileAssociation.Remove("Image_Sorter_PNG", ".png", Application.ExecutablePath, "PNG Bild", $@"{Application.StartupPath}\AssocIcons\png.ico");
FileAssociation.Remove("Image_Sorter_GIF", ".gif", Application.ExecutablePath, "GIF Bild", $@"{Application.StartupPath}\AssocIcons\gif.ico");
FileAssociation.Remove("Image_Sorter_JPEG", ".jpeg", Application.ExecutablePath, "JPEG Bild", $@"{Application.StartupPath}\AssocIcons\jpeg.ico");
FileAssociation.Remove("Image_Sorter_BMP", ".bmp", Application.ExecutablePath, "BMP Bild", $@"{Application.StartupPath}\AssocIcons\bmp.ico");
FileAssociation.Remove("Image_Sorter_TIF", ".tif", Application.ExecutablePath, "TIF Bild", $@"{Application.StartupPath}\AssocIcons\tif.ico");
FileAssociation.Remove("Image_Sorter_TIFF", ".tiff", Application.ExecutablePath, "TIFF Bild", $@"{Application.StartupPath}\AssocIcons\tiff.ico");
}
CheckSubfolders();
SearchImages();
CountPicsInPath();

View File

@ -111,6 +111,7 @@
<Compile Include="Cropper.Designer.cs">
<DependentUpon>Cropper.cs</DependentUpon>
</Compile>
<Compile Include="FileAssociation.cs" />
<Compile Include="Main.cs">
<SubType>Form</SubType>
</Compile>

View File

@ -60,6 +60,16 @@ namespace Mk0.Software.ImageSorter.Properties {
}
}
/// <summary>
/// Sucht eine lokalisierte Ressource vom Typ System.Drawing.Icon ähnlich wie (Symbol).
/// </summary>
internal static System.Drawing.Icon bmp {
get {
object obj = ResourceManager.GetObject("bmp", resourceCulture);
return ((System.Drawing.Icon)(obj));
}
}
/// <summary>
/// Sucht eine lokalisierte Ressource vom Typ System.Drawing.Bitmap.
/// </summary>
@ -80,6 +90,16 @@ namespace Mk0.Software.ImageSorter.Properties {
}
}
/// <summary>
/// Sucht eine lokalisierte Ressource vom Typ System.Drawing.Icon ähnlich wie (Symbol).
/// </summary>
internal static System.Drawing.Icon gif {
get {
object obj = ResourceManager.GetObject("gif", resourceCulture);
return ((System.Drawing.Icon)(obj));
}
}
/// <summary>
/// Sucht eine lokalisierte Ressource vom Typ System.Byte[].
/// </summary>
@ -100,6 +120,26 @@ namespace Mk0.Software.ImageSorter.Properties {
}
}
/// <summary>
/// Sucht eine lokalisierte Ressource vom Typ System.Drawing.Icon ähnlich wie (Symbol).
/// </summary>
internal static System.Drawing.Icon jpeg {
get {
object obj = ResourceManager.GetObject("jpeg", resourceCulture);
return ((System.Drawing.Icon)(obj));
}
}
/// <summary>
/// Sucht eine lokalisierte Ressource vom Typ System.Drawing.Icon ähnlich wie (Symbol).
/// </summary>
internal static System.Drawing.Icon jpg {
get {
object obj = ResourceManager.GetObject("jpg", resourceCulture);
return ((System.Drawing.Icon)(obj));
}
}
/// <summary>
/// Sucht eine lokalisierte Ressource vom Typ System.Drawing.Bitmap.
/// </summary>
@ -110,6 +150,36 @@ namespace Mk0.Software.ImageSorter.Properties {
}
}
/// <summary>
/// Sucht eine lokalisierte Ressource vom Typ System.Drawing.Icon ähnlich wie (Symbol).
/// </summary>
internal static System.Drawing.Icon png {
get {
object obj = ResourceManager.GetObject("png", resourceCulture);
return ((System.Drawing.Icon)(obj));
}
}
/// <summary>
/// Sucht eine lokalisierte Ressource vom Typ System.Drawing.Icon ähnlich wie (Symbol).
/// </summary>
internal static System.Drawing.Icon tif {
get {
object obj = ResourceManager.GetObject("tif", resourceCulture);
return ((System.Drawing.Icon)(obj));
}
}
/// <summary>
/// Sucht eine lokalisierte Ressource vom Typ System.Drawing.Icon ähnlich wie (Symbol).
/// </summary>
internal static System.Drawing.Icon tiff {
get {
object obj = ResourceManager.GetObject("tiff", resourceCulture);
return ((System.Drawing.Icon)(obj));
}
}
/// <summary>
/// Sucht eine lokalisierte Ressource vom Typ System.Drawing.Bitmap.
/// </summary>

View File

@ -118,21 +118,42 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="bmp" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\bmp.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="crop" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\crop.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="delete" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\delete.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="gif" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\gif.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="grab" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Cursors\grab.cur;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="grabbing" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Cursors\grabbing.cur;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="jpeg" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\jpeg.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="jpg" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\jpg.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="move" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\move.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="png" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\png.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="tif" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\tif.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="tiff" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\tiff.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="undo" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\undo.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>

View File

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