예제 #1
0
        void StartWithAdvancedOptions(MSession session)
        {
            // game directory
            var defaultPath = MinecraftPath.GetOSDefaultPath();
            var path        = Path.Combine(Environment.CurrentDirectory, "game dir");

            // create minecraft path instance
            var minecraft = new MinecraftPath(path);

            minecraft.SetAssetsPath(Path.Combine(defaultPath, "assets")); // this speed up asset downloads

            // get all version metadatas
            // you can also use MVersionLoader.GetVersionMetadatasFromLocal and GetVersionMetadatasFromWeb
            var versionMetadatas = MVersionLoader.GetVersionMetadatas(minecraft);

            foreach (var item in versionMetadatas)
            {
                Console.WriteLine("Name : {0}", item.Name);
                Console.WriteLine("Type : {0}", item.Type);
                Console.WriteLine("Path : {0}", item.Path);
                Console.WriteLine("IsLocalVersion : {0}", item.IsLocalVersion);
                Console.WriteLine("============================================");
            }
            Console.WriteLine("");
            Console.WriteLine("LatestRelease : {0}", versionMetadatas.LatestReleaseVersion?.Name);
            Console.WriteLine("LatestSnapshot : {0}", versionMetadatas.LatestSnapshotVersion?.Name);

            Console.WriteLine("Input Version Name (ex: 1.15.2) : ");
            var versionName = Console.ReadLine();

            // get MVersion from MVersionMetadata
            var version = versionMetadatas.GetVersion(versionName);

            if (version == null)
            {
                Console.WriteLine("{0} is not exist", versionName);
                return;
            }

            Console.WriteLine("\n\nVersion Information : ");
            Console.WriteLine("Id : {0}", version.Id);
            Console.WriteLine("Type : {0}", version.TypeStr);
            Console.WriteLine("ReleaseTime : {0}", version.ReleaseTime);
            Console.WriteLine("AssetId : {0}", version.AssetId);
            Console.WriteLine("JAR : {0}", version.Jar);
            Console.WriteLine("Libraries : {0}", version.Libraries.Length);

            if (version.IsInherited)
            {
                Console.WriteLine("Inherited Profile from {0}", version.ParentVersionId);
            }

            // Download mode
            Console.WriteLine("\nSelect download mode : ");
            Console.WriteLine("(1) Sequence Download");
            Console.WriteLine("(2) Parallel Download");
            var downloadModeInput = Console.ReadLine();

            MDownloader downloader;

            if (downloadModeInput == "1")
            {
                downloader = new MDownloader(minecraft, version); // Sequence Download
            }
            else if (downloadModeInput == "2")
            {
                downloader = new MParallelDownloader(minecraft, version); // Parallel Download (note: Parallel Download is not stable yet)
            }
            else
            {
                Console.WriteLine("Input 1 or 2");
                Console.ReadLine();
                return;
            }

            downloader.ChangeFile     += Downloader_ChangeFile;
            downloader.ChangeProgress += Downloader_ChangeProgress;

            // Start download
            downloader.DownloadAll();

            Console.WriteLine("Download Completed.\n");

            // Set java
            Console.WriteLine("Input java path (empty input will download java) : ");
            var javaInput = Console.ReadLine();

            if (javaInput == "")
            {
                var java = new MJava();
                java.ProgressChanged += Downloader_ChangeProgress;
                javaInput             = java.CheckJava();
            }

            // LaunchOption
            var option = new MLaunchOption()
            {
                JavaPath     = javaInput,
                Session      = session,
                StartVersion = version,
                Path         = minecraft,

                MaximumRamMb = 4096,
                ScreenWidth  = 1600,
                ScreenHeight = 900,
            };

            // Launch
            var launch  = new MLaunch(option);
            var process = launch.GetProcess();

            Console.WriteLine(process.StartInfo.Arguments);
            process.Start();
            Console.WriteLine("Started");
            Console.ReadLine();
        }
예제 #2
0
        private void btnLaunch_Click(object sender, EventArgs e)
        {
            //Launches game

            string selected = this.cbVersion.GetItemText(this.cbVersion.SelectedItem);

            System.Reflection.Assembly assembly   = System.Reflection.Assembly.GetExecutingAssembly();
            FileVersionInfo            versionInf = FileVersionInfo.GetVersionInfo(assembly.Location);

            if (guna2CheckBox1.Checked == true)

            {
                //Playing rpc
                if (Properties.Settings.Default.langtr == true)
                {
                    client.UpdateState($"{selected} oynuyor.");
                }
                else
                {
                    client.UpdateState($"Playing {selected}.");
                }
            }

            UpdateSession(MSession.GetOfflineSession(lbUsername.Text));
            if (Session == null)
            {
                MessageBox.Show("İlk önce giriş yap");
                return;
            }

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

            var launchOption = createLaunchOption();

            if (launchOption == null)
            {
                return;
            }
            //Creates launch options
            var version        = cbVersion.Text;
            var useParallel    = rbParallelDownload.Checked;
            var checkHash      = cbCheckFileHash.Checked;
            var downloadAssets = !cbSkipAssetsDownload.Checked;

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

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

                    MVersion versionInfo      = Versions.GetVersion(version);
                    launchOption.StartVersion = versionInfo;

                    MDownloader 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);
                    var process = launch.GetProcess();

                    StartProcess(process);
                }
                catch (MDownloadFileException mex)
                {
                    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)
                {
                    MessageBox.Show(wex.ToString() + "\n\nJava Problem");
                }
                catch (Exception ex)
                {
                    if (Properties.Settings.Default.langtr == true)
                    {
                        this.Alert("Oyun başlatılamadı", "Libaryler indirilemedi veya", "birşeyler ters gitti.", Form_Info.enmType.Error);
                    }//error
                    else
                    {
                        this.Alert("ERROR", "Libraries could not be downloaded or ", "something goes wrong.", Form_Info.enmType.Error);
                    }
                    MessageBox.Show(ex.ToString());
                }
            });

            th.Start();
        }
예제 #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
        public void CheckGameFilesParallel(MVersion version, bool downloadAsset = true, bool checkFileHash = true)
        {
            var downloader = new MParallelDownloader(MinecraftPath, version);

            downloadGameFiles(downloader, downloadAsset, checkFileHash);
        }