/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { //myPlayer.Update(gameTime); switch (myState) { case State.LOAD: myLoad.Update(gameTime); break; case State.MENU: myMenu.Update(gameTime); break; case State.PREPARE: myPrepare.Update(gameTime); break; case State.PLAY: myMapManager.Update(gameTime); break; case State.RESET: myReset = new Reset(); break; case State.UPGRADE: myUpgrade.Update(gameTime); break; } base.Update(gameTime); }
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("没有可用更新!", "自动更新"); } } } }
/// <summary>探测并安装星尘代理</summary> /// <param name="url">zip包下载源</param> /// <param name="version">版本号</param> /// <param name="target">目标目录</param> public Boolean ProbeAndInstall(String url = null, String version = null, String target = null) { //if (url.IsNullOrEmpty()) throw new ArgumentNullException(nameof(url)); if (url.IsNullOrEmpty()) { var set = NewLife.Setting.Current; if (Environment.Version.Major >= 5) { url = set.PluginServer.CombinePath("staragent50.zip"); } else if (Environment.Version.Major >= 4) { url = set.PluginServer.CombinePath("staragent45.zip"); } else { url = set.PluginServer.CombinePath("staragent31.zip"); } } // 尝试连接,获取版本 try { var info = GetInfo(); // 比目标版本高,不需要安装 if (String.Compare(info.Version, version) >= 0) { return(true); } if (!info.FileName.IsNullOrEmpty()) { info.FileName = info.FileName.TrimEnd(" (deleted)"); } if (target.IsNullOrEmpty()) { target = Path.GetDirectoryName(info.FileName); } XTrace.WriteLine("StarAgent在用版本 v{0},低于目标版本 v{1}", info.Version, version); } catch (Exception ex) { XTrace.WriteLine("没有探测到StarAgent,{0}", ex.GetTrue().Message); } if (target.IsNullOrEmpty()) { // 在进程中查找 var p = Process.GetProcesses().FirstOrDefault(e => e.ProcessName == "StarAgent"); if (p != null) { try { target = Path.GetDirectoryName(p.MainModule.FileName); } catch { target = Path.GetDirectoryName(p.MainWindowTitle); } XTrace.WriteLine("发现进程StarAgent,ProcessId={0},target={1}", p.Id, target); } } // 准备安装,甭管是否能够成功重启,先覆盖了文件再说 { if (target.IsNullOrEmpty()) { target = "..\\staragent"; } target = target.GetFullPath(); target.EnsureDirectory(false); XTrace.WriteLine("目标:{0}", target); var ug = new Upgrade { SourceFile = Path.GetFileName(url).GetFullPath(), DestinationPath = target, Log = XTrace.Log, }; XTrace.WriteLine("下载:{0}", url); var client = new HttpClient(); client.DownloadFileAsync(url, ug.SourceFile).Wait(); ug.Update(); File.Delete(ug.SourceFile); } { // 在进程中查找 var info = Info; var p = info != null && info.ProcessId > 0 ? Process.GetProcessById(info.ProcessId) : Process.GetProcesses().FirstOrDefault(e => e.ProcessName == "StarAgent"); // 在Linux中设置执行权限 var fileName = info?.FileName ?? target.CombinePath(Runtime.Linux ? "StarAgent" : "StarAgent.exe"); if (File.Exists(fileName) && Runtime.Linux) { Process.Start("chmod", $"+x {fileName}"); } // 重启目标 if (p != null) { try { p.Kill(); } catch (Win32Exception) { } catch (Exception ex) { XTrace.WriteException(ex); } } if (File.Exists(fileName)) { if (info?.Arguments == "-s") { Process.Start(fileName, "-start"); } else { var si = new ProcessStartInfo(fileName, "-run") { WorkingDirectory = Path.GetDirectoryName(fileName), UseShellExecute = true }; Process.Start(si); } } } return(true); }
protected override void Update(GameTime gameTime) { float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds; if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } _scrollingBackground.Update(elapsed * 100); if (_gameOver && !_playGameOver) { _upgrade.GameOver = true; _ship.GameOver = true; _spaceInvadersBoard.GameOver = true; _playGameOver = true; } if (_playGameOver && _play) { AssetsManager.GameOver.Play(); _playGameOver = false; _play = false; } else if (_playYouWin && _play) { AssetsManager.YouWin.Play(); _playYouWin = false; _play = false; } if (_spaceInvadersBoard.SpaceInvaderList.Count <= 0) { _playYouWin = true; } _spaceInvadersBoard.Update(gameTime); _ship.Update(gameTime); _upgrade.Update(gameTime); foreach (SpaceInvaderObject SpaceInvader in _spaceInvadersBoard.SpaceInvaderList) { SpaceInvader.UpdateShipPosition(_ship.ShipPosition); //Invader hits ship if (SpaceInvader.HasWeapon) { foreach (InvaderBullet Bullet in SpaceInvader.InvaderWeapon.Bullets) { if (CheckCollision(Bullet, _ship)) { Bullet.Hit = true; _ship.Lives--; } } } //Game Over if (CheckCollision(_ship, SpaceInvader) || _ship.Lives <= 0) { _gameOver = true; } } for (int i = 0; i < _upgrade.LaserUpgrades.Count; i++) { if (CheckCollision(_upgrade.LaserUpgrades[i], _ship)) { _ship.Weapon.WeaponState = WeaponState.Laser; AssetsManager.UpgradeSoundEffect.Play(); _upgrade.LaserUpgrades[i].DisposeFromList(); _upgrade.LaserUpgrades.RemoveAt(i); } } for (int i = 0; i < _upgrade.RocketUpgrades.Count; i++) { if (CheckCollision(_upgrade.RocketUpgrades[i], _ship)) { _ship.Weapon.WeaponState = WeaponState.Rocket; AssetsManager.UpgradeSoundEffect.Play(); _upgrade.RocketUpgrades[i].DisposeFromList(); _upgrade.RocketUpgrades.RemoveAt(i); } } if (_ship.Weapon.WeaponState == WeaponState.Normal) { foreach (NormalBullet Bullet in _ship.Weapon.NormalWeapon.Bullets) { foreach (SpaceInvaderObject SpaceInvader in _spaceInvadersBoard.SpaceInvaderList) { if (CheckCollision(Bullet, SpaceInvader)) { SpaceInvader.Hit = true; Bullet.Hit = true; } } } } else if (_ship.Weapon.WeaponState == WeaponState.Rocket) { foreach (RocketBullet Bullet in _ship.Weapon.RocketWeapon.Bullets) { foreach (SpaceInvaderObject SpaceInvader in _spaceInvadersBoard.SpaceInvaderList) { if (CheckCollision(Bullet, SpaceInvader)) { SpaceInvader.Hit = true; Bullet.Hit = true; } } } } else if (_ship.Weapon.WeaponState == WeaponState.Laser) { foreach (LaserBullet Bullet in _ship.Weapon.LaserWeapon.Bullets) { foreach (SpaceInvaderObject SpaceInvader in _spaceInvadersBoard.SpaceInvaderList) { if (CheckCollision(Bullet, SpaceInvader)) { SpaceInvader.Hit = true; Bullet.Hit = true; } } } } base.Update(gameTime); }
//切换任务 private void ChangeTask() { if (TaskChange.Equals("1")) { overTimeCount = 0; ConfigCore.InitWorker(""); CustomPath = ConfigCore.GetCustomPath(); if (CustomPath != "") { LogCore.Write($"切换任务:{CustomPath}"); } if (IsVoteTask() && IsAutoVote) { string projectName = ConfigCore.GetAutoVote("ProjectName"); string drop = ""; try { drop = IniReadWriter.ReadIniKeys("Command", "drop", "./handler.ini"); } catch (Exception) { } if (drop != projectName) { IniReadWriter.WriteIniKeys("Command", "drop", "", "./handler.ini"); } } } if (TaskName.Equals(TASK_SYS_WAIT_ORDER)) //待命 { NetCore.DisConnect(); TaskName = ConfigCore.GetTaskName(); if (TaskName.Equals(TASK_SYS_WAIT_ORDER)) { WaitOrder(); } } else if (TaskName.Equals(TASK_SYS_NET_TEST)) //网络TEST { NetCore.NetCheck(); if (Net.IsOnline()) { NetCore.DisConnect(); WaitOrder(); } } else if (TaskName.Equals(TASK_SYS_SHUTDOWN)) //关机 { WaitOrder(); Process.Start("shutdown.exe", "-s -t 0"); Form1.MainClose(); } else if (TaskName.Equals(TASK_SYS_RESTART)) //重启 { string computerRename = ConfigCore.GetComputerRename(); if (!StringUtil.isEmpty(computerRename)) { Computer.apiSetComputerNameEx(5, computerRename + "-" + ConfigCore.Sort); } WaitOrder(); Process.Start("shutdown.exe", "-r -t 0"); Form1.MainClose(); } else if (TaskName.Equals(TASK_SYS_UPDATE)) //升级 { WaitOrder(); Upgrade.Update(); Form1.MainClose(); } else if (TaskName.Equals(TASK_SYS_CLEAN)) //清理 { WaitOrder(); FileUtil.DeleteFolder(PathCore.WorkingPath + "\\投票项目"); } else if (IsVoteTask()) //投票 { NetCore.NetCheck(); if (CustomPath.Equals("")) { WaitOrder(); TaskChangeProcess(); return; } if (TaskChange.Equals("1")) { if (CustomPath.LastIndexOf("\\") + 1 <= CustomPath.Length && CustomPath.Substring(CustomPath.LastIndexOf("\\") + 1) == "vote.exe") { ProgressCore.StartProcess(CustomPath.Substring(0, CustomPath.Length - 9) + @"\启动九天.bat"); TaskName = TASK_VOTE_JIUTIAN; } else { IniReadWriter.WriteIniKeys("setsoft", "ghid", ConfigCore.Id, "c:\\gonghao.ini"); ProgressCore.StartProcess(CustomPath); TaskName = TASK_VOTE_PROJECT; IntPtr hwnd0, hwnd1, hwnd2, hwnd3, hwnd4; do { hwnd0 = HwndUtil.FindWindow("WTWindow", null); hwnd1 = HwndUtil.FindWindow("TForm1", null); hwnd2 = HwndUtil.FindWindow("ThunderRT6FormDC", null); hwnd3 = HwndUtil.FindWindow("obj_Form", null); hwnd4 = HwndUtil.FindWindow("TMainForm", null); if (hwnd0 != IntPtr.Zero) { string title = HwndUtil.GetControlText(hwnd0); if (title.Length >= 6 && title.Substring(0, 6) == "自动投票工具") { TaskName = TASK_VOTE_MM; } else if (title.Length >= 8 && title.Substring(0, 8) == "VOTE2016") { TaskName = TASK_VOTE_ML; } else if (title.IndexOf("自动投票软件") != -1) { TaskName = TASK_VOTE_HY; } } else if (hwnd1 != IntPtr.Zero) { TaskName = TASK_VOTE_YUANQIU; } else if (hwnd2 != IntPtr.Zero) { TaskName = TASK_VOTE_JT; } else if (hwnd3 != IntPtr.Zero) { TaskName = TASK_VOTE_DM; } else if (hwnd4 != IntPtr.Zero) { TaskName = TASK_VOTE_JZ; } Thread.Sleep(500); } while (TaskName.Trim().Equals(TASK_VOTE_PROJECT)); } bool safeWrite = false; Thread.Sleep(ConfigCore.Sort % 10 * 50); do { try { ConfigCore.WriteTaskName(TaskName); Thread.Sleep(200); string taskNameCheck = ConfigCore.GetTaskName(); if (StringUtil.isEmpty(taskNameCheck) || !taskNameCheck.Equals(TaskName)) { LogCore.Write("TaskName Write Error!"); ConfigCore.WriteTaskName(TaskName); throw new Exception(); } safeWrite = true; } catch (Exception) { Thread.Sleep(ConfigCore.Sort % 10 * 50); } } while (!safeWrite); } if (TaskName.Equals(TASK_VOTE_JIUTIAN)) { if (!TaskChange.Equals("1")) { ProgressCore.StartProcess(CustomPath.Substring(0, CustomPath.Length - 9) + @"\启动九天.bat"); Thread.Sleep(500); } JiuTian.Start(); } else { if (!TaskChange.Equals("1")) { ProgressCore.StartProcess(CustomPath); Thread.Sleep(500); } if (TaskName.Equals(TASK_VOTE_MM)) { MM.Start(); } else if (TaskName.Equals(TASK_VOTE_ML)) { //ML开始程序 } else if (TaskName.Equals(TASK_VOTE_YUANQIU)) { YuanQiu.Start(); } else if (TaskName.Equals(TASK_VOTE_JT)) { JT.start(); } else if (TaskName.Equals(TASK_VOTE_DM)) { //DM开始程序 } else if (TaskName.Equals(TASK_VOTE_JZ)) { JZ.start(); } else if (TaskName.Equals(TASK_VOTE_HY)) { HY.Start(); } } TaskPath = CustomPath; } else { TaskName = TASK_SYS_WAIT_ORDER; } }