Ejemplo n.º 1
0
        private byte[] GetLatestAssets()
        {
            try
            {
                using (WebClient wc = new WebClient())
                {
                    var rawJson = wc.DownloadString("https://launchermeta.mojang.com/mc/game/version_manifest.json?_t=" +
                                                    (long)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds);

                    VersionManifest manifest = VersionManifest.FromJson(rawJson);
                    Version         version  =
                        manifest.Versions.FirstOrDefault(x => x.Id == JavaProtocol.VersionId);                        //.OrderByDescending(x => x.ReleaseTime.ToUnixTimeSeconds()).FirstOrDefault();

                    var latestVersion = manifest.Versions.OrderByDescending(x => x.ReleaseTime.ToUnixTimeSeconds())
                                        .FirstOrDefault();

                    Log.Info($"Using java assets version {version.Id} ({version.Type.ToString()})");

                    if (version.ReleaseTime < latestVersion.ReleaseTime)
                    {
                        Log.Info($"Java assets outdated, latest version is: {latestVersion.Id} ({latestVersion.Type.ToString()})");
                    }

                    byte[] data;
                    string savedPath = Path.Combine("assets", $"java-{version.Id}.zip");
                    if (Storage.TryReadBytes(savedPath, out data))
                    {
                        return(data);
                    }
                    else
                    {
                        Log.Info("Downloading Minecraft:Java edition assets...");
                        LauncherMeta meta       = LauncherMeta.FromJson(wc.DownloadString(version.Url));
                        byte[]       clientData = wc.DownloadData(meta.Downloads.Client.Url);
                        if (Storage.TryWriteBytes(savedPath, clientData))
                        {
                            Storage.TryWriteBytes(VersionFile, Encoding.Unicode.GetBytes(savedPath));
                        }
                        return(clientData);
                    }
                }
            }
            catch
            {
                Log.Warn($"Failed to check for latest assets!");
                if (Storage.TryReadBytes(VersionFile, out byte[] value))
Ejemplo n.º 2
0
 public static string ToJson(this LauncherMeta self) => JsonConvert.SerializeObject(self, Converter.Settings);