Exemplo n.º 1
0
// If the version of the ntfs.sys driver shows that the KB2731284 hotfix or a later update
// is installed, zeroing out data files is unnecessary. The file version numbers used below
// are taken from the Hotfix File Information at http://support.microsoft.com/kb/2731284.
bool isKB2731284OrLaterUpdateInstalled() {
    UINT pathBufferSize = GetSystemDirectoryA(NULL, 0);
    if (pathBufferSize == 0) {
        DWORD gle = GetLastError();
        warning() << "GetSystemDirectoryA failed with " << errnoWithDescription(gle);
        return false;
    }

    std::unique_ptr<char[]> systemDirectory(new char[pathBufferSize]);
    UINT systemDirectoryPathLen;
    systemDirectoryPathLen = GetSystemDirectoryA(systemDirectory.get(), pathBufferSize);
    if (systemDirectoryPathLen == 0) {
        DWORD gle = GetLastError();
        warning() << "GetSystemDirectoryA failed with " << errnoWithDescription(gle);
        return false;
    }

    if (systemDirectoryPathLen != pathBufferSize - 1) {
        warning() << "GetSystemDirectoryA returned unexpected path length";
        return false;
    }

    string ntfsDotSysPath = systemDirectory.get();
    if (ntfsDotSysPath.back() != '\\') {
        ntfsDotSysPath.append("\\");
    }
    ntfsDotSysPath.append("drivers\\ntfs.sys");
    DWORD fileVersionMS;
    DWORD fileVersionLS;
    if (getFileVersion(ntfsDotSysPath.c_str(), fileVersionMS, fileVersionLS)) {
        WORD fileVersionFirstNumber = HIWORD(fileVersionMS);
        WORD fileVersionSecondNumber = LOWORD(fileVersionMS);
        WORD fileVersionThirdNumber = HIWORD(fileVersionLS);
        WORD fileVersionFourthNumber = LOWORD(fileVersionLS);

        if (fileVersionFirstNumber == 6 && fileVersionSecondNumber == 1 &&
            fileVersionThirdNumber == 7600 && fileVersionFourthNumber >= 21296 &&
            fileVersionFourthNumber <= 21999) {
            return true;
        } else if (fileVersionFirstNumber == 6 && fileVersionSecondNumber == 1 &&
                   fileVersionThirdNumber == 7601 && fileVersionFourthNumber >= 22083 &&
                   fileVersionFourthNumber <= 22999) {
            return true;
        }
    }

    return false;
}
GpuCapabilitiesWindows::FileVersion GpuCapabilitiesWindows::getDriverVersion() {

    FileVersion fileVersion;
    fileVersion.versionString = "";

    // Try to get driver file version
    if ( GpuCapabilities::getVendor() == GPU_VENDOR_NVIDIA ) {

        // Get fileversion of NVIDIA OpenGL dll
        LDEBUG("Reading file version of NVIDIA driver dll ... ");
        FileVersion fileVersion;
        //TODO: windows vista stores the name of the dll in the registry.
        //      its better to get the name from there (cdoer)
        if (getOSVersion() == OS_WIN_VISTA)
            fileVersion = getFileVersion("nvoglv32.dll");
        else
            fileVersion = getFileVersion(DRIVER_DLL_NVIDIA);

        if (fileVersion.versionString.length() == 0) {
            LDEBUG("Reading NVIDIA driver version failed.");
        }
        else {
            LDEBUG("Reading driver version successful.");
            return fileVersion;
        }
    }
    else if (getVendor() == GPU_VENDOR_ATI) {

        // Get fileversion of ATI OpenGL dll
        LDEBUG("Reading file version of ATI driver dll ... ");
        FileVersion fileVersion = getFileVersion(DRIVER_DLL_ATI);
        if ( fileVersion.versionString.length() == 0 ) {
            LDEBUG("Reading ATI driver version failed.");
        }
        else {
            LDEBUG("Reading driver version successful.");
            return fileVersion;
        }
    }

#ifdef CGT_WITH_WMI
    // unknown graphics board vendor or reading NVIDIA/Ati driver version failed:
    // get driver version from WMI
    LDEBUG("Reading driver version from WMI ...");

    // Win32_VideoController class: http://msdn2.microsoft.com/en-us/library/aa394512.aspx
    std::string version = WMIqueryStr("Win32_VideoController", "DriverVersion");

    if (version.length() == 0) {
        LDEBUG("Failed to retrieve driver version from WMI.");
        LWARNING("Failed to detect driver version.");
    }
    else {
        fileVersion.versionString = version;
        // do not parse driver version string since it is not necessarily a file version string
        fileVersion.d1 = 0;
        fileVersion.d2 = 0;
        fileVersion.d3 = 0;
        fileVersion.d4 = 0;
        fileVersion.version = 0;
        LDEBUG("Successfully read driver version from WMI");
    }
    return fileVersion;

#else
    LDEBUG("Compiled without WMI support.");
    LWARNING("Failed to detect driver version.");
    return fileVersion;
#endif

}
Exemplo n.º 3
0
// 版本更新核心函数
void CUpdate::doUpdateVersion()
{
	if (m_updateState == (unsigned char)EUS_UPDATE_FINISHED && m_newestVersion)
		return;
	// 先初始化本地文件版本
	if (InitMainGauge() == false)
	{
		wxMessageBox(_T("版本服务器连接失败,请联系客服"), _T("系统提示"),wxOK);
		return;
	}
	bool processSuccess = true;

	// 获取更新服务器地址
	if (true)
	{			
		wxInputStream *inputStream = getRemoteVersionFile();
		if (!inputStream)
		{
			wxMessageBox(_T("版本服务器连接失败,请联系客服"), _T("系统提示"),wxOK);
			return;
		}
		wxXmlDocument doc;	// XML版本文件		
		if (doc.Load(*inputStream) == false)
		{			
			wxMessageBox(_T("版本文件解析失败,请稍后重试或联系客服"), _T("系统提示"),wxOK);
			return;		
		}

		// 文件更新
		wxXmlNode *root = doc.GetRoot();		
		wxXmlNode *baseRoot = NULL;					// 保存根节点
		wxXmlNode *subRoot = NULL;						// 文件节点
		wxString gameName;								// 游戏名称		
		baseRoot = root->GetChildren();
		root = root->GetChildren();
		m_updateState = EUS_UPDATE;	

		// 游戏版本节点
		while(root)
		{			
			// 判断Game节点的游戏名称是否是山海志
			root->GetAttribute(_("name"), &gameName);			
			if (root->GetName() == _("game") && gameName.IsSameAs(_("SHZ")))
			{
				// 判断当前的游戏版本,是否需要更新: 
				wxString fileName, fileVersion, fileUrl, updateType, fileLocal, realVersion;				
				realVersion = root->GetPropVal(_("version"), _(""));							// 获取该更新列表对应的游戏版本
				m_showVersion = root->GetPropVal(_("gameVersion"), m_showVersion);				// 获取远程服务器版本号
				long remoteVersion;
				realVersion.ToLong(&remoteVersion);						
				if (needUpdate(remoteVersion) == false)
				{
					root = root->GetNext();
					continue;
				}

				// 游戏版本更新,获取Game节点的子节点所有文件属性
				subRoot = root->GetChildren();				
				while (subRoot)
				{
					updateType = subRoot->GetName();
					// 判断节点类型,包括[file/dir/zip/dat],还有注释,如果是注释,则跳到下一轮。
					// TODO: 将zip文件自动解压
					if (updateType.IsSameAs(_("comment")))
					{
						subRoot = subRoot->GetNext();
						continue;
					}
					// 文件信息获取
					fileLocal = subRoot->GetPropVal(_("local"), wxEmptyString).Trim();								// 本地存放路径
					fileName = subRoot->GetPropVal(_("name"), wxEmptyString).Trim();								// 文件名称
					fileVersion = subRoot->GetPropVal(_("version"),wxEmptyString).Trim();							// 文件版本
					fileUrl = subRoot->GetPropVal(_("url"),wxEmptyString).Trim();									// 文件服务器下载位置

					// 下载链接地址处理
					unsigned char urlType = EUT_NONE;
					if (fileUrl.IsEmpty() == false)
					{							
						if (fileUrl.StartsWith(_("ftp://")))
						{
							urlType = EUT_FTP;
							fileUrl = fileUrl.substr(6);
						}
						else if(fileUrl.StartsWith(_("http://"))) 
						{
							urlType = EUT_HTTP;
						}
						else if (fileUrl.StartsWith(_("https://")))
						{
							urlType = EUT_HTTPS;
						}
						else
						{
							assert("Invalid url for update...");
						}
					}

					// 创建目录
					if (updateType.IsSameAs(_("dir")))
					{
						// 创建文件夹:
						wxString dir = m_skinDir + "\\" + fileName;
						if (!::wxDirExists(dir))
						{
							::wxMkDir(dir);
						}
					}
					// 文件更新
					else if (updateType.IsSameAs(_("exe")) || updateType.IsSameAs(_("dll")))
					{
						// 文件更新
						if (getFileVersion(fileName).IsSameAs(fileVersion.c_str()) == false || fileVersion.IsEmpty())
						{
							processSuccess &= getUrlFile(fileUrl, urlType, fileLocal, fileName);
						}
					}
					// rar、dat 或者其它文件,立即更新覆盖
					else
					{
						if (fileUrl.IsEmpty()==false && urlType != EUT_NONE)
							processSuccess &= getUrlFile(fileUrl, urlType, fileLocal, fileName);
					}
					wxThread::Sleep(1);
					// 一个更新子块处理完成,处理下一个
					subRoot = subRoot->GetNext();
				}
			}
			// 不是山海志游戏的节点模块,或者是那个模块处理完了		
			root = root->GetNext();
		}
		// delete inputStream;
	}

	// 版本更新完成
	m_updateState = EUS_UPDATE_FINISHED;		
	if (m_updateVersion > 0 && processSuccess == true)
	{// 版本完全更新成功
		wxMessageBox(_T("游戏版本更新成功完成"),_T("版本更新"));
		setConfig(_("SYSTEM/version"), wxString::Format(wxT("%i"),m_updateVersion));
		setConfig(_("SYSTEM/gameVersion"), m_showVersion);
	}
}