private void SetupComponents(object sender, RoutedEventArgs e) { Closing += (o, args) => { Application.Current.Shutdown(); }; //Setup the command line interface Cmd = Cmd ?? CommandLine.GetInstance(); //Taskbar notification icon TaskbarIconManager.AddItem("Show", () => { ShowInTaskbar = true; Visibility = Visibility.Visible; Activate(); WindowState = WindowState.Maximized; }); TaskbarIconManager.AddItem("Exit", () => { Application.Current.Shutdown(0); }); TaskbarIconManager.CommitItems(); TaskbarIconManager.SetVisible(true); LoadedModules.SelectionChanged += LoadedModulesOnSelectionChanged; // Invokes commands recieved from TCP connections RemoteManager.CommandRecieved += (command, tcpClient) => { Task.Factory.StartNew(() => { UserModule mod = null; Command cm = null; if (UserModule.FindResponsibleUserModule(command, out mod, out cm, tcpClient)) { Dispatcher.Invoke(() => { Status = $"{(tcpClient != null ? (tcpClient.Client.RemoteEndPoint + " > ") : "")} [{mod.Name}:{mod.Prefix}] > {cm.LocalCommand}"; mod.GiveRegexCommand(cm); }); } }); }; RemoteManager.ClientConnected += client => { Dispatcher.Invoke(() => { Status = $"({client.Client.RemoteEndPoint}) has connected!"; }); }; RemoteManager.ClientDisconnected += client => { Dispatcher.Invoke(() => { Status = $"({client.Client.RemoteEndPoint}) has disconnected."; }); }; Command.Responded += (response, com, client) => { Dispatcher.Invoke(() => { Status = $"{((com != null && com != Command.Empty) ? $"[{com?.UserModuleName}] > " : "")}{response}"; }); }; }
public MainWindow() { InitializeComponent(); Loaded += MainWindow_Loaded; SourceInitialized += Main_HotkeyRegister; //Inside Hotkey Registration Region Closing += Main_HotkeyDeregister; //Inside Hotkey Registration Region //When the application is closing, remove the taskbar icon Closed += (sender, e) => { TaskbarIconManager.Dispose(); }; Loaded += SetupComponents; StateChanged += MainWindow_StateChanged; }
/// <summary> /// 下载游戏资源文件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DownloadResources_Click(object sender, RoutedEventArgs e) { if (Version.SelectedItem == null) { UI.MessageBox.QuickShow("选择一个版本再来下载 >__<", (MainWindow)Window.GetWindow(this)); return; } UI.MessageBox mb = new UI.MessageBox((MainWindow)Window.GetWindow(this)); mb.Title = "注意"; mb.Message = "Minecraft的游戏资源文件很大,可能在200M以上\n建议不要使用计费网络下载(如手机热点、上网卡)\n下载完成后将通知您"; mb.LeftButtonText = "继续下载"; mb.RightButtonText = "算了吧"; mb.LeftButtonClick += (obj) => { mb.Close(); }; bool isUserDontDownload = false; mb.RightButtonClick += (obj) => { mb.Close(); isUserDontDownload = true; }; mb.ShowDialog(); if (isUserDontDownload) { return; } UI.MessageBox.QuickShow("启动器将开启新线程下载,在下载完成前您可以继续游戏\n但是可能没有声音文件或者无法选择适合您的语言", (MainWindow)Window.GetWindow(this), "下载资源文件"); Thread downloadThread = new Thread((ThreadStart) delegate { string version = "", useApi = ""; Dispatcher.Invoke(delegate { version = ((VersionsInfo)Version.SelectedItem).id; useApi = Model.Download.Api.UsingApi; }); bool result = AquaL.Helper.ResourcesDownloadHelper.AutoDownloadResources( version, useApi); if (!result) { return; } TaskbarIconManager.Toast("AquaL资源下载", "资源文件下载完成!"); }); downloadThread.SetApartmentState(ApartmentState.STA); downloadThread.IsBackground = true; downloadThread.Start(); }
public static bool AutoDownloadResources(string id, string usingApi) { try { string MINECRAFT_PATH = AppDomain.CurrentDomain.BaseDirectory + ".minecraft/"; string SELECT_VERSION = id; if (!File.Exists(MINECRAFT_PATH + "versions/" + SELECT_VERSION + "/" + SELECT_VERSION + ".json")) { UI.MessageBox.QuickShow("请先下载该版本完整的Minecraft!", null); return(false); } JObject versionJson = JsonConvert.DeserializeObject(File.ReadAllText(MINECRAFT_PATH + "versions/" + SELECT_VERSION + "/" + SELECT_VERSION + ".json")) as JObject; string resourcesJsonUrl = versionJson["assetIndex"]["url"].ToString().Replace("https://launchermeta.mojang.com", usingApi).Replace("bmclapi2", "bmclapi"); WebClient wc = new WebClient(); wc.Credentials = CredentialCache.DefaultCredentials; Encoding enc = Encoding.GetEncoding("UTF-8"); Byte[] pageData = wc.DownloadData(resourcesJsonUrl); string json = enc.GetString(pageData); string resourcesDownloadApiDomain = usingApi; resourcesDownloadApiDomain = resourcesDownloadApiDomain.Replace("launchermeta.mojang.com", "resources.download.minecraft.net") .Replace("bmclapi2.bangbang93.com", "bmclapi2.bangbang93.com/assets"); List <DownloadFileTask> task = new List <DownloadFileTask>(); JsonData jd = JsonMapper.ToObject(json); IDictionary dict = jd as IDictionary; //第一个子元素中包含多个子元素 foreach (string key in jd["objects"].Keys) { string hash = jd["objects"][key]["hash"].ToString(); if (!Directory.Exists(MINECRAFT_PATH + "assets/objects/" + hash.Substring(0, 2))) { Directory.CreateDirectory(MINECRAFT_PATH + "assets/objects/" + hash.Substring(0, 2)); } task.Add(new DownloadFileTask( key, MINECRAFT_PATH + "assets/objects/" + hash.Substring(0, 2) + "/" + hash, new Uri(resourcesDownloadApiDomain + "/" + hash.Substring(0, 2) + "/" + hash) )); } if (!Directory.Exists(MINECRAFT_PATH + "assets/indexes/")) { Directory.CreateDirectory(MINECRAFT_PATH + "assets/indexes/"); } task.Add(new DownloadFileTask( "Index 文件", MINECRAFT_PATH + "assets/indexes/" + versionJson["assetIndex"]["id"].ToString() + ".json", new Uri(versionJson["assetIndex"]["url"].ToString().Replace("https://launchermeta.mojang.com", usingApi).Replace("bmclapi2", "bmclapi")))); MainWindow context = new MainWindow(new AquaL.Pages.FileDownload(task)); context.ShowDialog(); try { // 判断是否使用需要将文件复制一份 if (jd["virtual"] != null && (bool)jd["virtual"] == true) { bool isNoException = true; TaskbarIconManager.Toast("AquaL 下载游戏", "开始解压资源"); foreach (string key in jd["objects"].Keys) { try { string hash = jd["objects"][key]["hash"].ToString(); string hashPath = MINECRAFT_PATH + "assets/objects/" + hash.Substring(0, 2) + "/" + hash; string savePath = MINECRAFT_PATH + "assets/virtual/legacy/" + key; string saveDir = Path.GetDirectoryName(savePath); if (!Directory.Exists(saveDir)) { Directory.CreateDirectory(saveDir); } Console.WriteLine("解压文件:文件Hash" + hash + ",目标路径:" + savePath); File.Copy(hashPath, savePath); } catch (Exception ex) { isNoException = false; Console.WriteLine(ex.Message); } } TaskbarIconManager.Toast("AquaL 下载游戏", (isNoException ? "解压成功!" : "解压失败,可能部分文件出现异常")); } } catch { } return(true); } catch (Exception ex) { UI.MessageBox.QuickShow("资源文件下载失败!\n" + ex.Message, null); return(false); } }
public static void UpdateTaskbarIcon() { TaskbarIconManager.UpdateTaskbarIcon(); }