Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
MaximumLineLength is no configurable, but beware it can impact the pe…
…rformance to change it to more then 20.000
  • Loading branch information
Hirogen committed Feb 23, 2025
commit 2a28d41ddcc1cb92f03be09e198623a213550a81
7 changes: 5 additions & 2 deletions src/LogExpert.Tests/JSONSaveTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using LogExpert.Config;

using Newtonsoft.Json;

using NUnit.Framework;

using System.IO;

namespace LogExpert.Tests
Expand All @@ -17,14 +20,14 @@ public void SaveOptionsAsJSON()
string settingsFile = configDir + "\\settings.json";

Settings settings = null;

Assert.DoesNotThrow(CastSettings);
Assert.That(settings, Is.Not.Null);
Assert.That(settings.alwaysOnTop, Is.True);

ConfigManager.Settings.alwaysOnTop = false;
ConfigManager.Save(SettingsFlags.All);

settings = null;
Assert.DoesNotThrow(CastSettings);

Expand Down
42 changes: 21 additions & 21 deletions src/LogExpert/Classes/Log/PositionAwareStreamReaderBase.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
using System;
using LogExpert.Config;
using LogExpert.Entities;

using System;
using System.IO;
using System.Text;
using LogExpert.Entities;

namespace LogExpert.Classes.Log
{
public abstract class PositionAwareStreamReaderBase : LogStreamReaderBase
{
#region Fields

private const int MAX_LINE_LEN = 20000;

private static readonly Encoding[] _preambleEncodings = { Encoding.UTF8, Encoding.Unicode, Encoding.BigEndianUnicode, Encoding.UTF32 };

private readonly BufferedStream _stream;
Expand All @@ -35,7 +35,7 @@ protected PositionAwareStreamReaderBase(Stream stream, EncodingOptions encodingO
_posIncPrecomputed = GetPosIncPrecomputed(usedEncoding);

_reader = new StreamReader(_stream, usedEncoding, true);

Position = 0;
}

Expand All @@ -54,7 +54,7 @@ public sealed override long Position
/*
* 1: Sometime commented (+Encoding.GetPreamble().Length)
* 2: Date 1.1 3207
* 3: Error Message from Piet because of Unicode-Bugs.
* 3: Error Message from Piet because of Unicode-Bugs.
* No Idea, if this is OK.
* 4: 27.07.09: Preamble-Length is now calculated in CT, because Encoding.GetPreamble().Length
* always delivers a fixed length (does not mater what kind of data)
Expand All @@ -72,7 +72,7 @@ public sealed override long Position

public sealed override bool IsBufferComplete => true;

protected static int MaxLineLen => MAX_LINE_LEN;
protected static int MaxLineLen => ConfigManager.Settings.preferences.MaxLineLength;

#endregion

Expand Down Expand Up @@ -149,11 +149,11 @@ protected void MovePosition(int offset)
private int DetectPreambleLengthAndEncoding(out Encoding detectedEncoding)
{
/*
UTF-8: EF BB BF
UTF-16-Big-Endian-Byteorder: FE FF
UTF-16-Little-Endian-Byteorder: FF FE
UTF-32-Big-Endian-Byteorder: 00 00 FE FF
UTF-32-Little-Endian-Byteorder: FF FE 00 00
UTF-8: EF BB BF
UTF-16-Big-Endian-Byteorder: FE FF
UTF-16-Little-Endian-Byteorder: FF FE
UTF-32-Big-Endian-Byteorder: 00 00 FE FF
UTF-32-Little-Endian-Byteorder: FF FE 00 00
*/

byte[] readPreamble = new byte[4];
Expand Down Expand Up @@ -205,17 +205,17 @@ private int GetPosIncPrecomputed(Encoding usedEncoding)
switch (usedEncoding)
{
case UTF8Encoding _:
{
return 0;
}
{
return 0;
}
case UnicodeEncoding _:
{
return 2;
}
{
return 2;
}
default:
{
return 1;
}
{
return 1;
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/LogExpert/Config/Preferences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ public class Preferences

public bool ShowErrorMessageAllowOnlyOneInstances { get; set; }

public int MaxLineLength { get; set; } = 20000;

#endregion
}
}
1 change: 1 addition & 0 deletions src/LogExpert/Controls/LogWindow/LogWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,7 @@ internal void ChangeMultifileMask()
internal void ToggleColumnFinder(bool show, bool setFocus)
{
_guiStateArgs.ColumnFinderVisible = show;

if (show)
{
columnComboBox.AutoCompleteMode = AutoCompleteMode.Suggest;
Expand Down
122 changes: 72 additions & 50 deletions src/LogExpert/Controls/LogWindow/LogWindowsPublic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@ public void LoadFile(string fileName, EncodingOptions encodingOptions)

try
{
_logFileReader = new LogfileReader(fileName, EncodingOptions, IsMultiFile, Preferences.bufferCount, Preferences.linesPerBuffer, _multiFileOptions);
_logFileReader.UseNewReader = !Preferences.useLegacyReader;
_logFileReader = new LogfileReader(fileName, EncodingOptions, IsMultiFile, Preferences.bufferCount, Preferences.linesPerBuffer, _multiFileOptions)
{
UseNewReader = !Preferences.useLegacyReader
};
}
catch (LogFileException lfe)
{
Expand Down Expand Up @@ -154,8 +156,10 @@ public void LoadFilesAsMulti(string[] fileNames, EncodingOptions encodingOptions
EncodingOptions = encodingOptions;
_columnCache = new ColumnCache();

_logFileReader = new LogfileReader(fileNames, EncodingOptions, Preferences.bufferCount, Preferences.linesPerBuffer, _multiFileOptions);
_logFileReader.UseNewReader = !Preferences.useLegacyReader;
_logFileReader = new LogfileReader(fileNames, EncodingOptions, Preferences.bufferCount, Preferences.linesPerBuffer, _multiFileOptions)
{
UseNewReader = !Preferences.useLegacyReader
};
RegisterLogFileReaderEvents();
_logFileReader.StartMonitoring();
FileName = fileNames[^1];
Expand Down Expand Up @@ -207,23 +211,25 @@ public string SavePersistenceData(bool force)

public PersistenceData GetPersistenceData()
{
PersistenceData persistenceData = new();
persistenceData.bookmarkList = _bookmarkProvider.BookmarkList;
persistenceData.rowHeightList = _rowHeightList;
persistenceData.multiFile = IsMultiFile;
persistenceData.multiFilePattern = _multiFileOptions.FormatPattern;
persistenceData.multiFileMaxDays = _multiFileOptions.MaxDayTry;
persistenceData.currentLine = dataGridView.CurrentCellAddress.Y;
persistenceData.firstDisplayedLine = dataGridView.FirstDisplayedScrollingRowIndex;
persistenceData.filterVisible = !splitContainerLogWindow.Panel2Collapsed;
persistenceData.filterAdvanced = !advancedFilterSplitContainer.Panel1Collapsed;
persistenceData.filterPosition = splitContainerLogWindow.SplitterDistance;
persistenceData.followTail = _guiStateArgs.FollowTail;
persistenceData.fileName = FileName;
persistenceData.tabName = Text;
persistenceData.sessionFileName = SessionFileName;
persistenceData.columnizerName = CurrentColumnizer.GetName();
persistenceData.lineCount = _logFileReader.LineCount;
PersistenceData persistenceData = new()
{
bookmarkList = _bookmarkProvider.BookmarkList,
rowHeightList = _rowHeightList,
multiFile = IsMultiFile,
multiFilePattern = _multiFileOptions.FormatPattern,
multiFileMaxDays = _multiFileOptions.MaxDayTry,
currentLine = dataGridView.CurrentCellAddress.Y,
firstDisplayedLine = dataGridView.FirstDisplayedScrollingRowIndex,
filterVisible = !splitContainerLogWindow.Panel2Collapsed,
filterAdvanced = !advancedFilterSplitContainer.Panel1Collapsed,
filterPosition = splitContainerLogWindow.SplitterDistance,
followTail = _guiStateArgs.FollowTail,
fileName = FileName,
tabName = Text,
sessionFileName = SessionFileName,
columnizerName = CurrentColumnizer.GetName(),
lineCount = _logFileReader.LineCount
};
_filterParams.isFilterTail = filterTailCheckBox.Checked; // this option doesnt need a press on 'search'

if (Preferences.saveFilters)
Expand All @@ -233,9 +239,11 @@ public PersistenceData GetPersistenceData()

foreach (FilterPipe filterPipe in _filterPipeList)
{
FilterTabData data = new();
data.persistenceData = filterPipe.OwnLogWindow.GetPersistenceData();
data.filterParams = filterPipe.FilterParams;
FilterTabData data = new()
{
persistenceData = filterPipe.OwnLogWindow.GetPersistenceData(),
filterParams = filterPipe.FilterParams
};
persistenceData.filterTabDataList.Add(data);
}
}
Expand Down Expand Up @@ -467,9 +475,11 @@ public void CellPainting(DataGridView gridView, int rowIndex, DataGridViewCellPa

if (bookmark.Text.Length > 0)
{
StringFormat format = new();
format.LineAlignment = StringAlignment.Center;
format.Alignment = StringAlignment.Center;
StringFormat format = new()
{
LineAlignment = StringAlignment.Center,
Alignment = StringAlignment.Center
};
Brush brush2 = new SolidBrush(Color.FromArgb(255, 190, 100, 0));
Font font = new("Courier New", Preferences.fontSize, FontStyle.Bold);
e.Graphics.DrawString("i", font, brush2, new RectangleF(r.Left, r.Top, r.Width, r.Height),
Expand Down Expand Up @@ -916,7 +926,7 @@ public void SetBookmarkFromTrigger(int lineNum, string comment)
{
return;
}
ParamParser paramParser = new ParamParser(comment);
ParamParser paramParser = new(comment);
try
{
comment = paramParser.ReplaceParams(line, lineNum, FileName);
Expand Down Expand Up @@ -1160,26 +1170,31 @@ public void CopyMarkedLinesToTab()
{
if (dataGridView.SelectionMode == DataGridViewSelectionMode.FullRowSelect)
{
List<int> lineNumList = new List<int>();
List<int> lineNumList = [];

foreach (DataGridViewRow row in dataGridView.SelectedRows)
{
if (row.Index != -1)
{
lineNumList.Add(row.Index);
}
}

lineNumList.Sort();
// create dummy FilterPipe for connecting line numbers to original window
// setting IsStopped to true prevents further filter processing
FilterPipe pipe = new FilterPipe(new FilterParams(), this);
pipe.IsStopped = true;
FilterPipe pipe = new(new FilterParams(), this)
{
IsStopped = true
};

WritePipeToTab(pipe, lineNumList, Text + "->C", null);
}
else
{
string fileName = Path.GetTempFileName();
FileStream fStream = new FileStream(fileName, FileMode.Append, FileAccess.Write, FileShare.Read);
StreamWriter writer = new StreamWriter(fStream, Encoding.Unicode);
FileStream fStream = new(fileName, FileMode.Append, FileAccess.Write, FileShare.Read);
StreamWriter writer = new(fStream, Encoding.Unicode);

DataObject data = dataGridView.GetClipboardContent();
string text = data.GetText(TextDataFormat.Text);
Expand All @@ -1199,6 +1214,7 @@ public void ChangeEncoding(Encoding encoding)
{
_logFileReader.ChangeEncoding(encoding);
EncodingOptions.Encoding = encoding;

if (_guiStateArgs.CurrentEncoding.IsSingleByte != encoding.IsSingleByte ||
_guiStateArgs.CurrentEncoding.GetPreamble().Length != encoding.GetPreamble().Length)
{
Expand All @@ -1216,9 +1232,11 @@ public void Reload()
{
SavePersistenceData(false);

_reloadMemento = new ReloadMemento();
_reloadMemento.currentLine = dataGridView.CurrentCellAddress.Y;
_reloadMemento.firstDisplayedLine = dataGridView.FirstDisplayedScrollingRowIndex;
_reloadMemento = new ReloadMemento
{
currentLine = dataGridView.CurrentCellAddress.Y,
firstDisplayedLine = dataGridView.FirstDisplayedScrollingRowIndex
};
_forcedColumnizerForLoading = CurrentColumnizer;

if (_fileNames == null || !IsMultiFile)
Expand Down Expand Up @@ -1587,7 +1605,7 @@ public void PatternStatisticSelectRange(PatternArgs patternArgs)
{
if (dataGridView.SelectionMode == DataGridViewSelectionMode.FullRowSelect)
{
List<int> lineNumList = new List<int>();
List<int> lineNumList = new();
foreach (DataGridViewRow row in dataGridView.SelectedRows)
{
if (row.Index != -1)
Expand Down Expand Up @@ -1615,19 +1633,21 @@ public void PatternStatisticSelectRange(PatternArgs patternArgs)

public void PatternStatistic(PatternArgs patternArgs)
{
PatternStatisticFx fx = new PatternStatisticFx(TestStatistic);
PatternStatisticFx fx = new(TestStatistic);
fx.BeginInvoke(patternArgs, null, null);
}

public void ExportBookmarkList()
{
SaveFileDialog dlg = new SaveFileDialog();
dlg.Title = "Choose a file to save bookmarks into";
dlg.AddExtension = true;
dlg.DefaultExt = "csv";
dlg.Filter = "CSV file (*.csv)|*.csv|Bookmark file (*.bmk)|*.bmk";
dlg.FilterIndex = 1;
dlg.FileName = Path.GetFileNameWithoutExtension(FileName);
SaveFileDialog dlg = new()
{
Title = "Choose a file to save bookmarks into",
AddExtension = true,
DefaultExt = "csv",
Filter = "CSV file (*.csv)|*.csv|Bookmark file (*.bmk)|*.bmk",
FilterIndex = 1,
FileName = Path.GetFileNameWithoutExtension(FileName)
};
if (dlg.ShowDialog() == DialogResult.OK)
{
try
Expand All @@ -1645,10 +1665,12 @@ public void ExportBookmarkList()

public void ImportBookmarkList()
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.Title = "Choose a file to load bookmarks from";
dlg.AddExtension = true;
dlg.DefaultExt = "csv";
OpenFileDialog dlg = new()
{
Title = "Choose a file to load bookmarks from",
AddExtension = true,
DefaultExt = "csv"
};
dlg.DefaultExt = "csv";
dlg.Filter = "CSV file (*.csv)|*.csv|Bookmark file (*.bmk)|*.bmk";
dlg.FilterIndex = 1;
Expand All @@ -1658,7 +1680,7 @@ public void ImportBookmarkList()
try
{
// add to the existing bookmarks
SortedList<int, Bookmark> newBookmarks = new SortedList<int, Bookmark>();
SortedList<int, Bookmark> newBookmarks = new();
BookmarkExporter.ImportBookmarkList(FileName, dlg.FileName, newBookmarks);

// Add (or replace) to existing bookmark list
Expand Down
Loading