/// <summary> /// 用户选择用离线模式登陆,弹出输入账号框(保存由账号框负责) /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void LaunchSet_LoginWithOffline_Click(object sender, RoutedEventArgs e) { UI.MessageBox input = new UI.MessageBox((MainWindow)Window.GetWindow(this)); input.Title = "输入用户名"; input.Message = "建议不要乱输入,这个对于联机的话很重要的"; Page inputLayout = new Page(); Grid inputLayoutGrid = new Grid(); TextBox inputLayoutText = new TextBox(); inputLayoutText.Width = 180; inputLayoutGrid.Children.Add(inputLayoutText); inputLayout.Content = inputLayoutGrid; input.CustomContent = inputLayout; input.LeftButtonText = "确定"; input.RightButtonText = "取消"; input.LeftButtonClick += (args) => { if (inputLayoutText.Text == "") { UI.MessageBox.QuickShow("请输入用户名!", (MainWindow)Window.GetWindow(this)); return; } ConfigModel config = Config.GetConfig(); List <ConfigUser> users = (config.users == null ? new List <ConfigUser>() : config.users.ToList()); ConfigUser user = config.users[0]; user.name = inputLayoutText.Text; user.type = "offline"; user.theme = "default"; user.pass = ""; if (users.Count == 0) { users.Add(user); } else { users[0] = user; } config.users = users.ToArray(); Config.SaveConfig(config); UI.MessageBox.QuickShow("欢迎回来!" + inputLayoutText.Text, null); Config.IsFirstConfiging = false; input.Close(); ConfigModel loadConfig = Config.GetConfig(); LaunchSet_LoginTip.Content = "目前是" + (loadConfig.users[0].type == "online" ? "正版" : "盗版") + "模式,账号是" + loadConfig.users[0].name; }; input.ShowDialog(); }
/// <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(); }
private void step2_username_Click(object sender, RoutedEventArgs e) { UI.MessageBox input = new UI.MessageBox((MainWindow)Window.GetWindow(this)); input.Title = "输入用户名"; Page inputLayout = new Page(); Grid inputLayoutGrid = new Grid(); TextBox inputLayoutText = new TextBox(); inputLayoutText.Width = 180; inputLayoutGrid.Children.Add(inputLayoutText); inputLayout.Content = inputLayoutGrid; input.CustomContent = inputLayout; input.LeftButtonText = "确定"; input.RightButtonText = "取消"; input.LeftButtonClick += (args) => { if (inputLayoutText.Text == "") { UI.MessageBox.QuickShow("请输入用户名!", (MainWindow)Window.GetWindow(this)); return; } ConfigModel config = Config.GetConfig(); ConfigUser user = new ConfigUser(); user.name = inputLayoutText.Text; user.type = "offline"; user.theme = "default"; List <ConfigUser> users = (config.users == null ? new List <ConfigUser>() : config.users.ToList()); users.Add(user); config.users = users.ToArray(); Config.SaveConfig(config); UI.MessageBox.QuickShow("欢迎回来!" + inputLayoutText.Text, (MainWindow)Window.GetWindow(this)); input.Close(); MainWindow parent = (MainWindow)Window.GetWindow(this); parent.Close(); }; input.ShowDialog(); }
public static bool AutoDownloadMinecraft(string id, string usingApi) { string MINECRAFT_PATH = AppDomain.CurrentDomain.BaseDirectory + "/.minecraft/"; string SELECT_VERSION = id; // 判断 .minecraft/versions/版本号 文件夹是否存在,否则创建 if (!Directory.Exists(MINECRAFT_PATH + "versions/" + SELECT_VERSION + "/")) { Directory.CreateDirectory(MINECRAFT_PATH + "/versions/" + SELECT_VERSION + "/"); } else // 文件夹存在,询问是否覆盖 { // 资源文件完整情况下 if (File.Exists(MINECRAFT_PATH + "/versions/" + SELECT_VERSION + "/" + SELECT_VERSION + ".jar") && File.Exists(MINECRAFT_PATH + "/versions/" + SELECT_VERSION + "/" + SELECT_VERSION + ".json")) { UI.MessageBox mb = new UI.MessageBox(null); mb.Title = "已存在"; mb.Message = "该版本已存在,是否重新下载?"; mb.LeftButtonText = "重新下载"; mb.RightButtonText = "不要重下"; mb.LeftButtonClick += (obj) => { mb.Close(); }; bool isUserDontDownload = false; mb.RightButtonClick += (obj) => { mb.Close(); isUserDontDownload = true; }; mb.ShowDialog(); if (isUserDontDownload) { return(false); } } // 资源文件不完整情况下 else if (File.Exists(MINECRAFT_PATH + "/versions/" + SELECT_VERSION + "/" + SELECT_VERSION + ".jar") || File.Exists(MINECRAFT_PATH + "/versions/" + SELECT_VERSION + "/" + SELECT_VERSION + ".json")) { UI.MessageBox mb = new UI.MessageBox(null); mb.Title = "已存在"; mb.Message = "该版本已存在,但是不完整,是否重新下载?\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(false); } } } try { List <DownloadFileTask> task = new List <DownloadFileTask>(); task.Add(new DownloadFileTask( SELECT_VERSION + "-Jar", MINECRAFT_PATH + "/versions/" + SELECT_VERSION + "/" + SELECT_VERSION + ".jar", new Uri(usingApi + "/version/" + SELECT_VERSION + "/client"))); task.Add(new DownloadFileTask( SELECT_VERSION + "-Json", MINECRAFT_PATH + "/versions/" + SELECT_VERSION + "/" + SELECT_VERSION + ".json", new Uri(usingApi + "/version/" + SELECT_VERSION + "/json"))); MainWindow context = new MainWindow(new AquaL.Pages.FileDownload(task)); context.ShowDialog(); return(true); } catch (Exception ex) { UI.MessageBox.QuickShow("Minecraft本体下载失败!\n" + ex.Message, null); return(false); } }