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);
     }
 }
        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);
        }
示例#4
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 { }
            };
        }