mirror of
https://github.com/SlothDpal/Relaunch-Process.git
synced 2026-08-21 20:49:19 +03:00
Send a message at the start
This commit is contained in:
@@ -22,10 +22,10 @@ namespace Process_Auto_Relaunch
|
||||
public enum NotifyLevel
|
||||
{
|
||||
logNone = 0,
|
||||
logAlways = 1, // ������ �����
|
||||
logUpdateStatus = 2, // ������ � ������ ���������
|
||||
logHistory = 4, // ������ � ���� ������� ������������
|
||||
logDiscord = 8 // ������ � �������
|
||||
logAlways = 1, // ïèñàòü âåçäå
|
||||
logUpdateStatus = 2, // ïèñàòü â ñòðîêå ñîñòîÿíèÿ
|
||||
logHistory = 4, // ïèñàòü â îêíå èñòîðèè ïåðåçàïóñêîâ
|
||||
logDiscord = 8 // ïèñàòü â Äèñêîðä
|
||||
}
|
||||
private delegate void UpdateLogDelegate(string text, NotifyLevel level = NotifyLevel.logUpdateStatus);
|
||||
private readonly UpdateLogDelegate updateLogDelegate;
|
||||
@@ -45,8 +45,8 @@ namespace Process_Auto_Relaunch
|
||||
dwhHook.Url = Settings.Default.dwhURL;
|
||||
}
|
||||
else if (Settings.Default.dwhEnabled) {
|
||||
Debug.WriteLine($"������ � URL ���-���� ({Settings.Default.dwhURL}). ����� � Discord ��������.");
|
||||
HistoryLog($"������ � URL ���-���� ({Settings.Default.dwhURL}). ����� � Discord ��������.");
|
||||
Debug.WriteLine($"Îøèáêà â URL âåá-õóêà ({Settings.Default.dwhURL}). Âûâîä â Discord îòêëþ÷åí.");
|
||||
HistoryLog($"Îøèáêà â URL âåá-õóêà ({Settings.Default.dwhURL}). Âûâîä â Discord îòêëþ÷åí.");
|
||||
Settings.Default.dwhEnabled = false;
|
||||
Settings.Default.Save();
|
||||
}*/
|
||||
@@ -54,7 +54,7 @@ namespace Process_Auto_Relaunch
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ������� ������� �����
|
||||
/// Ñîáûòèå çàïóñêà ôîðìû
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
@@ -68,7 +68,7 @@ namespace Process_Auto_Relaunch
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// �������������� ��������
|
||||
/// Âîññòàíîâëåíèå íàñòðîåê
|
||||
/// </summary>
|
||||
private void LoadOldState()
|
||||
{
|
||||
@@ -80,7 +80,7 @@ namespace Process_Auto_Relaunch
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ����� ��� ������� ����������
|
||||
/// Ìåòîä äëÿ ñîáûòèÿ îòêëþ÷åíèÿ
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
@@ -96,12 +96,12 @@ namespace Process_Auto_Relaunch
|
||||
if (myBackgroundWorker.WorkerSupportsCancellation && myBackgroundWorker.IsBusy)
|
||||
{
|
||||
myBackgroundWorker.CancelAsync();
|
||||
UpdateStatus("��������...",NotifyLevel.logUpdateStatus);
|
||||
UpdateStatus("Îòìåíÿåì...",NotifyLevel.logUpdateStatus);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ����� ��� ������� ���������
|
||||
/// Ìåòîä äëÿ ñîáûòèÿ âêëþ÷åíèÿ
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
@@ -116,15 +116,15 @@ namespace Process_Auto_Relaunch
|
||||
if (String.IsNullOrEmpty(textBoxProcessName.Text))
|
||||
{
|
||||
error = true;
|
||||
MessageBox.Show("��� �������� �� ����� ���� ������!" +
|
||||
"\n������� ��� ��������", "������", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
MessageBox.Show("Èìÿ ïðîöåññà íå ìîæåò áûòü ïóñòûì!" +
|
||||
"\nÓêàæèòå èìÿ ïðîöåññà", "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
|
||||
if (String.IsNullOrEmpty(Settings.Default.startProgramPath))
|
||||
{
|
||||
error = true;
|
||||
MessageBox.Show("��������� ��� ������� �� �������." +
|
||||
"\n������� ��������� ��� �������", "������", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
MessageBox.Show("Ïðîãðàììà äëÿ çàïóñêà íå óêàçàíà." +
|
||||
"\nÓêàæèòå ïðîãðàììó äëÿ çàïóñêà", "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
|
||||
if (error)
|
||||
@@ -137,14 +137,15 @@ namespace Process_Auto_Relaunch
|
||||
if (!myBackgroundWorker.IsBusy)
|
||||
{
|
||||
myBackgroundWorker.RunWorkerAsync();
|
||||
Status($"Çàïóñêàåì íàáëþäåíèå...", NotifyLevel.logDiscord);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ���������� ������� � ���������
|
||||
/// Îáíîâëåíèå ñòàòóñà â ïðîãðàììå
|
||||
/// </summary>
|
||||
/// <param name="text">����� ��� �����������/�������� </param>
|
||||
/// <param name="level">����� ��� ���������� ��������</param>
|
||||
/// <param name="text">Òåêñò äëÿ îòîáðàæåíèÿ/îòïðàâêè </param>
|
||||
/// <param name="level">Ôëàãè äëÿ íàçíà÷åíèÿ îòïðàâêè</param>
|
||||
public void UpdateStatus( string text, NotifyLevel level )
|
||||
{
|
||||
if (!level.HasFlag(NotifyLevel.logAlways) && !level.HasFlag(NotifyLevel.logUpdateStatus)) return;
|
||||
@@ -152,10 +153,10 @@ namespace Process_Auto_Relaunch
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ���������� ������ � ������� ��������
|
||||
/// Äîáàâëåíèå ñòðîêè â Èñòîðèè Çàïóñêîâ
|
||||
/// </summary>
|
||||
/// <param name="text">����� ��� �����������/�������� </param>
|
||||
/// <param name="level">����� ��� ���������� ��������</param>
|
||||
/// <param name="text">Òåêñò äëÿ îòîáðàæåíèÿ/îòïðàâêè </param>
|
||||
/// <param name="level">Ôëàãè äëÿ íàçíà÷åíèÿ îòïðàâêè</param>
|
||||
private void HistoryLog( string text, NotifyLevel level )
|
||||
{
|
||||
if (!level.HasFlag(NotifyLevel.logAlways) && !level.HasFlag(NotifyLevel.logHistory)) return;
|
||||
@@ -163,10 +164,10 @@ namespace Process_Auto_Relaunch
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// �������� ������� � Discord
|
||||
/// Îòïðàâêà ñòàòóñà â Discord
|
||||
/// </summary>
|
||||
/// <param name="text">����� ��� �����������/�������� </param>
|
||||
/// <param name="level">����� ��� ���������� ��������</param>
|
||||
/// <param name="text">Òåêñò äëÿ îòîáðàæåíèÿ/îòïðàâêè </param>
|
||||
/// <param name="level">Ôëàãè äëÿ íàçíà÷åíèÿ îòïðàâêè</param>
|
||||
public void SendDiscordMessage( string text, NotifyLevel level )
|
||||
{
|
||||
if (!level.HasFlag(NotifyLevel.logAlways) && !level.HasFlag(NotifyLevel.logDiscord)) return;
|
||||
@@ -182,7 +183,7 @@ namespace Process_Auto_Relaunch
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Status($"������ �������� � �������.",NotifyLevel.logHistory);
|
||||
Status($"Îøèáêà îòïðàâêè â äèñêîðä.",NotifyLevel.logHistory);
|
||||
Debug.WriteLine($"Discord messaging error: {ex.Message}");
|
||||
//Settings.Default.dwhEnabled = false;
|
||||
//Settings.Default.Save();
|
||||
@@ -191,10 +192,10 @@ namespace Process_Auto_Relaunch
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ���������� ������� � ���������
|
||||
/// Îáíîâëåíèå ñòàòóñà â ïðîãðàììå
|
||||
/// </summary>
|
||||
/// <param name="text">����� ��� �����������/�������� </param>
|
||||
/// <param name="level">����� ��� ���������� ��������</param>
|
||||
/// <param name="text">Òåêñò äëÿ îòîáðàæåíèÿ/îòïðàâêè </param>
|
||||
/// <param name="level">Ôëàãè äëÿ íàçíà÷åíèÿ îòïðàâêè</param>
|
||||
public void Status(string text, NotifyLevel level = NotifyLevel.logUpdateStatus)
|
||||
{
|
||||
Invoke(updateLogDelegate, text, level);
|
||||
@@ -203,12 +204,12 @@ namespace Process_Auto_Relaunch
|
||||
private void CheckProgramState()
|
||||
{
|
||||
bool watching = radioButtonEnableWathing.Checked;
|
||||
Debug.WriteLine($"����������: {watching}");
|
||||
Debug.WriteLine($"Íàáëþäåíèå: {watching}");
|
||||
|
||||
groupBoxProcessName.Enabled = !watching;
|
||||
groupBoxProgramStart.Enabled = !watching;
|
||||
groupBoxActions.Enabled = !watching;
|
||||
btnShowDiscordSettings.Enabled = !watching; //��������� ������ �������� ��������
|
||||
btnShowDiscordSettings.Enabled = !watching; //îòêëþ÷àåì êíîïêó íàñòðîåê äèñêîðäà
|
||||
|
||||
Settings.Default.enableWatching = watching;
|
||||
|
||||
@@ -216,15 +217,15 @@ namespace Process_Auto_Relaunch
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ����� ����� ��� �������
|
||||
/// Âûáîð ôàéëà äëÿ çàïóñêà
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonSetProgramStart_Click(object sender, EventArgs e)
|
||||
{
|
||||
OpenFileDialog openFile = new OpenFileDialog();
|
||||
openFile.Filter = "����������� ����� (*.exe)|*.exe";
|
||||
openFile.Title = "������� ��������� �������";
|
||||
openFile.Filter = "Èñïîëíÿåìûå ôàéëû (*.exe)|*.exe";
|
||||
openFile.Title = "Óêàæèòå ïðîãðàììó çàïóñêà";
|
||||
|
||||
if (openFile.ShowDialog() == DialogResult.Cancel)
|
||||
{
|
||||
@@ -240,7 +241,7 @@ namespace Process_Auto_Relaunch
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ������� ����� ��������� �����
|
||||
/// Ñîáûòèå ïåðåä çàêðûòèåì ôîðìû
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
@@ -274,7 +275,7 @@ namespace Process_Auto_Relaunch
|
||||
}
|
||||
}
|
||||
|
||||
Status("������� ��� �������.", NotifyLevel.logAlways);
|
||||
Status("Ïðîöåññ áûë çàïóùåí.", NotifyLevel.logAlways);
|
||||
Process.Start(path, args);
|
||||
}
|
||||
|
||||
@@ -287,23 +288,23 @@ namespace Process_Auto_Relaunch
|
||||
{
|
||||
if (ProcessByNameIsRuning(textBoxProcessName.Text))
|
||||
{
|
||||
Status($"������� ��� �������",NotifyLevel.logUpdateStatus);
|
||||
if (i < (int)numericUpDown1.Value) SendDiscordMessage($"������� {textBoxProcessName.Text} �������.",NotifyLevel.logDiscord);
|
||||
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) Status($"������� {textBoxProcessName.Text} �� ������. ������ ����� {i} ���",NotifyLevel.logDiscord);
|
||||
if (i==(int)numericUpDown1.Value) Status($"Ïðîöåññ {textBoxProcessName.Text} íå íàéäåí. Çàïóñê ÷åðåç {i} ñåê",NotifyLevel.logDiscord);
|
||||
i--;
|
||||
Status($"������� {textBoxProcessName.Text} �� ������. ������ ����� {i}", NotifyLevel.logUpdateStatus);
|
||||
Status($"Ïðîöåññ {textBoxProcessName.Text} íå íàéäåí. Çàïóñê ÷åðåç {i}", NotifyLevel.logUpdateStatus);
|
||||
}
|
||||
|
||||
if (i <= 0 || radioButtonRestartNow.Checked)
|
||||
{
|
||||
i = (int)numericUpDown1.Value;
|
||||
Status($"��������� {textBoxProcessName.Text}", NotifyLevel.logUpdateStatus|NotifyLevel.logDiscord);
|
||||
Status($"Çàïóñêàåì {textBoxProcessName.Text}", NotifyLevel.logUpdateStatus|NotifyLevel.logDiscord);
|
||||
ProcessStart(Settings.Default.startProgramPath, textBoxArguments.Text);
|
||||
}
|
||||
}
|
||||
@@ -321,17 +322,17 @@ namespace Process_Auto_Relaunch
|
||||
{
|
||||
if (e.Cancelled)
|
||||
{
|
||||
Status("���������� ��������.",NotifyLevel.logUpdateStatus|NotifyLevel.logDiscord);
|
||||
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);
|
||||
MessageBox.Show("Error: " + e.Error.Message, "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Stop);
|
||||
radioButtonDisableWathing.Checked = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Status("���������� �����������.", NotifyLevel.logUpdateStatus|NotifyLevel.logDiscord);
|
||||
Status("Íàáëþäåíèå îñòàíîâëåíî.", NotifyLevel.logUpdateStatus|NotifyLevel.logDiscord);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user