Example #1
0
        public static MProfile FindProfile(Minecraft mc, MProfileInfo[] infos, string name)
        {
            MProfile startProfile = null;
            MProfile baseProfile  = null;

            foreach (var item in infos)
            {
                if (item.Name == name)
                {
                    startProfile = Parse(mc, item);
                    break;
                }
            }

            if (startProfile == null)
            {
                throw new Exception(name + "not found");
            }

            if (startProfile.IsInherted)
            {
                if (startProfile.ParentProfileId == startProfile.Id) // prevent StackOverFlowException
                {
                    throw new IOException("Invalid Profile : inheritFrom property is equal to id property.");
                }

                baseProfile = FindProfile(mc, infos, startProfile.ParentProfileId);
                inhert(baseProfile, startProfile);
            }

            return(startProfile);
        }
Example #2
0
        public MDownloader(MProfile _profile)
        {
            this.profile   = _profile;
            this.Minecraft = _profile.Minecraft;

            web = new WebDownload();
            web.DownloadProgressChangedEvent += Web_DownloadProgressChangedEvent;
        }
Example #3
0
        private string ExtractNatives(MProfile profile)
        {
            var    ran    = new Random();
            int    random = ran.Next(10000, 99999);
            string path   = Path.Combine(profile.Minecraft.Versions, profile.Id, "natives-" + random.ToString());

            ExtractNatives(profile, path);
            return(path);
        }
Example #4
0
        private void ExtractNatives(MProfile profile, string path)
        {
            Directory.CreateDirectory(path);

            foreach (var item in profile.Libraries)
            {
                try
                {
                    if (item.IsNative)
                    {
                        var z = new SharpZip(item.Path);
                        z.Unzip(path);
                    }
                }
                catch { }
            }

            profile.NativePath = path;
        }
Example #5
0
        private static MProfile ParseFromJson(Minecraft mc, string json, bool writeProfile = true)
        {
            var profile = new MProfile();
            var job     = JObject.Parse(json);

            profile.Id = job["id"]?.ToString();

            var assetindex = (JObject)job["assetIndex"];

            if (assetindex != null)
            {
                profile.AssetId   = n(assetindex["id"]?.ToString());
                profile.AssetUrl  = n(assetindex["url"]?.ToString());
                profile.AssetHash = n(assetindex["sha1"]?.ToString());
            }

            var client = job["downloads"]?["client"];

            if (client != null)
            {
                profile.ClientDownloadUrl = client["url"]?.ToString();
                profile.ClientHash        = client["sha1"]?.ToString();
            }

            profile.Libraries = MLibrary.Parser.ParseJson(mc.Library, (JArray)job["libraries"]);
            profile.MainClass = n(job["mainClass"]?.ToString());

            var ma = job["minecraftArguments"]?.ToString();

            if (ma != null)
            {
                profile.MinecraftArguments = ma;
            }

            var ag = job["arguments"];

            if (ag != null)
            {
                if (ag["game"] != null)
                {
                    profile.GameArguments = argParse((JArray)ag["game"]);
                }
                if (ag["jvm"] != null)
                {
                    profile.JvmArguments = argParse((JArray)ag["jvm"]);
                }
            }

            profile.ReleaseTime = job["releaseTime"]?.ToString();

            var ype = job["type"]?.ToString();

            profile.TypeStr = ype;
            profile.Type    = MProfileTypeConverter.FromString(ype);

            if (job["inheritsFrom"] != null)
            {
                profile.IsInherted      = true;
                profile.ParentProfileId = job["inheritsFrom"].ToString();
            }
            else
            {
                profile.Jar = profile.Id;
            }

            if (writeProfile)
            {
                var path = Path.Combine(mc.Versions, profile.Id);
                Directory.CreateDirectory(path);
                File.WriteAllText(Path.Combine(path, profile.Id + ".json"), json);
            }

            profile.Minecraft = mc;
            return(profile);
        }
Example #6
0
        static MProfile inhert(MProfile parentProfile, MProfile childProfile)
        {
            // Inhert list
            // Overload : AssetId, AssetUrl, AssetHash, ClientDownloadUrl, ClientHash, MainClass, MinecraftArguments
            // Combine : Libraries, GameArguments, JvmArguments

            // Overloads

            if (nc(childProfile.AssetId))
            {
                childProfile.AssetId = parentProfile.AssetId;
            }

            if (nc(childProfile.AssetUrl))
            {
                childProfile.AssetUrl = parentProfile.AssetUrl;
            }

            if (nc(childProfile.AssetHash))
            {
                childProfile.AssetHash = parentProfile.AssetHash;
            }

            if (nc(childProfile.ClientDownloadUrl))
            {
                childProfile.ClientDownloadUrl = parentProfile.ClientDownloadUrl;
            }

            if (nc(childProfile.ClientHash))
            {
                childProfile.ClientHash = parentProfile.ClientHash;
            }

            if (nc(childProfile.MainClass))
            {
                childProfile.MainClass = parentProfile.MainClass;
            }

            if (nc(childProfile.MinecraftArguments))
            {
                childProfile.MinecraftArguments = parentProfile.MinecraftArguments;
            }

            childProfile.Jar = parentProfile.Jar;

            // Combine

            if (parentProfile.Libraries != null)
            {
                if (childProfile.Libraries != null)
                {
                    childProfile.Libraries = childProfile.Libraries.Concat(parentProfile.Libraries).ToArray();
                }
                else
                {
                    childProfile.Libraries = parentProfile.Libraries;
                }
            }

            if (parentProfile.GameArguments != null)
            {
                if (childProfile.GameArguments != null)
                {
                    childProfile.GameArguments = childProfile.GameArguments.Concat(parentProfile.GameArguments).ToArray();
                }
                else
                {
                    childProfile.GameArguments = parentProfile.GameArguments;
                }
            }


            if (parentProfile.JvmArguments != null)
            {
                if (childProfile.JvmArguments != null)
                {
                    childProfile.JvmArguments = childProfile.JvmArguments.Concat(parentProfile.JvmArguments).ToArray();
                }
                else
                {
                    childProfile.JvmArguments = parentProfile.JvmArguments;
                }
            }

            return(childProfile);
        }