Compare commits

..

2 Commits

Author SHA1 Message Date
copilot-swe-agent[bot]
19bba7f229 Fix illegal path characters error in InfoPanel with defensive programming
Co-authored-by: emako <24737061+emako@users.noreply.github.com>
2025-08-08 15:07:53 +00:00
copilot-swe-agent[bot]
7a05793bf7 Initial plan 2025-08-08 15:00:33 +00:00
12 changed files with 199 additions and 136 deletions

View File

@@ -81,7 +81,8 @@ public class BackgroundVisualHost : FrameworkElement
private readonly CreateContentFunction _createContent;
private readonly Action _invalidateMeasure;
private readonly AutoResetEvent _sync = new(false);
private readonly AutoResetEvent _sync =
new AutoResetEvent(false);
public ThreadedVisualHelper(
CreateContentFunction createContent,
@@ -124,9 +125,15 @@ public class BackgroundVisualHost : FrameworkElement
}
}
#region Private Fields
public ThreadedVisualHelper ThreadedHelper;
private HostVisual _hostVisual;
#endregion Private Fields
#region IsContentShowingProperty
/// <summary>
/// Identifies the IsContentShowing dependency property.
/// </summary>
@@ -156,6 +163,10 @@ public class BackgroundVisualHost : FrameworkElement
bvh.HideContentHelper();
}
#endregion IsContentShowingProperty
#region CreateContent Property
/// <summary>
/// Identifies the CreateContent dependency property.
/// </summary>
@@ -185,4 +196,6 @@ public class BackgroundVisualHost : FrameworkElement
bvh.CreateContentHelper();
}
}
#endregion CreateContent Property
}

View File

@@ -58,16 +58,50 @@ public partial class InfoPanel : UserControl
Dispatcher.BeginInvoke(new Action(() => image.Source = source));
});
var name = Path.GetFileName(path);
string name;
try
{
name = Path.GetFileName(path);
}
catch (ArgumentException)
{
// Handle invalid path characters gracefully
name = path;
}
catch (PathTooLongException)
{
// Handle path too long scenarios
name = path;
}
filename.Text = string.IsNullOrEmpty(name) ? path : name;
try
{
var last = File.GetLastWriteTime(path);
modDate.Text = string.Format(TranslationHelper.Get("InfoPanel_LastModified"),
last.ToString(CultureInfo.CurrentCulture));
}
catch (ArgumentException)
{
// Handle invalid path characters gracefully
modDate.Text = TranslationHelper.Get("InfoPanel_LastModified_Unavailable") ?? "Last modified: Unavailable";
}
catch (UnauthorizedAccessException)
{
// Handle access denied scenarios
modDate.Text = TranslationHelper.Get("InfoPanel_LastModified_Unavailable") ?? "Last modified: Unavailable";
}
catch (PathTooLongException)
{
// Handle path too long scenarios
modDate.Text = TranslationHelper.Get("InfoPanel_LastModified_Unavailable") ?? "Last modified: Unavailable";
}
Stop = false;
_ = Task.Run(() =>
{
try
{
if (File.Exists(path))
{
@@ -117,6 +151,22 @@ public partial class InfoPanel : UserControl
$"{totalSizeL.ToPrettySize(2)} {t}";
});
}
}
catch (ArgumentException)
{
// Handle invalid path characters gracefully
Dispatcher.Invoke(() => { totalSize.Text = "Size: Unavailable"; });
}
catch (UnauthorizedAccessException)
{
// Handle access denied scenarios
Dispatcher.Invoke(() => { totalSize.Text = "Size: Unavailable"; });
}
catch (PathTooLongException)
{
// Handle path too long scenarios
Dispatcher.Invoke(() => { totalSize.Text = "Size: Unavailable"; });
}
});
}
}