3

感谢这篇文章,

如何使用 C# 以编程方式定位我的 Dropbox 文件夹?

我可以通过编程方式找到 Dropbox 文件夹。现在,如果不安装和使用各种 API,我该如何为 GoogleDrive 和 MS SkyDrive 做同样的事情?

Vb.Net 或 C# 解决方案都可以...

4

4 回答 4

2

OneDrive / SkyDrive

Chiwda的解决方案使我朝着正确的方向前进,但没有直接在我的机器上运行(Windows 8.1 German),因为注册表项不存在。

相反,这有效:

private static string getOneDriveFolderPath()
{
    var value1 = Registry.GetValue(
        @"HKEY_CURRENT_USER\Software\Microsoft\SkyDrive", 
        @"UserFolder", null);

    var path1 = value1 as string;
    if (path1 != null && Directory.Exist(path1)) return path1;

    var value2 = Registry.GetValue(
        @"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\SkyDrive",
        @"UserFolder", null);

    var path2 = value2 as string;
    if (path2 != null && Directory.Exists(path2)) return path2;

    var value3 = Registry.GetValue(
        @"HKEY_CURRENT_USER\Software\Microsoft\OneDrive",
        @"UserFolder", null);

    var path3 = value3 as string;
    if (path3 != null && Directory.Exists(path3)) return path3;

    return null;
}

代码首先尝试 Chiwda 答案中的路径,而不是尝试我机器上存在的路径。

于 2015-04-10T13:03:37.110 回答
2

我在这里找到了部分答案...

如何使用 C# 以编程方式定位我的 Google Drive 文件夹?

这是我的三个主要 Webfolder 服务的代码

Dim StoreFolder As String = ""
' Dropbox
Dim dbPath As String = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Dropbox\\host.db")
Dim lines() As String = System.IO.File.ReadAllLines(dbPath)
Dim dbBase64Text As Byte() = Convert.FromBase64String(lines(1))
StoreFolder = System.Text.ASCIIEncoding.ASCII.GetString(dbBase64Text)

' SkyDrive
StoreFolder = My.Computer.Registry.GetValue("HKEY_CURRENT_USER\Software\Microsoft\SkyDrive", "UserFolder", Nothing)

' Google Drive
Dim dbPath As String = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Google\\Drive\\sync_config.db")
File.Copy(dbPath, "temp.db", True)
StoreFolder = File.ReadAllText("temp.db", System.Text.Encoding.ASCII)
StoreFolder = StoreFolder.Substring(StoreFolder.IndexOf("local_sync_root_pathvalue") + 29)
StoreFolder = StoreFolder.Substring(0, StoreFolder.IndexOf(Char.ConvertFromUtf32(24)))
于 2012-12-04T12:44:26.863 回答
1

谷歌云端硬盘

再一次,Chiwda 的解决方案向我展示了正确的方法。Google Drive 需要有一个可用的 SQLite 库才能读取本地文件夹的路径。

我的代码:

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;
}

我已经在“sqlite-net”NuGet 包tryGetFolderFromGoogleDriveDB的帮助下实现了这个功能,该包也可以在 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>();
    }
}

请注意,sqlite-net 包执行 P/Invoke 本机sqlite3.dll文件,因此您必须确保它存储在与您正在使用此代码的可执行文件相同的文件夹中。

于 2015-04-10T13:34:35.317 回答
0

不完全是您将能够使用的,但您可以为 VB.net 对其进行逆向工程。我使用 VBA 将一些文档保存到用户 Dropbox 文件夹的解决方案。它会在默认安装位置查找它,如果找不到,则会提示输入文件夹。无论如何,大多数人都会离开默认位置 IMO,因此很少会错过它。从记忆中,SkyDrive 和 Google Drive 也遵循相同的默认位置模式,所以稍微调整一下应该能够找到所有这些模式。

Sub finddropbox()
Dim strOS, localdrive, dropboxfolder As String
Dim folderSelect As FileDialog
Dim objWMIService, colOperatingSystems, objOperatingSystem

strComputer = "."    
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")

For Each objOperatingSystem In colOperatingSystems
    strOS = objOperatingSystem.Caption
Next

If InStr(strOS, "XP") Then
    localdrive = Environ("USERPROFILE") & "\My Documents\"
Else
    localdrive = Environ("USERPROFILE")
End If

dropboxfolder = localdrive & "Dropbox\"
If Dir(dropboxfolder, vbDirectory) = vbNullString Then
    Set folderSelect = Application.FileDialog(msoFileDialogFolderPicker)
        With folderSelect
            .Title = "Select Dropbox Folder"
            .AllowMultiSelect = False
            .InitialFileName = Environ("SYSTEMDRIVE")
            If .Show = -1 Then
                dropboxfolder = .SelectedItems(1)
            End If
       End With
End If

Debug.Print dropboxfolder

End Sub
于 2013-12-19T12:00:11.920 回答