/// <summary> /// 실행에 필요한 파일들을 profile 에서 불러옵니다. /// </summary> /// <param name="_profile">불러올 프로파일</param> public MDownloader(MProfile _profile) { this.profile = _profile; web = new WebDownload(); web.DownloadProgressChangedEvent += Web_DownloadProgressChangedEvent; }
/// <summary> /// 네이티브 라이브러리들의 압축을 해제해 랜덤 폴더에 저장합니다. /// </summary> private string ExtractNatives(MProfile profile) { var ran = new Random(); int random = ran.Next(10000, 99999); //랜덤숫자 생성 string path = Minecraft.Versions + profile.Id + "\\natives-" + random.ToString(); //랜덤 숫자를 만들어 경로생성 ExtractNatives(profile, path); return(path); }
/// <summary> /// 네이티브 라이브러리들을 설정한 경로에 압축을 해제해 저장합니다. /// </summary> /// <param name="_path">압축 풀 폴더의 경로</param> private void ExtractNatives(MProfile profile, string path) { Directory.CreateDirectory(path); //폴더생성 foreach (var item in profile.Libraries) //네이티브 라이브러리 리스트를 foreach 로 하나씩 돌림 { try { if (item.IsNative) { using (var zip = ZipFile.Read(item.Path)) { zip.ExtractAll(path, ExtractExistingFileAction.OverwriteSilently); } } } catch { } } profile.NativePath = path; }
public static MProfile FindProfile(MProfileInfo[] infos, string name) { MProfile startProfile = null; MProfile baseProfile = null; foreach (var item in infos) { if (item.Name == name) { startProfile = Parse(item); break; } } if (startProfile.IsInherted) { baseProfile = FindProfile(infos, startProfile.ParentProfileId); inhert(baseProfile, startProfile); } return(startProfile); }
private static MProfile ParseFromJson(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((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 = Minecraft.Versions + profile.Id; Directory.CreateDirectory(path); File.WriteAllText(path + "\\" + profile.Id + ".json", json); } return(profile); }
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); }
private static MProfile ParseFromJson(string json) { 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.ParseJson((JArray)job["libraries"]); profile.MainClass = n(job["mainClass"]?.ToString()); var ma = job["minecraftArguments"]?.ToString(); if (ma != null) { profile.MinecraftArguments = ma; } var ag = job["arguments"]?.ToString(); if (ag != null) { profile.Arguments = ag; } profile.ReleaseTime = job["releaseTime"]?.ToString(); var ype = job["type"]?.ToString(); profile.TypeStr = ype; switch (ype) { case "release": profile.Type = MProfileType.Release; break; case "snapshot": profile.Type = MProfileType.Snapshot; break; case "old_alpha": profile.Type = MProfileType.OldAlpha; break; default: profile.Type = MProfileType.Unknown; break; } if (job["jar"] != null) { profile.IsForge = true; profile.InnerJarId = job["jar"].ToString(); } var path = Minecraft.Versions + profile.Id; Directory.CreateDirectory(path); File.WriteAllText(path + "\\" + profile.Id + ".json", json); return(profile); }