mirror of
https://github.com/SlothDpal/Relaunch-Process.git
synced 2026-02-22 17:27:38 +03:00
- added about window
- discord: async queue
This commit is contained in:
193
AboutBox.Designer.cs
generated
Normal file
193
AboutBox.Designer.cs
generated
Normal file
@@ -0,0 +1,193 @@
|
|||||||
|
namespace RelaunchProcess
|
||||||
|
{
|
||||||
|
partial class AboutBox
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Обязательная переменная конструктора.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Освободить все используемые ресурсы.
|
||||||
|
/// </summary>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Код, автоматически созданный конструктором форм Windows
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Требуемый метод для поддержки конструктора — не изменяйте
|
||||||
|
/// содержимое этого метода с помощью редактора кода.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(AboutBox));
|
||||||
|
this.tableLayoutPanel = new System.Windows.Forms.TableLayoutPanel();
|
||||||
|
this.logoPictureBox = new System.Windows.Forms.PictureBox();
|
||||||
|
this.labelProductName = new System.Windows.Forms.Label();
|
||||||
|
this.labelVersion = new System.Windows.Forms.Label();
|
||||||
|
this.labelCopyright = new System.Windows.Forms.LinkLabel();
|
||||||
|
this.labelCompanyName = new System.Windows.Forms.Label();
|
||||||
|
this.textBoxDescription = new System.Windows.Forms.TextBox();
|
||||||
|
this.okButton = new System.Windows.Forms.Button();
|
||||||
|
this.tableLayoutPanel.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.logoPictureBox)).BeginInit();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// tableLayoutPanel
|
||||||
|
//
|
||||||
|
this.tableLayoutPanel.ColumnCount = 2;
|
||||||
|
this.tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33F));
|
||||||
|
this.tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 67F));
|
||||||
|
this.tableLayoutPanel.Controls.Add(this.logoPictureBox, 0, 0);
|
||||||
|
this.tableLayoutPanel.Controls.Add(this.labelProductName, 1, 0);
|
||||||
|
this.tableLayoutPanel.Controls.Add(this.labelVersion, 1, 1);
|
||||||
|
this.tableLayoutPanel.Controls.Add(this.labelCopyright, 1, 2);
|
||||||
|
this.tableLayoutPanel.Controls.Add(this.labelCompanyName, 1, 3);
|
||||||
|
this.tableLayoutPanel.Controls.Add(this.textBoxDescription, 1, 4);
|
||||||
|
this.tableLayoutPanel.Controls.Add(this.okButton, 1, 5);
|
||||||
|
this.tableLayoutPanel.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
|
this.tableLayoutPanel.Location = new System.Drawing.Point(14, 14);
|
||||||
|
this.tableLayoutPanel.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||||
|
this.tableLayoutPanel.Name = "tableLayoutPanel";
|
||||||
|
this.tableLayoutPanel.RowCount = 6;
|
||||||
|
this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 10F));
|
||||||
|
this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 10F));
|
||||||
|
this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 10F));
|
||||||
|
this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 10F));
|
||||||
|
this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
|
||||||
|
this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 10F));
|
||||||
|
this.tableLayoutPanel.Size = new System.Drawing.Size(624, 407);
|
||||||
|
this.tableLayoutPanel.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// logoPictureBox
|
||||||
|
//
|
||||||
|
this.logoPictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
|
this.logoPictureBox.Image = ((System.Drawing.Image)(resources.GetObject("logoPictureBox.Image")));
|
||||||
|
this.logoPictureBox.Location = new System.Drawing.Point(4, 5);
|
||||||
|
this.logoPictureBox.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||||
|
this.logoPictureBox.Name = "logoPictureBox";
|
||||||
|
this.tableLayoutPanel.SetRowSpan(this.logoPictureBox, 6);
|
||||||
|
this.logoPictureBox.Size = new System.Drawing.Size(197, 397);
|
||||||
|
this.logoPictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
|
||||||
|
this.logoPictureBox.TabIndex = 12;
|
||||||
|
this.logoPictureBox.TabStop = false;
|
||||||
|
//
|
||||||
|
// labelProductName
|
||||||
|
//
|
||||||
|
this.labelProductName.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
|
this.labelProductName.Location = new System.Drawing.Point(214, 0);
|
||||||
|
this.labelProductName.Margin = new System.Windows.Forms.Padding(9, 0, 4, 0);
|
||||||
|
this.labelProductName.MaximumSize = new System.Drawing.Size(0, 26);
|
||||||
|
this.labelProductName.Name = "labelProductName";
|
||||||
|
this.labelProductName.Size = new System.Drawing.Size(406, 26);
|
||||||
|
this.labelProductName.TabIndex = 19;
|
||||||
|
this.labelProductName.Text = "Название продукта";
|
||||||
|
this.labelProductName.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
|
||||||
|
//
|
||||||
|
// labelVersion
|
||||||
|
//
|
||||||
|
this.labelVersion.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
|
this.labelVersion.Location = new System.Drawing.Point(214, 40);
|
||||||
|
this.labelVersion.Margin = new System.Windows.Forms.Padding(9, 0, 4, 0);
|
||||||
|
this.labelVersion.MaximumSize = new System.Drawing.Size(0, 26);
|
||||||
|
this.labelVersion.Name = "labelVersion";
|
||||||
|
this.labelVersion.Size = new System.Drawing.Size(406, 26);
|
||||||
|
this.labelVersion.TabIndex = 0;
|
||||||
|
this.labelVersion.Text = "Версия";
|
||||||
|
this.labelVersion.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
|
||||||
|
//
|
||||||
|
// labelCopyright
|
||||||
|
//
|
||||||
|
this.labelCopyright.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
|
this.labelCopyright.Location = new System.Drawing.Point(214, 80);
|
||||||
|
this.labelCopyright.Margin = new System.Windows.Forms.Padding(9, 0, 4, 0);
|
||||||
|
this.labelCopyright.MaximumSize = new System.Drawing.Size(0, 26);
|
||||||
|
this.labelCopyright.Name = "labelCopyright";
|
||||||
|
this.labelCopyright.Size = new System.Drawing.Size(406, 26);
|
||||||
|
this.labelCopyright.TabIndex = 21;
|
||||||
|
this.labelCopyright.TabStop = true;
|
||||||
|
this.labelCopyright.Text = "Авторские права";
|
||||||
|
this.labelCopyright.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
|
||||||
|
this.labelCopyright.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.labelCopyright_LinkClicked);
|
||||||
|
//
|
||||||
|
// labelCompanyName
|
||||||
|
//
|
||||||
|
this.labelCompanyName.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
|
this.labelCompanyName.Location = new System.Drawing.Point(214, 120);
|
||||||
|
this.labelCompanyName.Margin = new System.Windows.Forms.Padding(9, 0, 4, 0);
|
||||||
|
this.labelCompanyName.MaximumSize = new System.Drawing.Size(0, 26);
|
||||||
|
this.labelCompanyName.Name = "labelCompanyName";
|
||||||
|
this.labelCompanyName.Size = new System.Drawing.Size(406, 26);
|
||||||
|
this.labelCompanyName.TabIndex = 22;
|
||||||
|
this.labelCompanyName.Text = "Название организации";
|
||||||
|
this.labelCompanyName.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
|
||||||
|
//
|
||||||
|
// textBoxDescription
|
||||||
|
//
|
||||||
|
this.textBoxDescription.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
|
this.textBoxDescription.Location = new System.Drawing.Point(214, 165);
|
||||||
|
this.textBoxDescription.Margin = new System.Windows.Forms.Padding(9, 5, 4, 5);
|
||||||
|
this.textBoxDescription.Multiline = true;
|
||||||
|
this.textBoxDescription.Name = "textBoxDescription";
|
||||||
|
this.textBoxDescription.ReadOnly = true;
|
||||||
|
this.textBoxDescription.ScrollBars = System.Windows.Forms.ScrollBars.Both;
|
||||||
|
this.textBoxDescription.Size = new System.Drawing.Size(406, 193);
|
||||||
|
this.textBoxDescription.TabIndex = 23;
|
||||||
|
this.textBoxDescription.TabStop = false;
|
||||||
|
this.textBoxDescription.Text = "Описание";
|
||||||
|
//
|
||||||
|
// okButton
|
||||||
|
//
|
||||||
|
this.okButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
|
this.okButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
|
||||||
|
this.okButton.Location = new System.Drawing.Point(508, 368);
|
||||||
|
this.okButton.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||||
|
this.okButton.Name = "okButton";
|
||||||
|
this.okButton.Size = new System.Drawing.Size(112, 34);
|
||||||
|
this.okButton.TabIndex = 24;
|
||||||
|
this.okButton.Text = "&ОК";
|
||||||
|
//
|
||||||
|
// AboutBox
|
||||||
|
//
|
||||||
|
this.AcceptButton = this.okButton;
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(652, 435);
|
||||||
|
this.Controls.Add(this.tableLayoutPanel);
|
||||||
|
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
|
||||||
|
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
|
||||||
|
this.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||||
|
this.MaximizeBox = false;
|
||||||
|
this.MinimizeBox = false;
|
||||||
|
this.Name = "AboutBox";
|
||||||
|
this.Padding = new System.Windows.Forms.Padding(14);
|
||||||
|
this.ShowIcon = false;
|
||||||
|
this.ShowInTaskbar = false;
|
||||||
|
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
|
||||||
|
this.Text = "About";
|
||||||
|
this.tableLayoutPanel.ResumeLayout(false);
|
||||||
|
this.tableLayoutPanel.PerformLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.logoPictureBox)).EndInit();
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel;
|
||||||
|
private System.Windows.Forms.PictureBox logoPictureBox;
|
||||||
|
private System.Windows.Forms.Label labelProductName;
|
||||||
|
private System.Windows.Forms.Label labelVersion;
|
||||||
|
private System.Windows.Forms.LinkLabel labelCopyright;
|
||||||
|
private System.Windows.Forms.Label labelCompanyName;
|
||||||
|
private System.Windows.Forms.TextBox textBoxDescription;
|
||||||
|
private System.Windows.Forms.Button okButton;
|
||||||
|
}
|
||||||
|
}
|
||||||
116
AboutBox.cs
Normal file
116
AboutBox.cs
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace RelaunchProcess
|
||||||
|
{
|
||||||
|
partial class AboutBox : Form
|
||||||
|
{
|
||||||
|
public AboutBox()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
this.Text = String.Format("О программе {0}", AssemblyTitle);
|
||||||
|
this.labelProductName.Text = AssemblyProduct;
|
||||||
|
this.labelVersion.Text = String.Format("Версия {0}", AssemblyVersion);
|
||||||
|
this.labelCopyright.Text = AssemblyCopyright;
|
||||||
|
this.labelCompanyName.Text = AssemblyCompany;
|
||||||
|
this.textBoxDescription.Text = AssemblyDescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Методы доступа к атрибутам сборки
|
||||||
|
|
||||||
|
public string AssemblyTitle
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
|
||||||
|
if (attributes.Length > 0)
|
||||||
|
{
|
||||||
|
AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes[0];
|
||||||
|
if (titleAttribute.Title != "")
|
||||||
|
{
|
||||||
|
return titleAttribute.Title;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string AssemblyVersion
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return Assembly.GetExecutingAssembly().GetName().Version.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string AssemblyDescription
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false);
|
||||||
|
if (attributes.Length == 0)
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return ((AssemblyDescriptionAttribute)attributes[0]).Description;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string AssemblyProduct
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), false);
|
||||||
|
if (attributes.Length == 0)
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return ((AssemblyProductAttribute)attributes[0]).Product;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string AssemblyCopyright
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
|
||||||
|
if (attributes.Length == 0)
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string AssemblyCompany
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false);
|
||||||
|
if (attributes.Length == 0)
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return ((AssemblyCompanyAttribute)attributes[0]).Company;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private void labelCopyright_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
System.Diagnostics.Process.Start(labelCopyright.Text);
|
||||||
|
labelCopyright.LinkVisited = true;
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
MessageBox.Show("Ошибка открытия ссылки.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
1753
AboutBox.resx
Normal file
1753
AboutBox.resx
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,104 +1,101 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Net;
|
using System.Net.Http;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Discord.Webhook
|
namespace Discord.Webhook
|
||||||
{
|
{
|
||||||
public class DiscordWebhook
|
public class DiscordWebhook
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Webhook url
|
|
||||||
/// </summary>
|
|
||||||
public string Url { get; set; }
|
public string Url { get; set; }
|
||||||
|
|
||||||
private void AddField(MemoryStream stream, string bound, string cDisposition, string cType, byte[] data)
|
private UInt64 queueNum = 0;
|
||||||
{
|
private readonly ConcurrentQueue<(UInt64 num, DiscordMessage message, FileInfo[] files)> _queue = new ConcurrentQueue<(UInt64 num, DiscordMessage, FileInfo[])>();
|
||||||
string prefix = stream.Length > 0 ? "\r\n--" : "--";
|
private readonly SemaphoreSlim _semaphore = new SemaphoreSlim(1, 1);
|
||||||
string fBegin = $"{prefix}{bound}\r\n";
|
private bool _isProcessing;
|
||||||
|
|
||||||
byte[] fBeginBuffer = Utils.Encode(fBegin);
|
public async Task SendAsync(DiscordMessage message, params FileInfo[] files)
|
||||||
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));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Send webhook message
|
|
||||||
/// </summary>
|
|
||||||
public void Send(DiscordMessage message, params FileInfo[] files)
|
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(Url))
|
if (string.IsNullOrEmpty(Url))
|
||||||
throw new ArgumentNullException("Invalid Webhook URL.");
|
throw new ArgumentNullException("Invalid Webhook URL.");
|
||||||
|
|
||||||
string bound = "------------------------" + DateTime.Now.Ticks.ToString("x");
|
string boundary = "------------------------" + DateTime.Now.Ticks.ToString("x");
|
||||||
WebClient webhookRequest = new WebClient();
|
|
||||||
webhookRequest.Headers.Add("Content-Type", "multipart/form-data; boundary=" + bound);
|
|
||||||
|
|
||||||
MemoryStream stream = new MemoryStream();
|
using (var client = new HttpClient() { Timeout = TimeSpan.FromSeconds(30) })
|
||||||
for (int i = 0; i < files.Length; i++)
|
using (var content = new MultipartFormDataContent(boundary))
|
||||||
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
|
|
||||||
{
|
{
|
||||||
Uri uri = new Uri(this.Url);
|
// Добавляем JSON payload
|
||||||
webhookRequest.UploadData(uri, stream.ToArray());
|
var jsonContent = new StringContent(message.ToString(), Encoding.UTF8, "application/json");
|
||||||
}
|
jsonContent.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("form-data")
|
||||||
catch (WebException ex)
|
{
|
||||||
{
|
Name = "\"payload_json\""
|
||||||
throw new WebException(Utils.Decode(ex.Response.GetResponseStream()));
|
};
|
||||||
}
|
content.Add(jsonContent);
|
||||||
|
|
||||||
stream.Dispose();
|
// Добавляем файлы
|
||||||
|
for (int i = 0; i < files.Length; i++)
|
||||||
|
{
|
||||||
|
if (files[i].Exists)
|
||||||
|
{
|
||||||
|
var fileContent = new ByteArrayContent(File.ReadAllBytes(files[i].FullName));
|
||||||
|
fileContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/octet-stream");
|
||||||
|
fileContent.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("form-data")
|
||||||
|
{
|
||||||
|
Name = $"\"file_{i}\"",
|
||||||
|
FileName = $"\"{files[i].Name}\""
|
||||||
|
};
|
||||||
|
content.Add(fileContent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var response = await client.PostAsync(Url, content);
|
||||||
|
response.EnsureSuccessStatusCode();
|
||||||
|
}
|
||||||
|
catch (HttpRequestException ex)
|
||||||
|
{
|
||||||
|
Debug.WriteLine($"Discord webhook request failed: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task ProcessQueueAsync()
|
||||||
|
{
|
||||||
|
while (_queue.TryDequeue(out var item))
|
||||||
|
{
|
||||||
|
await _semaphore.WaitAsync();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Debug.WriteLine($"Processing message {item.num}. Queue size: {_queue.Count}");
|
||||||
|
await SendAsync(item.message, item.files);
|
||||||
|
Debug.WriteLine($"Message {item.num} sent.");
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
_semaphore.Release();
|
||||||
|
}
|
||||||
|
Task.Delay(500).Wait();
|
||||||
|
}
|
||||||
|
_isProcessing = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Send(DiscordMessage message, params FileInfo[] files)
|
||||||
|
{
|
||||||
|
_queue.Enqueue((queueNum++, message, files));
|
||||||
|
Debug.WriteLine($"Message {queueNum-1} added. Queue size: {_queue.Count}");
|
||||||
|
if (_isProcessing)
|
||||||
|
{
|
||||||
|
Debug.WriteLine("Already processing queue.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Debug.WriteLine("Run ProcessQueueAsync");
|
||||||
|
_isProcessing = true;
|
||||||
|
Task.Run(ProcessQueueAsync);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
3
Form1.Designer.cs
generated
3
Form1.Designer.cs
generated
@@ -407,7 +407,7 @@ namespace Process_Auto_Relaunch
|
|||||||
// webhookSettingsMenuItem
|
// webhookSettingsMenuItem
|
||||||
//
|
//
|
||||||
this.webhookSettingsMenuItem.Name = "webhookSettingsMenuItem";
|
this.webhookSettingsMenuItem.Name = "webhookSettingsMenuItem";
|
||||||
this.webhookSettingsMenuItem.Size = new System.Drawing.Size(120, 22);
|
this.webhookSettingsMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||||
this.webhookSettingsMenuItem.Text = "Вебхук";
|
this.webhookSettingsMenuItem.Text = "Вебхук";
|
||||||
this.webhookSettingsMenuItem.Click += new System.EventHandler(this.webhookDiscordToolStripMenuItem_Click);
|
this.webhookSettingsMenuItem.Click += new System.EventHandler(this.webhookDiscordToolStripMenuItem_Click);
|
||||||
//
|
//
|
||||||
@@ -416,6 +416,7 @@ namespace Process_Auto_Relaunch
|
|||||||
this.AboutProgram.Name = "AboutProgram";
|
this.AboutProgram.Name = "AboutProgram";
|
||||||
this.AboutProgram.Size = new System.Drawing.Size(104, 20);
|
this.AboutProgram.Size = new System.Drawing.Size(104, 20);
|
||||||
this.AboutProgram.Text = "О программе";
|
this.AboutProgram.Text = "О программе";
|
||||||
|
this.AboutProgram.Click += new System.EventHandler(this.AboutProgram_Click);
|
||||||
//
|
//
|
||||||
// Form1
|
// Form1
|
||||||
//
|
//
|
||||||
|
|||||||
9
Form1.cs
9
Form1.cs
@@ -13,6 +13,8 @@ using System.Data;
|
|||||||
using static System.Net.Mime.MediaTypeNames;
|
using static System.Net.Mime.MediaTypeNames;
|
||||||
using RelaunchProcess;
|
using RelaunchProcess;
|
||||||
using System.Timers;
|
using System.Timers;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
|
|
||||||
namespace Process_Auto_Relaunch
|
namespace Process_Auto_Relaunch
|
||||||
@@ -478,5 +480,12 @@ namespace Process_Auto_Relaunch
|
|||||||
discordSettings.ShowDialog(this);
|
discordSettings.ShowDialog(this);
|
||||||
discordSettings.Dispose();
|
discordSettings.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void AboutProgram_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
AboutBox aboutBox = new AboutBox();
|
||||||
|
aboutBox.ShowDialog(this);
|
||||||
|
aboutBox.Dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,22 @@
|
|||||||
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
||||||
<UseApplicationTrust>false</UseApplicationTrust>
|
<UseApplicationTrust>false</UseApplicationTrust>
|
||||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||||
|
<ShouldCreateLogs>True</ShouldCreateLogs>
|
||||||
|
<AdvancedSettingsExpanded>False</AdvancedSettingsExpanded>
|
||||||
|
<UpdateAssemblyVersion>False</UpdateAssemblyVersion>
|
||||||
|
<UpdateAssemblyFileVersion>False</UpdateAssemblyFileVersion>
|
||||||
|
<UpdateAssemblyInfoVersion>False</UpdateAssemblyInfoVersion>
|
||||||
|
<AssemblyVersionSettings>
|
||||||
|
</AssemblyVersionSettings>
|
||||||
|
<UpdatePackageVersion>False</UpdatePackageVersion>
|
||||||
|
<AssemblyInfoVersionType>SettingsVersion</AssemblyInfoVersionType>
|
||||||
|
<InheritWinAppVersionFrom>None</InheritWinAppVersionFrom>
|
||||||
|
<AssemblyFileVersionSettings>
|
||||||
|
</AssemblyFileVersionSettings>
|
||||||
|
<AssemblyInfoVersionSettings>
|
||||||
|
</AssemblyInfoVersionSettings>
|
||||||
|
<AssemblyInfoVersionSemVerSettings>
|
||||||
|
</AssemblyInfoVersionSemVerSettings>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<StartupObject>RelaunchProcess.Program</StartupObject>
|
<StartupObject>RelaunchProcess.Program</StartupObject>
|
||||||
@@ -71,7 +87,7 @@
|
|||||||
<HintPath>.\CSharpDiscordWebhook.dll</HintPath>
|
<HintPath>.\CSharpDiscordWebhook.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||||
<HintPath>packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
|
<HintPath>packages\Newtonsoft.Json.13.0.4\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
@@ -86,6 +102,12 @@
|
|||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="AboutBox.cs">
|
||||||
|
<SubType>Form</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="AboutBox.Designer.cs">
|
||||||
|
<DependentUpon>AboutBox.cs</DependentUpon>
|
||||||
|
</Compile>
|
||||||
<Compile Include="Discord\DiscordWebHook.cs" />
|
<Compile Include="Discord\DiscordWebHook.cs" />
|
||||||
<Compile Include="Discord\Structs.cs" />
|
<Compile Include="Discord\Structs.cs" />
|
||||||
<Compile Include="Discord\Utils.cs" />
|
<Compile Include="Discord\Utils.cs" />
|
||||||
@@ -103,6 +125,9 @@
|
|||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Program.cs" />
|
<Compile Include="Program.cs" />
|
||||||
<Compile Include="Settings.cs" />
|
<Compile Include="Settings.cs" />
|
||||||
|
<EmbeddedResource Include="AboutBox.resx">
|
||||||
|
<DependentUpon>AboutBox.cs</DependentUpon>
|
||||||
|
</EmbeddedResource>
|
||||||
<EmbeddedResource Include="DiscordSettings.resx">
|
<EmbeddedResource Include="DiscordSettings.resx">
|
||||||
<DependentUpon>DiscordSettings.cs</DependentUpon>
|
<DependentUpon>DiscordSettings.cs</DependentUpon>
|
||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
@@ -10,7 +10,7 @@ using System.Runtime.InteropServices;
|
|||||||
[assembly: AssemblyConfiguration("")]
|
[assembly: AssemblyConfiguration("")]
|
||||||
[assembly: AssemblyCompany("")]
|
[assembly: AssemblyCompany("")]
|
||||||
[assembly: AssemblyProduct("RelaunchProcess")]
|
[assembly: AssemblyProduct("RelaunchProcess")]
|
||||||
[assembly: AssemblyCopyright("")]
|
[assembly: AssemblyCopyright("https://github.com/Dark-raven-lab/Relaunch-Process")]
|
||||||
[assembly: AssemblyTrademark("")]
|
[assembly: AssemblyTrademark("")]
|
||||||
[assembly: AssemblyCulture("")]
|
[assembly: AssemblyCulture("")]
|
||||||
|
|
||||||
@@ -29,5 +29,7 @@ using System.Runtime.InteropServices;
|
|||||||
// Номер сборки
|
// Номер сборки
|
||||||
// Редакция
|
// Редакция
|
||||||
//
|
//
|
||||||
[assembly: AssemblyVersion("1.5.0.0")]
|
[assembly: AssemblyVersion("1.6.0.0")]
|
||||||
[assembly: AssemblyFileVersion("1.5.0.0")]
|
[assembly: AssemblyFileVersion("1.6.0.0")]
|
||||||
|
|
||||||
|
[assembly: AssemblyInformationalVersion("1.6.0.0")]
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<packages>
|
<packages>
|
||||||
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="net48" />
|
<package id="Newtonsoft.Json" version="13.0.4" targetFramework="net48" />
|
||||||
</packages>
|
</packages>
|
||||||
Reference in New Issue
Block a user