using CefSharp.DevTools.CSS; using HandyControl.Controls; using HandyControl.Data; using HandyControl.Tools; using LiveTools.Data; using Microsoft.Win32; using ryCommon; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; using System.Windows.Threading; namespace LiveTools { /// /// MainWindow2.xaml 的交互逻辑 /// public partial class MainWindow : HandyControl.Controls.Window { public MainWindow() { InitializeComponent(); this.Title = "紫林直播助手V"+RySoft.VersionStr; //2 设置定时器时间间隔 TimeSpan.FromSeconds(1) 以秒单位 timer.Interval = TimeSpan.FromMilliseconds(1000); //3 设置每隔时间要执行的方法 ,绑定方法到定时器上 //tick 是事件名, new System.EventHandler() 参数是方法名 timer.Tick += Timer_Tick; Random rd=new Random(); RandMinute=rd.Next(0, 60); } /// /// 软件启动时间 /// private DateTime dt_SoftStart = DateTime.Now; private int RandMinute = 0; private void Timer_Tick(object sender, EventArgs e) { if(DateTime.Now.Minute== RandMinute && DateTime.Now.Second== dt_SoftStart.Second) { var th = new Thread(delegate() { API.CheckedLogin(out _); }); th.Start(); } } DispatcherTimer timer = new DispatcherTimer(); protected override void OnContentRendered(EventArgs e) { base.OnContentRendered(e); //DataContext = ViewModelLocator.Instance.Main; //NonClientAreaContent = new NonClientAreaContent(); ControlMain.Content = new Content.MainWinContent(); } /// /// 检查自动更新 /// private void CheckUpdate(bool isSlient) { var th = new Thread(delegate () { Start(); }); th.Start(); void Start() { RyWeb.QuickWeb web=new RyWeb.QuickWeb(); var http= web.Get("http://reg.itjs.top/update/"+Config.SoftId+".json"); if(http.StatusCode== System.Net.HttpStatusCode.OK) { Json json = new Json(http.Html); var new_ver = json.GetJsonValue("new_ver"); if(RySoft.CompareVer(RySoft.VersionStr, new_ver)==1)//如果存在新版 { var update_date= json.GetJsonValue("update_date_str");//更新时间 var update_url = json.GetJsonValue("update_url");//更新网址 var mustupdate = json.GetJsonValue("mustupdate");//指定版本以下的必须更新 var is_must_update = false;//是否强制更新 if (RySoft.CompareVer(RySoft.VersionStr, mustupdate) == 1) { is_must_update = true; } var message = "发现存在新版[V" + new_ver + "],更新时间:" + update_date + "。"; Config.MustUpdate = is_must_update; Config.NewVerUrl = update_url; if (is_must_update) { message += "当前版本已经过老,必须更新后才能使用!"; } else { message += "是否进行更新?"; } if (!isSlient) { if (HandyControl.Controls.MessageBox.Show(new MessageBoxInfo { Message = message + "\r\n\r\n更新日志:\r\n" + json.GetJsonValue("update_desc", "暂无"), Caption = "发现新版本", Button = MessageBoxButton.YesNo, IconBrushKey = ResourceToken.AccentBrush, IconKey = ResourceToken.AskGeometry, }) == MessageBoxResult.Yes) { RyFiles.OpenUrl(update_url); } } else { Growl.Info(new GrowlInfo { Message = "[V" + new_ver + "]新版已推出,更新时间:" + update_date + "。\r\n更新日志:\r\n" + json.GetJsonValue("update_desc", "暂无"), CancelStr = "取消", ActionBeforeClose = isConfirmed => { //Growl.Info(isConfirmed.ToString()); return true; } }); } } } } } private void Window_Loaded(object sender, RoutedEventArgs e) { timer.Start(); try { RegistryKey LMach = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser,RegistryView.Registry64); RegistryKey softwareRun = LMach.CreateSubKey("Software\\RySoft\\"+Config.SoftId, true); if (softwareRun != null) { softwareRun.SetValue("InstallDir", Config.GetCurrentFolder); } softwareRun.Close(); LMach.Close(); } catch { } CheckUpdate(false); } } }