Ejemplo n.º 1
0
 public async Task Start()
 {
     _onGameLaunch(this, "LauncherCheckJava", VersionInfo);
     if (!SetupJava())
     {
         return;
     }
     if (!CleanNatives())
     {
         return;
     }
     _arguments.Add($"-Djava.library.path={_nativesDirectory}");
     _onGameLaunch(this, "LauncherSolveLib", VersionInfo);
     if (!await SetupLibraries())
     {
         return;
     }
     if (!await SetupNatives())
     {
         return;
     }
     _onGameLaunch(this, "LauncherBuildMCArg", VersionInfo);
     _arguments.Add(VersionInfo.MainClass);
     _arguments.AddRange(McArguments());
     Logger.Log(ChildProcess.JoinArguments(_arguments.ToArray()));
     _onGameLaunch(this, "LauncherGo", VersionInfo);
     if (!Launch())
     {
         return;
     }
     _onGameStart(this, VersionInfo);
 }
Ejemplo n.º 2
0
        public static ChildProcess Exec(string filename, string[] arguments = null)
        {
            var childProcess = new ChildProcess(filename, arguments);

            childProcess.Start();
            return(childProcess);
        }
Ejemplo n.º 3
0
 private bool Launch()
 {
     _childProcess =
         _config.LaunchMode == LaunchMode.Normal
         ? new ChildProcess(_config.Javaw, _arguments.ToArray())
         : new ChildProcess(_config.Javaw, _versionDirectory, _arguments.ToArray());
     if (!_childProcess.Start())
     {
         return(false);
     }
     _childProcess.OnStdOut += OnStdOut;
     _childProcess.OnStdErr += OnStdOut;
     _childProcess.OnExit   += ChildProcessOnExit;
     _errorCount             = CountError();
     return(true);
 }
Ejemplo n.º 4
0
        private void HandleHsError(IReadOnlyDictionary <string, int> nowValue)
        {
            var hsErrorPath = BmclCore.MinecraftDirectory;

            if (nowValue["hsError"] != _errorCount["hsError"])
            {
                Logger.Log("发现新的JVM错误报告");
                var hsErrorDir = new DirectoryInfo(hsErrorPath);
                var hsErrors   = hsErrorDir.GetFiles().Where(s => s.FullName.StartsWith("hs_err")).ToArray();
                Array.Sort(hsErrors,
                           (info1, info2) => (int)(info1.LastWriteTime - info2.LastWriteTime).TotalSeconds);
                var crashReportReader = new StreamReader(hsErrors[0].FullName);
                Logger.Log(crashReportReader.ReadToEnd(), Logger.LogType.Crash);
                crashReportReader.Close();
                ChildProcess.Exec(hsErrors[0].FullName);
            }
        }
Ejemplo n.º 5
0
        private void HandleCrashReport(IReadOnlyDictionary <string, int> nowValue)
        {
            var crashReportsPath = Path.Combine(BmclCore.MinecraftDirectory, "crash-reports");

            if (nowValue["crashReport"] != _errorCount["crashReport"] && Directory.Exists(crashReportsPath))
            {
                Logger.Log("发现新的错误报告");
                var clientCrashReportDir = new DirectoryInfo(crashReportsPath);
                var clientReports        = clientCrashReportDir.GetFiles();
                Array.Sort(clientReports,
                           (info1, info2) => (int)(info1.LastWriteTime - info2.LastWriteTime).TotalSeconds);
                var crashReportReader = new StreamReader(clientReports[0].FullName);
                Logger.Log(crashReportReader.ReadToEnd(), Logger.LogType.Crash);
                crashReportReader.Close();
                ChildProcess.Exec(clientReports[0].FullName);
            }
        }
Ejemplo n.º 6
0
        public Launcher(VersionInfo versionInfo, AuthResult authResult, Config config = null, bool disableXincgc = false)
        {
            _authResult       = authResult;
            VersionInfo       = versionInfo;
            State             = LauncherState.Initializing;
            _config           = config ?? Config.Load();
            _versionDirectory = Path.Combine(BmclCore.BaseDirectory, ".minecraft\\versions", VersionInfo.Id);
            _libraryDirectory = Path.Combine(BmclCore.MinecraftDirectory, "libraries");
            _nativesDirectory = Path.Combine(_versionDirectory, $"{VersionInfo.Id}-natives-{TimeHelper.TimeStamp()}");

            if (!disableXincgc)
            {
                _arguments.AddRange(new[] { "-Xincgc" });
            }
            if (!string.IsNullOrEmpty(_config.ExtraJvmArg))
            {
                _arguments.AddRange(ChildProcess.SplitCommandLine(_config.ExtraJvmArg));
            }
        }