Пример #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>
        public void LaunchServer(IMinecraftServer server, JavaVersion javaVersion, string jarFile, UInt32 minMem,
                                 UInt32 maxMem, string defaultParameters = "", string defaultFlags = "")
        {
            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);
        }
Пример #2
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
            this.CBServerType.Items.Clear();
            foreach (string servername in this._servers.Keys)
            {
                this.CBServerType.Items.Add(servername);
            }

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

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

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

            this.TBMaxRam.Maximum  = totalMb;
            this.TBMinRam.Maximum  = totalMb;
            this.NumMaxRam.Maximum = totalMb;
            this.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 < this.NumMaxRam.Maximum)
            {
                this.NumMaxRam.Value = maxRamValue;
            }
            else
            {
                this.NumMaxRam.Value = 1024;
            }
            if (minRamValue < this.NumMinRam.Maximum)
            {
                this.NumMinRam.Value = minRamValue;
            }
            else
            {
                this.NumMaxRam.Value = 1024;
            }

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

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

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

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

            Logger.Log(LogLevel.Info, "StarterTab", "UI Loaded");
            this._ready = true;
        }