From bf988190137577908b5228d9a38d837979e4cf77 Mon Sep 17 00:00:00 2001 From: SlothDpal <16717792+SlothDpal@users.noreply.github.com> Date: Tue, 21 May 2024 12:57:07 +0300 Subject: [PATCH 01/12] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=B1=D0=B0=20CSharpDi?= =?UTF-8?q?scordWebhook?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 5 +++- .gitmodules | 3 ++ CSharpDiscordWebhook | 1 + Form1.cs | 11 ++++++++ Process Auto Relaunch.csproj | 8 ++++++ Process Auto Relaunch.sln | 53 ++++++++++++++++++++++++++++++++++++ 6 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 .gitmodules create mode 160000 CSharpDiscordWebhook diff --git a/.gitignore b/.gitignore index 9491a2f..a39d60c 100644 --- a/.gitignore +++ b/.gitignore @@ -360,4 +360,7 @@ MigrationBackup/ .ionide/ # Fody - auto-generated XML schema -FodyWeavers.xsd \ No newline at end of file +FodyWeavers.xsd +/CSharpDiscordWebhook.dll +/Newtonsoft.Json.dll +/Newtonsoft.Json.xml diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..6bf865e --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "CSharpDiscordWebhook"] + path = CSharpDiscordWebhook + url = https://github.com/N4T4NM/CSharpDiscordWebhook.git diff --git a/CSharpDiscordWebhook b/CSharpDiscordWebhook new file mode 160000 index 0000000..93a4881 --- /dev/null +++ b/CSharpDiscordWebhook @@ -0,0 +1 @@ +Subproject commit 93a4881a98a3b8447e9d898ff0b3587d3e200bb0 diff --git a/Form1.cs b/Form1.cs index 7333ca4..51f6b67 100644 --- a/Form1.cs +++ b/Form1.cs @@ -7,6 +7,8 @@ using System.Threading; using System.Windows.Forms; using RelaunchProcess.Properties; using static System.Windows.Forms.VisualStyles.VisualStyleElement; +using Discord; +using Discord.Webhook; namespace Process_Auto_Relaunch { @@ -14,12 +16,17 @@ namespace Process_Auto_Relaunch { private delegate void UpdateLogDelegate(string text, bool add_history = false); private UpdateLogDelegate updateLogDelegate = null; + private DiscordWebhook DWHook; + private DiscordMessage DMessage; public Form1() { InitializeComponent(); this.updateLogDelegate = new UpdateLogDelegate(this.UpdateStatus); myBackgroundWorker.WorkerSupportsCancellation = true; + DWHook = new DiscordWebhook(); + DWHook.Url = "https://discord.com/api/webhooks/1241061556213776405/alNwHEtwe20MvBxFTSDWPKDarPCJpD-0oDUgdcT_5YrLqoybJq7oxNOCOqqmynuVD93p"; + } /// @@ -118,6 +125,10 @@ namespace Process_Auto_Relaunch { labelStatus.Text = text; + DMessage = new DiscordMessage(); + DMessage.Content = text; + DWHook.Send(DMessage); + if (add_history) { HistoryLog(text); diff --git a/Process Auto Relaunch.csproj b/Process Auto Relaunch.csproj index c45a3e1..0295b27 100644 --- a/Process Auto Relaunch.csproj +++ b/Process Auto Relaunch.csproj @@ -63,6 +63,10 @@ bin\x64\Release\ + + False + .\CSharpDiscordWebhook.dll + @@ -127,4 +131,8 @@ + + copy $(ProjectDir)\CSharpDiscordWebhook\CSharpDiscordWebhook\$(OutDir)\* $(TargetDir) +copy $(ProjectDir)\CSharpDiscordWebhook\CSharpDiscordWebhook\$(OutDir)\* $(ProjectDir) + \ No newline at end of file diff --git a/Process Auto Relaunch.sln b/Process Auto Relaunch.sln index cb81be4..0c368e4 100644 --- a/Process Auto Relaunch.sln +++ b/Process Auto Relaunch.sln @@ -4,11 +4,24 @@ Microsoft Visual Studio Solution File, Format Version 12.00 VisualStudioVersion = 17.9.34622.214 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Process Auto Relaunch", "Process Auto Relaunch.csproj", "{B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}" + ProjectSection(ProjectDependencies) = postProject + {11C71B78-004A-471F-B29D-C2CBE4673579} = {11C71B78-004A-471F-B29D-C2CBE4673579} + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CSharpDiscordWebhook", "CSharpDiscordWebhook\CSharpDiscordWebhook\CSharpDiscordWebhook.csproj", "{11C71B78-004A-471F-B29D-C2CBE4673579}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Debug|x64 = Debug|x64 + DebugDN|Any CPU = DebugDN|Any CPU + DebugDN|x64 = DebugDN|x64 + DebugDNF|Any CPU = DebugDNF|Any CPU + DebugDNF|x64 = DebugDNF|x64 + DebugDotNetFramework|Any CPU = DebugDotNetFramework|Any CPU + DebugDotNetFramework|x64 = DebugDotNetFramework|x64 + DebugFULL|Any CPU = DebugFULL|Any CPU + DebugFULL|x64 = DebugFULL|x64 Release|Any CPU = Release|Any CPU Release|x64 = Release|x64 EndGlobalSection @@ -17,10 +30,50 @@ Global {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.Debug|Any CPU.Build.0 = Debug|Any CPU {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.Debug|x64.ActiveCfg = Debug|x64 {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.Debug|x64.Build.0 = Debug|x64 + {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.DebugDN|Any CPU.ActiveCfg = Debug|Any CPU + {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.DebugDN|Any CPU.Build.0 = Debug|Any CPU + {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.DebugDN|x64.ActiveCfg = Debug|x64 + {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.DebugDN|x64.Build.0 = Debug|x64 + {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.DebugDNF|Any CPU.ActiveCfg = Debug|Any CPU + {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.DebugDNF|Any CPU.Build.0 = Debug|Any CPU + {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.DebugDNF|x64.ActiveCfg = Debug|x64 + {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.DebugDNF|x64.Build.0 = Debug|x64 + {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.DebugDotNetFramework|Any CPU.ActiveCfg = Debug|Any CPU + {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.DebugDotNetFramework|Any CPU.Build.0 = Debug|Any CPU + {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.DebugDotNetFramework|x64.ActiveCfg = Debug|x64 + {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.DebugDotNetFramework|x64.Build.0 = Debug|x64 + {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.DebugFULL|Any CPU.ActiveCfg = Debug|Any CPU + {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.DebugFULL|Any CPU.Build.0 = Debug|Any CPU + {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.DebugFULL|x64.ActiveCfg = Debug|x64 + {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.DebugFULL|x64.Build.0 = Debug|x64 {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.Release|Any CPU.ActiveCfg = Release|Any CPU {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.Release|Any CPU.Build.0 = Release|Any CPU {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.Release|x64.ActiveCfg = Release|x64 {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.Release|x64.Build.0 = Release|x64 + {11C71B78-004A-471F-B29D-C2CBE4673579}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {11C71B78-004A-471F-B29D-C2CBE4673579}.Debug|Any CPU.Build.0 = Debug|Any CPU + {11C71B78-004A-471F-B29D-C2CBE4673579}.Debug|x64.ActiveCfg = Debug|Any CPU + {11C71B78-004A-471F-B29D-C2CBE4673579}.Debug|x64.Build.0 = Debug|Any CPU + {11C71B78-004A-471F-B29D-C2CBE4673579}.DebugDN|Any CPU.ActiveCfg = DebugDN|Any CPU + {11C71B78-004A-471F-B29D-C2CBE4673579}.DebugDN|Any CPU.Build.0 = DebugDN|Any CPU + {11C71B78-004A-471F-B29D-C2CBE4673579}.DebugDN|x64.ActiveCfg = DebugDN|Any CPU + {11C71B78-004A-471F-B29D-C2CBE4673579}.DebugDN|x64.Build.0 = DebugDN|Any CPU + {11C71B78-004A-471F-B29D-C2CBE4673579}.DebugDNF|Any CPU.ActiveCfg = DebugDNF|Any CPU + {11C71B78-004A-471F-B29D-C2CBE4673579}.DebugDNF|Any CPU.Build.0 = DebugDNF|Any CPU + {11C71B78-004A-471F-B29D-C2CBE4673579}.DebugDNF|x64.ActiveCfg = DebugDNF|Any CPU + {11C71B78-004A-471F-B29D-C2CBE4673579}.DebugDNF|x64.Build.0 = DebugDNF|Any CPU + {11C71B78-004A-471F-B29D-C2CBE4673579}.DebugDotNetFramework|Any CPU.ActiveCfg = DebugDotNetFramework|Any CPU + {11C71B78-004A-471F-B29D-C2CBE4673579}.DebugDotNetFramework|Any CPU.Build.0 = DebugDotNetFramework|Any CPU + {11C71B78-004A-471F-B29D-C2CBE4673579}.DebugDotNetFramework|x64.ActiveCfg = DebugDotNetFramework|Any CPU + {11C71B78-004A-471F-B29D-C2CBE4673579}.DebugDotNetFramework|x64.Build.0 = DebugDotNetFramework|Any CPU + {11C71B78-004A-471F-B29D-C2CBE4673579}.DebugFULL|Any CPU.ActiveCfg = DebugFULL|Any CPU + {11C71B78-004A-471F-B29D-C2CBE4673579}.DebugFULL|Any CPU.Build.0 = DebugFULL|Any CPU + {11C71B78-004A-471F-B29D-C2CBE4673579}.DebugFULL|x64.ActiveCfg = DebugFULL|Any CPU + {11C71B78-004A-471F-B29D-C2CBE4673579}.DebugFULL|x64.Build.0 = DebugFULL|Any CPU + {11C71B78-004A-471F-B29D-C2CBE4673579}.Release|Any CPU.ActiveCfg = Release|Any CPU + {11C71B78-004A-471F-B29D-C2CBE4673579}.Release|Any CPU.Build.0 = Release|Any CPU + {11C71B78-004A-471F-B29D-C2CBE4673579}.Release|x64.ActiveCfg = Release|Any CPU + {11C71B78-004A-471F-B29D-C2CBE4673579}.Release|x64.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From 54ded842242b17d9220bf1ae0bb3826f017ec183 Mon Sep 17 00:00:00 2001 From: slothdpal <16717792+SlothDpal@users.noreply.github.com> Date: Tue, 21 May 2024 21:31:26 +0300 Subject: [PATCH 02/12] DiscordWebHook as updateLogDelegate Add: dwhURL dwhEnabled settings New: status messages --- App.config | 20 ++---- DiscordSettings.Designer.cs | 121 ++++++++++++++++++++++++++++++++ DiscordSettings.cs | 51 ++++++++++++++ DiscordSettings.resx | 120 +++++++++++++++++++++++++++++++ Form1.Designer.cs | 16 +++++ Form1.cs | 68 +++++++++++++++--- Form1.resx | 2 +- Process Auto Relaunch.csproj | 10 +++ Process Auto Relaunch.sln | 34 +-------- Properties/Settings.Designer.cs | 24 +++++++ Properties/Settings.settings | 6 ++ Settings.cs | 28 ++++++++ 12 files changed, 443 insertions(+), 57 deletions(-) create mode 100644 DiscordSettings.Designer.cs create mode 100644 DiscordSettings.cs create mode 100644 DiscordSettings.resx create mode 100644 Settings.cs diff --git a/App.config b/App.config index 18f8bfa..49cf587 100644 --- a/App.config +++ b/App.config @@ -32,21 +32,13 @@ 30 + + + + + False + - - - - - - - - - True - - - True - - diff --git a/DiscordSettings.Designer.cs b/DiscordSettings.Designer.cs new file mode 100644 index 0000000..c90946a --- /dev/null +++ b/DiscordSettings.Designer.cs @@ -0,0 +1,121 @@ +namespace RelaunchProcess +{ + partial class DiscordSettings + { + /// + /// 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.btnOk = new System.Windows.Forms.Button(); + this.btnCancel = new System.Windows.Forms.Button(); + this.chbxDiscordEnabled = new System.Windows.Forms.CheckBox(); + this.textDwhURL = new System.Windows.Forms.TextBox(); + this.lblDwhURL = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // btnOk + // + this.btnOk.Location = new System.Drawing.Point(193, 89); + this.btnOk.Name = "btnOk"; + this.btnOk.Size = new System.Drawing.Size(75, 23); + this.btnOk.TabIndex = 0; + this.btnOk.Text = "Сохранить"; + this.btnOk.UseVisualStyleBackColor = true; + this.btnOk.Click += new System.EventHandler(this.btnOk_Click); + // + // btnCancel + // + this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.btnCancel.Location = new System.Drawing.Point(274, 89); + this.btnCancel.Name = "btnCancel"; + this.btnCancel.Size = new System.Drawing.Size(75, 23); + this.btnCancel.TabIndex = 1; + this.btnCancel.Text = "Отменить"; + this.btnCancel.UseVisualStyleBackColor = true; + this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click); + // + // chbxDiscordEnabled + // + this.chbxDiscordEnabled.AutoSize = true; + this.chbxDiscordEnabled.Checked = true; + this.chbxDiscordEnabled.CheckState = System.Windows.Forms.CheckState.Checked; + this.chbxDiscordEnabled.Location = new System.Drawing.Point(12, 63); + this.chbxDiscordEnabled.Name = "chbxDiscordEnabled"; + this.chbxDiscordEnabled.Size = new System.Drawing.Size(232, 17); + this.chbxDiscordEnabled.TabIndex = 2; + this.chbxDiscordEnabled.Text = "Включить отправку сообщений в Discord"; + this.chbxDiscordEnabled.UseVisualStyleBackColor = true; + // + // textDwhURL + // + this.textDwhURL.Location = new System.Drawing.Point(12, 37); + this.textDwhURL.Name = "textDwhURL"; + this.textDwhURL.Size = new System.Drawing.Size(337, 20); + this.textDwhURL.TabIndex = 3; + // + // lblDwhURL + // + this.lblDwhURL.AutoSize = true; + this.lblDwhURL.Location = new System.Drawing.Point(9, 9); + this.lblDwhURL.Name = "lblDwhURL"; + this.lblDwhURL.Size = new System.Drawing.Size(147, 13); + this.lblDwhURL.TabIndex = 4; + this.lblDwhURL.Text = "URL-адрес Discord веб-хука"; + // + // DiscordSettings + // + this.AcceptButton = this.btnOk; + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.CancelButton = this.btnCancel; + this.ClientSize = new System.Drawing.Size(361, 128); + this.ControlBox = false; + this.Controls.Add(this.lblDwhURL); + this.Controls.Add(this.textDwhURL); + this.Controls.Add(this.chbxDiscordEnabled); + this.Controls.Add(this.btnCancel); + this.Controls.Add(this.btnOk); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "DiscordSettings"; + this.ShowIcon = false; + this.ShowInTaskbar = false; + this.Text = "Настройки Discord webhook"; + this.Load += new System.EventHandler(this.DiscordSettings_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Button btnOk; + private System.Windows.Forms.Button btnCancel; + private System.Windows.Forms.CheckBox chbxDiscordEnabled; + private System.Windows.Forms.TextBox textDwhURL; + private System.Windows.Forms.Label lblDwhURL; + } +} \ No newline at end of file diff --git a/DiscordSettings.cs b/DiscordSettings.cs new file mode 100644 index 0000000..9fffdd3 --- /dev/null +++ b/DiscordSettings.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Diagnostics; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using RelaunchProcess.Properties; + +namespace RelaunchProcess +{ + public partial class DiscordSettings : Form + { + public DiscordSettings() + { + InitializeComponent(); + } + + private void DiscordSettings_Load(object sender, EventArgs e) + { + chbxDiscordEnabled.Checked=Settings.Default.dwhEnabled; + textDwhURL.Text=Settings.Default.dwhURL; + } + + private void btnCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + } + + private void btnOk_Click(object sender, EventArgs e) + { + if (Uri.IsWellFormedUriString(textDwhURL.Text, UriKind.Absolute)) + { + Settings.Default.dwhEnabled = chbxDiscordEnabled.Checked; + Settings.Default.dwhURL = textDwhURL.Text; + Settings.Default.Save(); + DialogResult = DialogResult.OK; + Close(); + } + else + { + //TODO обработать ситуацию с неверным УРЛом + } + + + } + } +} diff --git a/DiscordSettings.resx b/DiscordSettings.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/DiscordSettings.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/Form1.Designer.cs b/Form1.Designer.cs index b71d12f..ef18e8f 100644 --- a/Form1.Designer.cs +++ b/Form1.Designer.cs @@ -53,6 +53,7 @@ namespace Process_Auto_Relaunch this.myBackgroundWorker = new System.ComponentModel.BackgroundWorker(); this.groupBoxHistory = new System.Windows.Forms.GroupBox(); this.richTextBoxHistory = new System.Windows.Forms.RichTextBox(); + this.btnShowDiscordSettings = new System.Windows.Forms.Button(); this.groupBoxActions.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit(); this.groupBoxProgramStart.SuspendLayout(); @@ -248,6 +249,7 @@ namespace Process_Auto_Relaunch this.groupBoxEnabled.Controls.Add(this.checkBoxSaveState); this.groupBoxEnabled.Controls.Add(this.radioButtonEnableWathing); this.groupBoxEnabled.Controls.Add(this.radioButtonDisableWathing); + this.groupBoxEnabled.Controls.Add(this.btnShowDiscordSettings); this.groupBoxEnabled.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(204))); this.groupBoxEnabled.Location = new System.Drawing.Point(13, 345); this.groupBoxEnabled.Margin = new System.Windows.Forms.Padding(4); @@ -354,6 +356,18 @@ namespace Process_Auto_Relaunch this.richTextBoxHistory.TabIndex = 0; this.richTextBoxHistory.Text = ""; // + // btnShowDiscordSettings + // + this.btnShowDiscordSettings.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.btnShowDiscordSettings.Location = new System.Drawing.Point(282, 16); + this.btnShowDiscordSettings.Margin = new System.Windows.Forms.Padding(4); + this.btnShowDiscordSettings.Name = "btnShowDiscordSettings"; + this.btnShowDiscordSettings.Size = new System.Drawing.Size(89, 34); + this.btnShowDiscordSettings.TabIndex = 1; + this.btnShowDiscordSettings.Text = "Discord"; + this.btnShowDiscordSettings.UseVisualStyleBackColor = true; + this.btnShowDiscordSettings.Click += new System.EventHandler(this.btnShowDiscordSettings_Click); + // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); @@ -366,6 +380,7 @@ namespace Process_Auto_Relaunch this.Controls.Add(this.groupBoxProgramStart); this.Controls.Add(this.groupBoxActions); this.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.Margin = new System.Windows.Forms.Padding(4); this.MaximizeBox = false; @@ -413,5 +428,6 @@ namespace Process_Auto_Relaunch private NumericUpDown numericUpDown1; private GroupBox groupBoxHistory; private RichTextBox richTextBoxHistory; + private Button btnShowDiscordSettings; } } diff --git a/Form1.cs b/Form1.cs index 51f6b67..6cba5b8 100644 --- a/Form1.cs +++ b/Form1.cs @@ -9,23 +9,38 @@ using RelaunchProcess.Properties; using static System.Windows.Forms.VisualStyles.VisualStyleElement; using Discord; using Discord.Webhook; +using System.Data; +using static System.Net.Mime.MediaTypeNames; +using RelaunchProcess; + namespace Process_Auto_Relaunch { public partial class Form1 : Form { private delegate void UpdateLogDelegate(string text, bool add_history = false); - private UpdateLogDelegate updateLogDelegate = null; - private DiscordWebhook DWHook; - private DiscordMessage DMessage; + private UpdateLogDelegate updateLogDelegate; + private DiscordWebhook dwhHook; + private DiscordMessage dwhMessage; + private DiscordSettings discordSettings; public Form1() { InitializeComponent(); - this.updateLogDelegate = new UpdateLogDelegate(this.UpdateStatus); + this.updateLogDelegate = this.UpdateStatus; + this.updateLogDelegate += this.SendDiscordMessage; myBackgroundWorker.WorkerSupportsCancellation = true; - DWHook = new DiscordWebhook(); - DWHook.Url = "https://discord.com/api/webhooks/1241061556213776405/alNwHEtwe20MvBxFTSDWPKDarPCJpD-0oDUgdcT_5YrLqoybJq7oxNOCOqqmynuVD93p"; + dwhHook = new DiscordWebhook(); + if ( Uri.IsWellFormedUriString(Settings.Default.dwhURL,UriKind.Absolute) && Settings.Default.dwhEnabled && Settings.Default.dwhURL!="") + { + dwhHook.Url = Settings.Default.dwhURL; + } + else if (Settings.Default.dwhEnabled) { + Debug.WriteLine($" URL - ({Settings.Default.dwhURL}). Discord ."); + HistoryLog($" URL - ({Settings.Default.dwhURL}). Discord ."); + Settings.Default.dwhEnabled = false; + Settings.Default.Save(); + } } @@ -125,10 +140,6 @@ namespace Process_Auto_Relaunch { labelStatus.Text = text; - DMessage = new DiscordMessage(); - DMessage.Content = text; - DWHook.Send(DMessage); - if (add_history) { HistoryLog(text); @@ -153,6 +164,7 @@ namespace Process_Auto_Relaunch groupBoxProcessName.Enabled = !watching; groupBoxProgramStart.Enabled = !watching; groupBoxActions.Enabled = !watching; + btnShowDiscordSettings.Enabled = !watching; Settings.Default.enableWatching = watching; @@ -233,12 +245,14 @@ namespace Process_Auto_Relaunch if (ProcessByNameIsRuning(textBoxProcessName.Text)) { Status($" {textBoxProcessName.Text} "); + if (i < (int)numericUpDown1.Value) SendDiscordMessage($" {textBoxProcessName.Text} .",true); i = (int)numericUpDown1.Value; } else { if (radioButtonRestartTimer.Checked) { + if (i==(int)numericUpDown1.Value) SendDiscordMessage($" {textBoxProcessName.Text} . {i}",true); i--; Status($" {textBoxProcessName.Text} . {i}"); } @@ -247,6 +261,7 @@ namespace Process_Auto_Relaunch { i = (int)numericUpDown1.Value; Status("..."); + SendDiscordMessage($" {textBoxProcessName.Text}",true); ProcessStart(Settings.Default.startProgramPath, textBoxArguments.Text); } } @@ -277,5 +292,38 @@ namespace Process_Auto_Relaunch Status(" ."); } } + + /// + /// + /// + /// + public void SendDiscordMessage(string message, bool addToHistory = false) + { + if (Settings.Default.dwhEnabled && addToHistory) + { + dwhHook.Url = Settings.Default.dwhURL; + dwhMessage.Username = "Relaunch process"; + dwhMessage.Content = ":arrows_counterclockwise: " + message; + try + { + dwhHook.Send(dwhMessage); + } + catch (Exception ex) + { + HistoryLog($"Discord messaging error: {ex.Message}"); + Debug.WriteLine($"Discord messaging error: {ex.Message}"); + Settings.Default.dwhEnabled = false; + Settings.Default.Save(); + } + } + + } + + private void btnShowDiscordSettings_Click(object sender, EventArgs e) + { + discordSettings = new DiscordSettings(); + discordSettings.ShowDialog(this); + discordSettings.Dispose(); + } } } diff --git a/Form1.resx b/Form1.resx index a2e57f8..50c97e1 100644 --- a/Form1.resx +++ b/Form1.resx @@ -121,7 +121,7 @@ 17, 17 - 131 + 40 diff --git a/Process Auto Relaunch.csproj b/Process Auto Relaunch.csproj index 0295b27..e265fbb 100644 --- a/Process Auto Relaunch.csproj +++ b/Process Auto Relaunch.csproj @@ -86,7 +86,17 @@ Form1.cs + + Form + + + DiscordSettings.cs + + + + DiscordSettings.cs + Form1.cs Designer diff --git a/Process Auto Relaunch.sln b/Process Auto Relaunch.sln index 0c368e4..7188f0d 100644 --- a/Process Auto Relaunch.sln +++ b/Process Auto Relaunch.sln @@ -14,12 +14,6 @@ Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Debug|x64 = Debug|x64 - DebugDN|Any CPU = DebugDN|Any CPU - DebugDN|x64 = DebugDN|x64 - DebugDNF|Any CPU = DebugDNF|Any CPU - DebugDNF|x64 = DebugDNF|x64 - DebugDotNetFramework|Any CPU = DebugDotNetFramework|Any CPU - DebugDotNetFramework|x64 = DebugDotNetFramework|x64 DebugFULL|Any CPU = DebugFULL|Any CPU DebugFULL|x64 = DebugFULL|x64 Release|Any CPU = Release|Any CPU @@ -30,18 +24,6 @@ Global {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.Debug|Any CPU.Build.0 = Debug|Any CPU {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.Debug|x64.ActiveCfg = Debug|x64 {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.Debug|x64.Build.0 = Debug|x64 - {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.DebugDN|Any CPU.ActiveCfg = Debug|Any CPU - {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.DebugDN|Any CPU.Build.0 = Debug|Any CPU - {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.DebugDN|x64.ActiveCfg = Debug|x64 - {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.DebugDN|x64.Build.0 = Debug|x64 - {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.DebugDNF|Any CPU.ActiveCfg = Debug|Any CPU - {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.DebugDNF|Any CPU.Build.0 = Debug|Any CPU - {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.DebugDNF|x64.ActiveCfg = Debug|x64 - {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.DebugDNF|x64.Build.0 = Debug|x64 - {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.DebugDotNetFramework|Any CPU.ActiveCfg = Debug|Any CPU - {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.DebugDotNetFramework|Any CPU.Build.0 = Debug|Any CPU - {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.DebugDotNetFramework|x64.ActiveCfg = Debug|x64 - {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.DebugDotNetFramework|x64.Build.0 = Debug|x64 {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.DebugFULL|Any CPU.ActiveCfg = Debug|Any CPU {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.DebugFULL|Any CPU.Build.0 = Debug|Any CPU {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.DebugFULL|x64.ActiveCfg = Debug|x64 @@ -54,20 +36,8 @@ Global {11C71B78-004A-471F-B29D-C2CBE4673579}.Debug|Any CPU.Build.0 = Debug|Any CPU {11C71B78-004A-471F-B29D-C2CBE4673579}.Debug|x64.ActiveCfg = Debug|Any CPU {11C71B78-004A-471F-B29D-C2CBE4673579}.Debug|x64.Build.0 = Debug|Any CPU - {11C71B78-004A-471F-B29D-C2CBE4673579}.DebugDN|Any CPU.ActiveCfg = DebugDN|Any CPU - {11C71B78-004A-471F-B29D-C2CBE4673579}.DebugDN|Any CPU.Build.0 = DebugDN|Any CPU - {11C71B78-004A-471F-B29D-C2CBE4673579}.DebugDN|x64.ActiveCfg = DebugDN|Any CPU - {11C71B78-004A-471F-B29D-C2CBE4673579}.DebugDN|x64.Build.0 = DebugDN|Any CPU - {11C71B78-004A-471F-B29D-C2CBE4673579}.DebugDNF|Any CPU.ActiveCfg = DebugDNF|Any CPU - {11C71B78-004A-471F-B29D-C2CBE4673579}.DebugDNF|Any CPU.Build.0 = DebugDNF|Any CPU - {11C71B78-004A-471F-B29D-C2CBE4673579}.DebugDNF|x64.ActiveCfg = DebugDNF|Any CPU - {11C71B78-004A-471F-B29D-C2CBE4673579}.DebugDNF|x64.Build.0 = DebugDNF|Any CPU - {11C71B78-004A-471F-B29D-C2CBE4673579}.DebugDotNetFramework|Any CPU.ActiveCfg = DebugDotNetFramework|Any CPU - {11C71B78-004A-471F-B29D-C2CBE4673579}.DebugDotNetFramework|Any CPU.Build.0 = DebugDotNetFramework|Any CPU - {11C71B78-004A-471F-B29D-C2CBE4673579}.DebugDotNetFramework|x64.ActiveCfg = DebugDotNetFramework|Any CPU - {11C71B78-004A-471F-B29D-C2CBE4673579}.DebugDotNetFramework|x64.Build.0 = DebugDotNetFramework|Any CPU - {11C71B78-004A-471F-B29D-C2CBE4673579}.DebugFULL|Any CPU.ActiveCfg = DebugFULL|Any CPU - {11C71B78-004A-471F-B29D-C2CBE4673579}.DebugFULL|Any CPU.Build.0 = DebugFULL|Any CPU + {11C71B78-004A-471F-B29D-C2CBE4673579}.DebugFULL|Any CPU.ActiveCfg = Debug|Any CPU + {11C71B78-004A-471F-B29D-C2CBE4673579}.DebugFULL|Any CPU.Build.0 = Debug|Any CPU {11C71B78-004A-471F-B29D-C2CBE4673579}.DebugFULL|x64.ActiveCfg = DebugFULL|Any CPU {11C71B78-004A-471F-B29D-C2CBE4673579}.DebugFULL|x64.Build.0 = DebugFULL|Any CPU {11C71B78-004A-471F-B29D-C2CBE4673579}.Release|Any CPU.ActiveCfg = Release|Any CPU diff --git a/Properties/Settings.Designer.cs b/Properties/Settings.Designer.cs index c388999..9c4d1e1 100644 --- a/Properties/Settings.Designer.cs +++ b/Properties/Settings.Designer.cs @@ -118,5 +118,29 @@ namespace RelaunchProcess.Properties { this["timer"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("")] + public string dwhURL { + get { + return ((string)(this["dwhURL"])); + } + set { + this["dwhURL"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("False")] + public bool dwhEnabled { + get { + return ((bool)(this["dwhEnabled"])); + } + set { + this["dwhEnabled"] = value; + } + } } } diff --git a/Properties/Settings.settings b/Properties/Settings.settings index ad9cd31..3f8eb41 100644 --- a/Properties/Settings.settings +++ b/Properties/Settings.settings @@ -26,5 +26,11 @@ 30 + + + + + False + \ No newline at end of file diff --git a/Settings.cs b/Settings.cs new file mode 100644 index 0000000..9ba1259 --- /dev/null +++ b/Settings.cs @@ -0,0 +1,28 @@ +namespace RelaunchProcess.Properties { + + + // Этот класс позволяет обрабатывать определенные события в классе параметров: + // Событие SettingChanging возникает перед изменением значения параметра. + // Событие PropertyChanged возникает после изменения значения параметра. + // Событие SettingsLoaded возникает после загрузки значений параметров. + // Событие SettingsSaving возникает перед сохранением значений параметров. + internal sealed partial class Settings { + + public Settings() { + // // Для добавления обработчиков событий для сохранения и изменения параметров раскомментируйте приведенные ниже строки: + // + // this.SettingChanging += this.SettingChangingEventHandler; + // + // this.SettingsSaving += this.SettingsSavingEventHandler; + // + } + + private void SettingChangingEventHandler(object sender, System.Configuration.SettingChangingEventArgs e) { + // Добавьте здесь код для обработки события SettingChangingEvent. + } + + private void SettingsSavingEventHandler(object sender, System.ComponentModel.CancelEventArgs e) { + // Добавьте здесь код для обработки события SettingsSaving. + } + } +} From 15b185f6f5f50aa7d20e4d96033ef7e4da6dfe05 Mon Sep 17 00:00:00 2001 From: SlothDpal <16717792+SlothDpal@users.noreply.github.com> Date: Wed, 22 May 2024 10:33:04 +0300 Subject: [PATCH 03/12] Change notify system, refactoring --- DiscordSettings.Designer.cs | 27 +++++++--- DiscordSettings.cs | 24 ++++----- Form1.cs | 103 ++++++++++++++++++------------------ 3 files changed, 85 insertions(+), 69 deletions(-) diff --git a/DiscordSettings.Designer.cs b/DiscordSettings.Designer.cs index c90946a..ba8d3c2 100644 --- a/DiscordSettings.Designer.cs +++ b/DiscordSettings.Designer.cs @@ -33,6 +33,7 @@ this.chbxDiscordEnabled = new System.Windows.Forms.CheckBox(); this.textDwhURL = new System.Windows.Forms.TextBox(); this.lblDwhURL = new System.Windows.Forms.Label(); + this.btnClearUrlField = new System.Windows.Forms.Button(); this.SuspendLayout(); // // btnOk @@ -43,7 +44,7 @@ this.btnOk.TabIndex = 0; this.btnOk.Text = "Сохранить"; this.btnOk.UseVisualStyleBackColor = true; - this.btnOk.Click += new System.EventHandler(this.btnOk_Click); + this.btnOk.Click += new System.EventHandler(this.BtnOk_Click); // // btnCancel // @@ -54,13 +55,13 @@ this.btnCancel.TabIndex = 1; this.btnCancel.Text = "Отменить"; this.btnCancel.UseVisualStyleBackColor = true; - this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click); + this.btnCancel.Click += new System.EventHandler(this.BtnCancel_Click); // // chbxDiscordEnabled // this.chbxDiscordEnabled.AutoSize = true; - this.chbxDiscordEnabled.Checked = true; - this.chbxDiscordEnabled.CheckState = System.Windows.Forms.CheckState.Checked; + this.chbxDiscordEnabled.Checked = global::RelaunchProcess.Properties.Settings.Default.dwhEnabled; + this.chbxDiscordEnabled.DataBindings.Add(new System.Windows.Forms.Binding("Checked", global::RelaunchProcess.Properties.Settings.Default, "dwhEnabled", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged)); this.chbxDiscordEnabled.Location = new System.Drawing.Point(12, 63); this.chbxDiscordEnabled.Name = "chbxDiscordEnabled"; this.chbxDiscordEnabled.Size = new System.Drawing.Size(232, 17); @@ -70,10 +71,12 @@ // // textDwhURL // + this.textDwhURL.DataBindings.Add(new System.Windows.Forms.Binding("Text", global::RelaunchProcess.Properties.Settings.Default, "dwhURL", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged)); this.textDwhURL.Location = new System.Drawing.Point(12, 37); this.textDwhURL.Name = "textDwhURL"; this.textDwhURL.Size = new System.Drawing.Size(337, 20); this.textDwhURL.TabIndex = 3; + this.textDwhURL.Text = global::RelaunchProcess.Properties.Settings.Default.dwhURL; // // lblDwhURL // @@ -84,14 +87,26 @@ this.lblDwhURL.TabIndex = 4; this.lblDwhURL.Text = "URL-адрес Discord веб-хука"; // + // btnClearUrlField + // + this.btnClearUrlField.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.btnClearUrlField.Location = new System.Drawing.Point(351, 38); + this.btnClearUrlField.Name = "btnClearUrlField"; + this.btnClearUrlField.Size = new System.Drawing.Size(19, 19); + this.btnClearUrlField.TabIndex = 5; + this.btnClearUrlField.Text = "X"; + this.btnClearUrlField.UseVisualStyleBackColor = true; + this.btnClearUrlField.Click += new System.EventHandler(this.BtnClearUrlField_Click); + // // DiscordSettings // this.AcceptButton = this.btnOk; this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.CancelButton = this.btnCancel; - this.ClientSize = new System.Drawing.Size(361, 128); + this.ClientSize = new System.Drawing.Size(375, 128); this.ControlBox = false; + this.Controls.Add(this.btnClearUrlField); this.Controls.Add(this.lblDwhURL); this.Controls.Add(this.textDwhURL); this.Controls.Add(this.chbxDiscordEnabled); @@ -104,7 +119,6 @@ this.ShowIcon = false; this.ShowInTaskbar = false; this.Text = "Настройки Discord webhook"; - this.Load += new System.EventHandler(this.DiscordSettings_Load); this.ResumeLayout(false); this.PerformLayout(); @@ -117,5 +131,6 @@ private System.Windows.Forms.CheckBox chbxDiscordEnabled; private System.Windows.Forms.TextBox textDwhURL; private System.Windows.Forms.Label lblDwhURL; + private System.Windows.Forms.Button btnClearUrlField; } } \ No newline at end of file diff --git a/DiscordSettings.cs b/DiscordSettings.cs index 9fffdd3..710f444 100644 --- a/DiscordSettings.cs +++ b/DiscordSettings.cs @@ -19,23 +19,19 @@ namespace RelaunchProcess InitializeComponent(); } - private void DiscordSettings_Load(object sender, EventArgs e) - { - chbxDiscordEnabled.Checked=Settings.Default.dwhEnabled; - textDwhURL.Text=Settings.Default.dwhURL; - } - - private void btnCancel_Click(object sender, EventArgs e) + private void BtnCancel_Click(object sender, EventArgs e) { DialogResult = DialogResult.Cancel; } - private void btnOk_Click(object sender, EventArgs e) + private void BtnOk_Click(object sender, EventArgs e) { - if (Uri.IsWellFormedUriString(textDwhURL.Text, UriKind.Absolute)) + if (Uri.IsWellFormedUriString(textDwhURL.Text, UriKind.Absolute)||textDwhURL.Text=="") { - Settings.Default.dwhEnabled = chbxDiscordEnabled.Checked; - Settings.Default.dwhURL = textDwhURL.Text; + if (textDwhURL.Text=="") + { + chbxDiscordEnabled.Checked = false; + } Settings.Default.Save(); DialogResult = DialogResult.OK; Close(); @@ -43,9 +39,13 @@ namespace RelaunchProcess else { //TODO обработать ситуацию с неверным УРЛом + MessageBox.Show("Неверный формат URL.", "URL", MessageBoxButtons.OK, MessageBoxIcon.Error); } + } - + private void BtnClearUrlField_Click(object sender, EventArgs e) + { + textDwhURL.Text = ""; } } } diff --git a/Form1.cs b/Form1.cs index 6cba5b8..10dd541 100644 --- a/Form1.cs +++ b/Form1.cs @@ -18,17 +18,26 @@ namespace Process_Auto_Relaunch { public partial class Form1 : Form { - private delegate void UpdateLogDelegate(string text, bool add_history = false); - private UpdateLogDelegate updateLogDelegate; + [Flags] + public enum NotifyLevel + { + logNone = 0, + logAlways = 1, // + logUpdateStatus = 2, // + logHistory = 4, // + logDiscord = 8 // + } + private delegate void UpdateLogDelegate(string text, NotifyLevel level = NotifyLevel.logUpdateStatus); + private readonly UpdateLogDelegate updateLogDelegate; private DiscordWebhook dwhHook; private DiscordMessage dwhMessage; - private DiscordSettings discordSettings; public Form1() { InitializeComponent(); this.updateLogDelegate = this.UpdateStatus; this.updateLogDelegate += this.SendDiscordMessage; + this.updateLogDelegate += this.HistoryLog; myBackgroundWorker.WorkerSupportsCancellation = true; dwhHook = new DiscordWebhook(); if ( Uri.IsWellFormedUriString(Settings.Default.dwhURL,UriKind.Absolute) && Settings.Default.dwhEnabled && Settings.Default.dwhURL!="") @@ -87,7 +96,7 @@ namespace Process_Auto_Relaunch if (myBackgroundWorker.WorkerSupportsCancellation && myBackgroundWorker.IsBusy) { myBackgroundWorker.CancelAsync(); - UpdateStatus("..."); + UpdateStatus("...",NotifyLevel.logUpdateStatus); } } @@ -136,24 +145,43 @@ namespace Process_Auto_Relaunch /// /// /// - public void UpdateStatus(string text, bool add_history = false) + public void UpdateStatus( string text, NotifyLevel level ) { + if (!level.HasFlag(NotifyLevel.logAlways) && !level.HasFlag(NotifyLevel.logUpdateStatus)) return; labelStatus.Text = text; - - if (add_history) - { - HistoryLog(text); - } } - private void HistoryLog(string text) + private void HistoryLog( string text, NotifyLevel level = NotifyLevel.logUpdateStatus ) { + if (!level.HasFlag(NotifyLevel.logAlways) && !level.HasFlag(NotifyLevel.logHistory)) return; richTextBoxHistory.Text += DateTime.Now.ToString() + ": " + text + "\n"; } - public void Status(string text, bool add_history = false) + public void SendDiscordMessage( string message, NotifyLevel level ) { - Invoke(updateLogDelegate, text, add_history); + if (!level.HasFlag(NotifyLevel.logAlways) && !level.HasFlag(NotifyLevel.logDiscord)) return; + if (Settings.Default.dwhEnabled) + { + dwhHook.Url = Settings.Default.dwhURL; + dwhMessage.Username = "Relaunch process"; + dwhMessage.Content = ":arrows_counterclockwise: " + message; + try + { + dwhHook.Send(dwhMessage); + } + catch (Exception ex) + { + HistoryLog($"Discord messaging error: {ex.Message}"); + Debug.WriteLine($"Discord messaging error: {ex.Message}"); + Settings.Default.dwhEnabled = false; + Settings.Default.Save(); + } + } + } + + public void Status(string text, NotifyLevel level) + { + updateLogDelegate.Invoke(text, level); } private void CheckProgramState() @@ -164,7 +192,7 @@ namespace Process_Auto_Relaunch groupBoxProcessName.Enabled = !watching; groupBoxProgramStart.Enabled = !watching; groupBoxActions.Enabled = !watching; - btnShowDiscordSettings.Enabled = !watching; + btnShowDiscordSettings.Enabled = !watching; // Settings.Default.enableWatching = watching; @@ -192,7 +220,6 @@ namespace Process_Auto_Relaunch textBoxProcessName.Text = textBoxProcessName.Text.Remove(textBoxProcessName.Text.Length-4); Settings.Default.startProgramPath = openFile.FileName; Settings.Default.Save(); - openFile.Dispose(); } @@ -231,7 +258,7 @@ namespace Process_Auto_Relaunch } } - Status(" .", true); + Status(" .", NotifyLevel.logUpdateStatus); Process.Start(path, args); } @@ -244,24 +271,23 @@ namespace Process_Auto_Relaunch { if (ProcessByNameIsRuning(textBoxProcessName.Text)) { - Status($" {textBoxProcessName.Text} "); - if (i < (int)numericUpDown1.Value) SendDiscordMessage($" {textBoxProcessName.Text} .",true); + Status($" ",NotifyLevel.logUpdateStatus); + if (i < (int)numericUpDown1.Value) SendDiscordMessage($" {textBoxProcessName.Text} .",NotifyLevel.logDiscord); i = (int)numericUpDown1.Value; } else { if (radioButtonRestartTimer.Checked) { - if (i==(int)numericUpDown1.Value) SendDiscordMessage($" {textBoxProcessName.Text} . {i}",true); + if (i==(int)numericUpDown1.Value) Status($" {textBoxProcessName.Text} . {i} ",NotifyLevel.logDiscord); i--; - Status($" {textBoxProcessName.Text} . {i}"); + Status($" {textBoxProcessName.Text} . {i}", NotifyLevel.logUpdateStatus); } if (i <= 0 || radioButtonRestartNow.Checked) { i = (int)numericUpDown1.Value; - Status("..."); - SendDiscordMessage($" {textBoxProcessName.Text}",true); + Status($" {textBoxProcessName.Text}", NotifyLevel.logUpdateStatus|NotifyLevel.logDiscord); ProcessStart(Settings.Default.startProgramPath, textBoxArguments.Text); } } @@ -279,48 +305,23 @@ namespace Process_Auto_Relaunch { if (e.Cancelled) { - Status(" ."); + Status(" .",NotifyLevel.logUpdateStatus); } else if (e.Error != null) { MessageBox.Show("Error: " + e.Error.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Stop); - Status(" ! .", true); + Status(" ! .", NotifyLevel.logUpdateStatus|NotifyLevel.logDiscord); radioButtonDisableWathing.Checked = true; } else { - Status(" ."); + Status(" .", NotifyLevel.logUpdateStatus|NotifyLevel.logDiscord); } } - /// - /// - /// - /// - public void SendDiscordMessage(string message, bool addToHistory = false) - { - if (Settings.Default.dwhEnabled && addToHistory) - { - dwhHook.Url = Settings.Default.dwhURL; - dwhMessage.Username = "Relaunch process"; - dwhMessage.Content = ":arrows_counterclockwise: " + message; - try - { - dwhHook.Send(dwhMessage); - } - catch (Exception ex) - { - HistoryLog($"Discord messaging error: {ex.Message}"); - Debug.WriteLine($"Discord messaging error: {ex.Message}"); - Settings.Default.dwhEnabled = false; - Settings.Default.Save(); - } - } - - } - private void btnShowDiscordSettings_Click(object sender, EventArgs e) { + DiscordSettings discordSettings; discordSettings = new DiscordSettings(); discordSettings.ShowDialog(this); discordSettings.Dispose(); From d0eff52e10a7a0c2785d654041332fbe49b47519 Mon Sep 17 00:00:00 2001 From: SlothDpal <16717792+SlothDpal@users.noreply.github.com> Date: Wed, 22 May 2024 11:16:04 +0300 Subject: [PATCH 04/12] URL clearing fix --- DiscordSettings.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/DiscordSettings.cs b/DiscordSettings.cs index 710f444..523a211 100644 --- a/DiscordSettings.cs +++ b/DiscordSettings.cs @@ -39,6 +39,7 @@ namespace RelaunchProcess else { //TODO обработать ситуацию с неверным УРЛом + textDwhURL.Text = ""; MessageBox.Show("Неверный формат URL.", "URL", MessageBoxButtons.OK, MessageBoxIcon.Error); } } From 81f43f911f86188856838a66d47fc79a72f9af5d Mon Sep 17 00:00:00 2001 From: SlothDpal <16717792+SlothDpal@users.noreply.github.com> Date: Thu, 23 May 2024 14:09:27 +0300 Subject: [PATCH 05/12] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D1=8B=20=D0=B0=D0=B2=D0=B0=D1=82=D0=B0=D1=80=20?= =?UTF-8?q?=D0=B8=20=D0=B8=D0=BC=D1=8F=20=D0=B1=D0=BE=D1=82=D0=B0=20=D0=B2?= =?UTF-8?q?=20Discord,=20=D0=BC=D0=B5=D0=BB=D0=BA=D0=B8=D0=B5=20=D1=84?= =?UTF-8?q?=D0=B8=D0=BA=D1=81=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.config | 6 ++ DiscordSettings.Designer.cs | 123 ++++++++++++++++++++++++-------- DiscordSettings.cs | 16 +++-- Form1.Designer.cs | 2 +- Form1.cs | 46 ++++++++---- Properties/Settings.Designer.cs | 27 ++++++- Properties/Settings.settings | 6 ++ 7 files changed, 173 insertions(+), 53 deletions(-) diff --git a/App.config b/App.config index 49cf587..ac315de 100644 --- a/App.config +++ b/App.config @@ -38,6 +38,12 @@ False + + Relauncher + + + https://distribution.faceit-cdn.net/images/7240adfa-6bda-43a0-abd0-8c599f176686.jpeg + diff --git a/DiscordSettings.Designer.cs b/DiscordSettings.Designer.cs index ba8d3c2..b468ace 100644 --- a/DiscordSettings.Designer.cs +++ b/DiscordSettings.Designer.cs @@ -30,15 +30,20 @@ { this.btnOk = new System.Windows.Forms.Button(); this.btnCancel = new System.Windows.Forms.Button(); - this.chbxDiscordEnabled = new System.Windows.Forms.CheckBox(); - this.textDwhURL = new System.Windows.Forms.TextBox(); this.lblDwhURL = new System.Windows.Forms.Label(); this.btnClearUrlField = new System.Windows.Forms.Button(); + this.lblDwhBotname = new System.Windows.Forms.Label(); + this.lblDwhAvatarUrl = new System.Windows.Forms.Label(); + this.textDwhAvatarUrl = new System.Windows.Forms.TextBox(); + this.textDwhBotName = new System.Windows.Forms.TextBox(); + this.textDwhURL = new System.Windows.Forms.TextBox(); + this.chbxDiscordEnabled = new System.Windows.Forms.CheckBox(); + this.btnClearAvatarUrlField = new System.Windows.Forms.Button(); this.SuspendLayout(); // // btnOk // - this.btnOk.Location = new System.Drawing.Point(193, 89); + this.btnOk.Location = new System.Drawing.Point(215, 155); this.btnOk.Name = "btnOk"; this.btnOk.Size = new System.Drawing.Size(75, 23); this.btnOk.TabIndex = 0; @@ -49,7 +54,7 @@ // btnCancel // this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; - this.btnCancel.Location = new System.Drawing.Point(274, 89); + this.btnCancel.Location = new System.Drawing.Point(296, 155); this.btnCancel.Name = "btnCancel"; this.btnCancel.Size = new System.Drawing.Size(75, 23); this.btnCancel.TabIndex = 1; @@ -57,31 +62,10 @@ this.btnCancel.UseVisualStyleBackColor = true; this.btnCancel.Click += new System.EventHandler(this.BtnCancel_Click); // - // chbxDiscordEnabled - // - this.chbxDiscordEnabled.AutoSize = true; - this.chbxDiscordEnabled.Checked = global::RelaunchProcess.Properties.Settings.Default.dwhEnabled; - this.chbxDiscordEnabled.DataBindings.Add(new System.Windows.Forms.Binding("Checked", global::RelaunchProcess.Properties.Settings.Default, "dwhEnabled", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged)); - this.chbxDiscordEnabled.Location = new System.Drawing.Point(12, 63); - this.chbxDiscordEnabled.Name = "chbxDiscordEnabled"; - this.chbxDiscordEnabled.Size = new System.Drawing.Size(232, 17); - this.chbxDiscordEnabled.TabIndex = 2; - this.chbxDiscordEnabled.Text = "Включить отправку сообщений в Discord"; - this.chbxDiscordEnabled.UseVisualStyleBackColor = true; - // - // textDwhURL - // - this.textDwhURL.DataBindings.Add(new System.Windows.Forms.Binding("Text", global::RelaunchProcess.Properties.Settings.Default, "dwhURL", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged)); - this.textDwhURL.Location = new System.Drawing.Point(12, 37); - this.textDwhURL.Name = "textDwhURL"; - this.textDwhURL.Size = new System.Drawing.Size(337, 20); - this.textDwhURL.TabIndex = 3; - this.textDwhURL.Text = global::RelaunchProcess.Properties.Settings.Default.dwhURL; - // // lblDwhURL // this.lblDwhURL.AutoSize = true; - this.lblDwhURL.Location = new System.Drawing.Point(9, 9); + this.lblDwhURL.Location = new System.Drawing.Point(9, 87); this.lblDwhURL.Name = "lblDwhURL"; this.lblDwhURL.Size = new System.Drawing.Size(147, 13); this.lblDwhURL.TabIndex = 4; @@ -90,13 +74,84 @@ // btnClearUrlField // this.btnClearUrlField.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(204))); - this.btnClearUrlField.Location = new System.Drawing.Point(351, 38); + this.btnClearUrlField.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(0)))), ((int)(((byte)(0))))); + this.btnClearUrlField.Location = new System.Drawing.Point(352, 103); this.btnClearUrlField.Name = "btnClearUrlField"; this.btnClearUrlField.Size = new System.Drawing.Size(19, 19); this.btnClearUrlField.TabIndex = 5; this.btnClearUrlField.Text = "X"; this.btnClearUrlField.UseVisualStyleBackColor = true; - this.btnClearUrlField.Click += new System.EventHandler(this.BtnClearUrlField_Click); + this.btnClearUrlField.Click += new System.EventHandler(this.ClearUrl); + // + // lblDwhBotname + // + this.lblDwhBotname.AutoSize = true; + this.lblDwhBotname.Location = new System.Drawing.Point(9, 9); + this.lblDwhBotname.Name = "lblDwhBotname"; + this.lblDwhBotname.Size = new System.Drawing.Size(127, 13); + this.lblDwhBotname.TabIndex = 6; + this.lblDwhBotname.Text = "Имя бота в сообщении:"; + // + // lblDwhAvatarUrl + // + this.lblDwhAvatarUrl.AutoSize = true; + this.lblDwhAvatarUrl.Location = new System.Drawing.Point(9, 48); + this.lblDwhAvatarUrl.Name = "lblDwhAvatarUrl"; + this.lblDwhAvatarUrl.Size = new System.Drawing.Size(102, 13); + this.lblDwhAvatarUrl.TabIndex = 6; + this.lblDwhAvatarUrl.Text = "URL аватара бота:"; + // + // textDwhAvatarUrl + // + this.textDwhAvatarUrl.DataBindings.Add(new System.Windows.Forms.Binding("Text", global::RelaunchProcess.Properties.Settings.Default, "dwhAvatarURL", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged)); + this.textDwhAvatarUrl.Location = new System.Drawing.Point(9, 64); + this.textDwhAvatarUrl.Name = "textDwhAvatarUrl"; + this.textDwhAvatarUrl.Size = new System.Drawing.Size(337, 20); + this.textDwhAvatarUrl.TabIndex = 7; + this.textDwhAvatarUrl.Text = global::RelaunchProcess.Properties.Settings.Default.dwhAvatarURL; + // + // textDwhBotName + // + this.textDwhBotName.DataBindings.Add(new System.Windows.Forms.Binding("Text", global::RelaunchProcess.Properties.Settings.Default, "dwhBotname", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged)); + this.textDwhBotName.Location = new System.Drawing.Point(9, 25); + this.textDwhBotName.MaxLength = 40; + this.textDwhBotName.Name = "textDwhBotName"; + this.textDwhBotName.Size = new System.Drawing.Size(211, 20); + this.textDwhBotName.TabIndex = 7; + this.textDwhBotName.Text = global::RelaunchProcess.Properties.Settings.Default.dwhBotname; + // + // textDwhURL + // + this.textDwhURL.DataBindings.Add(new System.Windows.Forms.Binding("Text", global::RelaunchProcess.Properties.Settings.Default, "dwhURL", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged)); + this.textDwhURL.Location = new System.Drawing.Point(9, 103); + this.textDwhURL.Name = "textDwhURL"; + this.textDwhURL.Size = new System.Drawing.Size(337, 20); + this.textDwhURL.TabIndex = 3; + this.textDwhURL.Text = global::RelaunchProcess.Properties.Settings.Default.dwhURL; + // + // chbxDiscordEnabled + // + this.chbxDiscordEnabled.AutoSize = true; + this.chbxDiscordEnabled.Checked = global::RelaunchProcess.Properties.Settings.Default.dwhEnabled; + this.chbxDiscordEnabled.DataBindings.Add(new System.Windows.Forms.Binding("Checked", global::RelaunchProcess.Properties.Settings.Default, "dwhEnabled", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged)); + this.chbxDiscordEnabled.Location = new System.Drawing.Point(9, 129); + this.chbxDiscordEnabled.Name = "chbxDiscordEnabled"; + this.chbxDiscordEnabled.Size = new System.Drawing.Size(232, 17); + this.chbxDiscordEnabled.TabIndex = 2; + this.chbxDiscordEnabled.Text = "Включить отправку сообщений в Discord"; + this.chbxDiscordEnabled.UseVisualStyleBackColor = true; + // + // btnClearAvatarUrlField + // + this.btnClearAvatarUrlField.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.btnClearAvatarUrlField.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(0)))), ((int)(((byte)(0))))); + this.btnClearAvatarUrlField.Location = new System.Drawing.Point(352, 65); + this.btnClearAvatarUrlField.Name = "btnClearAvatarUrlField"; + this.btnClearAvatarUrlField.Size = new System.Drawing.Size(19, 19); + this.btnClearAvatarUrlField.TabIndex = 5; + this.btnClearAvatarUrlField.Text = "X"; + this.btnClearAvatarUrlField.UseVisualStyleBackColor = true; + this.btnClearAvatarUrlField.Click += new System.EventHandler(this.ClearUrl); // // DiscordSettings // @@ -104,8 +159,13 @@ this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.CancelButton = this.btnCancel; - this.ClientSize = new System.Drawing.Size(375, 128); + this.ClientSize = new System.Drawing.Size(387, 188); this.ControlBox = false; + this.Controls.Add(this.textDwhAvatarUrl); + this.Controls.Add(this.textDwhBotName); + this.Controls.Add(this.lblDwhAvatarUrl); + this.Controls.Add(this.lblDwhBotname); + this.Controls.Add(this.btnClearAvatarUrlField); this.Controls.Add(this.btnClearUrlField); this.Controls.Add(this.lblDwhURL); this.Controls.Add(this.textDwhURL); @@ -132,5 +192,10 @@ private System.Windows.Forms.TextBox textDwhURL; private System.Windows.Forms.Label lblDwhURL; private System.Windows.Forms.Button btnClearUrlField; + private System.Windows.Forms.Label lblDwhBotname; + private System.Windows.Forms.TextBox textDwhBotName; + private System.Windows.Forms.Label lblDwhAvatarUrl; + private System.Windows.Forms.TextBox textDwhAvatarUrl; + private System.Windows.Forms.Button btnClearAvatarUrlField; } } \ No newline at end of file diff --git a/DiscordSettings.cs b/DiscordSettings.cs index 523a211..624c494 100644 --- a/DiscordSettings.cs +++ b/DiscordSettings.cs @@ -26,9 +26,12 @@ namespace RelaunchProcess private void BtnOk_Click(object sender, EventArgs e) { - if (Uri.IsWellFormedUriString(textDwhURL.Text, UriKind.Absolute)||textDwhURL.Text=="") + if ( (String.IsNullOrEmpty(textDwhURL.Text) || + Uri.IsWellFormedUriString(textDwhURL.Text, UriKind.Absolute)) && + (String.IsNullOrEmpty(textDwhAvatarUrl.Text) || + Uri.IsWellFormedUriString(textDwhAvatarUrl.Text, UriKind.Absolute)) ) { - if (textDwhURL.Text=="") + if (String.IsNullOrEmpty(textDwhURL.Text)) { chbxDiscordEnabled.Checked = false; } @@ -38,15 +41,14 @@ namespace RelaunchProcess } else { - //TODO обработать ситуацию с неверным УРЛом - textDwhURL.Text = ""; - MessageBox.Show("Неверный формат URL.", "URL", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("Неверный формат URL.\rОчистите или исправьте.", "URL", MessageBoxButtons.OK, MessageBoxIcon.Error); } } - private void BtnClearUrlField_Click(object sender, EventArgs e) + private void ClearUrl(object sender, EventArgs e) { - textDwhURL.Text = ""; + if ( (Button)sender == btnClearUrlField ) textDwhURL.Text = ""; + if ( (Button)sender == btnClearAvatarUrlField ) textDwhAvatarUrl.Text = ""; } } } diff --git a/Form1.Designer.cs b/Form1.Designer.cs index ef18e8f..0c65f12 100644 --- a/Form1.Designer.cs +++ b/Form1.Designer.cs @@ -166,7 +166,7 @@ namespace Process_Auto_Relaunch this.buttonSetProgramStart.TabIndex = 1; this.buttonSetProgramStart.Text = "Обзор"; this.buttonSetProgramStart.UseVisualStyleBackColor = true; - this.buttonSetProgramStart.Click += new System.EventHandler(this.buttonSetProgramStart_Click); + this.buttonSetProgramStart.Click += new System.EventHandler(this.ButtonSetProgramStart_Click); // // groupBoxProgramStart // diff --git a/Form1.cs b/Form1.cs index 10dd541..61e4881 100644 --- a/Form1.cs +++ b/Form1.cs @@ -40,7 +40,7 @@ namespace Process_Auto_Relaunch this.updateLogDelegate += this.HistoryLog; myBackgroundWorker.WorkerSupportsCancellation = true; dwhHook = new DiscordWebhook(); - if ( Uri.IsWellFormedUriString(Settings.Default.dwhURL,UriKind.Absolute) && Settings.Default.dwhEnabled && Settings.Default.dwhURL!="") + /*if ( Uri.IsWellFormedUriString(Settings.Default.dwhURL,UriKind.Absolute) && Settings.Default.dwhEnabled && Settings.Default.dwhURL!="") { dwhHook.Url = Settings.Default.dwhURL; } @@ -49,7 +49,7 @@ namespace Process_Auto_Relaunch HistoryLog($" URL - ({Settings.Default.dwhURL}). Discord ."); Settings.Default.dwhEnabled = false; Settings.Default.Save(); - } + }*/ } @@ -143,43 +143,59 @@ namespace Process_Auto_Relaunch /// /// /// - /// - /// + /// / + /// public void UpdateStatus( string text, NotifyLevel level ) { if (!level.HasFlag(NotifyLevel.logAlways) && !level.HasFlag(NotifyLevel.logUpdateStatus)) return; labelStatus.Text = text; } - private void HistoryLog( string text, NotifyLevel level = NotifyLevel.logUpdateStatus ) + /// + /// + /// + /// / + /// + private void HistoryLog( string text, NotifyLevel level ) { if (!level.HasFlag(NotifyLevel.logAlways) && !level.HasFlag(NotifyLevel.logHistory)) return; richTextBoxHistory.Text += DateTime.Now.ToString() + ": " + text + "\n"; } - public void SendDiscordMessage( string message, NotifyLevel level ) + /// + /// Discord + /// + /// / + /// + public void SendDiscordMessage( string text, NotifyLevel level ) { if (!level.HasFlag(NotifyLevel.logAlways) && !level.HasFlag(NotifyLevel.logDiscord)) return; if (Settings.Default.dwhEnabled) { dwhHook.Url = Settings.Default.dwhURL; - dwhMessage.Username = "Relaunch process"; - dwhMessage.Content = ":arrows_counterclockwise: " + message; + dwhMessage.Username = Settings.Default.dwhBotname; + dwhMessage.AvatarUrl = Settings.Default.dwhAvatarURL; + dwhMessage.Content = ":arrows_counterclockwise: " + text; try { dwhHook.Send(dwhMessage); } catch (Exception ex) { - HistoryLog($"Discord messaging error: {ex.Message}"); + Status($" .",NotifyLevel.logHistory); Debug.WriteLine($"Discord messaging error: {ex.Message}"); - Settings.Default.dwhEnabled = false; - Settings.Default.Save(); + //Settings.Default.dwhEnabled = false; + //Settings.Default.Save(); } } } - public void Status(string text, NotifyLevel level) + /// + /// + /// + /// / + /// + public void Status(string text, NotifyLevel level = NotifyLevel.logUpdateStatus) { updateLogDelegate.Invoke(text, level); } @@ -204,7 +220,7 @@ namespace Process_Auto_Relaunch /// /// /// - private void buttonSetProgramStart_Click(object sender, EventArgs e) + private void ButtonSetProgramStart_Click(object sender, EventArgs e) { OpenFileDialog openFile = new OpenFileDialog(); openFile.Filter = " (*.exe)|*.exe"; @@ -305,12 +321,12 @@ namespace Process_Auto_Relaunch { if (e.Cancelled) { - Status(" .",NotifyLevel.logUpdateStatus); + Status(" .",NotifyLevel.logUpdateStatus|NotifyLevel.logDiscord); } else if (e.Error != null) { + Status(" ! .", NotifyLevel.logUpdateStatus | NotifyLevel.logDiscord); MessageBox.Show("Error: " + e.Error.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Stop); - Status(" ! .", NotifyLevel.logUpdateStatus|NotifyLevel.logDiscord); radioButtonDisableWathing.Checked = true; } else diff --git a/Properties/Settings.Designer.cs b/Properties/Settings.Designer.cs index 9c4d1e1..a6205d2 100644 --- a/Properties/Settings.Designer.cs +++ b/Properties/Settings.Designer.cs @@ -12,7 +12,7 @@ namespace RelaunchProcess.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.9.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.10.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); @@ -142,5 +142,30 @@ namespace RelaunchProcess.Properties { this["dwhEnabled"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("Relauncher")] + public string dwhBotname { + get { + return ((string)(this["dwhBotname"])); + } + set { + this["dwhBotname"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("https://distribution.faceit-cdn.net/images/7240adfa-6bda-43a0-abd0-8c599f176686.j" + + "peg")] + public string dwhAvatarURL { + get { + return ((string)(this["dwhAvatarURL"])); + } + set { + this["dwhAvatarURL"] = value; + } + } } } diff --git a/Properties/Settings.settings b/Properties/Settings.settings index 3f8eb41..1f40892 100644 --- a/Properties/Settings.settings +++ b/Properties/Settings.settings @@ -32,5 +32,11 @@ False + + Relauncher + + + https://distribution.faceit-cdn.net/images/7240adfa-6bda-43a0-abd0-8c599f176686.jpeg + \ No newline at end of file From 25abcc4bda7d026bfa130e0d37ac89be3a8c0c66 Mon Sep 17 00:00:00 2001 From: SlothDpal <16717792+SlothDpal@users.noreply.github.com> Date: Thu, 23 May 2024 15:56:02 +0300 Subject: [PATCH 06/12] Process launch message fix --- Form1.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Form1.cs b/Form1.cs index 61e4881..be5219b 100644 --- a/Form1.cs +++ b/Form1.cs @@ -274,7 +274,7 @@ namespace Process_Auto_Relaunch } } - Status(" .", NotifyLevel.logUpdateStatus); + Status(" .", NotifyLevel.logAlways); Process.Start(path, args); } From 8233be32a3a049f682e3df8ad5f3227804553122 Mon Sep 17 00:00:00 2001 From: slothdpal <16717792+SlothDpal@users.noreply.github.com> Date: Thu, 23 May 2024 20:55:23 +0300 Subject: [PATCH 07/12] some fix --- Discord/DiscordWebHook.cs | 103 ++++++++++++++++ Discord/Structs.cs | 229 +++++++++++++++++++++++++++++++++++ Discord/Utils.cs | 108 +++++++++++++++++ Process Auto Relaunch.csproj | 11 +- Process Auto Relaunch.sln | 17 --- packages.config | 4 + 6 files changed, 453 insertions(+), 19 deletions(-) create mode 100644 Discord/DiscordWebHook.cs create mode 100644 Discord/Structs.cs create mode 100644 Discord/Utils.cs create mode 100644 packages.config diff --git a/Discord/DiscordWebHook.cs b/Discord/DiscordWebHook.cs new file mode 100644 index 0000000..25c8640 --- /dev/null +++ b/Discord/DiscordWebHook.cs @@ -0,0 +1,103 @@ +using System; +using System.IO; +using System.Net; +using System.Text; + +namespace Discord.Webhook +{ + public class DiscordWebhook + { + /// + /// Webhook url + /// + public string Url { get; set; } + + private void AddField(MemoryStream stream, string bound, string cDisposition, string cType, byte[] data) + { + string prefix = stream.Length > 0 ? "\r\n--" : "--"; + string fBegin = $"{prefix}{bound}\r\n"; + + byte[] fBeginBuffer = Utils.Encode(fBegin); + byte[] cDispositionBuffer = Utils.Encode(cDisposition); + byte[] cTypeBuffer = Utils.Encode(cType); + + stream.Write(fBeginBuffer, 0, fBeginBuffer.Length); + stream.Write(cDispositionBuffer, 0, cDispositionBuffer.Length); + stream.Write(cTypeBuffer, 0, cTypeBuffer.Length); + stream.Write(data, 0, data.Length); + } + + private void SetJsonPayload(MemoryStream stream, string bound, string json) + { + string cDisposition = "Content-Disposition: form-data; name=\"payload_json\"\r\n"; + string cType = "Content-Type: application/octet-stream\r\n\r\n"; + AddField(stream, bound, cDisposition, cType, Utils.Encode(json)); + } + + private void SetFile(MemoryStream stream, string bound, int index, FileInfo file) + { + string cDisposition = $"Content-Disposition: form-data; name=\"file_{index}\"; filename=\"{file.Name}\"\r\n"; + string cType = "Content-Type: application/octet-stream\r\n\r\n"; + AddField(stream, bound, cDisposition, cType, File.ReadAllBytes(file.FullName)); + } + + /// + /// Send webhook message + /// + public void Send(DiscordMessage message, params FileInfo[] files) + { + if (string.IsNullOrEmpty(Url)) + throw new ArgumentNullException("Invalid Webhook URL."); + + string bound = "------------------------" + DateTime.Now.Ticks.ToString("x"); + WebClient webhookRequest = new WebClient(); + webhookRequest.Headers.Add("Content-Type", "multipart/form-data; boundary=" + bound); + + MemoryStream stream = new MemoryStream(); + for (int i = 0; i < files.Length; i++) + SetFile(stream, bound, i, files[i]); + + string json = message.ToString(); + SetJsonPayload(stream, bound, json); + + byte[] bodyEnd = Utils.Encode($"\r\n--{bound}--"); + stream.Write(bodyEnd, 0, bodyEnd.Length); + + //byte[] beginBodyBuffer = Encoding.UTF8.GetBytes("--" + bound + "\r\n"); + //stream.Write(beginBodyBuffer, 0, beginBodyBuffer.Length); + //bool flag = file != null && file.Exists; + //if (flag) + //{ + // string fileBody = "Content-Disposition: form-data; name=\"file\"; filename=\"" + file.Name + "\"\r\nContent-Type: application/octet-stream\r\n\r\n"; + // byte[] fileBodyBuffer = Encoding.UTF8.GetBytes(fileBody); + // stream.Write(fileBodyBuffer, 0, fileBodyBuffer.Length); + // byte[] fileBuffer = File.ReadAllBytes(file.FullName); + // stream.Write(fileBuffer, 0, fileBuffer.Length); + // string fileBodyEnd = "\r\n--" + bound + "\r\n"; + // byte[] fileBodyEndBuffer = Encoding.UTF8.GetBytes(fileBodyEnd); + // stream.Write(fileBodyEndBuffer, 0, fileBodyEndBuffer.Length); + //} + //string jsonBody = string.Concat(new string[] + //{ + // "Content-Disposition: form-data; name=\"payload_json\"\r\nContent-Type: application/json\r\n\r\n", + // string.Format("{0}\r\n", message), + // "--", + // bound, + // "--" + //}); + //byte[] jsonBodyBuffer = Encoding.UTF8.GetBytes(jsonBody); + //stream.Write(jsonBodyBuffer, 0, jsonBodyBuffer.Length); + + try + { + webhookRequest.UploadData(this.Url, stream.ToArray()); + } + catch (WebException ex) + { + throw new WebException(Utils.Decode(ex.Response.GetResponseStream())); + } + + stream.Dispose(); + } + } +} diff --git a/Discord/Structs.cs b/Discord/Structs.cs new file mode 100644 index 0000000..a528c88 --- /dev/null +++ b/Discord/Structs.cs @@ -0,0 +1,229 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Drawing; + +namespace Discord +{ + + /// + /// Discord message data object + /// + public struct DiscordMessage + { + /// + /// Message content + /// + public string Content; + + /// + /// Read message to everyone on the channel + /// + public bool TTS; + + /// + /// Webhook profile username to be shown + /// + public string Username; + + /// + /// Webhook profile avater to be shown + /// + public string AvatarUrl; + + /// + /// List of embeds + /// + public List Embeds; + + public override string ToString() => Utils.StructToJson(this).ToString(Formatting.None); + } + + /// + /// Discord embed data object + /// + public struct DiscordEmbed + { + /// + /// Embed title + /// + public string Title; + + /// + /// Embed description + /// + public string Description; + + /// + /// Embed url + /// + public string Url; + + /// + /// Embed timestamp + /// + public DateTime? Timestamp; + + /// + /// Embed color + /// + public Color? Color; + + /// + /// Embed footer + /// + public EmbedFooter? Footer; + + /// + /// Embed image + /// + public EmbedMedia? Image; + + /// + /// Embed thumbnail + /// + public EmbedMedia? Thumbnail; + + /// + /// Embed video + /// + public EmbedMedia? Video; + + /// + /// Embed provider + /// + public EmbedProvider? Provider; + + /// + /// Embed author + /// + public EmbedAuthor? Author; + + /// + /// Embed fields list + /// + public List Fields; + + public override string ToString() => Utils.StructToJson(this).ToString(Formatting.None); + } + + /// + /// Discord embed footer data object + /// + public struct EmbedFooter + { + /// + /// Footer text + /// + public string Text; + + /// + /// Footer icon + /// + public string IconUrl; + + /// + /// Footer icon proxy + /// + public string ProxyIconUrl; + + public override string ToString() => Utils.StructToJson(this).ToString(Formatting.None); + } + + /// + /// Discord embed media data object (images/thumbs/videos) + /// + public struct EmbedMedia + { + /// + /// Media url + /// + public string Url; + + /// + /// Media proxy url + /// + public string ProxyUrl; + + /// + /// Media height + /// + public int? Height; + + /// + /// Media width + /// + public int? Width; + + public override string ToString() => Utils.StructToJson(this).ToString(Formatting.None); + } + + /// + /// Discord embed provider data object + /// + public struct EmbedProvider + { + /// + /// Provider name + /// + public string Name; + + /// + /// Provider url + /// + public string Url; + + public override string ToString() => Utils.StructToJson(this).ToString(Formatting.None); + } + + /// + /// Discord embed author data object + /// + public struct EmbedAuthor + { + /// + /// Author name + /// + public string Name; + + /// + /// Author url + /// + public string Url; + + /// + /// Author icon + /// + public string IconUrl; + + /// + /// Author icon proxy + /// + public string ProxyIconUrl; + + public override string ToString() => Utils.StructToJson(this).ToString(Formatting.None); + } + + /// + /// Discord embed field data object + /// + public struct EmbedField + { + /// + /// Field name + /// + public string Name; + + /// + /// Field value + /// + public string Value; + + /// + /// Field align + /// + public bool InLine; + + public override string ToString() => Utils.StructToJson(this).ToString(Formatting.None); + } +} diff --git a/Discord/Utils.cs b/Discord/Utils.cs new file mode 100644 index 0000000..ce9476e --- /dev/null +++ b/Discord/Utils.cs @@ -0,0 +1,108 @@ +using Newtonsoft.Json.Linq; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Drawing; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Text; + +namespace Discord +{ + public static class Utils + { + /// + /// Convert Color object into hex integer + /// + /// Color to be converted + /// Converted hex integer + public static int ColorToHex(Color color) + { + string HS = + color.R.ToString("X2") + + color.G.ToString("X2") + + color.B.ToString("X2"); + + return int.Parse(HS, System.Globalization.NumberStyles.HexNumber); + } + + internal static JObject StructToJson(object @struct) + { + Type type = @struct.GetType(); + JObject json = new JObject(); + + FieldInfo[] fields = type.GetFields(); + foreach (FieldInfo field in fields) + { + string name = FieldNameToJsonName(field.Name); + object value = field.GetValue(@struct); + if (value == null) + continue; + + if (value is bool) + json.Add(name, (bool)value); + else if (value is int) + json.Add(name, (int)value); + else if (value is Color) + json.Add(name, ColorToHex((Color)value)); + else if (value is string) + json.Add(name, value as string); + else if (value is DateTime) + json.Add(name, ((DateTime)value).ToString("yyyy-MM-ddTHH\\:mm\\:ss.fffffffzzz")); + else if (value is IList && value.GetType().IsGenericType) + { + JArray array = new JArray(); + foreach (object obj in value as IList) + array.Add(StructToJson(obj)); + json.Add(name, array); + } + else json.Add(name, StructToJson(value)); + } + return json; + } + + static string[] ignore = { "InLine" }; + internal static string FieldNameToJsonName(string name) + { + if (ignore.ToList().Contains(name)) + return name.ToLower(); + + List result = new List(); + + if (IsFullUpper(name)) + result.AddRange(name.ToLower().ToCharArray()); + else + for (int i = 0; i < name.Length; i++) + { + if (i > 0 && char.IsUpper(name[i])) + result.AddRange(new[] { '_', char.ToLower(name[i]) }); + else result.Add(char.ToLower(name[i])); + } + return string.Join("", result); + } + + internal static bool IsFullUpper(string str) + { + bool upper = true; + for (int i = 0; i < str.Length; i++) + { + if (!char.IsUpper(str[i])) + { + upper = false; + break; + } + } + return upper; + } + + public static string Decode(Stream source) + { + using (StreamReader reader = new StreamReader(source)) + return reader.ReadToEnd(); + } + + public static byte[] Encode(string source, string encoding = "utf-8") + => Encoding.GetEncoding(encoding).GetBytes(source); + } +} diff --git a/Process Auto Relaunch.csproj b/Process Auto Relaunch.csproj index e265fbb..3a337ee 100644 --- a/Process Auto Relaunch.csproj +++ b/Process Auto Relaunch.csproj @@ -67,6 +67,9 @@ False .\CSharpDiscordWebhook.dll + + packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll + @@ -80,6 +83,9 @@ + + + Form @@ -112,6 +118,7 @@ Resources.resx True + SettingsSingleFileGenerator Settings.Designer.cs @@ -142,7 +149,7 @@ - copy $(ProjectDir)\CSharpDiscordWebhook\CSharpDiscordWebhook\$(OutDir)\* $(TargetDir) -copy $(ProjectDir)\CSharpDiscordWebhook\CSharpDiscordWebhook\$(OutDir)\* $(ProjectDir) + rem copy $(ProjectDir)\CSharpDiscordWebhook\CSharpDiscordWebhook\$(OutDir)\* $(TargetDir) +rem copy $(ProjectDir)\CSharpDiscordWebhook\CSharpDiscordWebhook\$(OutDir)\* $(ProjectDir) \ No newline at end of file diff --git a/Process Auto Relaunch.sln b/Process Auto Relaunch.sln index 7188f0d..14cd0e9 100644 --- a/Process Auto Relaunch.sln +++ b/Process Auto Relaunch.sln @@ -4,11 +4,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 VisualStudioVersion = 17.9.34622.214 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Process Auto Relaunch", "Process Auto Relaunch.csproj", "{B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}" - ProjectSection(ProjectDependencies) = postProject - {11C71B78-004A-471F-B29D-C2CBE4673579} = {11C71B78-004A-471F-B29D-C2CBE4673579} - EndProjectSection -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CSharpDiscordWebhook", "CSharpDiscordWebhook\CSharpDiscordWebhook\CSharpDiscordWebhook.csproj", "{11C71B78-004A-471F-B29D-C2CBE4673579}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -32,18 +27,6 @@ Global {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.Release|Any CPU.Build.0 = Release|Any CPU {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.Release|x64.ActiveCfg = Release|x64 {B48F106C-F4E2-4BFB-9BAA-42FC13C03FDD}.Release|x64.Build.0 = Release|x64 - {11C71B78-004A-471F-B29D-C2CBE4673579}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {11C71B78-004A-471F-B29D-C2CBE4673579}.Debug|Any CPU.Build.0 = Debug|Any CPU - {11C71B78-004A-471F-B29D-C2CBE4673579}.Debug|x64.ActiveCfg = Debug|Any CPU - {11C71B78-004A-471F-B29D-C2CBE4673579}.Debug|x64.Build.0 = Debug|Any CPU - {11C71B78-004A-471F-B29D-C2CBE4673579}.DebugFULL|Any CPU.ActiveCfg = Debug|Any CPU - {11C71B78-004A-471F-B29D-C2CBE4673579}.DebugFULL|Any CPU.Build.0 = Debug|Any CPU - {11C71B78-004A-471F-B29D-C2CBE4673579}.DebugFULL|x64.ActiveCfg = DebugFULL|Any CPU - {11C71B78-004A-471F-B29D-C2CBE4673579}.DebugFULL|x64.Build.0 = DebugFULL|Any CPU - {11C71B78-004A-471F-B29D-C2CBE4673579}.Release|Any CPU.ActiveCfg = Release|Any CPU - {11C71B78-004A-471F-B29D-C2CBE4673579}.Release|Any CPU.Build.0 = Release|Any CPU - {11C71B78-004A-471F-B29D-C2CBE4673579}.Release|x64.ActiveCfg = Release|Any CPU - {11C71B78-004A-471F-B29D-C2CBE4673579}.Release|x64.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/packages.config b/packages.config new file mode 100644 index 0000000..0b14af3 --- /dev/null +++ b/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file From be702b6db6503deb483da3a4ec92e5ba38c9612d Mon Sep 17 00:00:00 2001 From: slothdpal <16717792+SlothDpal@users.noreply.github.com> Date: Thu, 23 May 2024 21:08:13 +0300 Subject: [PATCH 08/12] remove submodule --- CSharpDiscordWebhook | 1 - 1 file changed, 1 deletion(-) delete mode 160000 CSharpDiscordWebhook diff --git a/CSharpDiscordWebhook b/CSharpDiscordWebhook deleted file mode 160000 index 93a4881..0000000 --- a/CSharpDiscordWebhook +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 93a4881a98a3b8447e9d898ff0b3587d3e200bb0 From 1ed6ca0d0fb36734a45b5db37998bb43a45f5a6b Mon Sep 17 00:00:00 2001 From: slothdpal <16717792+SlothDpal@users.noreply.github.com> Date: Thu, 23 May 2024 21:14:18 +0300 Subject: [PATCH 09/12] remove submodule --- .gitmodules | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 .gitmodules diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 6bf865e..0000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "CSharpDiscordWebhook"] - path = CSharpDiscordWebhook - url = https://github.com/N4T4NM/CSharpDiscordWebhook.git From 34c6a66b0cc68b6a2de90582c0575b19bfe699b7 Mon Sep 17 00:00:00 2001 From: SlothDpal <16717792+SlothDpal@users.noreply.github.com> Date: Fri, 24 May 2024 10:57:54 +0300 Subject: [PATCH 10/12] fix DiscordWebHook.cs --- Discord/DiscordWebHook.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Discord/DiscordWebHook.cs b/Discord/DiscordWebHook.cs index 25c8640..d9dbe8a 100644 --- a/Discord/DiscordWebHook.cs +++ b/Discord/DiscordWebHook.cs @@ -90,7 +90,8 @@ namespace Discord.Webhook try { - webhookRequest.UploadData(this.Url, stream.ToArray()); + Uri uri = new Uri(this.Url); + webhookRequest.UploadData(uri, stream.ToArray()); } catch (WebException ex) { From f28fc0126ab8526cdd893674cdd689809ce46450 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Sun, 26 May 2024 22:33:32 +0400 Subject: [PATCH 11/12] Fix saving settings after cancel --- DiscordSettings.Designer.cs | 8 -------- DiscordSettings.cs | 21 ++++++++++++++++++++- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/DiscordSettings.Designer.cs b/DiscordSettings.Designer.cs index b468ace..aff52eb 100644 --- a/DiscordSettings.Designer.cs +++ b/DiscordSettings.Designer.cs @@ -103,37 +103,29 @@ // // textDwhAvatarUrl // - this.textDwhAvatarUrl.DataBindings.Add(new System.Windows.Forms.Binding("Text", global::RelaunchProcess.Properties.Settings.Default, "dwhAvatarURL", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged)); this.textDwhAvatarUrl.Location = new System.Drawing.Point(9, 64); this.textDwhAvatarUrl.Name = "textDwhAvatarUrl"; this.textDwhAvatarUrl.Size = new System.Drawing.Size(337, 20); this.textDwhAvatarUrl.TabIndex = 7; - this.textDwhAvatarUrl.Text = global::RelaunchProcess.Properties.Settings.Default.dwhAvatarURL; // // textDwhBotName // - this.textDwhBotName.DataBindings.Add(new System.Windows.Forms.Binding("Text", global::RelaunchProcess.Properties.Settings.Default, "dwhBotname", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged)); this.textDwhBotName.Location = new System.Drawing.Point(9, 25); this.textDwhBotName.MaxLength = 40; this.textDwhBotName.Name = "textDwhBotName"; this.textDwhBotName.Size = new System.Drawing.Size(211, 20); this.textDwhBotName.TabIndex = 7; - this.textDwhBotName.Text = global::RelaunchProcess.Properties.Settings.Default.dwhBotname; // // textDwhURL // - this.textDwhURL.DataBindings.Add(new System.Windows.Forms.Binding("Text", global::RelaunchProcess.Properties.Settings.Default, "dwhURL", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged)); this.textDwhURL.Location = new System.Drawing.Point(9, 103); this.textDwhURL.Name = "textDwhURL"; this.textDwhURL.Size = new System.Drawing.Size(337, 20); this.textDwhURL.TabIndex = 3; - this.textDwhURL.Text = global::RelaunchProcess.Properties.Settings.Default.dwhURL; // // chbxDiscordEnabled // this.chbxDiscordEnabled.AutoSize = true; - this.chbxDiscordEnabled.Checked = global::RelaunchProcess.Properties.Settings.Default.dwhEnabled; - this.chbxDiscordEnabled.DataBindings.Add(new System.Windows.Forms.Binding("Checked", global::RelaunchProcess.Properties.Settings.Default, "dwhEnabled", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged)); this.chbxDiscordEnabled.Location = new System.Drawing.Point(9, 129); this.chbxDiscordEnabled.Name = "chbxDiscordEnabled"; this.chbxDiscordEnabled.Size = new System.Drawing.Size(232, 17); diff --git a/DiscordSettings.cs b/DiscordSettings.cs index 624c494..b645589 100644 --- a/DiscordSettings.cs +++ b/DiscordSettings.cs @@ -4,6 +4,7 @@ using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Drawing; +using System.Drawing.Printing; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -17,6 +18,24 @@ namespace RelaunchProcess public DiscordSettings() { InitializeComponent(); + RestoreSettings(); + } + + private void RestoreSettings() + { + textDwhBotName.Text = Settings.Default.dwhBotname; + textDwhAvatarUrl.Text = Settings.Default.dwhAvatarURL; + textDwhURL.Text = Settings.Default.dwhURL; + chbxDiscordEnabled.Checked = Settings.Default.dwhEnabled; + } + + private void SaveSettings() + { + Settings.Default.dwhBotname = textDwhBotName.Text; + Settings.Default.dwhAvatarURL = textDwhAvatarUrl.Text; + Settings.Default.dwhURL = textDwhURL.Text; + Settings.Default.dwhEnabled = chbxDiscordEnabled.Checked; + Settings.Default.Save(); } private void BtnCancel_Click(object sender, EventArgs e) @@ -35,7 +54,7 @@ namespace RelaunchProcess { chbxDiscordEnabled.Checked = false; } - Settings.Default.Save(); + SaveSettings(); DialogResult = DialogResult.OK; Close(); } From 964f5389da2a14ce97214a8c8b22801e47b8e36e Mon Sep 17 00:00:00 2001 From: Vladimir Date: Sun, 26 May 2024 22:46:47 +0400 Subject: [PATCH 12/12] Renaming. Disabled settings discord if start work --- DiscordSettings.Designer.cs | 93 ++++++++++++++++++++++++------------- DiscordSettings.cs | 19 +++++++- Form1.Designer.cs | 26 +++++------ Form1.cs | 4 +- 4 files changed, 93 insertions(+), 49 deletions(-) diff --git a/DiscordSettings.Designer.cs b/DiscordSettings.Designer.cs index aff52eb..4a496ba 100644 --- a/DiscordSettings.Designer.cs +++ b/DiscordSettings.Designer.cs @@ -1,6 +1,6 @@ namespace RelaunchProcess { - partial class DiscordSettings + partial class WebhookSettings { /// /// Required designer variable. @@ -39,11 +39,14 @@ this.textDwhURL = new System.Windows.Forms.TextBox(); this.chbxDiscordEnabled = new System.Windows.Forms.CheckBox(); this.btnClearAvatarUrlField = new System.Windows.Forms.Button(); + this.groupBoxSettingsDiscord = new System.Windows.Forms.GroupBox(); + this.groupBoxSettingsDiscord.SuspendLayout(); this.SuspendLayout(); // // btnOk // - this.btnOk.Location = new System.Drawing.Point(215, 155); + this.btnOk.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.btnOk.Location = new System.Drawing.Point(236, 206); this.btnOk.Name = "btnOk"; this.btnOk.Size = new System.Drawing.Size(75, 23); this.btnOk.TabIndex = 0; @@ -53,8 +56,9 @@ // // btnCancel // + this.btnCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; - this.btnCancel.Location = new System.Drawing.Point(296, 155); + this.btnCancel.Location = new System.Drawing.Point(317, 206); this.btnCancel.Name = "btnCancel"; this.btnCancel.Size = new System.Drawing.Size(75, 23); this.btnCancel.TabIndex = 1; @@ -65,7 +69,7 @@ // lblDwhURL // this.lblDwhURL.AutoSize = true; - this.lblDwhURL.Location = new System.Drawing.Point(9, 87); + this.lblDwhURL.Location = new System.Drawing.Point(6, 103); this.lblDwhURL.Name = "lblDwhURL"; this.lblDwhURL.Size = new System.Drawing.Size(147, 13); this.lblDwhURL.TabIndex = 4; @@ -73,9 +77,10 @@ // // btnClearUrlField // + this.btnClearUrlField.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.btnClearUrlField.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(204))); this.btnClearUrlField.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(0)))), ((int)(((byte)(0))))); - this.btnClearUrlField.Location = new System.Drawing.Point(352, 103); + this.btnClearUrlField.Location = new System.Drawing.Point(350, 119); this.btnClearUrlField.Name = "btnClearUrlField"; this.btnClearUrlField.Size = new System.Drawing.Size(19, 19); this.btnClearUrlField.TabIndex = 5; @@ -86,58 +91,66 @@ // lblDwhBotname // this.lblDwhBotname.AutoSize = true; - this.lblDwhBotname.Location = new System.Drawing.Point(9, 9); + this.lblDwhBotname.Location = new System.Drawing.Point(6, 25); this.lblDwhBotname.Name = "lblDwhBotname"; - this.lblDwhBotname.Size = new System.Drawing.Size(127, 13); + this.lblDwhBotname.Size = new System.Drawing.Size(124, 13); this.lblDwhBotname.TabIndex = 6; - this.lblDwhBotname.Text = "Имя бота в сообщении:"; + this.lblDwhBotname.Text = "Имя бота в сообщении"; // // lblDwhAvatarUrl // this.lblDwhAvatarUrl.AutoSize = true; - this.lblDwhAvatarUrl.Location = new System.Drawing.Point(9, 48); + this.lblDwhAvatarUrl.Location = new System.Drawing.Point(6, 64); this.lblDwhAvatarUrl.Name = "lblDwhAvatarUrl"; - this.lblDwhAvatarUrl.Size = new System.Drawing.Size(102, 13); + this.lblDwhAvatarUrl.Size = new System.Drawing.Size(132, 13); this.lblDwhAvatarUrl.TabIndex = 6; - this.lblDwhAvatarUrl.Text = "URL аватара бота:"; + this.lblDwhAvatarUrl.Text = "URL-адрес аватара бота"; // // textDwhAvatarUrl // - this.textDwhAvatarUrl.Location = new System.Drawing.Point(9, 64); + this.textDwhAvatarUrl.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.textDwhAvatarUrl.Location = new System.Drawing.Point(6, 80); this.textDwhAvatarUrl.Name = "textDwhAvatarUrl"; - this.textDwhAvatarUrl.Size = new System.Drawing.Size(337, 20); + this.textDwhAvatarUrl.Size = new System.Drawing.Size(338, 20); this.textDwhAvatarUrl.TabIndex = 7; // // textDwhBotName // - this.textDwhBotName.Location = new System.Drawing.Point(9, 25); + this.textDwhBotName.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.textDwhBotName.Location = new System.Drawing.Point(6, 41); this.textDwhBotName.MaxLength = 40; this.textDwhBotName.Name = "textDwhBotName"; - this.textDwhBotName.Size = new System.Drawing.Size(211, 20); + this.textDwhBotName.Size = new System.Drawing.Size(212, 20); this.textDwhBotName.TabIndex = 7; // // textDwhURL // - this.textDwhURL.Location = new System.Drawing.Point(9, 103); + this.textDwhURL.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.textDwhURL.Location = new System.Drawing.Point(6, 119); this.textDwhURL.Name = "textDwhURL"; - this.textDwhURL.Size = new System.Drawing.Size(337, 20); + this.textDwhURL.Size = new System.Drawing.Size(338, 20); this.textDwhURL.TabIndex = 3; // // chbxDiscordEnabled // this.chbxDiscordEnabled.AutoSize = true; - this.chbxDiscordEnabled.Location = new System.Drawing.Point(9, 129); + this.chbxDiscordEnabled.Location = new System.Drawing.Point(12, 173); this.chbxDiscordEnabled.Name = "chbxDiscordEnabled"; this.chbxDiscordEnabled.Size = new System.Drawing.Size(232, 17); this.chbxDiscordEnabled.TabIndex = 2; this.chbxDiscordEnabled.Text = "Включить отправку сообщений в Discord"; this.chbxDiscordEnabled.UseVisualStyleBackColor = true; + this.chbxDiscordEnabled.CheckedChanged += new System.EventHandler(this.chbxDiscordEnabled_CheckedChanged); // // btnClearAvatarUrlField // + this.btnClearAvatarUrlField.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.btnClearAvatarUrlField.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(204))); this.btnClearAvatarUrlField.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(0)))), ((int)(((byte)(0))))); - this.btnClearAvatarUrlField.Location = new System.Drawing.Point(352, 65); + this.btnClearAvatarUrlField.Location = new System.Drawing.Point(350, 81); this.btnClearAvatarUrlField.Name = "btnClearAvatarUrlField"; this.btnClearAvatarUrlField.Size = new System.Drawing.Size(19, 19); this.btnClearAvatarUrlField.TabIndex = 5; @@ -145,32 +158,47 @@ this.btnClearAvatarUrlField.UseVisualStyleBackColor = true; this.btnClearAvatarUrlField.Click += new System.EventHandler(this.ClearUrl); // - // DiscordSettings + // groupBoxSettingsDiscord + // + this.groupBoxSettingsDiscord.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.groupBoxSettingsDiscord.Controls.Add(this.lblDwhBotname); + this.groupBoxSettingsDiscord.Controls.Add(this.textDwhURL); + this.groupBoxSettingsDiscord.Controls.Add(this.textDwhAvatarUrl); + this.groupBoxSettingsDiscord.Controls.Add(this.lblDwhURL); + this.groupBoxSettingsDiscord.Controls.Add(this.textDwhBotName); + this.groupBoxSettingsDiscord.Controls.Add(this.btnClearUrlField); + this.groupBoxSettingsDiscord.Controls.Add(this.lblDwhAvatarUrl); + this.groupBoxSettingsDiscord.Controls.Add(this.btnClearAvatarUrlField); + this.groupBoxSettingsDiscord.Location = new System.Drawing.Point(12, 12); + this.groupBoxSettingsDiscord.Name = "groupBoxSettingsDiscord"; + this.groupBoxSettingsDiscord.Size = new System.Drawing.Size(379, 155); + this.groupBoxSettingsDiscord.TabIndex = 8; + this.groupBoxSettingsDiscord.TabStop = false; + this.groupBoxSettingsDiscord.Text = "Discord"; + // + // WebhookSettings // this.AcceptButton = this.btnOk; this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.CancelButton = this.btnCancel; - this.ClientSize = new System.Drawing.Size(387, 188); + this.ClientSize = new System.Drawing.Size(404, 241); this.ControlBox = false; - this.Controls.Add(this.textDwhAvatarUrl); - this.Controls.Add(this.textDwhBotName); - this.Controls.Add(this.lblDwhAvatarUrl); - this.Controls.Add(this.lblDwhBotname); - this.Controls.Add(this.btnClearAvatarUrlField); - this.Controls.Add(this.btnClearUrlField); - this.Controls.Add(this.lblDwhURL); - this.Controls.Add(this.textDwhURL); this.Controls.Add(this.chbxDiscordEnabled); + this.Controls.Add(this.groupBoxSettingsDiscord); this.Controls.Add(this.btnCancel); this.Controls.Add(this.btnOk); - this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; this.MaximizeBox = false; this.MinimizeBox = false; - this.Name = "DiscordSettings"; + this.MinimumSize = new System.Drawing.Size(420, 280); + this.Name = "WebhookSettings"; this.ShowIcon = false; this.ShowInTaskbar = false; - this.Text = "Настройки Discord webhook"; + this.Text = "Настройки webhook"; + this.Load += new System.EventHandler(this.WebhookSettings_FormLoad); + this.groupBoxSettingsDiscord.ResumeLayout(false); + this.groupBoxSettingsDiscord.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); @@ -189,5 +217,6 @@ private System.Windows.Forms.Label lblDwhAvatarUrl; private System.Windows.Forms.TextBox textDwhAvatarUrl; private System.Windows.Forms.Button btnClearAvatarUrlField; + private System.Windows.Forms.GroupBox groupBoxSettingsDiscord; } } \ No newline at end of file diff --git a/DiscordSettings.cs b/DiscordSettings.cs index b645589..2693454 100644 --- a/DiscordSettings.cs +++ b/DiscordSettings.cs @@ -13,9 +13,9 @@ using RelaunchProcess.Properties; namespace RelaunchProcess { - public partial class DiscordSettings : Form + public partial class WebhookSettings : Form { - public DiscordSettings() + public WebhookSettings() { InitializeComponent(); RestoreSettings(); @@ -38,6 +38,16 @@ namespace RelaunchProcess Settings.Default.Save(); } + public void UpdateUI() + { + groupBoxSettingsDiscord.Enabled = !chbxDiscordEnabled.Checked; + } + + private void WebhookSettings_FormLoad(object sender, EventArgs e) + { + UpdateUI(); + } + private void BtnCancel_Click(object sender, EventArgs e) { DialogResult = DialogResult.Cancel; @@ -69,5 +79,10 @@ namespace RelaunchProcess if ( (Button)sender == btnClearUrlField ) textDwhURL.Text = ""; if ( (Button)sender == btnClearAvatarUrlField ) textDwhAvatarUrl.Text = ""; } + + private void chbxDiscordEnabled_CheckedChanged(object sender, EventArgs e) + { + UpdateUI(); + } } } diff --git a/Form1.Designer.cs b/Form1.Designer.cs index 0c65f12..74e4f83 100644 --- a/Form1.Designer.cs +++ b/Form1.Designer.cs @@ -48,12 +48,12 @@ namespace Process_Auto_Relaunch this.checkBoxSaveState = new System.Windows.Forms.CheckBox(); this.radioButtonEnableWathing = new System.Windows.Forms.RadioButton(); this.radioButtonDisableWathing = new System.Windows.Forms.RadioButton(); + this.btnShowDiscordSettings = new System.Windows.Forms.Button(); this.groupBoxStatus = new System.Windows.Forms.GroupBox(); this.labelStatus = new System.Windows.Forms.Label(); this.myBackgroundWorker = new System.ComponentModel.BackgroundWorker(); this.groupBoxHistory = new System.Windows.Forms.GroupBox(); this.richTextBoxHistory = new System.Windows.Forms.RichTextBox(); - this.btnShowDiscordSettings = new System.Windows.Forms.Button(); this.groupBoxActions.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit(); this.groupBoxProgramStart.SuspendLayout(); @@ -303,6 +303,18 @@ namespace Process_Auto_Relaunch this.radioButtonDisableWathing.UseVisualStyleBackColor = true; this.radioButtonDisableWathing.CheckedChanged += new System.EventHandler(this.radioButtonDisableWathing_CheckedChanged); // + // btnShowDiscordSettings + // + this.btnShowDiscordSettings.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.btnShowDiscordSettings.Location = new System.Drawing.Point(282, 16); + this.btnShowDiscordSettings.Margin = new System.Windows.Forms.Padding(4); + this.btnShowDiscordSettings.Name = "btnShowDiscordSettings"; + this.btnShowDiscordSettings.Size = new System.Drawing.Size(89, 34); + this.btnShowDiscordSettings.TabIndex = 1; + this.btnShowDiscordSettings.Text = "Webhook"; + this.btnShowDiscordSettings.UseVisualStyleBackColor = true; + this.btnShowDiscordSettings.Click += new System.EventHandler(this.btnShowDiscordSettings_Click); + // // groupBoxStatus // this.groupBoxStatus.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) @@ -356,18 +368,6 @@ namespace Process_Auto_Relaunch this.richTextBoxHistory.TabIndex = 0; this.richTextBoxHistory.Text = ""; // - // btnShowDiscordSettings - // - this.btnShowDiscordSettings.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); - this.btnShowDiscordSettings.Location = new System.Drawing.Point(282, 16); - this.btnShowDiscordSettings.Margin = new System.Windows.Forms.Padding(4); - this.btnShowDiscordSettings.Name = "btnShowDiscordSettings"; - this.btnShowDiscordSettings.Size = new System.Drawing.Size(89, 34); - this.btnShowDiscordSettings.TabIndex = 1; - this.btnShowDiscordSettings.Text = "Discord"; - this.btnShowDiscordSettings.UseVisualStyleBackColor = true; - this.btnShowDiscordSettings.Click += new System.EventHandler(this.btnShowDiscordSettings_Click); - // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); diff --git a/Form1.cs b/Form1.cs index be5219b..82311ba 100644 --- a/Form1.cs +++ b/Form1.cs @@ -337,8 +337,8 @@ namespace Process_Auto_Relaunch private void btnShowDiscordSettings_Click(object sender, EventArgs e) { - DiscordSettings discordSettings; - discordSettings = new DiscordSettings(); + WebhookSettings discordSettings; + discordSettings = new WebhookSettings(); discordSettings.ShowDialog(this); discordSettings.Dispose(); }