beta release

This commit is contained in:
Manuel Kamper 2022-10-23 22:50:36 +02:00
parent c74fb21a7f
commit 68c3f4d7bd
4 changed files with 197 additions and 21 deletions

View File

@ -0,0 +1,23 @@
namespace Mk0.Software.Bildduplikate
{
class Duplicate
{
private string image1;
private string image2;
public string Path1
{
get { return image1; }
}
public string Path2
{
get { return image2; }
}
public Duplicate(string image1, string image2)
{
this.image1 = image1;
this.image2 = image2;
}
}
}

View File

@ -38,8 +38,14 @@ namespace Mk0.Software.Bildduplikate
this.pictureBox2 = new System.Windows.Forms.PictureBox();
this.buttonKeinDuplikat = new System.Windows.Forms.Button();
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.splitContainer1 = new System.Windows.Forms.SplitContainer();
this.label3 = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
this.splitContainer1.Panel1.SuspendLayout();
this.splitContainer1.Panel2.SuspendLayout();
this.splitContainer1.SuspendLayout();
this.SuspendLayout();
//
// buttonCSV
@ -55,7 +61,7 @@ namespace Mk0.Software.Bildduplikate
// buttonDel1
//
this.buttonDel1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.buttonDel1.Location = new System.Drawing.Point(12, 362);
this.buttonDel1.Location = new System.Drawing.Point(12, 359);
this.buttonDel1.Name = "buttonDel1";
this.buttonDel1.Size = new System.Drawing.Size(75, 23);
this.buttonDel1.TabIndex = 2;
@ -67,7 +73,7 @@ namespace Mk0.Software.Bildduplikate
// buttonDel2
//
this.buttonDel2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDel2.Location = new System.Drawing.Point(408, 362);
this.buttonDel2.Location = new System.Drawing.Point(404, 359);
this.buttonDel2.Name = "buttonDel2";
this.buttonDel2.Size = new System.Drawing.Size(75, 23);
this.buttonDel2.TabIndex = 3;
@ -80,7 +86,7 @@ namespace Mk0.Software.Bildduplikate
//
this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(93, 367);
this.label1.Location = new System.Drawing.Point(12, 385);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(35, 13);
this.label1.TabIndex = 4;
@ -91,7 +97,7 @@ namespace Mk0.Software.Bildduplikate
//
this.label2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(489, 367);
this.label2.Location = new System.Drawing.Point(401, 385);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(35, 13);
this.label2.TabIndex = 5;
@ -100,27 +106,29 @@ namespace Mk0.Software.Bildduplikate
//
// pictureBox1
//
this.pictureBox1.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.pictureBox1.Location = new System.Drawing.Point(12, 41);
this.pictureBox1.BackColor = System.Drawing.SystemColors.Control;
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(380, 315);
this.pictureBox1.Size = new System.Drawing.Size(388, 315);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.pictureBox1.TabIndex = 6;
this.pictureBox1.TabStop = false;
this.pictureBox1.Visible = false;
this.pictureBox1.Click += new System.EventHandler(this.ButtonDel1_Click);
//
// pictureBox2
//
this.pictureBox2.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.pictureBox2.Location = new System.Drawing.Point(408, 41);
this.pictureBox2.BackColor = System.Drawing.SystemColors.Control;
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(380, 315);
this.pictureBox2.Size = new System.Drawing.Size(384, 315);
this.pictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.pictureBox2.TabIndex = 7;
this.pictureBox2.TabStop = false;
this.pictureBox2.Visible = false;
this.pictureBox2.Click += new System.EventHandler(this.ButtonDel2_Click);
//
// buttonKeinDuplikat
//
@ -134,14 +142,45 @@ namespace Mk0.Software.Bildduplikate
this.buttonKeinDuplikat.Visible = false;
this.buttonKeinDuplikat.Click += new System.EventHandler(this.ButtonKeinDuplikat_Click);
//
// splitContainer1
//
this.splitContainer1.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.splitContainer1.Enabled = false;
this.splitContainer1.Location = new System.Drawing.Point(12, 41);
this.splitContainer1.Name = "splitContainer1";
//
// splitContainer1.Panel1
//
this.splitContainer1.Panel1.Controls.Add(this.pictureBox1);
//
// splitContainer1.Panel2
//
this.splitContainer1.Panel2.Controls.Add(this.pictureBox2);
this.splitContainer1.Size = new System.Drawing.Size(776, 315);
this.splitContainer1.SplitterDistance = 388;
this.splitContainer1.TabIndex = 9;
//
// label3
//
this.label3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.label3.Location = new System.Drawing.Point(598, 17);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(190, 23);
this.label3.TabIndex = 10;
this.label3.Text = "label3";
this.label3.TextAlign = System.Drawing.ContentAlignment.TopRight;
this.label3.Visible = false;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.label3);
this.Controls.Add(this.splitContainer1);
this.Controls.Add(this.buttonKeinDuplikat);
this.Controls.Add(this.pictureBox2);
this.Controls.Add(this.pictureBox1);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.buttonDel2);
@ -151,6 +190,10 @@ namespace Mk0.Software.Bildduplikate
this.Text = "Bildduplikate by kmpr.at";
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).EndInit();
this.splitContainer1.Panel1.ResumeLayout(false);
this.splitContainer1.Panel2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit();
this.splitContainer1.ResumeLayout(false);
this.ResumeLayout(false);
this.PerformLayout();
@ -167,6 +210,8 @@ namespace Mk0.Software.Bildduplikate
private System.Windows.Forms.PictureBox pictureBox2;
private System.Windows.Forms.Button buttonKeinDuplikat;
private System.Windows.Forms.OpenFileDialog openFileDialog1;
private System.Windows.Forms.SplitContainer splitContainer1;
private System.Windows.Forms.Label label3;
}
}

View File

@ -1,17 +1,21 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Mk0.Software.Bildduplikate
{
public partial class Form1 : Form
{
static readonly string[] suffixes = { "Bytes", "KB", "MB", "GB", "TB", "PB" };
private int line = 0, total = 0;
private string file;
List<Duplicate> duplicates = new List<Duplicate>();
public Form1()
{
InitializeComponent();
@ -34,6 +38,24 @@ namespace Mk0.Software.Bildduplikate
private void LoadCSV(string fileName)
{
line = 0;
file = fileName;
using (StreamReader reader = new StreamReader(fileName))
{
while (!reader.EndOfStream)
{
var line = reader.ReadLine();
var values = line.Split(',');
Duplicate d = new Duplicate(values[0], values[1]);
duplicates.Add(d);
}
}
total = duplicates.Count;
LoadDuplicates(line);
buttonDel1.Visible = true;
buttonDel2.Visible = true;
@ -42,21 +64,106 @@ namespace Mk0.Software.Bildduplikate
pictureBox2.Visible = true;
label1.Visible = true;
label2.Visible = true;
label3.Visible = true;
}
private void LoadDuplicates(int line)
{
if(File.Exists(duplicates.ElementAt(line).Path1) && File.Exists(duplicates.ElementAt(line).Path2))
{
Image img1 = GetCopyImage(duplicates.ElementAt(line).Path1);
Image img2 = GetCopyImage(duplicates.ElementAt(line).Path2);
pictureBox1.Image = img1;
pictureBox2.Image = img2;
FileInfo f1 = new FileInfo(duplicates.ElementAt(line).Path1);
FileInfo f2 = new FileInfo(duplicates.ElementAt(line).Path2);
label1.Text = Path.GetFileName(duplicates.ElementAt(line).Path1) + Environment.NewLine + FormatSize(f1.Length) + Environment.NewLine + f1.LastWriteTime;
label2.Text = Path.GetFileName(duplicates.ElementAt(line).Path2) + Environment.NewLine + FormatSize(f2.Length) + Environment.NewLine + f2.LastWriteTime;
label3.Text = total + " Duplikate";
}
else
{
File_DeleteLine(line);
total--;
line++;
LoadDuplicates(line);
}
}
private string FormatSize(long length)
{
int counter = 0;
decimal number = (decimal)length;
while (Math.Round(number / 1024) >= 1)
{
number = number / 1024;
counter++;
}
return string.Format("{0:n1}{1}", number, suffixes[counter]);
}
private void ButtonKeinDuplikat_Click(object sender, EventArgs e)
{
File_DeleteLine(line);
line++;
total--;
LoadDuplicates(line);
}
private void ButtonDel1_Click(object sender, EventArgs e)
{
File.Delete(duplicates.ElementAt(line).Path1);
File_DeleteLine(line);
line++;
total--;
LoadDuplicates(line);
}
private void ButtonDel2_Click(object sender, EventArgs e)
{
File.Delete(duplicates.ElementAt(line).Path2);
File_DeleteLine(line);
line++;
total--;
LoadDuplicates(line);
}
private Image GetCopyImage(string path)
{
using (Image image = Image.FromFile(path))
{
Bitmap bitmap = new Bitmap(image);
return bitmap;
}
}
private void File_DeleteLine(int line)
{
line = line + 1;
StringBuilder sb = new StringBuilder();
using (StreamReader sr = new StreamReader(file))
{
int Countup = 0;
while (!sr.EndOfStream)
{
Countup++;
if (Countup != line)
{
using (StringWriter sw = new StringWriter(sb))
{
sw.WriteLine(sr.ReadLine());
}
}
else
{
sr.ReadLine();
}
}
}
using (StreamWriter sw = new StreamWriter(file))
{
sw.Write(sb.ToString());
}
}
}
}

View File

@ -46,6 +46,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Duplicate.cs" />
<Compile Include="Form1.cs">
<SubType>Form</SubType>
</Compile>