private void 检查更新ToolStripMenuItem_Click(Object sender, EventArgs e) { var cfg = XConfig.Current; cfg.LastUpdate = DateTime.Now; cfg.Save(); try { var root = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var up = new Upgrade(); up.Log = XTrace.Log; up.Name = "XCoder"; up.Server = cfg.UpdateServer; up.UpdatePath = root.CombinePath(up.UpdatePath); if (up.Check()) { up.Download(); up.Update(); } else if (up.Links != null && up.Links.Length > 0) { MessageBox.Show("没有可用更新!最新{0}".F(up.Links[0].Time), "自动更新"); } else { MessageBox.Show("没有可用更新!", "自动更新"); } } catch (Exception ex) { XTrace.WriteException(ex); MessageBox.Show("更新失败!" + ex.Message, "自动更新"); } }
static void AutoUpdate() { //// 稍微等待一下,等主程序执行完成 //Thread.Sleep(2000); // 文件保存配置信息 var file = "Update.config"; // 注意路径,避免写入到脚本文件所在路径 var root = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); file = root.CombinePath(file); if (File.Exists(file)) { var last = File.ReadAllText(file).ToDateTime(); // 每天只更新一次 if (last >= DateTime.Now.Date) { return; } } File.WriteAllText(file, DateTime.Now.ToFullString()); var up = new Upgrade(); if (Config.Debug) { up.Log = XTrace.Log; } up.Name = "XScript"; //up.Server = "https://git.oschina.net/NewLifeX/XScript"; //up.Server = "http://www.newlifex.com/showtopic-369.aspx"; up.Server = "http://x.newlifex.com"; up.UpdatePath = root.CombinePath(up.UpdatePath); if (up.Check()) { up.Log = XTrace.Log; // 从github.com下载需要处理Url if (up.Links.Length > 0) { var url = up.Links[0].Url; if ((url.Contains("github.com") || url.Contains("git.")) && url.Contains("/blob/")) { up.Links[0].Url = url.Replace("/blob/", "/raw/"); } } up.Download(); if (!_CodeFile) { up.Update(); } else { // 留到脚本执行完成以后自动更新 _upgrade = up; } } }
private static void Update(Boolean isAsync) { if (!isAsync) { XTrace.WriteLine("自动更新!"); } if (Setting.Current.LastUpdateTime.Date < DateTime.Now.Date) { Setting.Current.LastUpdateTime = DateTime.Now; var root = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var up = new Upgrade { Log = XTrace.Log, Name = "SmartIot-Scada.ConfigTool", Server = "http://wlw.smartiot.cc/update/SmartIot-Tool.html" }; up.UpdatePath = root.CombinePath(up.UpdatePath); if (up.Check()) { up.Download(); if (!isAsync) { up.Update(); } else { // 留到执行完成以后自动更新 _upgrade = up; } } } }
static void AutoUpdate() { var set = Setting.Current; if (set.LastCheck.AddDays(set.UpdateDays) > DateTime.Now) { return; } set.LastCheck = DateTime.Now; set.Save(); // 注意路径,避免写入到脚本文件所在路径 var root = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var up = new Upgrade(); if (Config.Debug) { up.Log = XTrace.Log; } up.Name = "XScript"; //up.Server = "https://git.oschina.net/NewLifeX/XScript"; //up.Server = "http://www.newlifex.com/showtopic-369.aspx"; //up.Server = "http://x.newlifex.com"; up.UpdatePath = root.CombinePath(up.UpdatePath); if (up.Check()) { up.Log = XTrace.Log; // 从github.com下载需要处理Url if (up.Links.Length > 0) { var url = up.Links[0].Url; if ((url.Contains("github.com") || url.Contains("git.")) && url.Contains("/blob/")) { up.Links[0].Url = url.Replace("/blob/", "/raw/"); } } up.Download(); if (!_CodeFile) { up.Update(); } else { // 留到脚本执行完成以后自动更新 _upgrade = up; } } }
static void Update(Boolean isAsync) { if (!isAsync) { XTrace.WriteLine("自动更新!"); } var cfg = XConfig.Current; if (cfg.LastUpdate.Date < DateTime.Now.Date) { cfg.LastUpdate = DateTime.Now; var root = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var up = new Upgrade(); up.Log = XTrace.Log; up.Name = "XCoder"; up.Server = cfg.UpdateServer; up.UpdatePath = root.CombinePath(up.UpdatePath); if (up.Check()) { up.Download(); if (!isAsync) { up.Update(); } else { // 留到执行完成以后自动更新 _upgrade = up; } } cfg.Save(); } if (isAsync) { // 释放T4模版 var b = File.Exists("XCoder.tt"); var txt = Source.GetText("XCoder.tt"); txt = txt.Replace("{XCoderPath}", AppDomain.CurrentDomain.BaseDirectory); File.WriteAllText("XCoder.tt", txt); //if (!b) MessageBox.Show("新版本增加XCoder.tt,拷贝到类库项目里面。\r\nVS中修改文件内参数,右键执行自定义工具!", "提示"); } }
static void AutoUpdate() { //// 稍微等待一下,等主程序执行完成 //Thread.Sleep(2000); // 文件保存配置信息 var file = "Update.config"; // 注意路径,避免写入到脚本文件所在路径 var root = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); file = root.CombinePath(file); if (File.Exists(file)) { var last = File.ReadAllText(file).ToDateTime(); // 每天只更新一次 if (last >= DateTime.Now.Date) { return; } } File.WriteAllText(file, DateTime.Now.ToFullString()); var up = new Upgrade(); if (Config.Debug) { up.Log = XTrace.Log; } up.Name = "XScript"; up.Server = "http://www.newlifex.com/showtopic-369.aspx"; up.UpdatePath = root.CombinePath(up.UpdatePath); if (up.Check()) { up.Download(); if (!_CodeFile) { up.Update(); } else { // 留到脚本执行完成以后自动更新 _upgrade = up; } } }
private void CheckUpdate(Boolean auto) { if (auto) { XTrace.WriteLine("自动更新!"); } var up = new Upgrade(); up.DeleteBackup("."); var cfg = XConfig.Current; if (cfg.LastUpdate.Date < DateTime.Now.Date || !auto) { cfg.LastUpdate = DateTime.Now; cfg.Save(); var root = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); up.Log = XTrace.Log; up.Name = "XCoder"; up.Server = cfg.UpdateServer; up.UpdatePath = root.CombinePath(up.UpdatePath); if (up.Check()) { up.Download(); if (!auto || MessageBox.Show($"发现新版本{up.Link.Time},是否更新?", "自动更新", MessageBoxButtons.YesNo) == DialogResult.Yes) { var rs = up.Update(); MessageBox.Show("更新" + (rs ? "成功" : "失败"), "自动更新"); } } else if (!auto) { if (up.Link != null) { MessageBox.Show($"没有可用更新!最新{up.Link.Time}", "自动更新"); } else { MessageBox.Show("没有可用更新!", "自动更新"); } } } }
public void CopyAndReplace() { //Directory.Delete("./Update", true); var url = "http://x.newlifex.com/star/staragent50.zip"; var fileName = Path.GetFileName(url); //fileName = "Update".CombinePath(fileName).EnsureDirectory(true); var ug = new Upgrade { Log = XTrace.Log }; ug.Download(url, fileName); // 解压 var source = ug.Extract(ug.SourceFile); // 覆盖 var dest = "./updateTest"; ug.CopyAndReplace(source, dest); }