internal static void StartMinecraft(Instance instance) { try { if (instance.Version == null) { App.InvokeAction(delegate { MCM.Utils.MessageBox.ShowDialog("Error", "Version not set in instance!"); }); return; } App.InvokeAction(delegate { App.mainWindow.btn_startMinecraft.IsEnabled = false; }); App.Log("Waiting for downloads to finish..."); DownloadManager.WaitForAllMCRequire(); App.Log("Downloads should be finished!"); Process p = new Process(); string java = SettingsManager.GetSetting("javapath").data.ToString(); p.StartInfo.FileName = java; MinecraftUser user = null; MinecraftData.AppdataPath = instance.Version.FullVersion.LocalPath; App.InvokeAction(delegate { user = mainWindow.GetSelectedUser(); }); if (!File.Exists(instance.MinecraftJarFilePath)) { throw new Exception("No version selected"); } DownloadPackage dp = new DownloadPackage("Libraries", true); dp.ShouldContinue = true; instance.Version.FullVersion.Libraries.ForEach(l => { if (!File.Exists(l.Extractpath)) { l.ScheduleExtract(dp); } }); if (dp.getDownloads().Count > 0) { DownloadManager.ScheduleDownload(dp); } App.Log("Waiting for minecraft download..."); DownloadManager.WaitForAllMCRequire(); p.StartInfo.Arguments = instance.GetStartArguments(user.username, user.password); App.Log("Starting Minecraft with arguments: " + p.StartInfo.FileName + " " + p.StartInfo.Arguments); p.StartInfo.UseShellExecute = false; p.EnableRaisingEvents = true; p.StartInfo.CreateNoWindow = true; p.StartInfo.RedirectStandardError = true; p.StartInfo.RedirectStandardOutput = true; p.OutputDataReceived += (s, e) => { App.LogMinecraft(e.Data); }; p.ErrorDataReceived += (s, e) => { // No prefix since everything minecraft outputs seems to be an error App.LogMinecraft(e.Data); }; p.Exited += (s, e) => { App.InvokeAction(delegate { App.mainWindow.btn_startMinecraft.IsEnabled = true; }); Thread.Sleep(200); Syncronizer.SyncOptions(instance); Syncronizer.SyncServerlist(instance); PluginManager.onCloseMinecraft(instance, user); }; PluginManager.onStartMinecraft(instance, user); p.Start(); p.BeginErrorReadLine(); p.BeginOutputReadLine(); } catch (Exception ex) { App.InvokeAction(delegate { App.mainWindow.btn_startMinecraft.IsEnabled = true; }); App.Log("An error occured while starting minecraft: " + ex.ToString()); } }