From 677c6555e84fc5181bc09ead7aa32b0f373e893b Mon Sep 17 00:00:00 2001 From: Philipp Crocoll Date: Tue, 25 Mar 2025 12:31:35 +0100 Subject: [PATCH] this change fixes an issue with OneDrive: sometimes, the wrong DriveId was used to list the user's shares which was leading to an empty file browser screen. Also, files can be used if they are shared directly (not the parent folder) --- .../Io/OneDrive2FileStorage.cs | 48 ++++++++++++------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/src/Kp2aBusinessLogic/Io/OneDrive2FileStorage.cs b/src/Kp2aBusinessLogic/Io/OneDrive2FileStorage.cs index 37d97296..96ad7679 100644 --- a/src/Kp2aBusinessLogic/Io/OneDrive2FileStorage.cs +++ b/src/Kp2aBusinessLogic/Io/OneDrive2FileStorage.cs @@ -1148,30 +1148,46 @@ namespace keepass2android.Io }); } - string? driveId = parentPath.DriveId; - if ((string.IsNullOrEmpty(driveId)) && (drives?.Any() == true)) - { - driveId = drives.First().Id; - } - if (!CanListShares) return result; + - var sharedWithMeResponse = await client.Drives[driveId].SharedWithMe.GetAsSharedWithMeGetResponseAsync(); - - foreach (DriveItem i in sharedWithMeResponse?.Value ?? []) + try { - var oneDrive2ItemLocation = parentPath.BuildShare(i.RemoteItem.Id, i.RemoteItem.Name, i.RemoteItem.WebUrl, i.RemoteItem.ParentReference.DriveId); - FileDescription sharedFileEntry = new FileDescription() + string? driveId = parentPath.DriveId; + if (string.IsNullOrEmpty(driveId)) { - CanWrite = true, CanRead = true, DisplayName = i.Name, - IsDirectory = true, - Path = oneDrive2ItemLocation.ToString() - }; - result.Add(sharedFileEntry); + driveId = (await client.Me.Drive.GetAsync()).Id; + } + if ((string.IsNullOrEmpty(driveId)) && (drives?.Any() == true)) + { + driveId = drives.First().Id; + } + var sharedWithMeResponse = await client.Drives[driveId].SharedWithMe.GetAsSharedWithMeGetResponseAsync(); + + foreach (DriveItem i in sharedWithMeResponse?.Value ?? []) + { + var oneDrive2ItemLocation = parentPath.BuildShare(i.RemoteItem.Id, i.RemoteItem.Name, i.RemoteItem.WebUrl, i.RemoteItem.ParentReference.DriveId); + FileDescription sharedFileEntry = new FileDescription() + { + CanWrite = true, + CanRead = true, + DisplayName = i.Name, + IsDirectory = (i.Folder != null) || ((i.RemoteItem != null) && (i.RemoteItem.Folder != null)), + Path = oneDrive2ItemLocation.ToString() + }; + result.Add(sharedFileEntry); + + } } + catch (Exception e) + { + logDebug("Failed to list shares: " + e); + } + + return result; }