Example #1
0
        public static MProfile Parse(Minecraft mc, MProfileInfo info)
        {
            string json;

            if (info.IsWeb)
            {
                using (var wc = new WebClient())
                {
                    json = wc.DownloadString(info.Path);
                    return(ParseFromJson(mc, json, true));
                }
            }
            else
            {
                return(ParseFromFile(mc, info.Path));
            }
        }
        /// <summary>
        /// Get All MProfileInfo from local
        /// </summary>
        public static MProfileInfo[] GetProfilesFromLocal(Minecraft mc)
        {
            var dirs = new DirectoryInfo(mc.Versions).GetDirectories();
            var arr  = new List <MProfileInfo>(dirs.Length);

            for (int i = 0; i < dirs.Length; i++)
            {
                var dir      = dirs[i];
                var filepath = System.IO.Path.Combine(dir.FullName, dir.Name + ".json");
                if (File.Exists(filepath))
                {
                    var info = new MProfileInfo();
                    info.IsWeb = false;
                    info.Name  = dir.Name;
                    info.Path  = filepath;
                    arr.Add(info);
                }
            }

            return(arr.ToArray());
        }
        /// <summary>
        /// Get All MProfileInfo from mojang server and local
        /// </summary>
        public static MProfileInfo[] GetProfiles(Minecraft mc)
        {
            var list = new HashSet <MProfileInfo>(GetProfilesFromLocal(mc));

            foreach (var item in GetProfilesFromWeb()) //다음 웹 프로파일을 불러옴
            {
                bool isexist = false;
                foreach (var local in list)
                {
                    if (local.Name == item.Name)
                    {
                        isexist = true;
                        break;
                    }
                }

                if (!isexist)
                {
                    list.Add(item);
                }
            }
            return(list.ToArray());
        }
Example #4
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 #5
0
        public static MProfile ParseFromFile(Minecraft mc, string path)
        {
            var json = File.ReadAllText(path);

            return(ParseFromJson(mc, json, false));
        }
Example #6
0
 public MForge(Minecraft mc)
 {
     this.Minecraft = mc;
 }