public static bool Download3rdClient()
 {
     ClientMainWindow.UpdateButtonStatic("正在获取客户端", true);
     try
     {
         string path            = gameroot_path + "3rdServerClient/";
         string archiveFullName = gameroot_path + "3rdServerClient.zip";
         HTTP   http            = HTTP.CreateHTTPDownLoad(App.updaterURL + "3rd/archive.zip", archiveFullName);
         http.onHttpDownloadMessage += (sender, e) => ClientMainWindow.UpdateStatusStatic(e.message, e.process);
         if (!http.Download())
         {
             return(false);
         }
         var zip = ZipFile.Open(archiveFullName, ZipArchiveMode.Read);
         zip.ExtractToDirectory(path);
         zip.Dispose();
         Thread.Sleep(200);
         File.Delete(archiveFullName);
         return(true);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.StackTrace, ex.Message);
         return(false);
     }
 }
示例#2
0
        private void Authorization_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                UserModel OldUser = new UserModel()
                {
                    Login    = Login.Text,
                    Password = Password.Password
                };


                switch (UserLogic.Authorization(OldUser))
                {
                case 1:
                    ClientMainWindow client = new ClientMainWindow();
                    client.Show();
                    this.Close();
                    break;

                case 2:
                    MasterMainWindow master = new MasterMainWindow();
                    master.Show();
                    this.Close();
                    break;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
 private void ProgramMainIcon_MouseClick(object sender, MouseEventArgs e)
 {
     switch (e.Button)
     {
     case MouseButtons.Left:
         ClientMainWindow window = ClientMainWindow.GetWindow(true);
         window.Show();
         break;
     }
 }
示例#4
0
        /// <summary>
        /// 通用的Java检查,用于启动游戏
        /// </summary>
        /// <param name="version">Java的版本号</param>
        /// <returns>是否检查成功</returns>
        public static bool CheckJava(int version)
        {
            string java_path = string.Format(java_path_builder, version);

            if (!File.Exists(java_path + @"\bin\javaw.exe"))
            {
                try
                {
                    string tuna_path = $"https://mirrors.tuna.tsinghua.edu.cn/AdoptOpenJDK/{version}/jre/x64/windows/";
                    if (!Environment.Is64BitOperatingSystem)
                    {
                        tuna_path = $"https://mirrors.tuna.tsinghua.edu.cn/AdoptOpenJDK/{version}/jre/x86/windows/";
                    }
                    string javas = HTTP.GetHttpStringData(tuna_path);
                    Regex  regex = new Regex(@"<a\shref=""(?<path>.*)""\stitle="".*hotspot.*\.zip"">");
                    Match  match = regex.Match(javas);
                    if (!match.Success)
                    {
                        goto pass;
                    }
                    string filename    = match.Groups["path"].ToString();
                    string remote_path = tuna_path + filename;
                    HTTP   http        = HTTP.CreateHTTPDownLoad(tuna_path + filename, java_path + filename);
                    http.onHttpDownloadMessage += (sender, e) => ClientMainWindow.UpdateStatusStatic(e.message, e.process);
                    while (!http.Download())
                    {
                        if (MessageBox.Show($"Java{version}下载失败了,你要重试吗?\r\n" + java_path + filename, "错误", MessageBoxButton.YesNo) == MessageBoxResult.No)
                        {
                            goto pass;
                        }
                    }
                    ClientMainWindow.UpdateStatusStatic($"正在释放Java{version}文件...");
                    var zip           = ZipFile.Open(java_path + filename, ZipArchiveMode.Read);
                    var temp_dir_name = java_path + filename.Remove(filename.LastIndexOf("."));
                    zip.ExtractToDirectory(temp_dir_name);
                    zip.Dispose();
                    FileContorl.CopyDir(Directory.EnumerateDirectories(temp_dir_name).ToArray()[0], java_path);
                    Thread.Sleep(200);
                    Directory.Delete(temp_dir_name, true);
                    File.Delete(java_path + filename);
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.StackTrace, e.Message);
                }
                return(true);

                pass :;
                return(false);
            }
            else
            {
                return(true);
            }
        }
        public static bool DoServer1ClientLaunch()
        {
            string uni_version_path = gameroot_path + @"UniversalClient\";

            if (!Server1ClientCheckUpdate())
            {
                return(false);
            }
            ClientMainWindow.GetWindow().UpdateButton("正在启动", true);
            return(LaunchClient(uni_version_path, 16));
        }
示例#6
0
        public static bool CheckJavaFX()
        {
            string java16_path = string.Format(java_path_builder, 16);

            if (!File.Exists(java16_path + @"jmods\javafx.web.jmod"))
            {
                try
                {
                    string javafx_path = "https://gluonhq.com/download/javafx-16-jmods-windows/";
                    if (!Environment.Is64BitOperatingSystem)
                    {
                        javafx_path = "https://gluonhq.com/download/javafx-16-jmods-windows-x86/";
                    }
                    //"https://download2.gluonhq.com/openjfx/16/openjfx-16_windows-x64_bin-jmods.zip";
                    string javafx_local_path = java16_path + "javafx.zip";
                    HTTP   http = HTTP.CreateHTTPDownLoad(javafx_path, javafx_local_path);
                    http.onHttpDownloadMessage += (sender, e) => ClientMainWindow.UpdateStatusStatic(e.message, e.process);
                    while (!http.Download())
                    {
                        if (MessageBox.Show("JavaFx下载失败了,你要重试吗?\r\n" + javafx_local_path, "错误", MessageBoxButton.YesNo) == MessageBoxResult.No)
                        {
                            goto pass;
                        }
                    }
                    ClientMainWindow.UpdateStatusStatic("正在释放JavaFx文件");
                    var zip2 = ZipFile.Open(javafx_local_path, ZipArchiveMode.Read);
                    zip2.ExtractToDirectory(java16_path + "javafx");
                    zip2.Dispose();
                    if (!Directory.Exists(java16_path + "jmods"))
                    {
                        Directory.CreateDirectory(java16_path + "jmods");
                    }
                    FileContorl.CopyDir(Directory.EnumerateDirectories(java16_path + "javafx").ToArray()[0], java16_path + "jmods");
                    Thread.Sleep(200);
                    Directory.Delete(java16_path + "javafx", true);
                    File.Delete(javafx_local_path);
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.StackTrace, e.Message);
                    goto pass;
                }
                return(true);

                pass :;
                return(false);
            }
            else
            {
                return(true);
            }
        }
        protected override void DefWndProc(ref Message m)
        {
            switch (m.Msg)
            {
            case 0xffff:
                ClientMainWindow.GetWindow(true).Show();
                ClientMainWindow.GetWindow(true).Activate();
                break;

            default:
                base.DefWndProc(ref m);
                break;
            }
        }
        private static bool LaunchClient(string path, int javaVersion)
        {
            Config.HMCLBaseConfig config = JsonConvert.DeserializeObject <Config.HMCLBaseConfig>(File.ReadAllText(path + "hmcl.json"));
            config.configurations["Default"].global.java     = "Custom";
            config.configurations["Default"].global.javaDir  = string.Format(java_path_builder, javaVersion).Replace("javaw.exe", "java.exe");
            config.configurations["Default"].global.serverIp = "";//"chobitslive.live:1152"; 会导致崩溃
            if (!Environment.Is64BitOperatingSystem)
            {
                config.configurations["Default"].global.maxMemory = 1024;
            }
            File.Delete(path + "hmcl.json");
            File.WriteAllText(path + "hmcl.json", JsonConvert.SerializeObject(config, Formatting.Indented));
            ProcessStartInfo processStartInfo = new ProcessStartInfo();

            processStartInfo.Arguments        = "-jar \"" + path + "Launcher.jar\"";
            processStartInfo.WorkingDirectory = path;
            processStartInfo.FileName         = string.Format(java_path_builder, 16);
            if (Process.Start(processStartInfo) == null)
            {
                MessageBox.Show("HMCL启动失败");
                if (ClientMainWindow.GetWindow() != null)
                {
                    ClientMainWindow.GetWindow().UpdateButton("开始游戏", false);
                }
                return(false);
            }
#if DEBUG
            else if (MessageBox.Show("操作结束,退出吗?", "询问", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
            {
                Environment.Exit(0);
            }
            ClientMainWindow.UpdateStatusStatic("", 1);
            ClientMainWindow.UpdateButtonStatic(" 开始游戏", false);
#else
            ClientMainWindow.UpdateStatusStatic("正在启动HMCL启动器...");
            if (isFirstLaunch(javaVersion))
            {
                MessageBox.Show($"如果你是笔记本用户,首次启动建议在英伟达控制面板中将“{processStartInfo.FileName}”改为使用“高性能”(独立显卡)来运行游戏,可获得极大性能提升", "建议");
            }
            //if (!File.Exists(local_path + ".dontexit")) Environment.Exit(0);
#endif
            return(true);
        }
        public static bool Server1ClientCheckUpdate()
        {
            string  localPath    = gameroot_path + @"UniversalClient\.minecraft\";
            string  internetPath = App.updaterURL + @"1st/minecraft/";
            string  customPath   = gameroot_path + @"UniversalClient\自定义文件目录\";
            Updater updater      = new Updater(internetPath, localPath, customPath);
            bool    isFailed     = false;

            updater.onUpdateMessage += (sender, e) =>
            {
                if (e.status == UpdaterEvent.MessageStatus.Info)
                {
                    ClientMainWindow.UpdateStatusStatic(e.message, e.process);
                }
                else if (e.status == UpdaterEvent.MessageStatus.Failed)
                {
                    isFailed = true;
                }
            };
            ClientMainWindow.UpdateButtonStatic("正在检查更新", true);
            updater.Run();
            return(!isFailed);
        }
示例#10
0
        private async void Application_Startup(object sender, StartupEventArgs e)
        {
            if (!Directory.Exists(dataFolder))
            {
                Directory.CreateDirectory(dataFolder);
            }
            #region 出现问题的启动方式
            if (!File.Exists(dataFolder + @".install"))
            {
                //    try
                //    {
                if (MessageBox.Show("当前运行程序的位置将会是程序的安装目录,是否继续?", "欢迎使用ChobitsLive我的世界客户端", MessageBoxButton.OKCancel) == MessageBoxResult.Cancel)
                {
                    Environment.Exit(0);
                }
                if (!Tools.ConsoleManager.IsAdministrator)
                {
                    Tools.ConsoleManager.RestartAsAdministrator(true);
                }
                //        redo:
                //        MessageBox.Show("请选择一个安装目录,这将安装 ChobitsLive客户端应用程序 到指定目录。\n程序会自动在目录下创建安装目录");
                //        FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
                //        folderBrowserDialog.SelectedPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
                //        folderBrowserDialog.Description = "选择安装目录";
                //        folderBrowserDialog.ShowDialog();
                //        if (folderBrowserDialog.SelectedPath == "") goto redo;
                //        string programPath = folderBrowserDialog.SelectedPath + @"\Chobits Live\Minecraft\";
                string programPath = AppDomain.CurrentDomain.BaseDirectory;
                //Directory.CreateDirectory(programPath);
                File.WriteAllText(dataFolder + ".install", programPath);
                Tools.ConsoleManager.CreateShortcutOnDesktop();
                if (!Environment.Is64BitOperatingSystem)
                {
                    MessageBox.Show("使用x86系统不适合玩MC,可能会卡顿,因为x86系统Java内存上限为1024MB");
                }
                //        string targetFileName = programPath + new FileInfo(Process.GetCurrentProcess().MainModule.FileName).Name;
                //        File.Copy(Process.GetCurrentProcess().MainModule.FileName, targetFileName);
                //        ProcessStartInfo processStartInfo = new ProcessStartInfo();
                //        processStartInfo.FileName = targetFileName;
                //        processStartInfo.Verb = "runas";
                //        Process.Start(processStartInfo);
                //        Environment.Exit(0);
                //    }
                //    catch(Exception ex)
                //    {
                //        MessageBox.Show(ex.StackTrace, ex.Message);
                //        Environment.Exit(-1);
                //    }
            }
            //Tools.CheckUpdate.ProgramEnvironmentCheck.CheckNuget();
            #endregion
            #region 检测是否有程序正在运行,正在运行就发送消息并退出
            string processID_Path = Path.Combine(dataFolder, ".processid");
            try
            {
                if (File.Exists(processID_Path))
                {
                    try
                    {
                        Process process = Process.GetProcessById(int.Parse(File.ReadAllText(processID_Path)));
                        IntPtr  backs   = Tools.ConsoleManager.FindWindow(null, "ChobitsLive Minecraft Client Background Service");
                        Tools.ConsoleManager.PostMessage(backs, 0xffff, 0, 0);
                        //MessageBox.Show(Tools.ConsoleManager.GetWindowTitle(backs),"发送数据");
                        Environment.Exit(0);
                        return;
                    }
                    catch (Exception ex) {
                        //MessageBox.Show(ex.StackTrace, ex.Message);
                    }
                }
                FileStream   fs = File.Create(processID_Path);
                StreamWriter sw = new StreamWriter(fs);
                sw.Write(Process.GetCurrentProcess().Id);
                sw.Dispose();
                fs.Close();
            }
            catch (Exception ex)
            {
                //MessageBox.Show(ex.StackTrace, ex.Message);
            }
            #endregion
            //
            //版本检查
            BackgroundService backs2 = BackgroundService.Service;
            PreLaunch.CheckUpdater();
            ProgramEnvironmentCheck.CheckVersion();
            backs2.Show();
            backs2.Hide();
            //new BackgroundService().Show();
            new Thread(() =>
            {
                if (!Tools.CheckUpdate.PreLaunch.CheckGameEnvironment())
                {
                    return;
                }
                ClientMainWindow.UpdateStatusStatic("操作结束", 1);
                ClientMainWindow.UpdateButtonStatic(" 开始游戏", false);
                // TODO 临时操作,之后可能会更改
#if DEBUG
                if (ClientMainWindow.GetWindow() != null)
                {
                    ClientMainWindow.GetWindow().UpdateButton("开始游戏", false);
                }
#else
                //Tools.GameLauncher.DoServer1ClientLaunch();
#endif
            }
                       ).Start();
            await Task.Run(() => Thread.Sleep(1000));

            ClientMainWindow.GetWindow(true).Show();
            //Tools.ConsoleManager.Show();
            AppDomain.CurrentDomain.ProcessExit += (sender1, e1) =>
            {
                try { File.Delete(processID_Path); } catch { }
            };
        }
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ClientMainWindow window = ClientMainWindow.GetWindow(true);

            window.Show();
        }