示例#1
0
 void output(string msg)
 {
     GameLog.AddLog(msg);
 }
示例#2
0
        // Start Game
        private async void Btn_Launch_Click(object sender, EventArgs e)
        {
            if (session == null)
            {
                MessageBox.Show("Login First");
                return;
            }

            if (cbVersion.Text == "")
            {
                MessageBox.Show("Select Version");
                return;
            }

            // disable ui
            setUIEnabled(false);

            try
            {
                // create LaunchOption
                var launchOption = new MLaunchOption()
                {
                    MaximumRamMb = int.Parse(TxtXmx.Text),
                    Session      = this.session,

                    VersionType         = Txt_VersionType.Text,
                    GameLauncherName    = Txt_GLauncherName.Text,
                    GameLauncherVersion = Txt_GLauncherVersion.Text,

                    FullScreen = cbFullscreen.Checked,

                    ServerIp = Txt_ServerIp.Text,

                    DockName = Txt_DockName.Text,
                    DockIcon = Txt_DockIcon.Text
                };

                if (!string.IsNullOrEmpty(javaPath))
                {
                    launchOption.JavaPath = javaPath;
                }

                if (!string.IsNullOrEmpty(txtXms.Text))
                {
                    launchOption.MinimumRamMb = int.Parse(txtXms.Text);
                }

                if (!string.IsNullOrEmpty(Txt_ServerPort.Text))
                {
                    launchOption.ServerPort = int.Parse(Txt_ServerPort.Text);
                }

                if (!string.IsNullOrEmpty(Txt_ScWd.Text) && !string.IsNullOrEmpty(Txt_ScHt.Text))
                {
                    launchOption.ScreenHeight = int.Parse(Txt_ScHt.Text);
                    launchOption.ScreenWidth  = int.Parse(Txt_ScWd.Text);
                }

                if (!string.IsNullOrEmpty(Txt_JavaArgs.Text))
                {
                    launchOption.JVMArguments = Txt_JavaArgs.Text.Split(' ');
                }

                if (rbParallelDownload.Checked)
                {
                    System.Net.ServicePointManager.DefaultConnectionLimit = 256;
                    launcher.FileDownloader = new AsyncParallelDownloader();
                }
                else
                {
                    launcher.FileDownloader = new SequenceDownloader();
                }

                // check file hash or don't check
                launcher.GameFileCheckers.AssetFileChecker.CheckHash   = cbSkipHashCheck.Checked;
                launcher.GameFileCheckers.ClientFileChecker.CheckHash  = cbSkipHashCheck.Checked;
                launcher.GameFileCheckers.LibraryFileChecker.CheckHash = cbSkipHashCheck.Checked;

                if (cbSkipAssetsDownload.Checked)
                {
                    launcher.GameFileCheckers.AssetFileChecker = null;
                }

                var process = await launcher.CreateProcessAsync(cbVersion.Text, launchOption); // Create Arguments and Process

                // process.Start(); // Just start game, or
                StartProcess(process);  // Start Process with debug options
            }
            catch (FormatException fex) // int.Parse exception
            {
                MessageBox.Show("Failed to create MLaunchOption\n\n" + fex);
            }
            catch (MDownloadFileException mex) // download exception
            {
                MessageBox.Show(
                    $"FileName : {mex.ExceptionFile.Name}\n" +
                    $"FilePath : {mex.ExceptionFile.Path}\n" +
                    $"FileUrl : {mex.ExceptionFile.Url}\n" +
                    $"FileType : {mex.ExceptionFile.Type}\n\n" +
                    mex.ToString());
            }
            catch (Win32Exception wex) // java exception
            {
                MessageBox.Show(wex + "\n\nIt seems your java setting has problem");
            }
            catch (Exception ex) // all exception
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                // re open log form
                if (logForm != null)
                {
                    logForm.Close();
                }

                logForm = new GameLog();
                logForm.Show();

                // enable ui
                setUIEnabled(true);
            }
        }
示例#3
0
        private void Btn_Launch_Click(object sender, EventArgs e)
        {
            // Launch

            if (Session == null)
            {
                MessageBox.Show("Login First");
                return;
            }

            if (cbVersion.Text == "")
            {
                MessageBox.Show("Select Version");
                return;
            }

            // disable ui
            setUIEnabled(false);

            // create LaunchOption
            var launchOption = createLaunchOption();

            if (launchOption == null)
            {
                return;
            }

            var version        = cbVersion.Text;
            var useParallel    = rbParallelDownload.Checked;
            var checkHash      = cbCheckFileHash.Checked;
            var downloadAssets = !cbSkipAssetsDownload.Checked;

            var th = new Thread(() =>
            {
                try
                {
                    if (useMJava) // Download Java
                    {
                        var mjava              = new MJava(MinecraftPath.Runtime);
                        mjava.ProgressChanged += Launcher_ProgressChanged;

                        var javapath          = mjava.CheckJava();
                        launchOption.JavaPath = javapath;
                    }

                    MVersion versionInfo      = Versions.GetVersion(version); // Get Version Info
                    launchOption.StartVersion = versionInfo;

                    MDownloader downloader; // Create Downloader
                    if (useParallel)
                    {
                        downloader = new MParallelDownloader(MinecraftPath, versionInfo, 10, true);
                    }
                    else
                    {
                        downloader = new MDownloader(MinecraftPath, versionInfo);
                    }

                    downloader.ChangeFile     += Launcher_FileChanged;
                    downloader.ChangeProgress += Launcher_ProgressChanged;
                    downloader.CheckHash       = checkHash;
                    downloader.DownloadAll(downloadAssets);

                    var launch  = new MLaunch(launchOption); // Create Arguments and Process
                    var process = launch.GetProcess();

                    StartProcess(process); // Start Process with debug options

                    // or just start process
                    // process.Start();
                }
                catch (MDownloadFileException mex) // download exception
                {
                    MessageBox.Show(
                        $"FileName : {mex.ExceptionFile.Name}\n" +
                        $"FilePath : {mex.ExceptionFile.Path}\n" +
                        $"FileUrl : {mex.ExceptionFile.Url}\n" +
                        $"FileType : {mex.ExceptionFile.Type}\n\n" +
                        mex.ToString());
                }
                catch (Win32Exception wex) // java exception
                {
                    MessageBox.Show(wex.ToString() + "\n\nIt seems your java setting has problem");
                }
                catch (Exception ex) // all exception
                {
                    MessageBox.Show(ex.ToString());
                }
                finally
                {
                    Invoke(new Action(() =>
                    {
                        // re open log form
                        if (logForm != null)
                        {
                            logForm.Close();
                        }

                        logForm = new GameLog();
                        logForm.Show();

                        // enable ui
                        setUIEnabled(true);
                    }));
                }
            });

            th.Start();
        }
示例#4
0
        private void Btn_Launch_Click(object sender, EventArgs e)
        {
            // Launch

            if (Session == null)
            {
                MessageBox.Show("Login First");
                return;
            }

            if (Cb_Version.Text == "")
            {
                return;
            }

            groupBox1.Enabled = false;
            groupBox2.Enabled = false;

            try
            {
                var version = Cb_Version.Text;
                var forge   = "";

                if (Cb_Forge.Checked)
                {
                    forge = Txt_ForgeVersion.Text;
                }

                var launchOption = new MLaunchOption()
                {
                    JavaPath     = Txt_Java.Text,
                    MaximumRamMb = int.Parse(Txt_Ram.Text),
                    Session      = this.Session,

                    VersionType         = Txt_VersionType.Text,
                    GameLauncherName    = Txt_GLauncherName.Text,
                    GameLauncherVersion = Txt_GLauncherVersion.Text,

                    ServerIp = Txt_ServerIp.Text,

                    DockName = Txt_DockName.Text,
                    DockIcon = Txt_DockIcon.Text
                };

                if (!string.IsNullOrEmpty(Txt_ServerPort.Text))
                {
                    launchOption.ServerPort = int.Parse(Txt_ServerPort.Text);
                }

                if (!string.IsNullOrEmpty(Txt_ScWd.Text) && !string.IsNullOrEmpty(Txt_ScHt.Text))
                {
                    launchOption.ScreenHeight = int.Parse(Txt_ScHt.Text);
                    launchOption.ScreenWidth  = int.Parse(Txt_ScWd.Text);
                }

                if (!string.IsNullOrEmpty(Txt_JavaArgs.Text))
                {
                    launchOption.JVMArguments = Txt_JavaArgs.Text.Split(' ');
                }

                var th = new Thread(() =>
                {
                    Process mc;

                    if (string.IsNullOrEmpty(forge))
                    {
                        mc = Launcher.CreateProcess(version, launchOption); // vanilla
                    }
                    else
                    {
                        mc = Launcher.CreateProcess(version, forge, launchOption); // forge
                    }
                    StartProcess(mc);
                });
                th.Start();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                var fWork = new Action(() =>
                {
                    if (logForm != null)
                    {
                        logForm.Close();
                    }

                    logForm = new GameLog();
                    logForm.Show();

                    groupBox1.Enabled = true;
                    groupBox2.Enabled = true;
                });

                if (this.InvokeRequired)
                {
                    this.Invoke(fWork);
                }
                else
                {
                    fWork.Invoke();
                }
            }
        }