From ffc071227601e86a90fedcc8595e2a0f19d232f6 Mon Sep 17 00:00:00 2001 From: Jaex Date: Tue, 3 Aug 2021 22:24:01 +0300 Subject: [PATCH] Make sure window title and process name length is max 255 chars --- ShareX.HelpersLib/NameParser/NameParser.cs | 8 +++--- ShareX/ImageInfo.cs | 30 ++++++++++++++++++++-- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/ShareX.HelpersLib/NameParser/NameParser.cs b/ShareX.HelpersLib/NameParser/NameParser.cs index 973178809..777906045 100644 --- a/ShareX.HelpersLib/NameParser/NameParser.cs +++ b/ShareX.HelpersLib/NameParser/NameParser.cs @@ -84,9 +84,9 @@ public string Parse(string pattern) if (WindowText != null) { string windowText = WindowText.Trim().Replace(' ', '_'); - if (MaxTitleLength > 0 && windowText.Length > MaxTitleLength) + if (MaxTitleLength > 0) { - windowText = windowText.Remove(MaxTitleLength); + windowText = windowText.Truncate(MaxTitleLength); } sb.Replace(CodeMenuEntryFilename.t.ToPrefixString(), windowText); } @@ -322,9 +322,9 @@ public string Parse(string pattern) result = Helpers.GetValidURL(result); } - if (MaxNameLength > 0 && result.Length > MaxNameLength) + if (MaxNameLength > 0) { - result = result.Remove(MaxNameLength); + result = result.Truncate(MaxNameLength); } return result; diff --git a/ShareX/ImageInfo.cs b/ShareX/ImageInfo.cs index 9d022ce3d..dc4af9e1f 100644 --- a/ShareX/ImageInfo.cs +++ b/ShareX/ImageInfo.cs @@ -32,8 +32,34 @@ namespace ShareX public class ImageInfo : IDisposable { public Bitmap Image { get; set; } - public string WindowTitle { get; set; } - public string ProcessName { get; set; } + + private string windowTitle; + + public string WindowTitle + { + get + { + return windowTitle; + } + set + { + windowTitle = value.Truncate(255); + } + } + + private string processName; + + public string ProcessName + { + get + { + return processName; + } + set + { + processName = value.Truncate(255); + } + } public ImageInfo() {