如何在没有API的情况下找到OneDrive(SkyDrive)和Google云端硬盘文件夹?

时间:2012-11-19 13:10:02

标签: vb.net google-drive-api onedrive

感谢这篇文章,

How do I programmatically locate my Dropbox folder using C#?

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

Vb.Net或C#解决方案没问题......

4 个答案:

答案 0 :(得分:2)

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

How do I programmatically locate my Google Drive folder using C#?

以下是我的三个主要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)))

答案 1 :(得分:1)

OneDrive / SkyDrive

solution of Chiwda导致我朝着正确的方向前进,但没有直接在我的机器上工作(Windows 8.1德语),因为注册表项不存在。

相反,这有效:

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的答案中尝试路径,而不是尝试我机器上的路径。

答案 2 :(得分:1)

Google云端硬盘

再次,Chiwda's solution向我展示了正确的方法。 Google云端硬盘需要有一个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;
}

我已在[{3}}的帮助下实施了tryGetFolderFromGoogleDriveDB功能,"sqlite-net" NuGet package也可以使用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>();
    }
}

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

答案 3 :(得分: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