コード例 #1
0
        private void refreshVersions(string showVersion)
        {
            cbVersion.Items.Clear();

            var th = new Thread(new ThreadStart(delegate
            {
                Versions = MVersionLoader.GetVersionMetadatas(MinecraftPath);
                Invoke(new Action(() =>
                {
                    bool showVersionExist = false;
                    foreach (var item in Versions)
                    {
                        if (showVersion != null && item.Name == showVersion)
                        {
                            showVersionExist = true;
                        }
                        cbVersion.Items.Add(item.Name);
                    }

                    if (showVersion == null || !showVersionExist)
                    {
                        btnSetLastVersion_Click(null, null);
                    }
                    else
                    {
                        cbVersion.Text = showVersion;
                    }
                }));
            }));

            th.Start();
        }
コード例 #2
0
        private async Task <MVersion> GetVersionMetadataAsync(string versionString)
        {
            var versionLoader = new MVersionLoader(new MinecraftPath(PackBuilder.ProfilePath));
            var versions      = await versionLoader.GetVersionMetadatasAsync();

            return(versions.GetVersion(versionString));
        }
コード例 #3
0
ファイル: Launcher.cshtml.cs プロジェクト: TURX/VL-Minecraft
 public async Task <IActionResult> OnPostDownload()
 {
     if (LStarted == true)
     {
         HttpContext.Session.Set("LQueryProgress", true);
         return(RedirectToPage("/Launcher"));
     }
     HttpContext.Session.Set("DLQueryProgress", true);
     if (DLStarted == false)
     {
         DLStarted            = true;
         DLFileKind           = string.Empty;
         DLFileName           = string.Empty;
         DLProgressedFileCnt  = "0";
         DLTotFileCnt         = "?";
         DLProgressPercentage = "0";
         DLSuccess            = "false";
         var         minecraft        = new MinecraftPath(Path.Combine(Utility.GetWorkingDir(), ".minecraft"));
         var         versionMetadatas = new MVersionLoader().GetVersionMetadatas(minecraft);
         var         version          = versionMetadatas.GetVersion("1.16.5");
         MDownloader downloader       = new MDownloader(minecraft, version);
         downloader.ChangeFile += (e) => {
             DLFileKind          = e.FileKind.ToString();
             DLFileName          = e.FileName;
             DLProgressedFileCnt = e.ProgressedFileCount.ToString();
             DLTotFileCnt        = e.TotalFileCount.ToString();
         };
         downloader.ChangeProgress += (sender, e) => {
             DLProgressPercentage = e.ProgressPercentage.ToString();
         };
         await Task.Run(() => {
             try
             {
                 downloader.DownloadAll();
                 HttpContext.Session.Set("SuccessMsg", Translation.Translate("launcher-success-dl"));
             } catch (Exception e)
             {
                 HttpContext.Session.Set("ErrorMsg", e.Message);
             }
             HttpContext.Session.Set("DLQueryProgress", false);
             DLSuccess = "true";
             DLStarted = false;
         });
     }
     return(RedirectToPage("/Launcher"));
 }
コード例 #4
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();
        }
コード例 #5
0
 public MVersionCollection UpdateVersions()
 {
     Versions = MVersionLoader.GetVersionMetadatas(MinecraftPath);
     return(Versions);
 }