Skip to content

Commit

Permalink
fix go to end when app log exceeds max size
Browse files Browse the repository at this point in the history
  • Loading branch information
digao-dalpiaz committed Jul 29, 2023
1 parent 1538446 commit b49a918
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
6 changes: 4 additions & 2 deletions DigaoDeskApp/Apps/DigaoApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ public class LogRecord
{
public DateTime Timestamp;
public string Text;
public int Size;
public LogType Type;
}

Expand Down Expand Up @@ -326,6 +327,7 @@ private void AddLog(string text, bool error, bool stop = false)
LogRecord r = new();
r.Timestamp = DateTime.Now;
r.Text = text;
r.Size = text.Length + Environment.NewLine.Length;
if (stop)
{
r.Type = LogType.STOP;
Expand All @@ -343,11 +345,11 @@ private void AddLog(string text, bool error, bool stop = false)
r.Type = LogType.INFO;
}
Logs.Add(r);
Interlocked.Add(ref _logSize, text.Length);
Interlocked.Add(ref _logSize, r.Size);

while (Logs.Count>1 && _logSize > Vars.Config.Apps.MaxLogSize)
{
Interlocked.Add(ref _logSize, -Logs[0].Text.Length);
Interlocked.Add(ref _logSize, -Logs[0].Size);
Logs.RemoveAt(0);
}

Expand Down
2 changes: 2 additions & 0 deletions DigaoDeskApp/Apps/FrmApps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,8 @@ private void AddRemainingLog(DigaoApplication app)
edLog.SelectionStart = 0;
edLog.SelectionLength = edLog.TextLength - Vars.Config.Apps.MaxLogSize;
edLog.SelectedText = "[...]";

edLog.SelectionStart = edLog.TextLength;
}
}
finally
Expand Down
6 changes: 6 additions & 0 deletions DigaoDeskApp/Controls/RichTextBoxEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,15 @@ public void SuspendPainting()
{
if (_Painting)
{
//--save position
_SuspendIndex = this.SelectionStart;
_SuspendLength = this.SelectionLength;
SendMessage(this.Handle, EM_GETSCROLLPOS, 0, ref _ScrollPoint);
//--

SendMessage(this.Handle, WM_SETREDRAW, 0, IntPtr.Zero);
_EventMask = SendMessage(this.Handle, EM_GETEVENTMASK, 0, IntPtr.Zero); // Stop sending of events

_Painting = false;
}
}
Expand All @@ -49,8 +53,10 @@ public void ResumePainting(bool restorePosition)
this.Select(_SuspendIndex, _SuspendLength);
SendMessage(this.Handle, EM_SETSCROLLPOS, 0, ref _ScrollPoint);
}

SendMessage(this.Handle, EM_SETEVENTMASK, 0, _EventMask); // turn on events
SendMessage(this.Handle, WM_SETREDRAW, 1, IntPtr.Zero);

_Painting = true;
this.Invalidate();
}
Expand Down
2 changes: 1 addition & 1 deletion DigaoDeskApp/Vars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace DigaoDeskApp
class Vars
{

public const string APP_VERSION = "1.10.5";
public const string APP_VERSION = "1.10.6";
public const string APP_REGKEY = @"SOFTWARE\DigaoDesk";

public const string GITHUB_LINK = "https://github.com/digao-dalpiaz/DigaoDesk";
Expand Down

0 comments on commit b49a918

Please sign in to comment.