版本信息提示
2017-08-09 16:38:07 访问(1402) 赞(0) 踩(0)
#region 版本信息提示
#region 获得Assembly的版本信息
/// <summary>
/// 获得Assembly的版本信息
/// </summary>
/// <param name="ass"></param>
/// <returns></returns>
protected string GetVersion(Assembly ass)
{
if (ass == null)
return "未知";
AssemblyName assName = ass.GetName();
if (assName == null)
return "未知";
if (assName.Version == null)
return "未知";
return assName.Version.ToString();
}
#endregion 获得Assembly的版本信息
#region 文件大小获得提示文字 - FileSizeGetText
/// <summary>
/// 获得文件大小的标签提示 - FileSizeGetLengthName +
/// </summary>
/// <param name="fileRate">文件倍数</param>
/// <returns></returns>
protected string FileSizeGetLengthName(int fileRate)
{
switch (fileRate)
{
case 0:
return "";
case 1:
return "KB";
case 2:
return "MB";
case 3:
return "GB";
case 4:
return "TB";
default:
return "TB";
}
}
/// <summary>
/// 文件大小获得提示文字 - FileSizeGetText +
/// </summary>
/// <param name="fileLength"></param>
/// <returns></returns>
protected string FileSizeGetText(long fileLength)
{
double dLen = (double)fileLength;
int fileRate = 0;
while (fileRate < 5)
{
if (dLen < 1024)
break;
++fileRate;
dLen = dLen / 1024;
}
dLen = Math.Round(dLen, 2);
return dLen.ToString() + FileSizeGetLengthName(fileRate);
}
#endregion 文件大小获得提示文字 - FileSizeGetText
#region 获得当前的版本信息
/// <summary>
/// 获得当前的版本信息
/// </summary>
/// <returns></returns>
protected string VersionInfoGet()
{
Assembly ass = this.GetType().Assembly;
string versionName = GetVersion(ass);
StringBuilder theResult = new StringBuilder();
theResult.AppendLine("版本号:" + versionName);
string str = Application.ExecutablePath;
FileInfo fi = new FileInfo(str);
if (!fi.Exists)
{
return theResult.ToString();
}
theResult.AppendLine("程序名称:" + fi.Name);
theResult.AppendLine("程序路径:" + fi.FullName);
theResult.AppendLine("程序大小:" + FileSizeGetText(fi.Length));
theResult.AppendLine("更新时间:" + fi.LastWriteTime.ToString("yyyy-MM-dd"));
return theResult.ToString();
}
#endregion 获得当前的版本信息
/// <summary>
/// 版本信息提示
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void 版本信息ToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
string str = VersionInfoGet();
MsgForm.MsgShowDialog(str);
}
catch (Exception err)
{
MessageBox.Show(err.Message);
}
}
#endregion 版本信息提示

上一条:
下一条:
相关评论
发表评论