Skip to content

Commit

Permalink
This repo is meant to help me explore what...
Browse files Browse the repository at this point in the history
Files.App.Utils.Cloud.GoogleDriveCloudDetector.GetProviders()

currently does, and what we want it to do.

In Files.App.Utils.Cloud.GoogleDriveCloudDetector.GetProviders(), first we get a
Sqlite database file at the following path:

"$($env:localappdata)/Google/DriveFS/root_preference_sqlite.db"

Then we copy that database to a temporary folder.

Then we run the following SQL queries against the copy:

SELECT * FROM roots

SELECT * FROM media WHERE fs_type=10

Then we traverse the ITEMs in each of the two response sets and create a new
GoogleDrive-type CloudProvider for each ITEM, with the CloudProvider.SyncFolder
property set to a (formatted) part of each ITEM's contents.

So far, in this scratch repo, I have confirmed that when Google Drive is mounted
as a folder, this Sqlite method for getting the mount paths DOESN'T work.

"When Google Drive is mounted as a folder" means when you have the "Google Drive
streaming location" setting set to "Folder" in Google Drive Preferences.

I have also confirmed that when Google Drive is mounted as a folder, the
registry method for getting the mount paths

( described here:
files-community/Files#15698 (comment) )

DOES work.

Next I will test the behavior of each method when Google Drive is mounted as a
dedicated drive.
  • Loading branch information
wharvex committed Jul 4, 2024
1 parent ae1b927 commit 92ea722
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 21 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Scratch Repo...
... for contributing to [Files](https://github.com/files-community/Files/).

Clone the repo, open the solution in Visual Studio, click "Start Without
Debugging" (empty green triangle button).

A window with a button that says "Click Me" should appear.

Click the button to see information about Google Drive "mount paths" on your
computer, gathered via different methods.
99 changes: 78 additions & 21 deletions WinUiTest/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,15 @@ public MainWindow()

private void myButton_Click(object sender, RoutedEventArgs e)
{
var appDataPath = UserDataPaths.GetDefault().LocalAppData;

const string googleDriveRegKeyName = @"Software\Google\DriveFS";

const string googleDriveRegValueName = "PerAccountPreferences";
var s = new StringBuilder();

using var googleDriveRegKey = Registry.CurrentUser.OpenSubKey(googleDriveRegKeyName);
// Sqlite approach to getting the mount paths.

var googleDriveRegValue = googleDriveRegKey?.GetValue(googleDriveRegValueName);
s.AppendLine("PATHS FROM SQLITE DATABASE\n");

var googleDriveRegValueJson = JsonDocument.Parse(googleDriveRegValue as string ?? "");
var localAppDataPath = UserDataPaths.GetDefault().LocalAppData;

var syncDbPath = GetDbPath(appDataPath);
var syncDbPath = GetDbPath(localAppDataPath);

SQLitePCL.Batteries_V2.Init();
using var database = new SqliteConnection($"Data Source='{syncDbPath}'");
Expand All @@ -60,23 +56,30 @@ private void myButton_Click(object sender, RoutedEventArgs e)
database
);

var s = new StringBuilder();

database.Open();

var reader = cmdRoot.ExecuteReader();
while (reader.Read())
{
s.AppendLine("hi");
}
TraverseDbResponses(cmdRoot, cmdMedia, s);

// Registry approach to getting the mount paths.

s.AppendLine("\nPATHS FROM REGISTRY\n");

var googleDriveRegValueJson = GetGoogleDriveRegValueJson(out var googleDriveRegValue);

s.AppendLine("LocalAppData: " + appDataPath);
s.AppendLine("google drive reg val: " + googleDriveRegValue);
s.AppendLine(
"google drive reg val json: "
+ googleDriveRegValueJson.RootElement.EnumerateObject().Count()
string.Join(
", ",
googleDriveRegValueJson
?.RootElement
.EnumerateObject()
.FirstOrDefault()
.Value.EnumerateArray()
.Select(item => item.GetProperty("value").GetProperty("mount_point_path"))
?? []
)
);
s.AppendLine("syncDbPath: " + syncDbPath);

s.AppendLine("\nRAW GOOGLE DRIVE REGISTRY VALUE\n\n" + googleDriveRegValue);

myButton.Content = s;
}
Expand All @@ -90,5 +93,59 @@ private string GetDbPath(string appDataPath)
.AsTask()
.Result.Path;
}

private JsonDocument? GetGoogleDriveRegValueJson(out object? googleDriveRegValue)
{
const string googleDriveRegKeyName = @"Software\Google\DriveFS";

const string googleDriveRegValueName = "PerAccountPreferences";

using var googleDriveRegKey = Registry.CurrentUser.OpenSubKey(googleDriveRegKeyName);

googleDriveRegValue = googleDriveRegKey?.GetValue(googleDriveRegValueName);

JsonDocument? googleDriveRegValueJson = null;
try
{
googleDriveRegValueJson = JsonDocument.Parse(googleDriveRegValue as string ?? "");
}
catch (JsonException je) { }

return googleDriveRegValueJson;
}

private void TraverseDbResponses(
SqliteCommand? cmdRoot,
SqliteCommand? cmdMedia,
StringBuilder s
)
{
var i = 0;
var reader = cmdRoot?.ExecuteReader();
while (reader?.Read() ?? false)
{
var path = reader["last_seen_absolute_path"].ToString();
if (string.IsNullOrWhiteSpace(path))
continue;
i++;
s.AppendLine("cmdRoot read: " + path);
}

reader = cmdMedia?.ExecuteReader();

while (reader?.Read() ?? false)
{
var path = reader["last_mount_point"].ToString();
if (string.IsNullOrWhiteSpace(path))
continue;
i++;
s.AppendLine("cmdMedia read: " + path);
}

if (i == 0)
{
s.AppendLine("<none>");
}
}
}
}
1 change: 1 addition & 0 deletions WinUiTest/WinUiTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<PublishProfile>win-$(Platform).pubxml</PublishProfile>
<UseWinUI>true</UseWinUI>
<EnableMsixTooling>true</EnableMsixTooling>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit 92ea722

Please sign in to comment.