TEST(Sample, IsDigits) { TEST_ASSERT_TRUE(IsDigits("10")); TEST_ASSERT_TRUE(IsDigits("01")); TEST_ASSERT_TRUE(IsDigits("17983472938729347293874239")); TEST_ASSERT_TRUE(IsDigits("1")); TEST_ASSERT_FALSE(IsDigits(0)); TEST_ASSERT_FALSE(IsDigits("")); TEST_ASSERT_FALSE(IsDigits("a")); TEST_ASSERT_FALSE(IsDigits("0x0")); TEST_ASSERT_FALSE(IsDigits("-10")); TEST_ASSERT_FALSE(IsDigits("1.0")); TEST_ASSERT_FALSE(IsDigits("1 0")); TEST_ASSERT_FALSE(IsDigits(".0")); }
// Compare two versions // int CAutoUpdater::CompareVersions(CString ver1, CString ver2) { int wVer1[4], wVer2[4]; int i; TCHAR *pVer1 = ver1.GetBuffer(256); TCHAR *pVer2 = ver2.GetBuffer(256); for (i=0; i<4; i++) { wVer1[i] = 0; wVer2[i] = 0; } // Get version 1 to DWORDs TCHAR *pToken = strtok(pVer1, _T(".")); if (pToken == NULL) { return -21; } i=2; while(pToken != NULL&&i>=0) { if (!IsDigits(pToken)) { return -21; // Error in structure, too many parameters } wVer1[i] = atoi(pToken); pToken = strtok(NULL, _T(".")); i--; } ver1.ReleaseBuffer(); // Get version 2 to DWORDs pToken = strtok(pVer2, _T(".")); if (pToken == NULL) { return -22; } i=2; while(pToken != NULL && i>=0) { if (!IsDigits(pToken)) { return -22; // Error in structure, too many parameters } wVer2[i] = atoi(pToken); pToken = strtok(NULL, _T(".")); i--; } ver2.ReleaseBuffer(); // Compare the versions for (i=2; i>=0; i--) { if (wVer1[i] > wVer2[i]) { return 1; // ver1 > ver 2 } else if (wVer1[i] < wVer2[i]) { return -1; } } return 0; // ver 1 == ver 2 }
/** * Determines whether the command line contains just the directory to apply the * update to (old command line) or if it contains the installation directory and * the directory to apply the update to. * * @param argc The argc value normally sent to updater.exe * @param argv The argv value normally sent to updater.exe * @param boolean True if the command line contains just the directory to apply * the update to */ static bool IsOldCommandline(int argc, LPWSTR *argv) { return argc == 4 && !wcscmp(argv[3], L"-1") || argc >= 4 && (wcsstr(argv[3], L"/replace") || IsDigits(argv[3])); }