判断程序是否需要更新
        /// <summary>
/// 是否需要更新
/// </summary>
/// <param name="newestVersion"></param>
/// <returns></returns>
public bool ShouldUpdate(string newestVersion)
{
string currentVersion = GetAssemblyVersion();
int[] newVersionNums = ToIntArray(newestVersion.Split('.'));
int[] curVersionNums = ToIntArray(currentVersion.Split('.'));
for (int i = 0; i < Math.Min(newVersionNums.Length, curVersionNums.Length); i++)
{
if (newVersionNums[i] > curVersionNums[i])
return true;
if (newVersionNums[i] < curVersionNums[i])
return false;
}
return false;
}
private int[] ToIntArray(string[] strArray)
{
int[] ret = new int[strArray.Length];
for (int i = 0; i < ret.Length; i++)
ret[i] = int.Parse(strArray[i]);
return ret;
}
private string GetAssemblyVersion()
{
return System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
}
/// 是否需要更新
/// </summary>
/// <param name="newestVersion"></param>
/// <returns></returns>
public bool ShouldUpdate(string newestVersion)
{
string currentVersion = GetAssemblyVersion();
int[] newVersionNums = ToIntArray(newestVersion.Split('.'));
int[] curVersionNums = ToIntArray(currentVersion.Split('.'));
for (int i = 0; i < Math.Min(newVersionNums.Length, curVersionNums.Length); i++)
{
if (newVersionNums[i] > curVersionNums[i])
return true;
if (newVersionNums[i] < curVersionNums[i])
return false;
}
return false;
}
private int[] ToIntArray(string[] strArray)
{
int[] ret = new int[strArray.Length];
for (int i = 0; i < ret.Length; i++)
ret[i] = int.Parse(strArray[i]);
return ret;
}
private string GetAssemblyVersion()
{
return System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
}
                    
                
                
            
        
浙公网安备 33010602011771号