From 86b1d718b039f4c80788522da576793d670acd47 Mon Sep 17 00:00:00 2001 From: Jaex Date: Sun, 12 Dec 2021 14:33:14 +0300 Subject: [PATCH] Added process names to history stats output --- ShareX.HistoryLib/Forms/HistoryForm.cs | 22 +++++++++++++++++----- ShareX/TaskMetadata.cs | 6 ++++-- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/ShareX.HistoryLib/Forms/HistoryForm.cs b/ShareX.HistoryLib/Forms/HistoryForm.cs index 4fc744e1e..81f73c255 100644 --- a/ShareX.HistoryLib/Forms/HistoryForm.cs +++ b/ShareX.HistoryLib/Forms/HistoryForm.cs @@ -332,6 +332,8 @@ private void UpdatePictureBox() private string OutputStats(HistoryItem[] historyItems) { + string empty = "(empty)"; + StringBuilder sb = new StringBuilder(); sb.AppendLine(Resources.HistoryItemCounts); @@ -360,9 +362,9 @@ private string OutputStats(HistoryItem[] historyItems) IEnumerable fileExtensions = historyItems. Where(x => !string.IsNullOrEmpty(x.FileName) && !x.FileName.EndsWith(")")). Select(x => Helpers.GetFileNameExtension(x.FileName)). - GroupBy(x => x). + GroupBy(x => string.IsNullOrWhiteSpace(x) ? empty : x). OrderByDescending(x => x.Count()). - Select(x => string.Format("{0} ({1})", x.Key, x.Count())); + Select(x => string.Format("[{0}] {1}", x.Count(), x.Key)); sb.AppendLine(string.Join(Environment.NewLine, fileExtensions)); @@ -370,11 +372,21 @@ private string OutputStats(HistoryItem[] historyItems) sb.AppendLine(Resources.HistoryStats_Hosts); IEnumerable hosts = historyItems. - GroupBy(x => x.Host). + GroupBy(x => string.IsNullOrWhiteSpace(x.Host) ? empty : x.Host). OrderByDescending(x => x.Count()). - Select(x => string.Format("{0} ({1})", x.Key, x.Count())); + Select(x => string.Format("[{0}] {1}", x.Count(), x.Key)); - sb.Append(string.Join(Environment.NewLine, hosts)); + sb.AppendLine(string.Join(Environment.NewLine, hosts)); + + sb.AppendLine(); + sb.AppendLine("Process names:"); // TODO: Translate + + IEnumerable processNames = historyItems. + GroupBy(x => string.IsNullOrWhiteSpace(x.TagsProcessName) ? empty : x.TagsProcessName). + OrderByDescending(x => x.Count()). + Select(x => string.Format("[{0}] {1}", x.Count(), x.Key)); + + sb.Append(string.Join(Environment.NewLine, processNames)); return sb.ToString(); } diff --git a/ShareX/TaskMetadata.cs b/ShareX/TaskMetadata.cs index 788769c5c..b0d5ef17a 100644 --- a/ShareX/TaskMetadata.cs +++ b/ShareX/TaskMetadata.cs @@ -31,6 +31,8 @@ namespace ShareX { public class TaskMetadata : IDisposable { + private const int WindowInfoMaxLength = 255; + public Bitmap Image { get; set; } private string windowTitle; @@ -43,7 +45,7 @@ public string WindowTitle } set { - windowTitle = value.Truncate(255); + windowTitle = value.Truncate(WindowInfoMaxLength); } } @@ -57,7 +59,7 @@ public string ProcessName } set { - processName = value.Truncate(255); + processName = value.Truncate(WindowInfoMaxLength); } }