Google Drive
Again, Chiwda's solution showed me the right way. Google Drive needs to have an SQLite library available in order to read the path to the local folder.
My code:
private static string checkGetGoogleDriveLocation()
{
var appDataPath = Environment.GetFolderPath(
Environment.SpecialFolder.LocalApplicationData);
var dbPath = Path.Combine(appDataPath,
@"Google\Drive\user_default\sync_config.db");
if (!File.Exists(dbPath)) return null;
var tmp = dbPath + Guid.NewGuid();
File.CopyFile(dbPath, tmp);
var folderPath = tryGetFolderFromGoogleDriveDB(tmp);
if (string.IsNullOrEmpty(folderPath) || !Directory.Exists(folderPath)) return null;
File.Delete(folderPath);
return folderPath;
}
I've implemented the tryGetFolderFromGoogleDriveDB
function with the help of the "sqlite-net" NuGet package which is also available on GitHub:
private static string tryGetFolderFromGoogleDriveDB(string dbFilePath)
{
using (var conn = new SQLiteConnection(dbFilePath, SQLiteOpenFlags.ReadOnly))
{
var cmd = conn.CreateCommand(
@"select data_value from data where entry_key='local_sync_root_path'");
return cmd.ExecuteScalar<string>();
}
}
Please note that the sqlite-net package does P/Invoke the native sqlite3.dll file so you have to ensure that it is stored in the same folder as your executable you are using this code with.