Bug 737056 - Replace NS_CompareVersions more intuitive C++ API called mozilla::Version. r=bsmedberg

This commit is contained in:
Peng Kang 2012-04-18 23:22:29 -04:00
Родитель 8fa603ffab
Коммит cc08b1a8bc
8 изменённых файлов: 133 добавлений и 31 удалений

Просмотреть файл

@ -2725,19 +2725,20 @@ nsPluginHost::ReadPluginInfo()
return rv;
// kPluginRegistryVersion
PRInt32 vdiff = NS_CompareVersions(values[1], kPluginRegistryVersion);
PRInt32 vdiff = mozilla::CompareVersions(values[1], kPluginRegistryVersion);
mozilla::Version version(values[1]);
// If this is a registry from some future version then don't attempt to read it
if (vdiff > 0)
return rv;
// If this is a registry from before the minimum then don't attempt to read it
if (NS_CompareVersions(values[1], kMinimumRegistryVersion) < 0)
if (version < kMinimumRegistryVersion)
return rv;
// Registry v0.10 and upwards includes the plugin version field
bool regHasVersion = NS_CompareVersions(values[1], "0.10") >= 0;
bool regHasVersion = (version >= "0.10");
// Registry v0.13 and upwards includes the architecture
if (NS_CompareVersions(values[1], "0.13") >= 0) {
if (version >= "0.13") {
char* archValues[6];
if (!reader.NextLine()) {
@ -2771,7 +2772,7 @@ nsPluginHost::ReadPluginInfo()
}
// Registry v0.13 and upwards includes the list of invalid plugins
bool hasInvalidPlugins = (NS_CompareVersions(values[1], "0.13") >= 0);
bool hasInvalidPlugins = (version >= "0.13");
if (!ReadSectionHeader(reader, "PLUGINS"))
return rv;
@ -2779,7 +2780,7 @@ nsPluginHost::ReadPluginInfo()
#if defined(XP_MACOSX)
bool hasFullPathInFileNameField = false;
#else
bool hasFullPathInFileNameField = (NS_CompareVersions(values[1], "0.11") < 0);
bool hasFullPathInFileNameField = (version < "0.11");
#endif
while (reader.NextLine()) {

Просмотреть файл

@ -230,7 +230,7 @@ ArchiveReader::VerifyProductInformation(const char *MARChannelID,
- 12.0a1 being older than 12.0
- 12.0 being older than 12.1a1 */
int versionCompareResult =
NS_CompareVersions(appVersion, productInfoBlock.productVersion);
mozilla::CompareVersions(appVersion, productInfoBlock.productVersion);
if (1 == versionCompareResult) {
rv = VERSION_DOWNGRADE_ERROR;
}

Просмотреть файл

@ -2931,8 +2931,8 @@ XREMain::XRE_mainInit(const nsXREAppData* aAppData, bool* aExitFlag)
SetAllocatedString(mAppData->maxVersion, "1.*");
}
if (NS_CompareVersions(mAppData->minVersion, gToolkitVersion) > 0 ||
NS_CompareVersions(mAppData->maxVersion, gToolkitVersion) < 0) {
if (mozilla::Version(mAppData->minVersion) > gToolkitVersion ||
mozilla::Version(mAppData->maxVersion) < gToolkitVersion) {
Output(true, "Error: Platform version '%s' is not compatible with\n"
"minVersion >= %s\nmaxVersion <= %s\n",
gToolkitVersion,

Просмотреть файл

@ -243,7 +243,7 @@ IsOlderVersion(nsILocalFile *versionFile, const char *appVersion)
if (strncmp(buf, kNull, sizeof(kNull) - 1) == 0)
return false;
if (NS_CompareVersions(appVersion, buf) > 0)
if (mozilla::Version(appVersion) > buf)
return true;
return false;

Просмотреть файл

@ -45,7 +45,7 @@ NS_IMETHODIMP
nsVersionComparatorImpl::Compare(const nsACString& A, const nsACString& B,
PRInt32 *aResult)
{
*aResult = NS_CompareVersions(PromiseFlatCString(A).get(),
*aResult = mozilla::CompareVersions(PromiseFlatCString(A).get(),
PromiseFlatCString(B).get());
return NS_OK;

Просмотреть файл

@ -388,7 +388,7 @@ CheckVersionFlag(const nsString& aFlag, const nsString& aData,
return false;
if (aResult != eOK) {
PRInt32 c = NS_CompareVersions(NS_ConvertUTF16toUTF8(aValue).get(),
PRInt32 c = mozilla::CompareVersions(NS_ConvertUTF16toUTF8(aValue).get(),
NS_ConvertUTF16toUTF8(testdata).get());
if ((c == 0 && comparison & COMPARE_EQ) ||
(c < 0 && comparison & COMPARE_LT) ||

Просмотреть файл

@ -306,10 +306,13 @@ CompareVP(VersionPartW &v1, VersionPartW &v2)
return wcscmp(v1.extraD, v2.extraD);
}
#endif
namespace mozilla {
#ifdef XP_WIN
PRInt32
NS_CompareVersions(const PRUnichar *A, const PRUnichar *B)
CompareVersions(const PRUnichar *A, const PRUnichar *B)
{
PRUnichar *A2 = wcsdup(A);
if (!A2)
@ -344,7 +347,7 @@ NS_CompareVersions(const PRUnichar *A, const PRUnichar *B)
#endif
PRInt32
NS_CompareVersions(const char *A, const char *B)
CompareVersions(const char *A, const char *B)
{
char *A2 = strdup(A);
if (!A2)
@ -377,3 +380,5 @@ NS_CompareVersions(const char *A, const char *B)
return result;
}
} // namespace mozilla

Просмотреть файл

@ -39,23 +39,119 @@
#define nsVersionComparator_h__
#include "nscore.h"
#ifdef XP_WIN
/**
* Compare two version strings.
*
* @see nsIVersionComparator
*/
PRInt32 NS_COM_GLUE
NS_CompareVersions(const PRUnichar *A, const PRUnichar *B);
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#if defined(XP_WIN) && !defined(UPDATER_NO_STRING_GLUE_STL)
#include <wchar.h>
#include "nsStringGlue.h"
#endif
/**
* Compare two version strings.
*
* @see nsIVersionComparator
*/
namespace mozilla {
PRInt32 NS_COM_GLUE
NS_CompareVersions(const char *A, const char *B);
CompareVersions(const char *A, const char *B);
#ifdef XP_WIN
PRInt32 NS_COM_GLUE
CompareVersions(const PRUnichar *A, const PRUnichar *B);
#endif
struct NS_COM_GLUE Version
{
Version(const char* versionString)
{
versionContent = strdup(versionString);
}
const char* ReadContent() const
{
return versionContent;
}
~Version()
{
free(versionContent);
}
bool operator< (const Version& rhs) const
{
return CompareVersions(versionContent, rhs.ReadContent()) == -1;
}
bool operator<= (const Version& rhs) const
{
return CompareVersions(versionContent, rhs.ReadContent()) < 1;
}
bool operator> (const Version& rhs) const
{
return CompareVersions(versionContent, rhs.ReadContent()) == 1;
}
bool operator>= (const Version& rhs) const
{
return CompareVersions(versionContent, rhs.ReadContent()) > -1;
}
bool operator== (const Version& rhs) const
{
return CompareVersions(versionContent, rhs.ReadContent()) == 0;
}
bool operator!= (const Version& rhs) const
{
return CompareVersions(versionContent, rhs.ReadContent()) != 0;
}
private:
char* versionContent;
};
#ifdef XP_WIN
struct NS_COM_GLUE VersionW
{
VersionW(const PRUnichar *versionStringW)
{
versionContentW = wcsdup(versionStringW);
}
const PRUnichar* ReadContentW() const
{
return versionContentW;
}
~VersionW()
{
free(versionContentW);
}
bool operator< (const VersionW& rhs) const
{
return CompareVersions(versionContentW, rhs.ReadContentW()) == -1;
}
bool operator<= (const VersionW& rhs) const
{
return CompareVersions(versionContentW, rhs.ReadContentW()) < 1;
}
bool operator> (const VersionW& rhs) const
{
return CompareVersions(versionContentW, rhs.ReadContentW()) == 1;
}
bool operator>= (const VersionW& rhs) const
{
return CompareVersions(versionContentW, rhs.ReadContentW()) > -1;
}
bool operator== (const VersionW& rhs) const
{
return CompareVersions(versionContentW, rhs.ReadContentW()) == 0;
}
bool operator!= (const VersionW& rhs) const
{
return CompareVersions(versionContentW, rhs.ReadContentW()) != 0;
}
private:
PRUnichar* versionContentW;
};
#endif
} // namespace mozilla
#endif // nsVersionComparator_h__