Make sure window title and process name length is max 255 chars

This commit is contained in:
Jaex 2021-08-03 22:24:01 +03:00
parent eb0e88ee57
commit ffc0712276
2 changed files with 32 additions and 6 deletions

View file

@ -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;

View file

@ -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()
{