implemented highlights in info values #8

added path to info values #12
implemented gighlighting of button for expected worse duplicate #20
This commit is contained in:
Manuel Kamper 2022-10-31 17:55:02 +01:00
parent 814a6e404a
commit 4ee53f2fda
2 changed files with 177 additions and 31 deletions

View File

@ -41,7 +41,6 @@ namespace Mk0.Software.Bildduplikate
this.label3 = new System.Windows.Forms.Label();
this.buttonReload = new System.Windows.Forms.Button();
this.splitContainer2 = new System.Windows.Forms.SplitContainer();
this.textBoxDesc1 = new System.Windows.Forms.TextBox();
this.buttonAPISetting = new System.Windows.Forms.Button();
this.buttonAPILoad = new System.Windows.Forms.Button();
this.richTextBoxDesc1 = new System.Windows.Forms.RichTextBox();
@ -97,7 +96,7 @@ namespace Mk0.Software.Bildduplikate
this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox1.Location = new System.Drawing.Point(0, 0);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(480, 362);
this.pictureBox1.Size = new System.Drawing.Size(480, 385);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.pictureBox1.TabIndex = 6;
this.pictureBox1.TabStop = false;
@ -110,7 +109,7 @@ namespace Mk0.Software.Bildduplikate
this.pictureBox2.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox2.Location = new System.Drawing.Point(0, 0);
this.pictureBox2.Name = "pictureBox2";
this.pictureBox2.Size = new System.Drawing.Size(476, 362);
this.pictureBox2.Size = new System.Drawing.Size(476, 385);
this.pictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.pictureBox2.TabIndex = 7;
this.pictureBox2.TabStop = false;
@ -145,7 +144,7 @@ namespace Mk0.Software.Bildduplikate
// splitContainer1.Panel2
//
this.splitContainer1.Panel2.Controls.Add(this.pictureBox2);
this.splitContainer1.Size = new System.Drawing.Size(960, 362);
this.splitContainer1.Size = new System.Drawing.Size(960, 385);
this.splitContainer1.SplitterDistance = 480;
this.splitContainer1.TabIndex = 9;
this.splitContainer1.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Form1_KeyDown);
@ -181,7 +180,6 @@ namespace Mk0.Software.Bildduplikate
// splitContainer2.Panel1
//
this.splitContainer2.Panel1.Controls.Add(this.richTextBoxDesc1);
this.splitContainer2.Panel1.Controls.Add(this.textBoxDesc1);
this.splitContainer2.Panel1.Controls.Add(this.buttonDel1);
//
// splitContainer2.Panel2
@ -193,18 +191,6 @@ namespace Mk0.Software.Bildduplikate
this.splitContainer2.TabIndex = 12;
this.splitContainer2.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Form1_KeyDown);
//
// textBoxDesc1
//
this.textBoxDesc1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.textBoxDesc1.BackColor = System.Drawing.SystemColors.Control;
this.textBoxDesc1.Location = new System.Drawing.Point(-47, 32);
this.textBoxDesc1.Multiline = true;
this.textBoxDesc1.Name = "textBoxDesc1";
this.textBoxDesc1.Size = new System.Drawing.Size(524, 49);
this.textBoxDesc1.TabIndex = 3;
this.textBoxDesc1.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
this.textBoxDesc1.Visible = false;
//
// buttonAPISetting
//
this.buttonAPISetting.Location = new System.Drawing.Point(174, 12);
@ -227,11 +213,19 @@ namespace Mk0.Software.Bildduplikate
//
// richTextBoxDesc1
//
this.richTextBoxDesc1.Location = new System.Drawing.Point(123, 8);
this.richTextBoxDesc1.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.richTextBoxDesc1.BackColor = System.Drawing.SystemColors.Control;
this.richTextBoxDesc1.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.richTextBoxDesc1.Location = new System.Drawing.Point(3, 32);
this.richTextBoxDesc1.Name = "richTextBoxDesc1";
this.richTextBoxDesc1.Size = new System.Drawing.Size(256, 96);
this.richTextBoxDesc1.ReadOnly = true;
this.richTextBoxDesc1.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.None;
this.richTextBoxDesc1.Size = new System.Drawing.Size(474, 78);
this.richTextBoxDesc1.TabIndex = 4;
this.richTextBoxDesc1.Text = "";
this.richTextBoxDesc1.Visible = false;
//
// richTextBoxDesc2
//
@ -246,6 +240,7 @@ namespace Mk0.Software.Bildduplikate
this.richTextBoxDesc2.Size = new System.Drawing.Size(469, 78);
this.richTextBoxDesc2.TabIndex = 5;
this.richTextBoxDesc2.Text = "";
this.richTextBoxDesc2.Visible = false;
//
// Main
//
@ -276,7 +271,6 @@ namespace Mk0.Software.Bildduplikate
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit();
this.splitContainer1.ResumeLayout(false);
this.splitContainer2.Panel1.ResumeLayout(false);
this.splitContainer2.Panel1.PerformLayout();
this.splitContainer2.Panel2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).EndInit();
this.splitContainer2.ResumeLayout(false);
@ -297,7 +291,6 @@ namespace Mk0.Software.Bildduplikate
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Button buttonReload;
private System.Windows.Forms.SplitContainer splitContainer2;
private System.Windows.Forms.TextBox textBoxDesc1;
private System.Windows.Forms.Button buttonAPISetting;
private System.Windows.Forms.Button buttonAPILoad;
private System.Windows.Forms.RichTextBox richTextBoxDesc1;

View File

@ -82,7 +82,7 @@ namespace Mk0.Software.Bildduplikate
/// </summary>
/// <param name="lineDup"></param>
/// <param name="api"></param>
private void LoadDuplicates(int lineDup, bool api=false)
private void LoadDuplicates(int lineDup, bool api = false)
{
if (Duplicates.Count > lineDup)
{
@ -94,27 +94,131 @@ namespace Mk0.Software.Bildduplikate
pictureBox2.Image = img2;
FileInfo f1 = new FileInfo(Duplicates.ElementAt(lineDup).Path1);
FileInfo f2 = new FileInfo(Duplicates.ElementAt(lineDup).Path2);
int dup1 = 0, dup2 = 0;
string size1, size2;
if(f1.Length==f2.Length)
if (f1.Length == f2.Length)
{
size1 = "<b>" + FormatSize(f1.Length) + "</b>";
size2 = "<b>" + FormatSize(f2.Length) + "</b>";
size1 = @"\b " + FormatSize(f1.Length) + @" \b0 ";
size2 = @"\b " + FormatSize(f2.Length) + @" \b0 ";
dup1++;
dup1++;
dup2++;
dup2++;
}
else if(f1.Length>f2.Length)
else if (f1.Length > f2.Length)
{
size1 = "<b>" + FormatSize(f1.Length) + "</b>";
size1 = @"\b " + FormatSize(f1.Length) + @" \b0 ";
size2 = FormatSize(f2.Length);
dup1++;
dup1++;
}
else
{
size1 = FormatSize(f1.Length);
size2 = "<b>" + FormatSize(f2.Length) + "</b>";
size2 = @"\b " + FormatSize(f2.Length) + @" \b0 ";
dup2++;
dup2++;
}
textBoxDesc1.Text = Path.GetFileName(Duplicates.ElementAt(lineDup).Path1) + Environment.NewLine + size1 + Environment.NewLine + f1.LastWriteTime + Environment.NewLine + img1.Width + "x" + img1.Height;
richTextBoxDesc2.Text = Path.GetFileName(Duplicates.ElementAt(lineDup).Path2) + Environment.NewLine + size2 + Environment.NewLine + f2.LastWriteTime + Environment.NewLine + img2.Width + "x" + img2.Height;
string filePath1 = Path.GetDirectoryName(Duplicates.ElementAt(lineDup).Path1);
string filePath2 = Path.GetDirectoryName(Duplicates.ElementAt(lineDup).Path2);
if (filePath1 == filePath2)
{
filePath1 = @"\b " + GetRtfUnicodeEscapedString(filePath1) + @" \b0 ";
filePath2 = @"\b " + GetRtfUnicodeEscapedString(filePath2) + @" \b0 ";
dup1++;
dup2++;
}
string fileName1 = Path.GetFileName(Duplicates.ElementAt(lineDup).Path1);
string fileName2 = Path.GetFileName(Duplicates.ElementAt(lineDup).Path2);
if (fileName1 == fileName2)
{
fileName1 = @"\b " + GetRtfUnicodeEscapedString(fileName1) + @" \b0 ";
fileName2 = @"\b " + GetRtfUnicodeEscapedString(fileName2) + @" \b0 ";
dup1++;
dup2++;
}
DateTime lastTime1 = f1.LastWriteTime;
DateTime lastTime2 = f2.LastWriteTime;
string lastTime1str, lastTime2str;
if (lastTime1 == lastTime2)
{
lastTime1str = @"\b " + lastTime1.ToString() + @" \b0 ";
lastTime2str = @"\b " + lastTime2.ToString() + @" \b0 ";
dup1++;
dup2++;
}
else if (lastTime1 > lastTime2)
{
lastTime1str = @"\b " + lastTime1.ToString() + @" \b0 ";
lastTime2str = lastTime2.ToString();
dup1++;
}
else
{
lastTime1str = lastTime1.ToString();
lastTime2str = @"\b " + lastTime2.ToString() + @" \b0 ";
dup2++;
}
float res1 = img1.HorizontalResolution;
float res2 = img2.HorizontalResolution;
string res1str, res2str;
if (res1 == res2)
{
if (img1.Height == img2.Height && img1.Width == img2.Width)
{
res1str = @"\b " + img1.Width + "x" + img1.Height + " @ " + res1 + " DPI" + @" \b0 ";
res2str = @"\b " + img2.Width + "x" + img2.Height + " @ " + res2 + " DPI" + @" \b0 ";
dup1++;
dup1++;
dup2++;
dup2++;
}
else if (img1.Height > img2.Height && img1.Width > img2.Width)
{
res1str = @"\b " + img1.Width + "x" + img1.Height + " @ " + res1 + " DPI" + @" \b0 ";
res2str = img2.Width + "x" + img2.Height + " @ " + res2 + " DPI";
dup1++;
dup1++;
}
else if (img2.Height > img1.Height && img2.Width > img1.Width)
{
res1str = img1.Width + "x" + img1.Height + " @ " + res1 + " DPI";
res2str = @"\b " + img2.Width + "x" + img2.Height + " @ " + res2 + " DPI" + @" \b0 ";
dup2++;
dup2++;
}
else
{
res1str = img1.Width + "x" + img1.Height + " @ " + res1 + " DPI";
res2str = img2.Width + "x" + img2.Height + " @ " + res2 + " DPI";
}
}
else if (res1 > res2)
{
res1str = @"\b " + img1.Width + "x" + img1.Height + " @ " + res1 + " DPI" + @" \b0 ";
res2str = img2.Width + "x" + img2.Height + " @ " + res2 + " DPI";
dup1++;
dup1++;
}
else
{
res1str = img1.Width + "x" + img1.Height + " @ " + res1 + " DPI";
res2str = @"\b " + img2.Width + "x" + img2.Height + " @ " + res2 + " DPI" + @" \b0 ";
dup2++;
dup2++;
}
richTextBoxDesc1.Rtf = @"{\rtf1\utf-8 " + filePath1 + @"\line " + fileName1 + @"\line " + size1 + @"\line " + lastTime1str + @"\line " + res1str + " }";
richTextBoxDesc2.Rtf = @"{\rtf1\utf-8 " + filePath2 + @"\line " + fileName2 + @"\line " + size2 + @"\line " + lastTime2str + @"\line " + res2str + " }";
richTextBoxDesc1.SelectAll();
richTextBoxDesc1.SelectionAlignment = HorizontalAlignment.Right;
label3.Text = total + " Duplikate";
ButtonHighlight(dup1, dup2);
UIElementsVisible(true);
}
else
@ -163,13 +267,57 @@ namespace Mk0.Software.Bildduplikate
}
}
/// <summary>
/// Highlight Button which is possibly the worst duplicate
/// </summary>
/// <param name="dup1"></param>
/// <param name="dup2"></param>
private void ButtonHighlight(int dup1, int dup2)
{
if (dup1 < dup2)
{
buttonDel1.Font = new Font(buttonDel1.Font.Name, buttonDel1.Font.Size, FontStyle.Bold);
buttonDel2.Font = new Font(buttonDel2.Font.Name, buttonDel2.Font.Size, FontStyle.Regular);
}
else if (dup2 < dup1)
{
buttonDel1.Font = new Font(buttonDel1.Font.Name, buttonDel1.Font.Size, FontStyle.Regular);
buttonDel2.Font = new Font(buttonDel2.Font.Name, buttonDel2.Font.Size, FontStyle.Bold);
}
else
{
buttonDel1.Font = new Font(buttonDel1.Font.Name, buttonDel1.Font.Size, FontStyle.Regular);
buttonDel2.Font = new Font(buttonDel2.Font.Name, buttonDel2.Font.Size, FontStyle.Regular);
}
}
/// <summary>
/// Helper for RTF Unicode
/// </summary>
/// <param name="s"></param>
/// <returns></returns>
private static string GetRtfUnicodeEscapedString(string s)
{
var sb = new StringBuilder();
foreach (var c in s)
{
if (c == '\\' || c == '{' || c == '}')
sb.Append(@"\" + c);
else if (c <= 0x7f)
sb.Append(c);
else
sb.Append("\\u" + Convert.ToUInt32(c) + "?");
}
return sb.ToString();
}
/// <summary>
/// UI-Elements shown or not shown
/// </summary>
/// <param name="vis"></param>
private void UIElementsVisible(bool vis)
{
textBoxDesc1.Visible = vis;
richTextBoxDesc1.Visible = vis;
richTextBoxDesc2.Visible = vis;
label3.Visible = vis;
buttonDel1.Visible = vis;
@ -354,6 +502,11 @@ namespace Mk0.Software.Bildduplikate
}
}
/// <summary>
/// Show API Settings Dialog
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonAPI_Click(object sender, EventArgs e)
{
API api = new API();