CnCrypt代码 之 一个好用的版本比对函数

void	GetVersion(LPWSTR lpVersion, int *arrVersion, int iVersionNum)
{
	int iVersion = 0;
	wstring sSubVersion(L"");
	memset(arrVersion, 0, sizeof(int)*iVersionNum);

	for (int iIndex = 0; iIndex < (int)wcslen(lpVersion); iIndex++)
	{
		if (lpVersion[iIndex] == '.' || lpVersion[iIndex] == ',')
		{
			sSubVersion = Trim(sSubVersion);
			arrVersion[iVersion++] = _wtoi(sSubVersion.c_str());
			sSubVersion = L"";
		}
		else
		{
			sSubVersion += lpVersion[iIndex];
		}
		if (iVersion == iVersionNum)
		{
			break;
		}
	}
	if (iVersion < iVersionNum && !sSubVersion.empty())
	{
		arrVersion[iVersion++] = _wtoi(sSubVersion.c_str());
	}
}


int		CompareVersion(LPWSTR lpVersion1, LPWSTR lpVersion2)
{
	int arrVersion1[4], arrVersion2[4];
	GetVersion(lpVersion1, arrVersion1, 4);
	GetVersion(lpVersion2, arrVersion2, 4);
	//比较两个版本
	return memcmp(arrVersion1, arrVersion2, sizeof(arrVersion1));
}

你可能感兴趣的:(CnCrypt代码 之 一个好用的版本比对函数)