internal static MenuData GetData(BackgroundWorker worker, string path, int level) { MenuData menuData = new MenuData { RowDatas = new List <RowData>(), Validity = MenuDataValidity.Invalid, Level = level }; if (!worker.CancellationPending) { string[] directories = Array.Empty <string>(); try { directories = Directory.GetDirectories(path); Array.Sort(directories, new WindowsExplorerSort()); } catch (UnauthorizedAccessException ex) { Log.Warn($"path:'{path}'", ex); menuData.Validity = MenuDataValidity.NoAccess; } catch (IOException ex) { Log.Warn($"path:'{path}'", ex); } foreach (string directory in directories) { if (worker != null && worker.CancellationPending) { break; } bool hiddenEntry = false; if (FolderOptions.IsHidden(directory, ref hiddenEntry)) { continue; } RowData rowData = ReadRowData(directory, false); rowData.ContainsMenu = true; rowData.HiddenEntry = hiddenEntry; string resolvedLnkPath = string.Empty; rowData.ReadIcon(true, ref resolvedLnkPath); menuData.RowDatas.Add(rowData); } } if (!worker.CancellationPending) { string[] files = Array.Empty <string>(); try { files = Directory.GetFiles(path); Array.Sort(files, new WindowsExplorerSort()); } catch (UnauthorizedAccessException ex) { Log.Warn($"path:'{path}'", ex); menuData.Validity = MenuDataValidity.NoAccess; } catch (IOException ex) { Log.Warn($"path:'{path}'", ex); } foreach (string file in files) { if (worker != null && worker.CancellationPending) { break; } bool hiddenEntry = false; if (FolderOptions.IsHidden(file, ref hiddenEntry)) { continue; } RowData rowData = ReadRowData(file, false); string resolvedLnkPath = string.Empty; if (rowData.ReadIcon(false, ref resolvedLnkPath)) { rowData = ReadRowData(resolvedLnkPath, true, rowData); rowData.ContainsMenu = true; rowData.HiddenEntry = hiddenEntry; } menuData.RowDatas.Add(rowData); } } if (!worker.CancellationPending) { if (menuData.Validity == MenuDataValidity.Invalid) { menuData.Validity = MenuDataValidity.Valid; } } return(menuData); }