📄 updateutil.cs
字号:
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Threading;
using System.Net;
using System.IO;
using System.Data;
namespace WorkFlow.util
{
using System;
using System.Text;
using System.Runtime.InteropServices;
/// <summary>
/// 自动更新检查。
/// </summary>
public class UpdateUtil
{
protected static Form main = null;
private const string htmlWeiteUpateFlie = @"<html><body><b>版本号:</b>[{0}] <b>更新内容:</b>{1} <b>({2} {3})</b><br></body></html>";
private static readonly string hostPath = System.Environment.CurrentDirectory;
protected static void CheckAndPrompt()
{
string remoteVersion;
string localVersion;
remoteVersion = GetRemoteVersion();
localVersion = GetLocalVersion();
if (remoteVersion!=localVersion)
{
try
{
MessageBoxButtons buttons = MessageBoxButtons.OKCancel;
if (MessageBox.Show(main, "当前版本号:"+localVersion+"\r\n"+"需要下载的版本:"+remoteVersion+"\r\n请点击确定,按照说明按装新版本。", "请下载指定版本软件", buttons)==System.Windows.Forms.DialogResult.OK)
{
//当需要更新版本时,首先将path设置到c:根目录,以便启动IExplore可执行文件
System.Environment.CurrentDirectory = "c:/";
System.Diagnostics.Process.Start("IExplore.exe","http://61.135.133.75/StoreClientUpdate/workflow/update.htm");
}
main.Close();
}
finally
{
System.Environment.CurrentDirectory = hostPath;
}
}
}
public static void CheckVersion(Form _main)
{
main = _main;
Thread thread = new Thread(new System.Threading.ThreadStart(CheckAndPrompt));
thread.Start();
}
public static string GetRemoteVersion()
{
try
{
HttpWebRequest request = (HttpWebRequest)System.Net.WebRequest.Create("http://61.135.133.75/StoreClientUpdate/workflow/version.txt");
HttpWebResponse res = (HttpWebResponse)request.GetResponse();
System.IO.StreamReader reader = new System.IO.StreamReader(res.GetResponseStream());
byte[] buf = new byte[1024];
StringBuilder builder = new StringBuilder();
string line;
while (reader.Peek()>=0)
{
line = reader.ReadLine();
builder.Append(line);
}
return builder.ToString().Trim();
}
catch(System.Net.WebException ex)
{
System.Diagnostics.Trace.WriteLine(ex.Message);
}
return "null";
}
public static string GetLocalVersion()
{
string version = "null";
System.Reflection.Assembly[] assemblies = System.Threading.Thread.GetDomain().GetAssemblies();
foreach(System.Reflection.Assembly ass in assemblies)
{
System.Diagnostics.Trace.WriteLine(ass.GetName().Name);
if (ass.GetName().Name=="WorkFlow")
{
version = ass.GetName().Version.ToString();
break;
}
}
return version;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -