* Improved loading speed for the application where target folders contain a lot of images inside (async counting of the images)

* More accurate counting of images in target folder (with filetypes in capital letters too and also counting images from subdirectories)
This commit is contained in:
Manuel Kamper 2022-08-13 19:45:21 +02:00
parent ca92f75ad4
commit 32a7d146a0
6 changed files with 79 additions and 42 deletions

View File

@ -79,7 +79,7 @@ namespace Mk0.Software.ImageSorter
}
else if (type == 3)
{
for (int i = 0; i < len; i = i + BYTEJUMP_SHORT)
for (int i = 0; i < len; i += BYTEJUMP_SHORT)
{
ushort val = BitConverter.ToUInt16(value, i);
ev += val.ToString();
@ -89,7 +89,7 @@ namespace Mk0.Software.ImageSorter
}
else if (type == 4)
{
for (int i = 0; i < len; i = i + BYTEJUMP_LONG)
for (int i = 0; i < len; i += BYTEJUMP_LONG)
{
uint val = BitConverter.ToUInt32(value, i);
ev += val.ToString();
@ -99,7 +99,7 @@ namespace Mk0.Software.ImageSorter
}
else if (type == 5)
{
for (int i = 0; i < len; i = i + BYTEJUMP_RATIONAL)
for (int i = 0; i < len; i += BYTEJUMP_RATIONAL)
{
uint numer = BitConverter.ToUInt32(value, i);
uint denom = BitConverter.ToUInt32(value, i + BYTEJUMP_LONG);
@ -138,7 +138,7 @@ namespace Mk0.Software.ImageSorter
{
try
{
for (int i = 0; i < len; i = i + BYTEJUMP_SLONG)
for (int i = 0; i < len; i += BYTEJUMP_SLONG)
{
int val = BitConverter.ToInt32(value, i);
ev += val.ToString();
@ -153,7 +153,7 @@ namespace Mk0.Software.ImageSorter
}
else if (type == 10)
{
for (int i = 0; i < len; i = i + BYTEJUMP_SRATIONAL)
for (int i = 0; i < len; i += BYTEJUMP_SRATIONAL)
{
int numer = BitConverter.ToInt32(value, i);
int denom = BitConverter.ToInt32(value, i + BYTEJUMP_SLONG);
@ -481,8 +481,8 @@ namespace Mk0.Software.ImageSorter
// Make the numerator "store" the sign
if (denom < 0)
{
numer = numer * -1;
denom = denom * -1;
numer *= -1;
denom *= -1;
}
Reduce(ref numer, ref denom);
@ -507,8 +507,8 @@ namespace Mk0.Software.ImageSorter
{
Int32 common = GCD(Math.Abs(numer), denom);
numer = numer / common;
denom = denom / common;
numer /= common;
denom /= common;
}
}
@ -519,9 +519,9 @@ namespace Mk0.Software.ImageSorter
{
while (num1 != num2)
if (num1 > num2)
num1 = num1 - num2;
num1 -= num2;
else
num2 = num2 - num1;
num2 -= num1;
return num1;
}
@ -569,8 +569,8 @@ namespace Mk0.Software.ImageSorter
{
UInt32 common = GCD(numer, denom);
numer = numer / common;
denom = denom / common;
numer /= common;
denom /= common;
}
}
@ -581,9 +581,9 @@ namespace Mk0.Software.ImageSorter
{
while (num1 != num2)
if (num1 > num2)
num1 = num1 - num2;
num1 -= num2;
else
num2 = num2 - num1;
num2 -= num1;
return num1;
}

View File

@ -693,7 +693,7 @@
this.MinimumSize = new System.Drawing.Size(983, 605);
this.Name = "Main";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Image Sorter v1.57 | © 2015-2022 by mk0.at";
this.Text = "Image Sorter v1.58 | © 2015-2022 by mk0.at";
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);

View File

@ -16,6 +16,7 @@ using System.Linq;
using System.Threading;
using System.Windows.Forms;
using Mk0.Software.OnlineUpdater;
using System.Threading.Tasks;
namespace Mk0.Software.ImageSorter
{
@ -23,7 +24,7 @@ namespace Mk0.Software.ImageSorter
{
public string quellPath = "";
public string zielPath = "";
private string[] fileTypes = { "jpg", "png", "jpeg", "gif", "tif", "tiff", "bmp" };
private string[] fileTypes = { "jpg", "png", "jpeg", "gif", "tif", "tiff", "bmp", "JPG", "PNG", "GIF", "JPEG", "TIF", "TIFF", "BMP" };
private int moved = 0;
private int imageIndex;
private List<Button> buttons = new List<Button>();
@ -179,7 +180,7 @@ namespace Mk0.Software.ImageSorter
if (!groupBoxInformationen.Visible)
{
groupBoxZiele.Location = new Point(groupBoxZiele.Location.X, 12);
groupBoxZiele.Height = groupBoxZiele.Height + 87;
groupBoxZiele.Height += 87;
}
CheckSubfolders();
SearchImages();
@ -364,16 +365,6 @@ namespace Mk0.Software.ImageSorter
Top = top
};
int count = 0;
foreach (string type in fileTypes)
{
try
{
count += Directory.GetFiles(folder, "*." + type).Count();
}
catch (Exception)
{
}
}
button.Text = Path.GetFileNameWithoutExtension(folder).ToString() + " (" + count + ")";
button.Size = new Size(225, 30);
button.Click += new EventHandler(MovePicture);
@ -389,6 +380,48 @@ namespace Mk0.Software.ImageSorter
{
panelButtons.Controls.Add(button);
}
AsyncCountFilesInFolders();
}
/// <summary>
/// Zählt die Files in den Folders asynchron und addiert anschließend die Zahl zum Button-Text hinzu
/// </summary>
/// <returns></returns>
private async Task AsyncCountFilesInFolders()
{
await Task.Run(() =>
{
foreach (Control ctl in panelButtons.Controls)
{
if (ctl is Button)
{
try
{
string[] folderButton = ctl.Text.Split('(');
int count = int.Parse(folderButton[1].Substring(0, folderButton[1].Length - 1)); //sollte das nicht später gezählt werden??
string targetPath = Path.Combine(zielPath, folderButton[0].Substring(0, folderButton[0].Length - 1));
foreach (string type in fileTypes)
{
try
{
count += Directory.EnumerateFiles(targetPath, "*." + type, System.IO.SearchOption.AllDirectories).Count();
}
catch (Exception)
{
}
}
if (ctl.InvokeRequired)
ctl.Invoke(new Action(() => ctl.Text = folderButton[0] + "(" + count + ")"));
else
ctl.Text = folderButton[0] + "(" + count + ")";
}
catch (Exception)
{
}
}
}
});
}
/// <summary>
@ -697,7 +730,7 @@ namespace Mk0.Software.ImageSorter
LoadPicture(imageIndex);
CheckUndo();
if(Properties.Settings.Default.fading)
if (Properties.Settings.Default.fading)
{
btn.BackColor = Color.LightSalmon;
btn.ForeColor = Color.MediumSeaGreen;
@ -1222,7 +1255,7 @@ namespace Mk0.Software.ImageSorter
Properties.Settings.Default.lastTop = Top;
Properties.Settings.Default.lastLeft = Left;
Properties.Settings.Default.showInfo = groupBoxInformationen.Visible;
Properties.Settings.Default.fullScreen = (WindowState == FormWindowState.Maximized ? true : false);
Properties.Settings.Default.fullScreen = WindowState == FormWindowState.Maximized;
Properties.Settings.Default.Save();
}
@ -1462,14 +1495,14 @@ namespace Mk0.Software.ImageSorter
//ausblenden
groupBoxInformationen.Visible = false;
groupBoxZiele.Location = new Point(groupBoxZiele.Location.X, 12);
groupBoxZiele.Height = groupBoxZiele.Height + 87;
groupBoxZiele.Height += 87;
}
else
{
//einblenden
groupBoxInformationen.Visible = true;
groupBoxZiele.Location = new Point(groupBoxZiele.Location.X, 99);
groupBoxZiele.Height = groupBoxZiele.Height - 87;
groupBoxZiele.Height -= 87;
}
}

View File

@ -33,7 +33,7 @@
<PublisherName>manuelkamper.com</PublisherName>
<OpenBrowserOnPublish>false</OpenBrowserOnPublish>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.57.0.0</ApplicationVersion>
<ApplicationVersion>1.58.0.0</ApplicationVersion>
<UseApplicationTrust>true</UseApplicationTrust>
<CreateDesktopShortcut>true</CreateDesktopShortcut>
<ExcludeDeploymentUrl>true</ExcludeDeploymentUrl>

View File

@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
// übernehmen, indem Sie "*" eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.57.*")]
[assembly: AssemblyVersion("1.58.*")]
//[assembly: AssemblyFileVersion("1.6.0.0")]

View File

@ -81,10 +81,12 @@ namespace Mk0.Software.ImageSorter
private void ButtonChangeLightBackgroundColour_Click(object sender, EventArgs e)
{
ColorDialog colorDlg = new ColorDialog();
colorDlg.Color = Properties.Settings.Default.lightBackgroundColour;
colorDlg.AnyColor = true;
colorDlg.SolidColorOnly = false;
ColorDialog colorDlg = new ColorDialog
{
Color = Properties.Settings.Default.lightBackgroundColour,
AnyColor = true,
SolidColorOnly = false
};
if (colorDlg.ShowDialog() == DialogResult.OK)
{
Properties.Settings.Default.lightBackgroundColour = colorDlg.Color;
@ -95,10 +97,12 @@ namespace Mk0.Software.ImageSorter
private void ButtonChangeDarkBackgroundColour_Click(object sender, EventArgs e)
{
ColorDialog colorDlg = new ColorDialog();
colorDlg.Color = Properties.Settings.Default.darkBackgroundColour;
colorDlg.AnyColor = true;
colorDlg.SolidColorOnly = false;
ColorDialog colorDlg = new ColorDialog
{
Color = Properties.Settings.Default.darkBackgroundColour,
AnyColor = true,
SolidColorOnly = false
};
if (colorDlg.ShowDialog() == DialogResult.OK)
{
Properties.Settings.Default.darkBackgroundColour = colorDlg.Color;