From 6e97e3b8fba4bdef422311ec4840f33e9672aa67 Mon Sep 17 00:00:00 2001 From: Manuel Kamper Date: Fri, 16 Aug 2024 22:06:32 +0200 Subject: [PATCH] 2.8 --- Mk0.Software.ImageSorter/App.config | 15 +++ Mk0.Software.ImageSorter/DownloadHandler.cs | 50 +++++++ Mk0.Software.ImageSorter/Inpaint.Designer.cs | 91 +++++++++++++ Mk0.Software.ImageSorter/Inpaint.cs | 127 ++++++++++++++++++ Mk0.Software.ImageSorter/Inpaint.resx | 120 +++++++++++++++++ Mk0.Software.ImageSorter/Main.Designer.cs | 20 ++- Mk0.Software.ImageSorter/Main.cs | 84 +++++++++++- Mk0.Software.ImageSorter/MenuHandler.cs | 27 ++++ .../Mk0.Software.ImageSorter.csproj | 45 ++++++- .../Properties/AssemblyInfo.cs | 4 +- .../Properties/Resources.Designer.cs | 30 +++++ .../Properties/Resources.resx | 9 ++ .../Properties/Settings.Designer.cs | 62 ++++++++- .../Properties/Settings.settings | 15 +++ .../Resources/inpaint-icon.png | Bin 0 -> 3252 bytes .../Resources/inpaint-reload.png | Bin 0 -> 1731 bytes .../Resources/inpaint-reloadfile.png | Bin 0 -> 1858 bytes Mk0.Software.ImageSorter/Settings.Designer.cs | 73 +++++++++- Mk0.Software.ImageSorter/Settings.cs | 12 ++ Mk0.Software.ImageSorter/Settings.resx | 4 + Mk0.Software.ImageSorter/packages.config | 4 + 21 files changed, 779 insertions(+), 13 deletions(-) create mode 100644 Mk0.Software.ImageSorter/DownloadHandler.cs create mode 100644 Mk0.Software.ImageSorter/Inpaint.Designer.cs create mode 100644 Mk0.Software.ImageSorter/Inpaint.cs create mode 100644 Mk0.Software.ImageSorter/Inpaint.resx create mode 100644 Mk0.Software.ImageSorter/MenuHandler.cs create mode 100644 Mk0.Software.ImageSorter/Resources/inpaint-icon.png create mode 100644 Mk0.Software.ImageSorter/Resources/inpaint-reload.png create mode 100644 Mk0.Software.ImageSorter/Resources/inpaint-reloadfile.png diff --git a/Mk0.Software.ImageSorter/App.config b/Mk0.Software.ImageSorter/App.config index 36c5073..9bef681 100644 --- a/Mk0.Software.ImageSorter/App.config +++ b/Mk0.Software.ImageSorter/App.config @@ -58,6 +58,21 @@ False + + + + + 0 + + + 0 + + + 0 + + + 0 + diff --git a/Mk0.Software.ImageSorter/DownloadHandler.cs b/Mk0.Software.ImageSorter/DownloadHandler.cs new file mode 100644 index 0000000..6f0bd12 --- /dev/null +++ b/Mk0.Software.ImageSorter/DownloadHandler.cs @@ -0,0 +1,50 @@ +using System; +using System.IO; +using CefSharp; + +namespace Mk0.Software.ImageSorter +{ + class DownloadHandler :IDownloadHandler + { + public event EventHandler OnBeforeDownloadFired; + + public event EventHandler OnDownloadUpdatedFired; + + public bool CanDownload(IWebBrowser chromiumWebBrowser, IBrowser browser, string url, string requestMethod) + { + return true; + } + + public void OnBeforeDownload(IWebBrowser chromiumWebBrowser, IBrowser browser, DownloadItem downloadItem, IBeforeDownloadCallback callback) + { + + } + + public void OnDownloadUpdated(IWebBrowser chromiumWebBrowser, IBrowser browser, DownloadItem downloadItem, IDownloadItemCallback callback) + { + OnDownloadUpdatedFired?.Invoke(this, downloadItem); + } + + bool IDownloadHandler.OnBeforeDownload(IWebBrowser chromiumWebBrowser, IBrowser browser, DownloadItem downloadItem, IBeforeDownloadCallback callback) + { + OnBeforeDownloadFired?.Invoke(this, downloadItem); + + if (!callback.IsDisposed) + { + using (callback) + { + string DownloadsDirectoryPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "inpaint-tmp"); + + callback.Continue( + Path.Combine( + DownloadsDirectoryPath, + downloadItem.SuggestedFileName + ), + showDialog: false + ); + } + } + return true; + } + } +} diff --git a/Mk0.Software.ImageSorter/Inpaint.Designer.cs b/Mk0.Software.ImageSorter/Inpaint.Designer.cs new file mode 100644 index 0000000..e591f90 --- /dev/null +++ b/Mk0.Software.ImageSorter/Inpaint.Designer.cs @@ -0,0 +1,91 @@ +namespace Mk0.Software.ImageSorter +{ + partial class Inpaint + { + /// + /// 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.buttonPaste = new System.Windows.Forms.Button(); + this.buttonReload = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // buttonPaste + // + this.buttonPaste.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.buttonPaste.BackColor = System.Drawing.Color.DodgerBlue; + this.buttonPaste.BackgroundImage = global::Mk0.Software.ImageSorter.Properties.Resources.inpaint_reloadfile; + this.buttonPaste.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center; + this.buttonPaste.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.buttonPaste.Location = new System.Drawing.Point(657, 12); + this.buttonPaste.Name = "buttonPaste"; + this.buttonPaste.Size = new System.Drawing.Size(130, 39); + this.buttonPaste.TabIndex = 1; + this.buttonPaste.TabStop = false; + this.buttonPaste.UseVisualStyleBackColor = false; + this.buttonPaste.Click += new System.EventHandler(this.ButtonPaste_Click); + // + // buttonReload + // + this.buttonReload.BackColor = System.Drawing.Color.DodgerBlue; + this.buttonReload.BackgroundImage = global::Mk0.Software.ImageSorter.Properties.Resources.inpaint_reload; + this.buttonReload.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center; + this.buttonReload.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.buttonReload.Location = new System.Drawing.Point(12, 12); + this.buttonReload.Name = "buttonReload"; + this.buttonReload.Size = new System.Drawing.Size(130, 39); + this.buttonReload.TabIndex = 2; + this.buttonReload.TabStop = false; + this.buttonReload.UseVisualStyleBackColor = false; + this.buttonReload.Click += new System.EventHandler(this.ButtonReload_Click); + // + // Inpaint + // + this.AllowDrop = true; + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 561); + this.Controls.Add(this.buttonReload); + this.Controls.Add(this.buttonPaste); + this.MaximizeBox = false; + this.MinimizeBox = false; + this.MinimumSize = new System.Drawing.Size(800, 600); + this.Name = "Inpaint"; + this.ShowIcon = false; + this.ShowInTaskbar = false; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "Image Sorter | Inpaint"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Inpaint_FormClosing); + this.Shown += new System.EventHandler(this.Inpaint_Shown); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Button buttonPaste; + private System.Windows.Forms.Button buttonReload; + } +} \ No newline at end of file diff --git a/Mk0.Software.ImageSorter/Inpaint.cs b/Mk0.Software.ImageSorter/Inpaint.cs new file mode 100644 index 0000000..400c2fc --- /dev/null +++ b/Mk0.Software.ImageSorter/Inpaint.cs @@ -0,0 +1,127 @@ +using CefSharp.WinForms; +using System; +using System.Windows.Forms; +using System.Collections.Specialized; +using CefSharp; +using System.IO; + +namespace Mk0.Software.ImageSorter +{ + public partial class Inpaint : Form + { + private readonly string url; + private readonly string file; + public ChromiumWebBrowser browser; + + public Inpaint(string url, string file) + { + InitializeComponent(); + this.url = url; + this.file = file; + InitializeChromium(); + } + + private void InitializeChromium() + { + browser = new ChromiumWebBrowser(url) + { + DownloadHandler = new DownloadHandler(), + MenuHandler = new MenuHandler(), + TabIndex = 0 + }; + this.Controls.Add(browser); + browser.Dock = DockStyle.Fill; + } + + private void Inpaint_FormClosing(object sender, FormClosingEventArgs e) + { + if (!File.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "inpaint-tmp", Path.GetFileNameWithoutExtension(file) + "_cleanup" + Path.GetExtension(file)))) + { + DialogResult res = MessageBox.Show("Sie haben kein bearbeitetes Bild heruntergeladen. Klicken sie dazu auf den Downloadbutton am unteren Fensterrand.\n\nWollen sie die bearbeitete Datei doch noch herunterladen (Ja)?\n\nFalls sie ihre Änderungen verwerfen wollen, Klicken sie (Nein).", "Inpaint Frage", MessageBoxButtons.YesNo, MessageBoxIcon.Question); + switch (res) + { + case DialogResult.Yes: + { + e.Cancel = true; + break; + } + case DialogResult.No: + { + Properties.Settings.Default.lastWidthInpaint = Width; + Properties.Settings.Default.lastHeightInpaint = Height; + Properties.Settings.Default.lastTopInpaint = Top; + Properties.Settings.Default.lastLeftInpaint = Left; + Properties.Settings.Default.Save(); + break; + + } + } + } + } + + private void Inpaint_Shown(object sender, EventArgs e) + { + if (Properties.Settings.Default.lastHeightInpaint >= MinimumSize.Height) + { + Height = Properties.Settings.Default.lastHeightInpaint; + } + if (Properties.Settings.Default.lastWidthInpaint >= MinimumSize.Width) + { + Width = Properties.Settings.Default.lastWidthInpaint; + } + if (Properties.Settings.Default.lastTopInpaint <= Screen.PrimaryScreen.Bounds.Height && Properties.Settings.Default.lastTopInpaint >= 0) + { + Top = Properties.Settings.Default.lastTopInpaint; + } + if (Properties.Settings.Default.lastLeftInpaint <= Screen.PrimaryScreen.Bounds.Width && Properties.Settings.Default.lastLeftInpaint >= 0) + { + Left = Properties.Settings.Default.lastLeftInpaint; + } + CopyPasteImage(); + ToolTip t1 = new ToolTip + { + AutoPopDelay = 5000, + InitialDelay = 1000, + ReshowDelay = 500 + }; + t1.SetToolTip(buttonPaste, "Bild erneut in Inpaint laden/Zurücksetzen (F5)"); + ToolTip t2 = new ToolTip + { + AutoPopDelay = 5000, + InitialDelay = 1000, + ReshowDelay = 500 + }; + t2.SetToolTip(buttonReload, "Inpaint neu laden (Strg + F5)"); + } + + private void CopyPasteImage() + { + System.Threading.Thread.Sleep(125); + StringCollection c = new StringCollection + { + file + }; + Clipboard.SetFileDropList(c); + browser.Select(); + browser.Focus(); + SendKeys.Send("^{v}"); + browser.Select(); + browser.Focus(); + SendKeys.Send("^{v}"); + browser.Select(); + browser.Focus(); + SendKeys.Send("^{v}"); + } + + private void ButtonPaste_Click(object sender, EventArgs e) + { + CopyPasteImage(); + } + + private void ButtonReload_Click(object sender, EventArgs e) + { + browser.Reload(); + CopyPasteImage(); + } + } +} diff --git a/Mk0.Software.ImageSorter/Inpaint.resx b/Mk0.Software.ImageSorter/Inpaint.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Mk0.Software.ImageSorter/Inpaint.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.ImageSorter/Main.Designer.cs b/Mk0.Software.ImageSorter/Main.Designer.cs index ab94012..05f6038 100644 --- a/Mk0.Software.ImageSorter/Main.Designer.cs +++ b/Mk0.Software.ImageSorter/Main.Designer.cs @@ -87,6 +87,7 @@ this.panelPreview = new System.Windows.Forms.Panel(); this.buttonHeart = new System.Windows.Forms.Button(); this.buttonChristmas = new System.Windows.Forms.Button(); + this.buttonWebRemove = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxImage)).BeginInit(); this.contextMenuStrip.SuspendLayout(); this.groupBoxInformationen.SuspendLayout(); @@ -844,11 +845,27 @@ this.buttonChristmas.Visible = false; this.buttonChristmas.Click += new System.EventHandler(this.ButtonChristmas_Click); // + // buttonWebRemove + // + this.buttonWebRemove.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.buttonWebRemove.BackgroundImage = global::Mk0.Software.ImageSorter.Properties.Resources.inpaint_icon; + this.buttonWebRemove.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonWebRemove.FlatAppearance.BorderColor = System.Drawing.Color.Silver; + this.buttonWebRemove.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.buttonWebRemove.Location = new System.Drawing.Point(239, 536); + this.buttonWebRemove.Name = "buttonWebRemove"; + this.buttonWebRemove.Size = new System.Drawing.Size(23, 23); + this.buttonWebRemove.TabIndex = 23; + this.buttonWebRemove.Tag = ""; + this.buttonWebRemove.UseVisualStyleBackColor = true; + this.buttonWebRemove.Click += new System.EventHandler(this.ButtonWebRemove_Click); + // // Main // this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; this.ClientSize = new System.Drawing.Size(967, 566); + this.Controls.Add(this.buttonWebRemove); this.Controls.Add(this.groupBoxTransformation); this.Controls.Add(this.groupBoxRander); this.Controls.Add(this.buttonChristmas); @@ -871,7 +888,7 @@ this.KeyPreview = true; this.MinimumSize = new System.Drawing.Size(983, 605); this.Name = "Main"; - this.Text = "Image Sorter v2.7 | © 2015-2023 by kmpr.at"; + this.Text = "Image Sorter v2.8 | © 2015-2024 by kmpr.at"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Main_FormClosing); this.Load += new System.EventHandler(this.Main_Load); this.Shown += new System.EventHandler(this.Main_Shown); @@ -957,5 +974,6 @@ private System.Windows.Forms.Button buttonRandAlle; private System.Windows.Forms.Button buttonRandObenUnten; private System.Windows.Forms.Button buttonRandLinksRechts; + private System.Windows.Forms.Button buttonWebRemove; } } diff --git a/Mk0.Software.ImageSorter/Main.cs b/Mk0.Software.ImageSorter/Main.cs index 3242ac2..de526bf 100644 --- a/Mk0.Software.ImageSorter/Main.cs +++ b/Mk0.Software.ImageSorter/Main.cs @@ -17,6 +17,8 @@ using System.Threading; using System.Windows.Forms; using Mk0.Software.OnlineUpdater; using System.Threading.Tasks; +using System.Text.RegularExpressions; +using System.Net.Http; namespace Mk0.Software.ImageSorter { @@ -381,6 +383,13 @@ namespace Mk0.Software.ImageSorter ReshowDelay = 500 }; t24.SetToolTip(buttonChristmas, "Frohe Weihnachten!"); + ToolTip t25 = new ToolTip + { + AutoPopDelay = 5000, + InitialDelay = 1000, + ReshowDelay = 500 + }; + t25.SetToolTip(buttonWebRemove, "Objekte aus Bild entfernen (X)"); } /// @@ -1402,6 +1411,13 @@ namespace Mk0.Software.ImageSorter Properties.Settings.Default.fullScreen = WindowState == FormWindowState.Maximized; Properties.Settings.Default.preview = panelPreview.Visible; Properties.Settings.Default.Save(); + try + { + Array.ForEach(Directory.GetFiles(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "inpaint-tmp")), File.Delete); + } + catch (Exception) + { + } } /// @@ -1719,11 +1735,17 @@ namespace Mk0.Software.ImageSorter e.Handled = true; } - if (e.KeyCode==Keys.P) + if (e.KeyCode == Keys.P) { buttonPreview.PerformClick(); e.Handled = true; } + + if (e.KeyCode == Keys.X) + { + buttonWebRemove.PerformClick(); + e.Handled = true; + } } /// @@ -2174,5 +2196,65 @@ namespace Mk0.Software.ImageSorter { Process.Start("https://www.kmpr.at/christmas.php"); } + + /// + /// Öffnet IOPaint Webseite um Objekte aus Bildern entfernen zu können + /// + /// + /// + private void ButtonWebRemove_Click(object sender, EventArgs e) + { + if (CheckInpaint()) + { + Inpaint ip = new Inpaint(Properties.Settings.Default.inpaintUrl, pictureBoxImage.ImageLocation); + ip.ShowDialog(); + string oldFileName = pictureBoxImage.ImageLocation; + string newFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "inpaint-tmp", Path.GetFileNameWithoutExtension(pictureBoxImage.ImageLocation) + "_cleanup" + Path.GetExtension(pictureBoxImage.ImageLocation)); + if (File.Exists(newFileName)) + { + File.Delete(oldFileName); + File.Move(newFileName, oldFileName); + LoadPicture(imageIndex); + } + } + else + { + MessageBox.Show("Die URL zu IOPaint wurde nicht konfiguriert, oder ist falsch konfiguriert (geben sie diese mit http(s):// ein), oder IOPaint lieferte einen Fehler.\n\nPassen sie die URL in den Einstellungen im Register \"Inpaint\" an.", "Inpaint Konfigurationsfehler", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + /// + /// Prüft ob Inpaint URL korrekt ist und IOPaint läuft + /// + /// + private bool CheckInpaint() + { + string Pattern = @"^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$"; + Regex Rgx = new Regex(Pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase); + if (Rgx.IsMatch(Properties.Settings.Default.inpaintUrl)) + { + try + { + HttpClient client = new HttpClient + { + BaseAddress = new Uri(Properties.Settings.Default.inpaintUrl) + }; + HttpResponseMessage response = client.GetAsync("api/v1/server-config").Result; + if (response.IsSuccessStatusCode) + { + var resp = response.Content.ReadAsStringAsync().Result; + if (resp.ToString().Contains("\"model_type\":\"inpaint\",")) + { + return true; + } + } + } + catch (Exception) + { + return false; + } + } + return false; + } } } \ No newline at end of file diff --git a/Mk0.Software.ImageSorter/MenuHandler.cs b/Mk0.Software.ImageSorter/MenuHandler.cs new file mode 100644 index 0000000..14d2fbd --- /dev/null +++ b/Mk0.Software.ImageSorter/MenuHandler.cs @@ -0,0 +1,27 @@ +using CefSharp; + +namespace Mk0.Software.ImageSorter +{ + internal class MenuHandler : IContextMenuHandler + { + public void OnBeforeContextMenu(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model) + { + model.Clear(); + } + + public bool OnContextMenuCommand(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IContextMenuParams parameters, CefMenuCommand commandId, CefEventFlags eventFlags) + { + return false; + } + + public void OnContextMenuDismissed(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame) + { + + } + + public bool RunContextMenu(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback) + { + return false; + } + } +} diff --git a/Mk0.Software.ImageSorter/Mk0.Software.ImageSorter.csproj b/Mk0.Software.ImageSorter/Mk0.Software.ImageSorter.csproj index daa107c..52f6857 100644 --- a/Mk0.Software.ImageSorter/Mk0.Software.ImageSorter.csproj +++ b/Mk0.Software.ImageSorter/Mk0.Software.ImageSorter.csproj @@ -1,5 +1,8 @@  + + + Debug @@ -17,6 +20,8 @@ Svn SubversionScc + + publish\ true Disk @@ -33,7 +38,7 @@ manuelkamper.com false 0 - 2.7.0.0 + 2.8.0.0 true true true @@ -52,12 +57,12 @@ AnyCPU - pdbonly + none true bin\Release\ TRACE prompt - 4 + 0 image.ico @@ -75,6 +80,15 @@ false + + ..\packages\CefSharp.Common.126.2.180\lib\net462\CefSharp.dll + + + ..\packages\CefSharp.Common.126.2.180\lib\net462\CefSharp.Core.dll + + + ..\packages\CefSharp.WinForms.126.2.180\lib\net462\CefSharp.WinForms.dll + ..\..\Mk0.GUI.Banner\Mk0.GUI.Banner\bin\Release\Mk0.GUI.Banner.dll @@ -100,6 +114,7 @@ + @@ -116,6 +131,7 @@ Dateirenamer.cs + Form @@ -123,12 +139,19 @@ EXIF.cs + + Form + + + Inpaint.cs + Form Main.cs + @@ -152,6 +175,9 @@ EXIF.cs + + Inpaint.cs + Main.cs @@ -191,6 +217,9 @@ + + + @@ -295,6 +324,16 @@ + + + Dieses Projekt verweist auf mindestens ein NuGet-Paket, das auf diesem Computer fehlt. Verwenden Sie die Wiederherstellung von NuGet-Paketen, um die fehlenden Dateien herunterzuladen. Weitere Informationen finden Sie unter "http://go.microsoft.com/fwlink/?LinkID=322105". Die fehlende Datei ist "{0}". + + + + + + +