2

看起来有一个内置函数,VerCompare但它需要包含所有四个组件的字符串,例如 1.2.3.4。我没有尝试在 InstallScript 中进行字符串操作,并且希望有人已经拥有获取版本字符串并根据需要添加 .0 的代码。

4

1 回答 1

7

需要一些错误检查,但这里是一般的想法:

prototype NUMBER CompareVersions(STRING, STRING);
prototype STRING FormatVersion(STRING);

function NUMBER CompareVersions(leftVersion, rightVersion)
    STRING formattedLeftVersion, formattedRightVersion;
begin
    formattedLeftVersion = FormatVersion(leftVersion);
    formattedRightVersion = FormatVersion(rightVersion);

    return VerCompare(formattedLeftVersion, formattedRightVersion, VERSION);
end;

function STRING FormatVersion(version)
    STRING formattedVersion;
    LIST tokens;
    NUMBER count;
begin
    tokens = ListCreate(STRINGLIST);
    StrGetTokens(tokens, version, ".");
    count = ListCount(tokens);
    ListSetIndex(tokens, LISTLAST);
    while (count < 4)
        ListAddString(tokens, "0", AFTER);
        count = count + 1;
    endwhile;
    StrPutTokens(tokens, formattedVersion, ".", FALSE);
    ListDestroy(tokens);
    return formattedVersion;
 end;
于 2012-11-20T15:34:55.693 回答