public void Execute(ListVersionsOptions options)
        {
            var json     = _httpClient.GetStringAsync(VERSION_MANIFEST_URL).Result;
            var manifest = RawVersionListManifest.ParseList(json);

            foreach (var version in manifest.Versions)
            {
                var message = string.Format("{0,-50}{1}", version.VersionId, version.ReleaseType);
                _logger.LogInformation(message);
            }
        }
        private void UpdateVersions()
        {
            if (_configuration.Arguments.OfflineMode)
            {
                if (File.Exists(_configuration.McVersions + @"\versions.json"))
                {
                    _versionList = RawVersionListManifest.ParseList(File.ReadAllText(_configuration.McVersions + @"\versions.json"));
                    return;
                }
                MessageBox.Show(_configuration.Localization.SomeFilesMissingMessage);
                Environment.Exit(0);
            }

            RawVersionListManifest remoteManifest = RawVersionListManifest.ParseList(new WebClient().DownloadString(
                                                                                         new Uri("https://launchermeta.mojang.com/mc/game/version_manifest.json")));

            if (!Directory.Exists(_configuration.McVersions))
            {
                Directory.CreateDirectory(_configuration.McVersions);
            }
            if (!File.Exists(_configuration.McVersions + @"\versions.json"))
            {
                File.WriteAllText(_configuration.McVersions + @"\versions.json", remoteManifest.ToString());
                _versionList = remoteManifest;
                return;
            }

            RawVersionListManifest localManifest =
                RawVersionListManifest.ParseList(File.ReadAllText(_configuration.McVersions + @"\versions.json"));

            if (remoteManifest.Versions.Count == localManifest.Versions.Count &&
                remoteManifest.LatestVersions.Release == localManifest.LatestVersions.Release &&
                remoteManifest.LatestVersions.Snapshot == localManifest.LatestVersions.Snapshot)
            {
                _versionList = localManifest;

                return;
            }

            File.WriteAllText(_configuration.McVersions + @"\versions.json", remoteManifest.ToString());
            _versionList = remoteManifest;
        }
Ejemplo n.º 3
0
        private void DownloadVersion(string version)
        {
            string path = Path.Combine(_mcVersions, version + @"\");

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            AppendLog($"Validating files for Minecraft {version}...");
            SetStatusLabel(FindResource("r_LabelStatusValidatingVersion").ToString());

            if (!File.Exists($@"{path}\{version}.json"))
            {
                RawVersionListManifest versionList =
                    RawVersionListManifest.ParseList(_webClient.DownloadString(@"https://launchermeta.mojang.com/mc/game/version_manifest.json"));
                AppendLog(" Downloading JSON...");
                _webClient.DownloadFile(
                    new Uri(versionList.GetVersion(version)?.ManifestUrl ?? string.Format(
                                "https://s3.amazonaws.com/Minecraft.Download/versions/{0}/{0}.json", version)),
                    string.Format(@"{0}\{1}\{1}.json", _mcVersions, version));
            }

            VersionManifest selectedVersionManifest = VersionManifest.ParseVersion(
                new DirectoryInfo(_mcVersions + @"\" + version), false);

            if ((!File.Exists($"{path}/{version}.jar")) && selectedVersionManifest.InheritsFrom == null)
            {
                AppendLog(" Downloading JAR...");
                _webClient.DownloadFile(new Uri(selectedVersionManifest.DownloadInfo?.Client.Url
                                                ?? string.Format(
                                                    "https://s3.amazonaws.com/Minecraft.Download/versions/{0}/{0}.jar",
                                                    version)),
                                        string.Format("{0}/{1}/{1}.jar", _mcVersions, version));
            }

            if (selectedVersionManifest.InheritsFrom != null)
            {
                DownloadVersion(selectedVersionManifest.InheritsFrom);
            }
        }