Author Topic: [v1.8.3.12] Capture a Screenshot exception while editing an invalid path  (Read 1274 times)

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
When an invalid path is entered into the "Write screenshot to a specific file" field of the "Capture a Screenshot" action, and the ". . ." button is clicked to open the file picker, a "The path is not of a legal form." exception is thrown:

Quote
System.ArgumentException: The path is not of a legal form.
   at System.IO.Path.NewNormalizePath(String path, Int32 maxPathLength, Boolean expandShortPaths)
   at System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths)
   at System.IO.Path.GetFullPathInternal(String path)
   at System.IO.DirectoryInfo.Init(String path, Boolean checkHost)
   at System.IO.DirectoryInfo..ctor(String path)
   at ..()
   at ..(Object , EventArgs )
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at Telerik.WinControls.RadControl.OnClick(EventArgs e)
   at Telerik.WinControls.UI.RadButtonBase.buttonElement_Click(Object sender, EventArgs e)
   at Telerik.WinControls.RadElement.OnClick(EventArgs e)
   at Telerik.WinControls.UI.RadButtonItem.OnClick(EventArgs e)
   at Telerik.WinControls.UI.RadButtonElement.OnClick(EventArgs e)
   at Telerik.WinControls.RadElement.DoClick(EventArgs e)
   at Telerik.WinControls.RadElement.RaiseBubbleEvent(RadElement sender, RoutedEventArgs args)
   at Telerik.WinControls.RadItem.RaiseBubbleEvent(RadElement sender, RoutedEventArgs args)
   at Telerik.WinControls.RadElement.RaiseRoutedEvent(RadElement sender, RoutedEventArgs args)
   at Telerik.WinControls.RadElement.DoMouseUp(MouseEventArgs e)
   at Telerik.WinControls.ComponentInputBehavior.OnMouseUp(MouseEventArgs e)
   at Telerik.WinControls.RadControl.OnMouseUp(MouseEventArgs e)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at Telerik.WinControls.RadControl.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Strangely, while all other illegal characters seem to throw the "The path is not of a legal form." exception, using "|", '"', "<" or ">" will throw an "Illegal characters in path." exception instead.

The "Write screenshot into a folder" does not appear to have the issue (different picker though).

Neither path is checked for legality when "OK" is clicked to add or edit the action.

No exception is thrown when saving a screenshot with an invalid path set, as the "Write screenshot into a folder" fails and writes "Unable to capture screenshot: [Directory does not exist: []]" to the log, and the "Write screenshot to a specific file" option either writes the file to the working directory (usually the VoiceAttack installation directory) if it's an allowable file name, or fails and writes "Unable to capture screenshot: [Unable to save captured image: The specified path is invalid.]" to the log.


As a side note: If a valid path for "Write screenshot to a specific file" does not end in an extension, the output file will not have one either.
Perhaps this was done for flexibility in allowing users to specify a nonstandard extension, but for most users it may be useful that if no extension is explicitly specified, the default for the chosen file type could be added automatically.

Also, the action does not show the chosen path or filename in the action list, which could be useful as well.


EDIT: Fixed in v1.8.3.16; Path is now shown in the action list
« Last Edit: February 23, 2020, 05:01:48 PM by Pfeil »

Gary

  • Administrator
  • Hero Member
  • *****
  • Posts: 2832
Re: [v1.8.3.12] Capture a Screenshot exception while editing an invalid path
« Reply #1 on: February 21, 2020, 10:01:00 PM »
Thanks for the great explanation, Pfeil.

I've fixed the '...' bombing out.  Not a whole lot of checking is done for validity, as the user can use tokens (token names can have > in them).  It was crashing on the check to extract the directory name (before it gets to the picker).  Any failure at all will just resolve to the last picked directory.

I've added the extension to files that have not been given an extension (for user convenience) and touched up the action list.  Good suggestions ;)