コード例 #1
0
        public static string GetJavaVersion()
        {
            object value = JavaPath.GetJavaRegistry().GetValue("CurrentVersion", null);

            if (value == null)
            {
                throw new JavaNotFoundException();
            }
            return(value.ToString());
        }
コード例 #2
0
        public static string GetJavaHome()
        {
            object obj = JavaPath.GetJavaRegistry().OpenSubKey(JavaPath.GetJavaVersion());

            if (obj == null)
            {
                throw new JavaNotFoundException();
            }
            obj = ((RegistryKey)obj).GetValue("JavaHome", null);
            if (obj == null)
            {
                throw new JavaNotFoundException();
            }
            return(obj.ToString());
        }
コード例 #3
0
 private static Process ApplyProcessInfo(string binary, string[] parameters)
 {
     return(new Process
     {
         StartInfo =
         {
             FileName               = Path.Combine(JavaPath.GetJavaBinaryPath(), binary),
             Arguments              = JavaPath.CombineParameters(parameters),
             UseShellExecute        = false,
             WindowStyle            = ProcessWindowStyle.Hidden,
             RedirectStandardOutput = true,
             RedirectStandardError  = true,
             RedirectStandardInput  = true
         }
     });
 }
コード例 #4
0
        public static string GetJavaBinaryPath()
        {
            object obj = JavaPath.GetJavaRegistry().OpenSubKey(JavaPath.GetJavaVersion());

            if (obj == null)
            {
                throw new JavaNotFoundException();
            }
            obj = ((RegistryKey)obj).GetValue("JavaHome", null);
            if (obj == null)
            {
                throw new JavaNotFoundException();
            }
            obj = Path.Combine(obj.ToString(), "bin");
            if (!Directory.Exists(obj.ToString()))
            {
                throw new JavaNotFoundException();
            }
            return(obj.ToString());
        }
コード例 #5
0
 public static Process CreateJava(params string[] parameters)
 {
     return(JavaPath.ApplyProcessInfo("java.exe", parameters));
 }
コード例 #6
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            string selectedJar = e.Argument.ToString();

            Authentication authentication = new Authentication();

            Control.CheckForIllegalCrossThreadCalls = false;
            base.Hide();
            Control.CheckForIllegalCrossThreadCalls = true;
            authentication.SessionId = "12345";
            if (!string.IsNullOrEmpty(Program.LoginPasswort))
            {
                this.sw.SetText("Login...");
                Control.CheckForIllegalCrossThreadCalls = false;
                this.sw.TopMost = false;
                Control.CheckForIllegalCrossThreadCalls = true;
                authentication.Username    = Program.LoginUsername;
                authentication.Password    = Program.LoginPasswort;
                authentication.LoginApiUri = new Uri("https://login.minecraft.net");
                if (!authentication.Login())
                {
                    MessageBox.Show("Passwort oder Username falsch, du bekommst leider keinen Zugriff auf Premium-Server.");
                }
                else
                {
                    this.sw.SetText("Login erfolgreich!");
                }
                Control.CheckForIllegalCrossThreadCalls = false;
                this.sw.TopMost = true;
                Control.CheckForIllegalCrossThreadCalls = true;
            }
            try
            {
                this.sw.SetText("Minecraft wird vorbereitet...");
                double num  = this.computer.AvailablePhysicalMemory / 1048576uL;
                int    num2 = -65535;
                int    num3 = 0;
                bool   flag = false;
                while (num2 != 0 && num3 < 20)
                {
                    num *= 0.9;
                    double num4 = num / 2.0;
                    int    num5 = (int)Math.Round(num / 4.0, 0) * 4;
                    int    num6 = (int)Math.Round(num4 / 4.0, 0) * 4;
                    num3++;
                    this.sw.SetText("Starte mit " + num5 + " MB RAM...");
                    int num7 = 0;
                    while (num7 < 2 && num2 != 0)
                    {
                        Process process = JavaPath.CreateJavaW(new string[]
                        {
                            "-Xms" + num6 + "M",
                            "-Xmx" + num5 + "M",
                            "-XX:UseSSE=3",
                            "-Djava.library.path=" + Program.NativesPath,
                            flag ? "-Xincgc" : null,
                            "-cp",
                            string.Join(";", new string[]
                            {
                                selectedJar,
                                Path.Combine(Program.BinPath, "lwjgl.jar"),
                                Path.Combine(Program.BinPath, "lwjgl_util.jar"),
                                Path.Combine(Program.BinPath, "jinput.jar")
                            }),
                            "net.minecraft.client.Minecraft",
                            Program.LoginUsername,
                            "12345"
                        });
                        process.EnableRaisingEvents = true;
                        process.StartInfo.EnvironmentVariables["AppData"] = Environment.CurrentDirectory;
                        process.Start();
                        while (!process.HasExited)
                        {
                            string text = process.StandardOutput.ReadLine();
                            if (text != null)
                            {
                                this.sw.SetText(text);
                                Control.CheckForIllegalCrossThreadCalls = false;
                                base.TopMost    = true;
                                base.ControlBox = false;
                                Control.CheckForIllegalCrossThreadCalls = true;
                                if (text.ToLower().Contains("lwjgl"))
                                {
                                    Control.CheckForIllegalCrossThreadCalls = false;
                                    this.sw.Hide();
                                    Control.CheckForIllegalCrossThreadCalls = true;
                                }
                            }
                        }
                        num2 = process.ExitCode;
                        flag = !flag;
                        num7++;
                    }
                }
                if (num2 != 0)
                {
                    MessageBox.Show("Java hat einen Fehler festgestellt. Fehlercode: " + num2, "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                }
            }
            catch (JavaNotFoundException)
            {
                MessageBox.Show("Auf diesem Computer ist kein Java installiert. Bitte nachinstallieren!", "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Java konnte nicht gestartet werden: " + ex.Message, "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
        }