|
34 | 34 | using System.Linq;
|
35 | 35 | using System.Net;
|
36 | 36 | using System.Runtime.CompilerServices;
|
| 37 | +using System.Runtime.InteropServices; |
37 | 38 | using System.Text;
|
38 | 39 | using System.Text.Json;
|
39 | 40 | using System.Threading;
|
@@ -1478,10 +1479,9 @@ public async Task<int> EnumerateItemsFromStandardFolderAsync(string path, Cancel
|
1478 | 1479 | }
|
1479 | 1480 | else if (res == FileSystemStatusCode.Unauthorized)
|
1480 | 1481 | {
|
1481 |
| - //TODO: proper dialog |
1482 | 1482 | await DialogDisplayHelper.ShowDialogAsync(
|
1483 | 1483 | "AccessDenied".GetLocalizedResource(),
|
1484 |
| - "SubDirectoryAccessDenied".GetLocalizedResource()); |
| 1484 | + "AccessDeniedToFolder".GetLocalizedResource()); |
1485 | 1485 | return -1;
|
1486 | 1486 | }
|
1487 | 1487 | else if (res == FileSystemStatusCode.NotFound)
|
@@ -1531,13 +1531,13 @@ await DialogDisplayHelper.ShowDialogAsync(
|
1531 | 1531 | }
|
1532 | 1532 | else
|
1533 | 1533 | {
|
1534 |
| - (IntPtr hFile, WIN32_FIND_DATA findData) = await Task.Run(() => |
| 1534 | + (IntPtr hFile, WIN32_FIND_DATA findData, int errorCode) = await Task.Run(() => |
1535 | 1535 | {
|
1536 | 1536 | FINDEX_INFO_LEVELS findInfoLevel = FINDEX_INFO_LEVELS.FindExInfoBasic;
|
1537 | 1537 | int additionalFlags = FIND_FIRST_EX_LARGE_FETCH;
|
1538 | 1538 | IntPtr hFileTsk = FindFirstFileExFromApp(path + "\\*.*", findInfoLevel, out WIN32_FIND_DATA findDataTsk, FINDEX_SEARCH_OPS.FindExSearchNameMatch, IntPtr.Zero,
|
1539 | 1539 | additionalFlags);
|
1540 |
| - return (hFileTsk, findDataTsk); |
| 1540 | + return (hFileTsk, findDataTsk, hFileTsk.ToInt64() == -1 ? Marshal.GetLastWin32Error() : 0); |
1541 | 1541 | }).WithTimeoutAsync(TimeSpan.FromSeconds(5));
|
1542 | 1542 |
|
1543 | 1543 | var itemModifiedDate = DateTime.Now;
|
@@ -1584,6 +1584,17 @@ await DialogDisplayHelper.ShowDialogAsync(
|
1584 | 1584 | else if (hFile.ToInt64() == -1)
|
1585 | 1585 | {
|
1586 | 1586 | await EnumFromStorageFolderAsync(path, currentFolder, rootFolder, currentStorageFolder, cancellationToken);
|
| 1587 | + if (!filesAndFolders.Any()) |
| 1588 | + { |
| 1589 | + // https://learn.microsoft.com/en-us/windows/win32/debug/system-error-codes--0-499- |
| 1590 | + if (errorCode == 0x5) // ERROR_ACCESS_DENIED |
| 1591 | + { |
| 1592 | + await DialogDisplayHelper.ShowDialogAsync( |
| 1593 | + "AccessDenied".GetLocalizedResource(), |
| 1594 | + "AccessDeniedToFolder".GetLocalizedResource()); |
| 1595 | + return -1; |
| 1596 | + } |
| 1597 | + } |
1587 | 1598 | return 1;
|
1588 | 1599 | }
|
1589 | 1600 | else
|
|
0 commit comments