在驱动安装时,通过inf文件安装,碰到有些驱动包中可能有多个inf文件,不知道选择哪一个来安装。但一个个打开,会发现它们的版本其实好像不一样。因此想到读取每一个inf文件中的版本信息,与自己提前决定好的版本号相比较,匹配就选择那一个inf文件。
以下是匹配版本号的代码,用到了Qt的代码:
bool isSameVersion(const QString& strSrcPath, const QString& version)
{bool isSame = false;string strSrcPath2 = strSrcPath.toStdString();size_t len = strSrcPath2.length();wchar_t* bufSrcPath = new wchar_t[len + 1];MultiByteToWideChar(CP_ACP, 0, strSrcPath2.c_str(), len, bufSrcPath, len * sizeof(wchar_t));bufSrcPath[len] = 0;//获取inf文件中Version模块中的DriverVer字段值TCHAR srcVersion[100] = { 0 };GetPrivateProfileString(L"version", L"DriverVer", L"", srcVersion, sizeof(srcVersion), bufSrcPath);//01/20/2021,22.30.0.11 ;DATE HAS TO BE IN FOLLOWING FORMAT MM/DD/YYYYQString infVersion = QString::fromWCharArray(srcVersion);infVersion = infVersion.mid(0, infVersion.indexOf(";"));infVersion = infVersion.mid(infVersion.indexOf(",")+1);infVersion = infVersion.replace(" ", "");if (infVersion == version)isSame = true;delete[] bufSrcPath;bufSrcPath = nullptr;return isSame;
}