From 3ba1f4d384af1f7bf3b66f6415376d6be9bd4c58 Mon Sep 17 00:00:00 2001 From: Manuel Kamper Date: Fri, 28 Oct 2022 15:01:12 +0200 Subject: [PATCH] implemented API #9 --- Mk0.Software.Bildduplikate/API.Designer.cs | 133 +++++++ Mk0.Software.Bildduplikate/API.cs | 24 ++ Mk0.Software.Bildduplikate/API.resx | 120 ++++++ Mk0.Software.Bildduplikate/APIResponse.cs | 11 + .../APIResponsePayload.cs | 12 + Mk0.Software.Bildduplikate/App.config | 36 +- Mk0.Software.Bildduplikate/Duplicate.cs | 8 +- Mk0.Software.Bildduplikate/Form1.cs | 216 ----------- .../{Form1.Designer.cs => Main.Designer.cs} | 93 +++-- Mk0.Software.Bildduplikate/Main.cs | 345 ++++++++++++++++++ .../{Form1.resx => Main.resx} | 0 .../Mk0.Software.Bildduplikate.csproj | 35 +- Mk0.Software.Bildduplikate/Program.cs | 2 +- .../Properties/AssemblyInfo.cs | 4 +- .../Properties/Settings.Designer.cs | 65 +++- .../Properties/Settings.settings | 20 +- Mk0.Software.Bildduplikate/packages.config | 7 + 17 files changed, 850 insertions(+), 281 deletions(-) create mode 100644 Mk0.Software.Bildduplikate/API.Designer.cs create mode 100644 Mk0.Software.Bildduplikate/API.cs create mode 100644 Mk0.Software.Bildduplikate/API.resx create mode 100644 Mk0.Software.Bildduplikate/APIResponse.cs create mode 100644 Mk0.Software.Bildduplikate/APIResponsePayload.cs delete mode 100644 Mk0.Software.Bildduplikate/Form1.cs rename Mk0.Software.Bildduplikate/{Form1.Designer.cs => Main.Designer.cs} (78%) create mode 100644 Mk0.Software.Bildduplikate/Main.cs rename Mk0.Software.Bildduplikate/{Form1.resx => Main.resx} (100%) create mode 100644 Mk0.Software.Bildduplikate/packages.config diff --git a/Mk0.Software.Bildduplikate/API.Designer.cs b/Mk0.Software.Bildduplikate/API.Designer.cs new file mode 100644 index 0000000..6756ef5 --- /dev/null +++ b/Mk0.Software.Bildduplikate/API.Designer.cs @@ -0,0 +1,133 @@ + +namespace Mk0.Software.Bildduplikate +{ + partial class API + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + 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; + } +} \ No newline at end of file diff --git a/Mk0.Software.Bildduplikate/API.cs b/Mk0.Software.Bildduplikate/API.cs new file mode 100644 index 0000000..e956e32 --- /dev/null +++ b/Mk0.Software.Bildduplikate/API.cs @@ -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(); + } + } +} diff --git a/Mk0.Software.Bildduplikate/API.resx b/Mk0.Software.Bildduplikate/API.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Mk0.Software.Bildduplikate/API.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Mk0.Software.Bildduplikate/APIResponse.cs b/Mk0.Software.Bildduplikate/APIResponse.cs new file mode 100644 index 0000000..2865a0b --- /dev/null +++ b/Mk0.Software.Bildduplikate/APIResponse.cs @@ -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 payload { get; set; } + } +} diff --git a/Mk0.Software.Bildduplikate/APIResponsePayload.cs b/Mk0.Software.Bildduplikate/APIResponsePayload.cs new file mode 100644 index 0000000..4717687 --- /dev/null +++ b/Mk0.Software.Bildduplikate/APIResponsePayload.cs @@ -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; } + } +} diff --git a/Mk0.Software.Bildduplikate/App.config b/Mk0.Software.Bildduplikate/App.config index 193aecc..b907526 100644 --- a/Mk0.Software.Bildduplikate/App.config +++ b/Mk0.Software.Bildduplikate/App.config @@ -1,6 +1,40 @@ - + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Mk0.Software.Bildduplikate/Duplicate.cs b/Mk0.Software.Bildduplikate/Duplicate.cs index 510a518..33a1ae1 100644 --- a/Mk0.Software.Bildduplikate/Duplicate.cs +++ b/Mk0.Software.Bildduplikate/Duplicate.cs @@ -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; } } } diff --git a/Mk0.Software.Bildduplikate/Form1.cs b/Mk0.Software.Bildduplikate/Form1.cs deleted file mode 100644 index f42c1e3..0000000 --- a/Mk0.Software.Bildduplikate/Form1.cs +++ /dev/null @@ -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 duplicates = new List(); - - 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); - } - } -} diff --git a/Mk0.Software.Bildduplikate/Form1.Designer.cs b/Mk0.Software.Bildduplikate/Main.Designer.cs similarity index 78% rename from Mk0.Software.Bildduplikate/Form1.Designer.cs rename to Mk0.Software.Bildduplikate/Main.Designer.cs index a6f2d7b..176d9a3 100644 --- a/Mk0.Software.Bildduplikate/Form1.Designer.cs +++ b/Mk0.Software.Bildduplikate/Main.Designer.cs @@ -1,7 +1,7 @@  namespace Mk0.Software.Bildduplikate { - partial class Form1 + partial class Main { /// /// Erforderliche Designervariable. @@ -29,12 +29,10 @@ namespace Mk0.Software.Bildduplikate /// 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; } } diff --git a/Mk0.Software.Bildduplikate/Main.cs b/Mk0.Software.Bildduplikate/Main.cs new file mode 100644 index 0000000..4157c93 --- /dev/null +++ b/Mk0.Software.Bildduplikate/Main.cs @@ -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 duplicates = new List(); + + 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 = "" + FormatSize(f1.Length) + ""; + size2 = "" + FormatSize(f2.Length) + ""; + } + else if(f1.Length>f2.Length) + { + size1 = "" + FormatSize(f1.Length) + ""; + size2 = FormatSize(f2.Length); + } + else + { + size1 = FormatSize(f1.Length); + size2 = "" + FormatSize(f2.Length) + ""; + } + + 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(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(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(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(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(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); + } + } +} diff --git a/Mk0.Software.Bildduplikate/Form1.resx b/Mk0.Software.Bildduplikate/Main.resx similarity index 100% rename from Mk0.Software.Bildduplikate/Form1.resx rename to Mk0.Software.Bildduplikate/Main.resx diff --git a/Mk0.Software.Bildduplikate/Mk0.Software.Bildduplikate.csproj b/Mk0.Software.Bildduplikate/Mk0.Software.Bildduplikate.csproj index 69c3675..d6e4d5d 100644 --- a/Mk0.Software.Bildduplikate/Mk0.Software.Bildduplikate.csproj +++ b/Mk0.Software.Bildduplikate/Mk0.Software.Bildduplikate.csproj @@ -24,7 +24,7 @@ false true 0 - 1.3.0.0 + 1.4.0.0 false true true @@ -65,7 +65,18 @@ + + ..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll + + + ..\packages\System.Memory.4.5.5\lib\net461\System.Memory.dll + + + + ..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll + + @@ -77,17 +88,28 @@ + + - + Form - - Form1.cs + + Main.cs + + + Form + + + API.cs - - Form1.cs + + API.cs + + + Main.cs ResXFileCodeGenerator @@ -99,6 +121,7 @@ Resources.resx + SettingsSingleFileGenerator Settings.Designer.cs diff --git a/Mk0.Software.Bildduplikate/Program.cs b/Mk0.Software.Bildduplikate/Program.cs index 570a809..3233982 100644 --- a/Mk0.Software.Bildduplikate/Program.cs +++ b/Mk0.Software.Bildduplikate/Program.cs @@ -16,7 +16,7 @@ namespace Mk0.Software.Bildduplikate { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); - Application.Run(new Form1()); + Application.Run(new Main()); } } } diff --git a/Mk0.Software.Bildduplikate/Properties/AssemblyInfo.cs b/Mk0.Software.Bildduplikate/Properties/AssemblyInfo.cs index 6978265..6e4f5e1 100644 --- a/Mk0.Software.Bildduplikate/Properties/AssemblyInfo.cs +++ b/Mk0.Software.Bildduplikate/Properties/AssemblyInfo.cs @@ -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")] diff --git a/Mk0.Software.Bildduplikate/Properties/Settings.Designer.cs b/Mk0.Software.Bildduplikate/Properties/Settings.Designer.cs index f8ff55d..b3fb522 100644 --- a/Mk0.Software.Bildduplikate/Properties/Settings.Designer.cs +++ b/Mk0.Software.Bildduplikate/Properties/Settings.Designer.cs @@ -1,29 +1,62 @@ //------------------------------------------------------------------------------ // -// 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. // //------------------------------------------------------------------------------ - -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; + } + } } } diff --git a/Mk0.Software.Bildduplikate/Properties/Settings.settings b/Mk0.Software.Bildduplikate/Properties/Settings.settings index 3964565..3709d35 100644 --- a/Mk0.Software.Bildduplikate/Properties/Settings.settings +++ b/Mk0.Software.Bildduplikate/Properties/Settings.settings @@ -1,7 +1,15 @@  - - - - - - + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Mk0.Software.Bildduplikate/packages.config b/Mk0.Software.Bildduplikate/packages.config new file mode 100644 index 0000000..b184c7a --- /dev/null +++ b/Mk0.Software.Bildduplikate/packages.config @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file