2

本质上,这是这里问题的 Qt/C++ 变体:

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

到目前为止我尝试过的内容如下

    QString gDrivePath =  QDesktopServices::storageLocation(QDesktopServices::DataLocation);
    gDrivePath += "\\Google\\Drive\\sync_config.db";
    bool result = QFile::copy(gDrivePath, "gdrive.db");

    QFile gdrivefile("gdrive.db");
    if(!gdrivefile.open(QIODevice::ReadOnly | QIODevice::Text)) {
        QMessageBox::information(0, "Google Drive path read error", gdrivefile.errorString());
    }

    QTextStream gin(&gdrivefile);
    gin.setCodec("ASCII");
    while(!gin.atEnd()) {
        qDebug() << gin.readLine().toLocal8Bit();
    }
    gdrivefile.close();

就像上面链接的问题中给出的那样,代码会复制 db 文件并尝试逐行读取它。唯一的问题是它正在从包含所需“local_sync_root_pathvalue”的文件中跳过一大块数据

有任何想法吗 ?

4

1 回答 1

1

我最终使用 qt 中的 sql 类来实现这一壮举。

代码:

    QString gDrivePath =  QDesktopServices::storageLocation(QDesktopServices::DataLocation);
    gDrivePath += "\\Google\\Drive\\sync_config.db";
    QFile::copy(gDrivePath, "gdrive.db");

    QFile gDriveFile("gdrive.db");
    if(!gDriveFile.open(QIODevice::ReadOnly)) {
        qDebug() << "Error in opening Google Drive File" << gDriveFile.errorString();
    }
    else {
        QSqlDatabase gDrivedb = QSqlDatabase::addDatabase("QSQLITE");
        gDrivedb.setDatabaseName("gdrive.db");
        if (gDrivedb.open()) {
            QSqlQuery query(gDrivedb);
            if (query.exec("select * from data where entry_key='local_sync_root_path'")) {
                 while (query.next()) {
                     QString gDrivePath = query.value(2).toString().remove(0,4);
                     qDebug() << "Google Drive at - " << gDrivePath;
                 }
            } else {
                qDebug() << "Error in querying Google Drive db" << query.lastError();
            }
        }
        else
            qDebug() << "Error in Opening  Google Drive db";
        gDriveFile.close();
    }
于 2013-09-06T07:05:32.173 回答