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