implemented API #9

This commit is contained in:
Manuel Kamper 2022-10-28 15:01:12 +02:00
parent c9cbfd9c3d
commit 3ba1f4d384
17 changed files with 850 additions and 281 deletions

133
Mk0.Software.Bildduplikate/API.Designer.cs generated Normal file
View File

@ -0,0 +1,133 @@

namespace Mk0.Software.Bildduplikate
{
partial class API
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.textBoxApiUrl = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.textBoxPath1 = new System.Windows.Forms.TextBox();
this.textBoxPath2 = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.buttonSave = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(12, 9);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(43, 13);
this.label1.TabIndex = 0;
this.label1.Text = "API Url:";
//
// textBoxApiUrl
//
this.textBoxApiUrl.Location = new System.Drawing.Point(15, 25);
this.textBoxApiUrl.Name = "textBoxApiUrl";
this.textBoxApiUrl.Size = new System.Drawing.Size(446, 20);
this.textBoxApiUrl.TabIndex = 1;
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(12, 88);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(75, 13);
this.label2.TabIndex = 2;
this.label2.Text = "Replace Path:";
//
// textBoxPath1
//
this.textBoxPath1.Location = new System.Drawing.Point(15, 104);
this.textBoxPath1.Name = "textBoxPath1";
this.textBoxPath1.Size = new System.Drawing.Size(206, 20);
this.textBoxPath1.TabIndex = 3;
//
// textBoxPath2
//
this.textBoxPath2.Location = new System.Drawing.Point(15, 143);
this.textBoxPath2.Name = "textBoxPath2";
this.textBoxPath2.Size = new System.Drawing.Size(206, 20);
this.textBoxPath2.TabIndex = 4;
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(12, 127);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(29, 13);
this.label3.TabIndex = 5;
this.label3.Text = "with:";
//
// buttonSave
//
this.buttonSave.Location = new System.Drawing.Point(386, 141);
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(75, 23);
this.buttonSave.TabIndex = 6;
this.buttonSave.Text = "Save";
this.buttonSave.UseVisualStyleBackColor = true;
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
//
// API
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(476, 180);
this.Controls.Add(this.buttonSave);
this.Controls.Add(this.label3);
this.Controls.Add(this.textBoxPath2);
this.Controls.Add(this.textBoxPath1);
this.Controls.Add(this.label2);
this.Controls.Add(this.textBoxApiUrl);
this.Controls.Add(this.label1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "API";
this.ShowIcon = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "API";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox textBoxApiUrl;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox textBoxPath1;
private System.Windows.Forms.TextBox textBoxPath2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Button buttonSave;
}
}

View File

@ -0,0 +1,24 @@
using System;
using System.Windows.Forms;
namespace Mk0.Software.Bildduplikate
{
public partial class API : Form
{
public API()
{
InitializeComponent();
textBoxApiUrl.Text = Properties.Settings.Default.ApiUrl;
textBoxPath1.Text = Properties.Settings.Default.ReplacePath;
textBoxPath2.Text = Properties.Settings.Default.ReplaceWith;
}
private void ButtonSave_Click(object sender, EventArgs e)
{
Properties.Settings.Default.ApiUrl = textBoxApiUrl.Text.Trim();
Properties.Settings.Default.ReplacePath = textBoxPath1.Text.Trim();
Properties.Settings.Default.ReplaceWith = textBoxPath2.Text.Trim();
Properties.Settings.Default.Save();
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,11 @@
using System.Collections.Generic;
namespace Mk0.Software.Bildduplikate
{
class APIResponse
{
public string response_code { get; set; }
public string response_desc { get; set; }
public List<APIResponsePayload> payload { get; set; }
}
}

View File

@ -0,0 +1,12 @@
using System;
namespace Mk0.Software.Bildduplikate
{
class APIResponsePayload
{
public string id { get; set; }
public string file1 { get; set; }
public string file2 { get; set; }
public DateTime date { get; set; }
}
}

View File

@ -1,6 +1,40 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="Mk0.Software.Bildduplikate.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
</startup>
<userSettings>
<Mk0.Software.Bildduplikate.Properties.Settings>
<setting name="ApiUrl" serializeAs="String">
<value />
</setting>
<setting name="ReplacePath" serializeAs="String">
<value />
</setting>
<setting name="ReplaceWith" serializeAs="String">
<value />
</setting>
</Mk0.Software.Bildduplikate.Properties.Settings>
</userSettings>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.2" newVersion="4.0.1.2" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.6.0" newVersion="4.0.6.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

View File

@ -4,6 +4,7 @@
{
private string image1;
private string image2;
private string id;
public string Path1
{
@ -13,11 +14,16 @@
{
get { return image2; }
}
public string ID
{
get { return id; }
}
public Duplicate(string image1, string image2)
public Duplicate(string image1, string image2, string id = "")
{
this.image1 = image1;
this.image2 = image2;
this.id = id;
}
}
}

View File

@ -1,216 +0,0 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
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, offset = 0;
private string file;
private List<Duplicate> duplicates = new List<Duplicate>();
public Form1()
{
InitializeComponent();
}
private void ButtonCSV_Click(object sender, EventArgs e)
{
openFileDialog1.Title = "Select CSV";
openFileDialog1.DefaultExt = "csv";
openFileDialog1.Filter = "CSV (*.csv)|*.csv";
openFileDialog1.FilterIndex = 2;
openFileDialog1.CheckFileExists = true;
openFileDialog1.CheckPathExists = true;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
LoadCSV(openFileDialog1.FileName);
}
}
private void LoadCSV(string fileName)
{
line = 0;
total = 0;
file = fileName;
offset = 0;
duplicates.Clear();
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);
}
private void LoadDuplicates(int lineDup)
{
if (duplicates.Count > lineDup)
{
if (File.Exists(duplicates.ElementAt(lineDup).Path1) && File.Exists(duplicates.ElementAt(lineDup).Path2))
{
Image img1 = GetCopyImage(duplicates.ElementAt(lineDup).Path1);
Image img2 = GetCopyImage(duplicates.ElementAt(lineDup).Path2);
pictureBox1.Image = img1;
pictureBox2.Image = img2;
FileInfo f1 = new FileInfo(duplicates.ElementAt(lineDup).Path1);
FileInfo f2 = new FileInfo(duplicates.ElementAt(lineDup).Path2);
label1.Text = Path.GetFileName(duplicates.ElementAt(lineDup).Path1) + Environment.NewLine + FormatSize(f1.Length) + Environment.NewLine + f1.LastWriteTime + Environment.NewLine + img1.Width + "x" + img1.Height;
label2.Text = Path.GetFileName(duplicates.ElementAt(lineDup).Path2) + Environment.NewLine + FormatSize(f2.Length) + Environment.NewLine + f2.LastWriteTime + Environment.NewLine + img2.Width + "x" + img2.Height;
label3.Text = total + " Duplikate";
UIElementsVisible(true);
}
else
{
File_DeleteLine(lineDup);
total--;
line++;
LoadDuplicates(line);
}
}
else
{
MessageBox.Show("Alle Duplikate in CSV abgearbeitet", "Fertig!", MessageBoxButtons.OK, MessageBoxIcon.Information);
UIElementsVisible(false);
}
}
private void UIElementsVisible(bool vis)
{
label1.Visible = vis;
label2.Visible = vis;
label3.Visible = vis;
buttonDel1.Visible = vis;
buttonDel2.Visible = vis;
buttonKeinDuplikat.Visible = vis;
pictureBox1.Visible = vis;
pictureBox2.Visible = vis;
}
private string FormatSize(long length)
{
int counter = 0;
decimal number = (decimal)length;
while (Math.Round(number / 1024) >= 1)
{
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 Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.C)
{
ButtonCSV_Click(sender, e);
}
else if (e.KeyCode == Keys.D1 || e.KeyCode == Keys.NumPad1)
{
ButtonDel1_Click(sender, e);
}
else if (e.KeyCode == Keys.D2 || e.KeyCode == Keys.NumPad2)
{
ButtonDel2_Click(sender, e);
}
else if (e.KeyCode == Keys.D0 || e.KeyCode == Keys.NumPad0)
{
ButtonKeinDuplikat_Click(sender, e);
}
else if (e.KeyCode == Keys.R)
{
ButtonReload_Click(sender, e);
}
}
private void ButtonReload_Click(object sender, EventArgs e)
{
LoadDuplicates(line);
}
private void File_DeleteLine(int lineFile)
{
int linetodelete = lineFile + 1 - offset;
offset++;
StringBuilder sb = new StringBuilder();
using (StreamReader sr = new StreamReader(file))
{
int Countup = 0;
while (!sr.EndOfStream)
{
Countup++;
if (Countup != linetodelete)
{
using (StringWriter sw = new StringWriter(sb))
{
sw.WriteLine(sr.ReadLine());
}
}
else
{
sr.ReadLine();
}
}
}
using (StreamWriter sw = new StreamWriter(file))
{
sw.Write(sb.ToString());
}
Debug.Print("lösche Zeile " + linetodelete);
}
}
}

View File

@ -1,7 +1,7 @@

namespace Mk0.Software.Bildduplikate
{
partial class Form1
partial class Main
{
/// <summary>
/// Erforderliche Designervariable.
@ -29,12 +29,10 @@ namespace Mk0.Software.Bildduplikate
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Main));
this.buttonCSV = new System.Windows.Forms.Button();
this.buttonDel1 = new System.Windows.Forms.Button();
this.buttonDel2 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.pictureBox2 = new System.Windows.Forms.PictureBox();
this.buttonKeinDuplikat = new System.Windows.Forms.Button();
@ -43,6 +41,10 @@ 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.textBoxDesc2 = new System.Windows.Forms.TextBox();
this.buttonAPISetting = new System.Windows.Forms.Button();
this.buttonAPILoad = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
@ -88,27 +90,6 @@ namespace Mk0.Software.Bildduplikate
this.buttonDel2.Visible = false;
this.buttonDel2.Click += new System.EventHandler(this.ButtonDel2_Click);
//
// label1
//
this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.label1.Location = new System.Drawing.Point(-219, 29);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(604, 50);
this.label1.TabIndex = 4;
this.label1.Text = "label1";
this.label1.TextAlign = System.Drawing.ContentAlignment.TopRight;
this.label1.Visible = false;
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(3, 29);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(35, 13);
this.label2.TabIndex = 5;
this.label2.Text = "label2";
this.label2.Visible = false;
//
// pictureBox1
//
this.pictureBox1.BackColor = System.Drawing.SystemColors.Control;
@ -198,23 +179,68 @@ namespace Mk0.Software.Bildduplikate
//
// splitContainer2.Panel1
//
this.splitContainer2.Panel1.Controls.Add(this.textBoxDesc1);
this.splitContainer2.Panel1.Controls.Add(this.buttonDel1);
this.splitContainer2.Panel1.Controls.Add(this.label1);
//
// splitContainer2.Panel2
//
this.splitContainer2.Panel2.Controls.Add(this.textBoxDesc2);
this.splitContainer2.Panel2.Controls.Add(this.buttonDel2);
this.splitContainer2.Panel2.Controls.Add(this.label2);
this.splitContainer2.Size = new System.Drawing.Size(775, 81);
this.splitContainer2.SplitterDistance = 388;
this.splitContainer2.TabIndex = 12;
this.splitContainer2.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Form1_KeyDown);
//
// Form1
// 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(-139, 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;
//
// textBoxDesc2
//
this.textBoxDesc2.BackColor = System.Drawing.SystemColors.Control;
this.textBoxDesc2.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.textBoxDesc2.Location = new System.Drawing.Point(3, 32);
this.textBoxDesc2.Multiline = true;
this.textBoxDesc2.Name = "textBoxDesc2";
this.textBoxDesc2.Size = new System.Drawing.Size(592, 44);
this.textBoxDesc2.TabIndex = 4;
this.textBoxDesc2.Visible = false;
//
// buttonAPISetting
//
this.buttonAPISetting.Location = new System.Drawing.Point(174, 12);
this.buttonAPISetting.Name = "buttonAPISetting";
this.buttonAPISetting.Size = new System.Drawing.Size(75, 23);
this.buttonAPISetting.TabIndex = 13;
this.buttonAPISetting.Text = "API Setting";
this.buttonAPISetting.UseVisualStyleBackColor = true;
this.buttonAPISetting.Click += new System.EventHandler(this.ButtonAPI_Click);
//
// buttonAPILoad
//
this.buttonAPILoad.Location = new System.Drawing.Point(255, 12);
this.buttonAPILoad.Name = "buttonAPILoad";
this.buttonAPILoad.Size = new System.Drawing.Size(75, 23);
this.buttonAPILoad.TabIndex = 14;
this.buttonAPILoad.Text = "Load API";
this.buttonAPILoad.UseVisualStyleBackColor = true;
this.buttonAPILoad.Click += new System.EventHandler(this.ButtonAPILoad_Click);
//
// Main
//
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.buttonAPILoad);
this.Controls.Add(this.buttonAPISetting);
this.Controls.Add(this.splitContainer2);
this.Controls.Add(this.buttonReload);
this.Controls.Add(this.label3);
@ -223,8 +249,8 @@ namespace Mk0.Software.Bildduplikate
this.Controls.Add(this.buttonCSV);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.KeyPreview = true;
this.Name = "Form1";
this.Text = "Bildduplikate v1.3 by kmpr.at";
this.Name = "Main";
this.Text = "Bildduplikate v1.4 by kmpr.at";
this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Form1_KeyDown);
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).EndInit();
@ -233,6 +259,7 @@ 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);
this.splitContainer2.Panel2.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).EndInit();
@ -246,8 +273,6 @@ namespace Mk0.Software.Bildduplikate
private System.Windows.Forms.Button buttonCSV;
private System.Windows.Forms.Button buttonDel1;
private System.Windows.Forms.Button buttonDel2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.PictureBox pictureBox2;
private System.Windows.Forms.Button buttonKeinDuplikat;
@ -256,6 +281,10 @@ 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.TextBox textBoxDesc2;
private System.Windows.Forms.Button buttonAPISetting;
private System.Windows.Forms.Button buttonAPILoad;
}
}

View File

@ -0,0 +1,345 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Windows.Forms;
using System.Web.Script.Serialization;
namespace Mk0.Software.Bildduplikate
{
public partial class Main : Form
{
static readonly string[] suffixes = { "Bytes", "KB", "MB", "GB", "TB", "PB" };
private int line = 0, total = 0, offset = 0;
private string file;
private bool api = false;
private List<Duplicate> duplicates = new List<Duplicate>();
public Main()
{
InitializeComponent();
}
private void ButtonCSV_Click(object sender, EventArgs e)
{
openFileDialog1.Title = "Select CSV";
openFileDialog1.DefaultExt = "csv";
openFileDialog1.Filter = "CSV (*.csv)|*.csv";
openFileDialog1.FilterIndex = 2;
openFileDialog1.CheckFileExists = true;
openFileDialog1.CheckPathExists = true;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
LoadCSV(openFileDialog1.FileName);
}
}
private void LoadCSV(string fileName)
{
line = 0;
total = 0;
file = fileName;
offset = 0;
duplicates.Clear();
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;
api = false;
LoadDuplicates(line);
}
private void LoadDuplicates(int lineDup, bool api=false)
{
if (duplicates.Count > lineDup)
{
if (File.Exists(duplicates.ElementAt(lineDup).Path1) && File.Exists(duplicates.ElementAt(lineDup).Path2))
{
Image img1 = GetCopyImage(duplicates.ElementAt(lineDup).Path1);
Image img2 = GetCopyImage(duplicates.ElementAt(lineDup).Path2);
pictureBox1.Image = img1;
pictureBox2.Image = img2;
FileInfo f1 = new FileInfo(duplicates.ElementAt(lineDup).Path1);
FileInfo f2 = new FileInfo(duplicates.ElementAt(lineDup).Path2);
string size1, size2;
if(f1.Length==f2.Length)
{
size1 = "<b>" + FormatSize(f1.Length) + "</b>";
size2 = "<b>" + FormatSize(f2.Length) + "</b>";
}
else if(f1.Length>f2.Length)
{
size1 = "<b>" + FormatSize(f1.Length) + "</b>";
size2 = FormatSize(f2.Length);
}
else
{
size1 = FormatSize(f1.Length);
size2 = "<b>" + FormatSize(f2.Length) + "</b>";
}
textBoxDesc1.Text = Path.GetFileName(duplicates.ElementAt(lineDup).Path1) + Environment.NewLine + size1 + Environment.NewLine + f1.LastWriteTime + Environment.NewLine + img1.Width + "x" + img1.Height;
textBoxDesc2.Text = Path.GetFileName(duplicates.ElementAt(lineDup).Path2) + Environment.NewLine + size2 + Environment.NewLine + f2.LastWriteTime + Environment.NewLine + img2.Width + "x" + img2.Height;
label3.Text = total + " Duplikate";
UIElementsVisible(true);
}
else
{
if (api)
{
WebClient webClient = new WebClient();
webClient.Headers[HttpRequestHeader.ContentType] = "application/json";
string json = webClient.UploadString(Properties.Settings.Default.ApiUrl + "?isDuplicate", "{\"duplicateId\":" + duplicates.ElementAt(lineDup).ID + "}");
var resObj = new JavaScriptSerializer().Deserialize<APIResponse>(json);
if (resObj.response_code != "200") { MessageBox.Show("Fehler", resObj.response_desc, MessageBoxButtons.OK, MessageBoxIcon.Error); }
else
{
total--;
line++;
LoadDuplicates(line, api);
}
}
else
{
File_DeleteLine(lineDup);
total--;
line++;
LoadDuplicates(line, api);
}
}
}
else
{
MessageBox.Show("Alle Duplikate in CSV abgearbeitet", "Fertig!", MessageBoxButtons.OK, MessageBoxIcon.Information);
UIElementsVisible(false);
}
}
private void UIElementsVisible(bool vis)
{
textBoxDesc1.Visible = vis;
textBoxDesc2.Visible = vis;
label3.Visible = vis;
buttonDel1.Visible = vis;
buttonDel2.Visible = vis;
buttonKeinDuplikat.Visible = vis;
pictureBox1.Visible = vis;
pictureBox2.Visible = vis;
}
private string FormatSize(long length)
{
int counter = 0;
decimal number = (decimal)length;
while (Math.Round(number / 1024) >= 1)
{
number /= 1024;
counter++;
}
return string.Format("{0:n1}{1}", number, suffixes[counter]);
}
private void ButtonKeinDuplikat_Click(object sender, EventArgs e)
{
if (api)
{
WebClient webClient = new WebClient();
webClient.Headers[HttpRequestHeader.ContentType] = "application/json";
string json = webClient.UploadString(Properties.Settings.Default.ApiUrl + "?noDuplicate", "{\"duplicateId\":" + duplicates.ElementAt(line).ID + "}");
var resObj = new JavaScriptSerializer().Deserialize<APIResponse>(json);
if (resObj.response_code != "200") { MessageBox.Show("Fehler", resObj.response_desc, MessageBoxButtons.OK, MessageBoxIcon.Error); }
else
{
total--;
line++;
LoadDuplicates(line, api);
}
}
else
{
File_DeleteLine(line);
total--;
line++;
LoadDuplicates(line, api);
}
}
private void ButtonDel1_Click(object sender, EventArgs e)
{
if (api)
{
WebClient webClient = new WebClient();
webClient.Headers[HttpRequestHeader.ContentType] = "application/json";
string json = webClient.UploadString(Properties.Settings.Default.ApiUrl + "?isDuplicate", "{\"duplicateId\":" + duplicates.ElementAt(line).ID + "}");
var resObj = new JavaScriptSerializer().Deserialize<APIResponse>(json);
if (resObj.response_code != "200") { MessageBox.Show("Fehler", resObj.response_desc, MessageBoxButtons.OK, MessageBoxIcon.Error); }
else
{
File.Delete(duplicates.ElementAt(line).Path1);
total--;
line++;
LoadDuplicates(line, api);
}
}
else
{
File.Delete(duplicates.ElementAt(line).Path1);
File_DeleteLine(line);
line++;
total--;
LoadDuplicates(line);
}
}
private void ButtonDel2_Click(object sender, EventArgs e)
{
if (api)
{
WebClient webClient = new WebClient();
webClient.Headers[HttpRequestHeader.ContentType] = "application/json";
string json = webClient.UploadString(Properties.Settings.Default.ApiUrl + "?isDuplicate", "{\"duplicateId\":" + duplicates.ElementAt(line).ID + "}");
var resObj = new JavaScriptSerializer().Deserialize<APIResponse>(json);
if (resObj.response_code != "200") { MessageBox.Show("Fehler", resObj.response_desc, MessageBoxButtons.OK, MessageBoxIcon.Error); }
else
{
File.Delete(duplicates.ElementAt(line).Path2);
total--;
line++;
LoadDuplicates(line, api);
}
}
else
{
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 Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.C)
{
ButtonCSV_Click(sender, e);
}
else if (e.KeyCode == Keys.D1 || e.KeyCode == Keys.NumPad1)
{
ButtonDel1_Click(sender, e);
}
else if (e.KeyCode == Keys.D2 || e.KeyCode == Keys.NumPad2)
{
ButtonDel2_Click(sender, e);
}
else if (e.KeyCode == Keys.D0 || e.KeyCode == Keys.NumPad0)
{
ButtonKeinDuplikat_Click(sender, e);
}
else if (e.KeyCode == Keys.R)
{
ButtonReload_Click(sender, e);
}
}
private void ButtonAPI_Click(object sender, EventArgs e)
{
API api = new API();
api.ShowDialog();
}
private void ButtonAPILoad_Click(object sender, EventArgs e)
{
WebClient webClient = new WebClient();
webClient.Headers[HttpRequestHeader.ContentType] = "application/json";
string json = webClient.UploadString(Properties.Settings.Default.ApiUrl+"?getDuplicates", "{\"amount\":500}");
var resObj = new JavaScriptSerializer().Deserialize<APIResponse>(json);
if (resObj.response_code != "200") { MessageBox.Show("Fehler", resObj.response_desc, MessageBoxButtons.OK, MessageBoxIcon.Error); }
else
{
duplicates.Clear();
line = 0;
total = 0;
file = "";
api = true;
offset = 0;
foreach (APIResponsePayload pl in resObj.payload)
{
Duplicate d = new Duplicate(ReplacePath(pl.file1), ReplacePath(pl.file2), pl.id);
duplicates.Add(d);
}
total = duplicates.Count;
LoadDuplicates(line, true);
}
}
private string ReplacePath(string file)
{
return file.Replace(Properties.Settings.Default.ReplacePath, Properties.Settings.Default.ReplaceWith);
}
private void ButtonReload_Click(object sender, EventArgs e)
{
LoadDuplicates(line);
}
private void File_DeleteLine(int lineFile)
{
int linetodelete = lineFile + 1 - offset;
offset++;
StringBuilder sb = new StringBuilder();
using (StreamReader sr = new StreamReader(file))
{
int Countup = 0;
while (!sr.EndOfStream)
{
Countup++;
if (Countup != linetodelete)
{
using (StringWriter sw = new StringWriter(sb))
{
sw.WriteLine(sr.ReadLine());
}
}
else
{
sr.ReadLine();
}
}
}
using (StreamWriter sw = new StreamWriter(file))
{
sw.Write(sb.ToString());
}
Debug.Print("lösche Zeile " + linetodelete);
}
}
}

View File

@ -24,7 +24,7 @@
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.3.0.0</ApplicationVersion>
<ApplicationVersion>1.4.0.0</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<PublishWizardCompleted>true</PublishWizardCompleted>
<BootstrapperEnabled>true</BootstrapperEnabled>
@ -65,7 +65,18 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath>
</Reference>
<Reference Include="System.Core" />
<Reference Include="System.Memory, Version=4.0.1.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Memory.4.5.5\lib\net461\System.Memory.dll</HintPath>
</Reference>
<Reference Include="System.Numerics" />
<Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
</Reference>
<Reference Include="System.Web.Extensions" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
@ -77,17 +88,28 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="APIResponse.cs" />
<Compile Include="APIResponsePayload.cs" />
<Compile Include="Duplicate.cs" />
<Compile Include="Form1.cs">
<Compile Include="Main.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
<Compile Include="Main.Designer.cs">
<DependentUpon>Main.cs</DependentUpon>
</Compile>
<Compile Include="API.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="API.Designer.cs">
<DependentUpon>API.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
<EmbeddedResource Include="API.resx">
<DependentUpon>API.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Main.resx">
<DependentUpon>Main.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
@ -99,6 +121,7 @@
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<None Include="Mk0.Software.Bildduplikate_TemporaryKey.pfx" />
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>

View File

@ -16,7 +16,7 @@ namespace Mk0.Software.Bildduplikate
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
Application.Run(new Main());
}
}
}

View File

@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
// indem Sie "*" wie unten gezeigt eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.3.0.0")]
[assembly: AssemblyFileVersion("1.3.0.0")]
[assembly: AssemblyVersion("1.4.0.0")]
[assembly: AssemblyFileVersion("1.4.0.0")]

View File

@ -1,29 +1,62 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
// Dieser Code wurde von einem Tool generiert.
// Laufzeitversion:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn
// der Code erneut generiert wird.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Mk0.Software.Bildduplikate.Properties
{
namespace Mk0.Software.Bildduplikate.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
{
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.10.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default
{
get
{
public static Settings Default {
get {
return defaultInstance;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("")]
public string ApiUrl {
get {
return ((string)(this["ApiUrl"]));
}
set {
this["ApiUrl"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("")]
public string ReplacePath {
get {
return ((string)(this["ReplacePath"]));
}
set {
this["ReplacePath"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("")]
public string ReplaceWith {
get {
return ((string)(this["ReplaceWith"]));
}
set {
this["ReplaceWith"] = value;
}
}
}
}

View File

@ -1,7 +1,15 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
</SettingsFile>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="Mk0.Software.Bildduplikate.Properties" GeneratedClassName="Settings">
<Profiles />
<Settings>
<Setting Name="ApiUrl" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="ReplacePath" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="ReplaceWith" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
</Settings>
</SettingsFile>

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="System.Buffers" version="4.5.1" targetFramework="net48" />
<package id="System.Memory" version="4.5.5" targetFramework="net48" />
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net48" />
<package id="System.Runtime.CompilerServices.Unsafe" version="4.5.3" targetFramework="net48" />
</packages>