示例#1
0
void MConfig::on_windowsDrvAddPushButton_clicked()
{
    QString infFileName = QFileDialog::getOpenFileName(this,
                                                       tr("Locate the Windows driver you want to add"), "/home", tr("Windows installation information file (*.inf)"));
    if (!infFileName.isEmpty())
    {
        // Search in the inf file the name of the .sys file
        QFile infFile(infFileName);
        infFile.open(QFile::ReadOnly|QFile::Text);

        QString s;
        bool found = false;
        bool exist = false;
        QStringList foundSysFiles;
        QDir sysDir(infFileName);
        sysDir.cdUp();
        while ((!infFile.atEnd())) {
            s = infFile.readLine();
            if (s.contains("ServiceBinary",Qt::CaseInsensitive)) {
                s = s.right(s.length() - s.lastIndexOf('\\'));
                s = s.remove('\\');
                s = s.remove('\n');
                found = true;
                if (this->checkSysFileExists(sysDir, s, Qt::CaseInsensitive)) {
                    exist = true;
                }
                else {
                    foundSysFiles << s;
                }
            }
        }
        infFile.close();

        if (found) {
            if (!exist) {
                QMessageBox::warning(0, QString(tr("*.sys file not found")), tr("The *.sys files must be in the same location as the *.inf file. %1 cannot be found").arg(foundSysFiles.join(", ")));
            }
            else {
                QString cmd = QString("ndiswrapper -i %1").arg(infFileName);
                system(cmd.toAscii());
                cmd = QString("ndiswrapper -ma");
                system(cmd.toAscii());
                on_windowsDrvDiagnosePushButton_clicked();
            }
        }
        else {
            QMessageBox::critical(0, QString(tr("sys file reference not found")).arg(infFile.fileName()), tr("The sys file for the given driver cannot be determined after parsing the inf file"));
        }
    }
}
示例#2
0
BOOL InfFile::UninstallAllInfFiles(
    const char *_pClassGUID,
    const char *_pClass,
    const char *_pProvider)
{
  Trace("Scan INF files .");

  DWORD size;

  if (!SetupGetInfFileList(NULL, INF_STYLE_WIN4, NULL, 0, &size)) {
    DWORD err = GetLastError();

    Trace("\n");

    ShowError(MB_OK|MB_ICONSTOP, err, "SetupGetInfFileList()");
    return FALSE;
  }

  Trace("...");

  size += 256; // possible new INF files were added since
  char *pList = (char *)LocalAlloc(LPTR, size*sizeof(pList[0]));

  if (pList) {
    if (!SetupGetInfFileList(NULL, INF_STYLE_WIN4, pList, size, NULL)) {
      DWORD err = GetLastError();

      Trace("\n");

      ShowError(MB_OK|MB_ICONSTOP, err, "SetupGetInfFileList(%lu)", (unsigned long)size);
      LocalFree(pList);
      return FALSE;
    }
  } else {
    Trace("\n");

    SetLastError(ERROR_NOT_ENOUGH_MEMORY);
    ShowLastError(MB_OK|MB_ICONSTOP, "LocalAlloc(%lu)", (unsigned long)size);
    return FALSE;
  }

  Trace(".");

  char windir[MAX_PATH];

  size = GetEnvironmentVariable("windir", windir, sizeof(windir)/sizeof(windir[0]));

  if (!size || size >= sizeof(windir)/sizeof(windir[0])) {
    DWORD err = !size ? GetLastError() : ERROR_BUFFER_OVERFLOW;

    ShowError(MB_OK|MB_ICONSTOP, err, "GetEnvironmentVariable(windir)");

    LocalFree(pList);
    return FALSE;
  }

  char *p = pList;
  int i;
  int m;

  p = pList;
  i = 0;

  do {
    i++;
    p += lstrlen(p) + 1;
  } while (*p);

  m = i/3;

  if (m == 0)
    m = 1;

  p = pList;
  i = 0;

  do {
    if (++i%m == 0)
      Trace(".");

    char infPath[MAX_PATH];

    if (SNPRINTF(infPath, sizeof(infPath)/sizeof(infPath[0]), "%s\\inf\\%s", windir, p) > 0) {
      InfFile infFile(infPath, NULL);

      if (infFile.Compare(_pClassGUID, _pClass, _pProvider, FALSE)) {
        int res;

        if (!Silent()) {
          res = ShowMsg(MB_YESNO,
            "The file %s possible should be deleted too.\n"
            "\n"
            "%s:\n"
            "  ClassGUID = %s\n"
            "  Class = %s\n"
            "  Provider = %s\n"
            "\n"
            "Would you like to delete it?\n",
            infFile.Path(),
            infFile.Path(),
            infFile.ClassGUID(FALSE),
            infFile.Class(FALSE),
            infFile.Provider(FALSE));
        } else {
          Trace("\nThe file %s possible should be deleted too\n"
                "  ClassGUID = %s\n"
                "  Class = %s\n"
                "  Provider = %s\n",
                infFile.Path(),
                infFile.ClassGUID(FALSE),
                infFile.Class(FALSE),
                infFile.Provider(FALSE));

          res = IDNO;
        }

        if (res == IDYES) {
          Trace("\n");
          UninstallInf(infFile.Path());
        }
      }
    }

    p += lstrlen(p) + 1;
  } while (*p);

  Trace(" done.\n");

  LocalFree(pList);

  return TRUE;
}