You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
143 lines
3.9 KiB
143 lines
3.9 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Sog
|
|
{
|
|
/// <summary>
|
|
/// xx.xx.code
|
|
/// main.min.buildcode
|
|
/// </summary>
|
|
public static class AppVersion
|
|
{
|
|
public const int VersionSegNum = 3;
|
|
|
|
public static string ToStringVersion(long version, int verSegNum = VersionSegNum)
|
|
{
|
|
if (verSegNum == 3)
|
|
{
|
|
long v1 = (version >> 32) & 0xffff;
|
|
long v2 = (version >> 16) & 0xffff;
|
|
long v3 = version & 0xffff;
|
|
return v1 + "." + v2 + "." + v3;
|
|
}
|
|
|
|
if (verSegNum == 4)
|
|
{
|
|
long v1 = version >> 48;
|
|
long v2 = (version >> 32) & 0x0000ffff;
|
|
long v3 = (version & 0xffff0000) >> 16;
|
|
long vCode = (version & 0x0000ffff);
|
|
return v1 + "." + v2 + "." + v3 + "." + vCode;
|
|
}
|
|
|
|
return "";
|
|
}
|
|
|
|
public static long ToIntVersion(string version, int verSegNum = VersionSegNum)
|
|
{
|
|
try
|
|
{
|
|
string[] arrayID = version.Split('.');
|
|
|
|
// 非法版本号
|
|
if (arrayID.Length < verSegNum || (verSegNum != 3 && verSegNum != 4))
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
long v1 = UInt16.Parse(arrayID[0]);
|
|
long v2 = UInt16.Parse(arrayID[1]);
|
|
long v3 = UInt16.Parse(arrayID[2]);
|
|
long iVersion;
|
|
|
|
if (arrayID.Length == 3)
|
|
{
|
|
iVersion = (v1 << 32) + (v2 << 16) + v3;
|
|
}
|
|
else
|
|
{
|
|
long vCode = UInt16.Parse(arrayID[3]);
|
|
iVersion = (v1 << 48) + (v2 << 32) + (v3 << 16) + vCode;
|
|
}
|
|
|
|
return iVersion;
|
|
}
|
|
catch(Exception)
|
|
{
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
public static int GetLastVersion(string version, int verSegNum = VersionSegNum)
|
|
{
|
|
try
|
|
{
|
|
string[] arrayID = version.Split('.');
|
|
|
|
// 非法版本号
|
|
if (arrayID.Length < verSegNum || verSegNum != 3)
|
|
{
|
|
TraceLog.Error("AppVersion.GetLastVersion error version {0}", version);
|
|
return 0;
|
|
}
|
|
|
|
int lastVersion = Int32.Parse(arrayID[2]);
|
|
return lastVersion;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
TraceLog.Error("AppVersion.GetLastVersion error version {0}", version);
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
public static ushort GetCodeFromVersion(long version, int verSegNum = VersionSegNum)
|
|
{
|
|
if (verSegNum == 3)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
long vCode = (version & 0x0000ffff);
|
|
return (ushort)vCode;
|
|
}
|
|
|
|
public static ushort GetMinFromVersion(long version, int verSegNum = VersionSegNum)
|
|
{
|
|
if (verSegNum == 3)
|
|
{
|
|
return (ushort)(version & 0xffff);
|
|
}
|
|
|
|
long v3 = (version & 0xffff0000) >> 16;
|
|
return (ushort)v3;
|
|
}
|
|
|
|
public static ushort GetMidFromVersion(long version, int verSegNum = VersionSegNum)
|
|
{
|
|
if (verSegNum == 3)
|
|
{
|
|
return (ushort)((version >> 16) & 0xffff);
|
|
}
|
|
|
|
long v2 = (version >> 32) & 0x0000ffff;
|
|
return (ushort)v2;
|
|
}
|
|
|
|
public static ushort GetMaxFromVersion(long version, int verSegNum = VersionSegNum)
|
|
{
|
|
if (verSegNum == 3)
|
|
{
|
|
return (ushort)((version >> 32) & 0xffff);
|
|
}
|
|
|
|
long v1 = version >> 48;
|
|
return (ushort)v1;
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|