Compare commits

..
4 Commits
Author SHA1 Message Date
kislovdm dc92c80b43 Исправлена нагрузка на проц
.NET Core Desktop / build (Debug) (push) Has been cancelled
2026-06-15 09:23:49 +03:00
kislovdm 724644c8eb ++ 2026-04-30 12:55:19 +03:00
kislovdm 23768dbe0e Исправление скрола логов
.NET Core Desktop / build (Debug) (push) Has been cancelled
2026-04-30 12:33:00 +03:00
kislovdm ace23b954e auth
.NET Core Desktop / build (Debug) (push) Has been cancelled
2026-04-27 01:46:52 +03:00
5 changed files with 134 additions and 12 deletions
+1 -1
View File
@@ -1 +1 @@
1.0.20
1.0.23
+1
View File
@@ -23,6 +23,7 @@ git tag -m "Version v%VERSION%: %~1" -a v%VERSION%
git push origin v%VERSION%
git push --tags
git push
GOTO End
pause
+4 -4
View File
@@ -6,10 +6,10 @@
<LangVersion>7.3</LangVersion>
<RootNamespace>MonsterMonitor</RootNamespace>
<AssemblyName>devenv</AssemblyName>
<AssemblyVersion>1.0.20</AssemblyVersion>
<Version>1.0.20</Version>
<FileVersion>1.0.20</FileVersion>
<InformationalVersion>1.0.20</InformationalVersion>
<AssemblyVersion>1.0.23</AssemblyVersion>
<Version>1.0.23</Version>
<FileVersion>1.0.23</FileVersion>
<InformationalVersion>1.0.23</InformationalVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Costura.Fody" Version="6.0.0">
+45 -1
View File
@@ -1,4 +1,5 @@
using System;
using System.Threading;
using System.Windows.Forms;
using MonsterMonitor.UI;
@@ -6,9 +7,21 @@ namespace MonsterMonitor
{
internal static class Program
{
private const string SingleInstanceMutexName = @"Global\MonsterMonitor_v2_SingleInstance";
private const string ActivateEventName = @"Global\MonsterMonitor_v2_Activate";
[STAThread]
private static void Main()
{
var createdNew = false;
using (var mutex = new Mutex(true, SingleInstanceMutexName, out createdNew))
{
if (!createdNew)
{
TrySignalExistingInstance();
return;
}
Application.ThreadException += (sender, args) =>
{
MessageBox.Show(
@@ -29,7 +42,38 @@ namespace MonsterMonitor
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
using (var activateEvent = new EventWaitHandle(false, EventResetMode.AutoReset, ActivateEventName))
{
var form = new MainForm();
ThreadPool.RegisterWaitForSingleObject(
activateEvent,
(state, timedOut) =>
{
var mainForm = state as MainForm;
mainForm?.RestoreAndActivateFromExternalSignal();
},
form,
Timeout.Infinite,
false);
Application.Run(form);
}
}
}
private static void TrySignalExistingInstance()
{
try
{
using (var activateEvent = EventWaitHandle.OpenExisting(ActivateEventName))
{
activateEvent.Set();
}
}
catch
{
// Если не удалось отправить сигнал, просто завершаем второй инстанс.
}
}
}
}
+83 -6
View File
@@ -1,14 +1,19 @@
using System;
using System.Drawing;
using System.Threading.Tasks;
using System.Windows.Forms;
using MonsterMonitor.Models;
using MonsterMonitor.Services;
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Net.Mime.MediaTypeNames;
namespace MonsterMonitor.UI
{
public sealed class MainForm : Form
{
private const int EmGetFirstVisibleLine = 0x00CE;
private const int EmLineScroll = 0x00B6;
private readonly RichTextBox _console = new RichTextBox();
private readonly Button _btnSettings = new Button();
private readonly Button _btnExit = new Button();
@@ -25,7 +30,7 @@ namespace MonsterMonitor.UI
public MainForm()
{
Text = string.Format("Monster Monitor v{0}", Application.ProductVersion);
Text = string.Format("Monster Monitor v{0}", System.Windows.Forms.Application.ProductVersion);
Width = 980;
Height = 620;
StartPosition = FormStartPosition.CenterScreen;
@@ -135,6 +140,33 @@ namespace MonsterMonitor.UI
Activate();
}
public void RestoreAndActivateFromExternalSignal()
{
if (InvokeRequired)
{
BeginInvoke(new Action(RestoreAndActivateFromExternalSignal));
return;
}
_log.Info("Получен сигнал активации от второго инстанса.");
if (!Visible)
{
Show();
}
if (WindowState == FormWindowState.Minimized)
{
WindowState = FormWindowState.Normal;
}
// Небольшой трюк для надежного вывода окна на передний план.
TopMost = true;
Activate();
TopMost = false;
Focus();
}
private void ExitApplication()
{
_allowClose = true;
@@ -159,20 +191,65 @@ namespace MonsterMonitor.UI
private void AppendLog(LogEntry entry)
{
if (_console.Text.Length > 100000)
{
_console.ResetText();
}
System.Windows.Forms.Application.DoEvents();
if (InvokeRequired)
{
BeginInvoke(new Action<LogEntry>(AppendLog), entry);
return;
}
System.Windows.Forms.Application.DoEvents();
var wasNearBottom = IsConsoleNearBottom();
var firstVisibleLineBeforeAppend = GetFirstVisibleLine(_console);
_console.SelectionStart = _console.TextLength;
_console.SelectionLength = 0;
_console.SelectionColor = GetColor(entry.Level);
_console.AppendText($"[{entry.Timestamp:HH:mm:ss}] [{entry.Level}] {entry.Message}{Environment.NewLine}");
_console.SelectionColor = _console.ForeColor;
_console.ScrollToCaret();
System.Windows.Forms.Application.DoEvents();
if (wasNearBottom)
{
_console.ScrollToCaret();
return;
}
System.Windows.Forms.Application.DoEvents();
var firstVisibleLineAfterAppend = GetFirstVisibleLine(_console);
var linesToRestore = firstVisibleLineBeforeAppend - firstVisibleLineAfterAppend;
if (linesToRestore != 0)
{
SendMessage(_console.Handle, EmLineScroll, IntPtr.Zero, (IntPtr)linesToRestore);
}
System.Windows.Forms.Application.DoEvents();
}
private bool IsConsoleNearBottom()
{
if (_console.TextLength == 0)
{
return true;
}
var bottomLeftPoint = new Point(1, Math.Max(0, _console.ClientSize.Height - 1));
var lastVisibleCharIndex = _console.GetCharIndexFromPosition(bottomLeftPoint);
return lastVisibleCharIndex >= _console.TextLength - 2;
}
private static int GetFirstVisibleLine(RichTextBox richTextBox)
{
return SendMessage(richTextBox.Handle, EmGetFirstVisibleLine, IntPtr.Zero, IntPtr.Zero).ToInt32();
}
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
private void ConfigureUpdateTimer()
{
_updateTimer.Interval = (int)TimeSpan.FromHours(1).TotalMilliseconds;