Ejemplo n.º 1
0
        /// <summary>
        ///     Launch a new server
        /// </summary>
        /// <param name="server">the server type that will be executed</param>
        /// <param name="javaVersion">the java version to use</param>
        /// <param name="jarFile">the jar file to run</param>
        /// <param name="minMem">the minimum amount of memory to set</param>
        /// <param name="maxMem">the maximum amount of memory to set</param>
        /// <param name="defaultParameters">the parameters entered by the user (optional)</param>
        /// <param name="defaultFlags">the flags entered by the user (optional)</param>
        /// <param name="automated">
        ///     If this is an automated launch. Automated launches won't check for server updates and limit
        ///     popups.
        /// </param>
        public void LaunchServer(IMinecraftServer server, JavaVersion javaVersion, string jarFile, UInt32 minMem,
                                 UInt32 maxMem, string defaultParameters = "", string defaultFlags = "", Boolean automated = false)
        {
            server.PrepareLaunch();
            string parameters = server.GetLaunchParameters(defaultParameters);
            string flags      = server.GetLaunchFlags(defaultFlags);
            string argument   = parameters + " -Xms" + minMem + "M -Xmx" + maxMem + "M -jar \"" + jarFile + "\" " + flags;
            string executable = JavaApi.GetJavaPath(javaVersion);

            ProcessHandler.StartServer(executable, argument, server);
        }
Ejemplo n.º 2
0
 /// <summary>
 ///     Get the path of the selected java instance
 /// </summary>
 /// <returns></returns>
 public string GetSelectedJavaPath()
 {
     return(JavaApi.GetJavaPath(GetSelectedJavaVersion()));
 }
Ejemplo n.º 3
0
        /// <summary>
        ///     Add content and settings to the UI
        /// </summary>
        private void LoadUi()
        {
            Logger.Log(LogLevel.Info, "StarterTab", "Loading UI");
            // Add all servers to the list
            CBServerType.Items.Clear();
            foreach (string servername in _servers.Keys)
            {
                CBServerType.Items.Add(servername);
            }

            int selectedServer = Config.ReadInt("Starter", "ServerType", 0);

            // check if this server id exists
            if (selectedServer < CBServerType.Items.Count)
            {
                CBServerType.SelectedIndex = selectedServer;
            }
            else
            {
                if (CBServerType.Items.Count > 0)
                {
                    CBServerType.SelectedIndex = 0;
                }
            }
            LoadServer();
            //Selecting a server will enable/disable the available/unavailable features

            // Cache total amount of ram, set maximum values
            int totalMb = Convert.ToInt32(MemoryCounter.TotalMemoryMb());

            TBMaxRam.Maximum  = totalMb;
            TBMinRam.Maximum  = totalMb;
            NumMaxRam.Maximum = totalMb;
            NumMinRam.Maximum = totalMb;

            int minRamValue = Config.ReadInt("Starter", "MinRam", 128);
            int maxRamValue = Config.ReadInt("Starter", "MaxRam", 1024);

            // check for sub-zero values
            if (minRamValue < 0)
            {
                minRamValue = 0;
            }
            if (maxRamValue < 0)
            {
                maxRamValue = 0;
            }

            // value should be less than maximum value
            if (maxRamValue < NumMaxRam.Maximum)
            {
                NumMaxRam.Value = maxRamValue;
            }
            else
            {
                NumMaxRam.Value = 1024;
            }
            if (minRamValue < NumMinRam.Maximum)
            {
                NumMinRam.Value = minRamValue;
            }
            else
            {
                NumMaxRam.Value = 1024;
            }

            // Add options for installed java versions
            CBJavaVersion.Items.Clear();
            if (JavaApi.IsInstalled(JavaVersion.Jre6X32))
            {
                CBJavaVersion.Items.Add("Java 6 - 32 bit");
            }
            if (JavaApi.IsInstalled(JavaVersion.Jre6X64))
            {
                CBJavaVersion.Items.Add("Java 6 - 64 bit");
            }
            if (JavaApi.IsInstalled(JavaVersion.Jre7X32))
            {
                CBJavaVersion.Items.Add("Java 7 - 32 bit");
            }
            if (JavaApi.IsInstalled(JavaVersion.Jre7X64))
            {
                CBJavaVersion.Items.Add("Java 7 - 64 bit");
            }
            if (JavaApi.IsInstalled(JavaVersion.Jre8X32))
            {
                CBJavaVersion.Items.Add("Java 8 - 32 bit");
            }
            if (JavaApi.IsInstalled(JavaVersion.Jre8X64))
            {
                CBJavaVersion.Items.Add("Java 8 - 64 bit");
            }

            int javaType = Config.ReadInt("Starter", "JavaVersion", 0);

            if (javaType < CBJavaVersion.Items.Count)
            {
                CBJavaVersion.SelectedIndex = javaType;
            }
            else
            {
                if (CBJavaVersion.Items.Count > 0)
                {
                    CBJavaVersion.SelectedIndex = 0;
                }
            }

            TxtJarFile.Text = Config.ReadString("Starter", "JarFile", "");
            TxtOptArg.Text  = Config.ReadString("Starter", "OptionalArguments", "");
            TxtOptFlag.Text = Config.ReadString("Starter", "OptionalFlags", "");

            Logger.Log(LogLevel.Info, "StarterTab", "UI Loaded");
            _ready = true;
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     Validate the input. Return true if input is valid and server can be started.
        /// </summary>
        /// <returns>Returns true if all input is valid</returns>
        /// <remarks>
        ///     Important checks: RAM less than 1024Mb on 32bit, java installed, valid .jar file
        ///     This method is NOT thread-safe
        /// </remarks>
        public Boolean ValidateInput()
        {
            if (GetSelectedServer().HasCustomAssembly)
            {
                return(true);
            }

            BtnLaunch.Enabled = false;
            errorProvider.SetError(BtnLaunch, "The provided settings are invalid");

            if (!File.Exists(TxtJarFile.Text))
            {
                errorProvider.SetError(TxtJarFile,
                                       "File does not exist. Press the download button or change the file path to an existing file.");
                return(false);
            }
            if (!TxtJarFile.Text.EndsWith(".jar"))
            {
                errorProvider.SetError(TxtJarFile,
                                       "File should be a *.jar file. This file is not a .jar file, or the extension is incorrect.");
                return(false);
            }
            if (new FileInfo(TxtJarFile.Text).Length < 1024)
            {
                errorProvider.SetError(TxtJarFile, "File is corrupt. Download again.");
                return(false);
            }

            if (JavaApi.Is32Bitversion(GetSelectedJavaVersion()))
            {
                if (NumMaxRam.Value > 1024)
                {
                    NumMaxRam.Value = 1024;
                    errorProvider.SetError(NumMaxRam,
                                           "You are using a 32bit version of java. In this case, RAM is limited to 1024mb due to java limitations.");
                }
                else
                {
                    errorProvider.SetError(NumMaxRam, "");
                }
                if (NumMinRam.Value > 1024)
                {
                    NumMinRam.Value = 1024;
                    errorProvider.SetError(NumMinRam,
                                           "You are using a 32bit version of java. In this case, RAM is limited to 1024mb due to java limitations.");
                }
                if (NumMinRam.Value > 768)
                {
                    errorProvider.SetError(NumMinRam,
                                           "To prevent issues, a value below 768mb is recommended here. Recommended value: 128mb");
                }
                else
                {
                    errorProvider.SetError(NumMinRam, "");
                }
            }

            BtnLaunch.Enabled = true;
            errorProvider.SetError(BtnLaunch, "");
            errorProvider.SetError(TxtJarFile, "");
            return(true);
        }