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()); } }
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()); } }
void bt_Click(object sender, System.Windows.RoutedEventArgs e) { if (changingVersion) { MessageBox.ShowDialog("Warning", "The version is currently being changed/downloaded! Cannot change now!"); } else { ChangeMCVersion cv = new ChangeMCVersion(); if (cv.ShowDialog() == true) { this.changingVersion = true; TinyMinecraftVersion prevVer = this.Version; this.Version = cv.version; try { Task.Factory.StartNew(delegate { if (!File.Exists(cv.version.FullVersion.BinaryPath)) { Download dl = cv.version.FullVersion.ScheduleJarDownload(); PluginAPI.PluginManager.onVersionDownload(dl); DownloadPackage dp = new DownloadPackage("Libraries", true); dp.ShouldContinue = true; cv.version.FullVersion.Libraries.ForEach(l => { if (!File.Exists(l.Extractpath)) { l.ScheduleExtract(dp); } }); if (dp.getDownloads().Count > 0) { DownloadManager.ScheduleDownload(dp); } dl.WaitForComplete(); CopyJar(); App.InvokeAction(delegate { (App.mainWindow.listBox_instanceInfo.Items[0] as Label).Content = (this.Version == null ? "no version" : this.Version.Key); App.mainWindow.UpdateInstances(); }); this.changingVersion = false; } else { CopyJar(); App.InvokeAction(delegate { (App.mainWindow.listBox_instanceInfo.Items[0] as Label).Content = (this.Version == null ? "no version" : this.Version.Key); App.mainWindow.UpdateInstances(); }); this.changingVersion = false; } }); } catch (Exception ex) { MCM.Utils.MessageBox.ShowDialog("Error", "The selected version could not be changed because: " + ex.Message); this.Version = prevVer; (App.mainWindow.listBox_instanceInfo.Items[0] as Label).Content = (this.Version == null ? "no version" : this.Version.Key); App.mainWindow.UpdateInstances(); this.changingVersion = false; } } PluginManager.onChangeVersion(this); } }
void bt_Click(object sender, System.Windows.RoutedEventArgs e) { if (changingVersion) { MessageBox.ShowDialog("Warning", "The version is currently being changed/downloaded! Cannot change now!"); } else { ChangeMCVersion cv = new ChangeMCVersion(); if (cv.ShowDialog() == true) { this.changingVersion = true; TinyMinecraftVersion prevVer = this.Version; this.Version = cv.version; try { Task.Factory.StartNew(delegate { if (!File.Exists(cv.version.FullVersion.BinaryPath)) { Download dl = cv.version.FullVersion.ScheduleJarDownload(); PluginAPI.PluginManager.onVersionDownload(dl); DownloadPackage dp = new DownloadPackage("Libraries", true); dp.ShouldContinue = true; cv.version.FullVersion.Libraries.ForEach(l => { if (!File.Exists(l.Extractpath)) { l.ScheduleExtract(dp); } }); if (dp.getDownloads().Count > 0) DownloadManager.ScheduleDownload(dp); dl.WaitForComplete(); CopyJar(); App.InvokeAction(delegate { (App.mainWindow.listBox_instanceInfo.Items[0] as Label).Content = (this.Version == null ? "no version" : this.Version.Key); App.mainWindow.UpdateInstances(); }); this.changingVersion = false; } else { CopyJar(); App.InvokeAction(delegate { (App.mainWindow.listBox_instanceInfo.Items[0] as Label).Content = (this.Version == null ? "no version" : this.Version.Key); App.mainWindow.UpdateInstances(); }); this.changingVersion = false; } }); } catch (Exception ex) { MCM.Utils.MessageBox.ShowDialog("Error", "The selected version could not be changed because: " + ex.Message); this.Version = prevVer; (App.mainWindow.listBox_instanceInfo.Items[0] as Label).Content = (this.Version == null ? "no version" : this.Version.Key); App.mainWindow.UpdateInstances(); this.changingVersion = false; } } PluginManager.onChangeVersion(this); } }