#1393 Scale up Sensor column on resize & Log file rotation method (#1397)

* Add CSV file rotation method

Add a new option to choose how the csv file is being rotated.
Before it was everyday, which meant that we had to make sure the csv file was deleted before recording a new session.
Now by default it's set to "Per session" meaning anytime you start a new session it create a new CSV file.
Unless the daily method is used, in this case it will behave like before (1 file per day)

* Scale up the first TreeView column ("Sensor") on resize

The first ("Sensor") column being the most important and most likely the one that need the more space as hardware names can be pretty long.
I've changed so that the first column is the one scaling up when the tree view is being resized (instead of the last one)

* Change treeview column resize behaviour

I've made so that the separator a controlling the size of the column to the left instead of the right.
This make a lot easier to scale up the last column, but worth for the first one.
Thought the previous commit made it so that the first column size is resize by the total with of the tree view.
Sounds weird like that, but feel much more natural than before, and there is no overflow anymore.

* Fix typo in daily file rotation menu item tool tip

Co-authored-by: PhyxionNL <7643972+PhyxionNL@users.noreply.github.com>

* Fix requested changes

---------

Co-authored-by: PhyxionNL <7643972+PhyxionNL@users.noreply.github.com>
This commit is contained in:
hcabel
2024-08-06 13:42:58 +02:00
committed by GitHub
co-authored by PhyxionNL
parent eaf35a7ab9
commit 499ac0e214
4 changed files with 361 additions and 233 deletions
File diff suppressed because it is too large Load Diff
+52 -1
View File
@@ -112,8 +112,11 @@ public sealed partial class MainForm : Form
nodeTextBoxMax.DrawText += NodeTextBoxText_DrawText;
nodeTextBoxText.EditorShowing += NodeTextBoxText_EditorShowing;
foreach (TreeColumn column in treeView.Columns)
for (int i = 1; i < treeView.Columns.Count; i++)
{
TreeColumn column = treeView.Columns[i];
column.Width = Math.Max(20, Math.Min(400, _settings.GetValue("treeView.Columns." + column.Header + ".Width", column.Width)));
}
TreeModel treeModel = new();
_root = new Node(Environment.MachineName) { Image = EmbeddedResources.GetImage("computer.png") };
@@ -387,6 +390,9 @@ public sealed partial class MainForm : Form
},
_settings);
perSessionFileRotationMenuItem.Checked = _logger.FileRotationMethod == LoggerFileRotation.PerSession;
dailyFileRotationMenuItem.Checked = _logger.FileRotationMethod == LoggerFileRotation.Daily;
_sensorValuesTimeWindow.Changed += (sender, e) =>
{
TimeSpan timeWindow = TimeSpan.Zero;
@@ -1259,6 +1265,37 @@ public sealed partial class MainForm : Form
_selectionDragging = false;
}
private void TreeView_SizeChanged(object sender, EventArgs e)
{
int newWidth = treeView.Width;
for (int i = 1; i < treeView.Columns.Count; i++)
{
if (treeView.Columns[i].IsVisible)
newWidth -= treeView.Columns[i].Width;
}
treeView.Columns[0].Width = newWidth;
}
private void TreeView_ColumnWidthChanged(TreeColumn column)
{
int index = treeView.Columns.IndexOf(column);
int columnsWidth = 0;
foreach (TreeColumn treeColumn in treeView.Columns)
{
if (treeColumn.IsVisible)
columnsWidth += treeColumn.Width;
}
int nextColumnIndex = index + 1;
while (nextColumnIndex < treeView.Columns.Count && treeView.Columns[nextColumnIndex].IsVisible == false)
nextColumnIndex++;
if (nextColumnIndex < treeView.Columns.Count) {
int diff = treeView.Width - columnsWidth;
treeView.Columns[nextColumnIndex].Width = Math.Max(20, treeView.Columns[nextColumnIndex].Width + diff);
}
}
private void ServerPortMenuItem_Click(object sender, EventArgs e)
{
new PortForm(this).ShowDialog();
@@ -1268,4 +1305,18 @@ public sealed partial class MainForm : Form
{
new AuthForm(this).ShowDialog();
}
private void perSessionFileRotationMenuItem_Click(object sender, EventArgs e)
{
dailyFileRotationMenuItem.Checked = false;
perSessionFileRotationMenuItem.Checked = true;
_logger.FileRotationMethod = LoggerFileRotation.PerSession;
}
private void dailyFileRotationMenuItem_Click(object sender, EventArgs e)
{
dailyFileRotationMenuItem.Checked = true;
perSessionFileRotationMenuItem.Checked = false;
_logger.FileRotationMethod = LoggerFileRotation.Daily;
}
}
+29 -9
View File
@@ -15,7 +15,7 @@ namespace LibreHardwareMonitor.Utilities;
public class Logger
{
private const string FileNameFormat = "LibreHardwareMonitorLog-{0:yyyy-MM-dd}.csv";
private const string FileNameFormat = "LibreHardwareMonitorLog-{0:yyyy-MM-dd}{1}.csv";
private readonly IComputer _computer;
@@ -25,6 +25,8 @@ public class Logger
private ISensor[] _sensors;
private DateTime _lastLoggedTime = DateTime.MinValue;
public LoggerFileRotation FileRotationMethod = LoggerFileRotation.PerSession;
public Logger(IComputer computer)
{
_computer = computer;
@@ -80,9 +82,10 @@ public class Logger
}
}
private static string GetFileName(DateTime date)
private static string GetFileName(DateTime date, uint sessionNumber = 0)
{
return AppDomain.CurrentDomain.BaseDirectory + Path.DirectorySeparatorChar + string.Format(FileNameFormat, date);
return AppDomain.CurrentDomain.BaseDirectory + Path.DirectorySeparatorChar
+ string.Format(FileNameFormat, date, sessionNumber == 0 ? "" : "-" + sessionNumber);
}
private bool OpenExistingLogFile()
@@ -170,13 +173,30 @@ public class Logger
if (_lastLoggedTime + LoggingInterval - new TimeSpan(5000000) > now)
return;
if (_day != now.Date || !File.Exists(_fileName))
switch (FileRotationMethod)
{
_day = now.Date;
_fileName = GetFileName(_day);
if (!OpenExistingLogFile())
CreateNewLogFile();
case LoggerFileRotation.PerSession:
// Create file if it does not exist or the logging interval has passed (+ some margin)
if (!File.Exists(_fileName) || now - _lastLoggedTime > (LoggingInterval + TimeSpan.FromMilliseconds(100)))
{
uint sessionNumber = 1;
do {
_fileName = GetFileName(DateTime.Now, sessionNumber);
sessionNumber++;
} while (File.Exists(_fileName));
CreateNewLogFile();
}
break;
case LoggerFileRotation.Daily:
// Create a new file if the day has changed or the file does not exist
if (_day != now.Date || !File.Exists(_fileName))
{
_day = now.Date;
_fileName = GetFileName(_day);
if (!OpenExistingLogFile())
CreateNewLogFile();
}
break;
}
try
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LibreHardwareMonitor.Utilities
{
public enum LoggerFileRotation
{
// Keep the same file for the entire record session
PerSession = 0,
// Create a new file every day
Daily,
}
}