Пример #1
0
        public static bool DoServer3ClientLaunch()
        {
            if (!Environment.Is64BitOperatingSystem)
            {
                MessageBox.Show(
                    "你的电脑达不到游玩该客户端所必须的最低标准: 64位操作系统\n如果真的想玩,就去刷机吧……",
                    "错误",
                    MessageBoxButton.OK,
                    MessageBoxImage.Error);
                return(false);
            }
            string client3Path = gameroot_path + @"3rdServerClient\";

            if (!PreLaunch.CheckJava(11))
            {
                return(false);
            }
            if (!File.Exists(client3Path + "Launcher.jar"))
            {
                if (!Download3rdClient())
                {
                    return(false);
                }
            }
            if (!Server3ClientCheckUpdate())
            {
                return(false);
            }
            return(LaunchClient(client3Path, 11));
        }
 public JobHostRunner WithPreLaunch(MethodInfo methodInfo)
 {
     PreLaunch.Add(methodInfo);
     return(this);
 }
Пример #3
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 { }
            };
        }