Skip to content

Commit

Permalink
[BUG] Fix ArgumentException: Illegal characters in path (#171), versi…
Browse files Browse the repository at this point in the history
…on 1.0.17.43
  • Loading branch information
Hofknecht committed May 20, 2021
1 parent a972ae3 commit 027e514
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
17 changes: 14 additions & 3 deletions Business/Menus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,11 @@ internal static MenuData GetData(BackgroundWorker worker, string path, int level

try
{
if (FileLnk.IsNetworkRoot(path))
if (string.IsNullOrEmpty(path))
{
Log.Info($"path is null or empty");
}
else if (FileLnk.IsNetworkRoot(path))
{
directories = GetDirectoriesInNetworkLocation(path);
static string[] GetDirectoriesInNetworkLocation(string networkLocationRootPath)
Expand Down Expand Up @@ -352,13 +356,16 @@ static string[] GetDirectoriesInNetworkLocation(string networkLocationRootPath)
Log.Warn($"path:'{path}'", ex);
}

foreach (string directory in directories)
foreach (string directoryWithIllegalCharacters in directories)
{
if (worker != null && worker.CancellationPending)
{
break;
}

// https://github.com/Hofknecht/SystemTrayMenu/issues/171
string directory = directoryWithIllegalCharacters.Replace("\x00", string.Empty);

bool hiddenEntry = false;
if (FolderOptions.IsHidden(directory, ref hiddenEntry))
{
Expand All @@ -381,7 +388,11 @@ static string[] GetDirectoriesInNetworkLocation(string networkLocationRootPath)

try
{
if (!FileLnk.IsNetworkRoot(path))
if (string.IsNullOrEmpty(path))
{
Log.Info($"path is null or empty");
}
else if (!FileLnk.IsNetworkRoot(path))
{
files = Directory.GetFiles(path);
}
Expand Down
3 changes: 2 additions & 1 deletion Utilities/Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ internal static void ProcessStart(
catch (Exception ex)
{
if (ex is FileNotFoundException ||
ex is Win32Exception)
ex is Win32Exception ||
ex is InvalidOperationException)
{
Warn($"fileName:'{fileName}' arguments:'{arguments}'", ex);
MessageBox.Show(ex.Message);
Expand Down

0 comments on commit 027e514

Please sign in to comment.