Beispiel #1
0
        /// <summary>
        /// 获取版本丢失的natives文件
        /// </summary>
        /// <param name="core">所使用的核心</param>
        /// <param name="version">要检查的版本</param>
        /// <returns>返回Key为路径,value为native实例的集合</returns>
        public static Dictionary <string, Native> GetLostNatives(LaunchHandler core, Modules.Version version)
        {
            Dictionary <string, Native> lostNatives = new Dictionary <string, Native>();

            try
            {
                foreach (var item in version.Natives)
                {
                    string path = core.GetNativePath(item);
                    if (lostNatives.ContainsKey(path))
                    {
                        continue;
                    }
                    else if (!File.Exists(path))
                    {
                        lostNatives.Add(path, item);
                    }
                }

                return(lostNatives);
            }
            catch
            {
                return(lostNatives);
            }
        }
Beispiel #2
0
        /// <summary>
        /// 返回全部丢失的文件路径
        /// </summary>
        /// <param name="core">所使用的核心</param>
        /// <param name="version">要检查的版本</param>
        /// <returns>丢失文件的路径列表</returns>
        public static List <string> GetAllLostDepend(LaunchHandler core, Modules.Version version)
        {
            List <string> lost    = new List <string>();
            string        jarPath = core.GetJarPath(version);

            if (!File.Exists(jarPath))
            {
                lost.Add(jarPath);
            }
            lost.AddRange(GetLostLibs(core, version).Keys);
            lost.AddRange(GetLostNatives(core, version).Keys);
            return(lost);
        }
Beispiel #3
0
 public JAssets GetAssets(Modules.Version version)
 {
     try
     {
         lock (locker)
         {
             string assetsPath = handler.GetAssetsIndexPath(version.Assets);
             if (!File.Exists(assetsPath))
             {
                 return(null);
             }
             var ja = GetAssetsByJson(File.ReadAllText(assetsPath));
             return(ja);
         }
     }
     catch (Exception)
     {
         return(null);
     }
 }
Beispiel #4
0
        public static string GetCoreDownloadURL(DownloadSource source, Modules.Version ver)
        {
            if (ver.Downloads != null)
            {
                switch (source)
                {
                case DownloadSource.Mojang:
                    return(ver.Downloads.Client.URL);

                case DownloadSource.BMCLAPI:
                    return(ver.Downloads.Client.URL.Replace(MojangMainUrl, BMCLUrl));

                default:
                    return(ver.Downloads.Client.URL);
                }
            }
            else
            {
                return(string.Format("{0}version/{1}/client", BMCLUrl, ver.ID));
            }
        }
Beispiel #5
0
        public static DownloadTask GetCoreDownloadTask(DownloadSource downloadSource, Modules.Version version, LaunchHandler core)
        {
            string from = GetCoreDownloadURL(downloadSource, version);
            string to   = core.GetJarPath(version);

            return(new DownloadTask("游戏版本核心", from, to));
        }
Beispiel #6
0
        public Modules.Version JsonToVersion(string jsonStr)
        {
            if (string.IsNullOrWhiteSpace(jsonStr))
            {
                return(null);
            }
            var obj = JObject.Parse(jsonStr);

            Modules.Version ver = new Modules.Version();
            ver = obj.ToObject <Modules.Version>();
            JObject innerVer = null;

            if (ver.InheritsVersion != null)
            {
                innerVer = JObject.Parse(GetVersionJsonText(ver.InheritsVersion));
            }
            if (obj.ContainsKey("arguments"))
            {
                #region 处理新版本引导

                #region 处理版本继承
                if (innerVer != null && innerVer.ContainsKey("arguments"))
                {
                    JObject innerVerArg = (JObject)innerVer["arguments"];
                    if (innerVerArg.ContainsKey("game"))
                    {
                        ver.MinecraftArguments += string.Format("{0} ", ParseGameArgFromJson(innerVerArg["game"]));
                    }
                    if (innerVerArg.ContainsKey("jvm"))
                    {
                        ver.JvmArguments += string.Format("{0} ", ParseJvmArgFromJson(innerVerArg["jvm"]));
                    }
                }
                #endregion

                JObject verArg = (JObject)obj["arguments"];

                #region 游戏参数
                if (verArg.ContainsKey("game"))
                {
                    JToken gameArg = verArg["game"];
                    ver.MinecraftArguments += ParseGameArgFromJson(gameArg);
                }
                #endregion

                #region JVM参数
                if (verArg.ContainsKey("jvm"))
                {
                    JToken jvmArg = verArg["jvm"];
                    ver.JvmArguments += ParseJvmArgFromJson(jvmArg);
                }
                #endregion
            }
            #endregion
            else
            {
                #region 旧版本添加默认JVM参数
                ver.JvmArguments = "-Djava.library.path=${natives_directory} -cp ${classpath}";
                #endregion
            }

            #region 处理库文件
            ver.Libraries = new List <Modules.Library>();
            ver.Natives   = new List <Modules.Native>();
            var libToken = obj["libraries"];
            foreach (JToken lib in libToken)
            {
                var libObj = lib.ToObject <Library>();
                var parts  = libObj.Name.Split(':');

                if (libObj.Natives == null)
                {
                    if (CheckAllowed(libObj.Rules))
                    {
                        Modules.Library library = new Modules.Library()
                        {
                            Package = parts[0],
                            Name    = parts[1],
                            Version = parts[2]
                        };
                        if (!string.IsNullOrWhiteSpace(libObj.Url))
                        {
                            library.Url = libObj.Url;
                        }
                        ver.Libraries.Add(library);
                    }
                }
                else
                {
                    if (CheckAllowed(libObj.Rules))
                    {
                        var native = new Modules.Native
                        {
                            Package      = parts[0],
                            Name         = parts[1],
                            Version      = parts[2],
                            NativeSuffix = libObj.Natives["windows"].Replace("${arch}", SystemTools.GetSystemArch() == ArchEnum.x64 ? "64" : "32")
                        };
                        ver.Natives.Add(native);
                        if (libObj.Extract != null)
                        {
                            native.Exclude = libObj.Extract.Exculde;
                        }
                    }
                }

                if (((JObject)lib).ContainsKey("url"))
                {
                }
            }
            #endregion

            #region 处理版本继承
            if (ver.InheritsVersion != null)
            {
                var iv = GetVersion(ver.InheritsVersion);
                if (iv != null)
                {
                    ver.Assets     = iv.Assets;
                    ver.AssetIndex = iv.AssetIndex;
                    ver.Natives.AddRange(iv.Natives);
                    ver.Libraries.AddRange(iv.Libraries);
                    ver.Jar = iv.ID;
                }
            }
            #endregion

            return(ver);
        }
Beispiel #7
0
 public async static Task <List <VersionOption> > GetOptionsAsync(LaunchHandler core, Modules.Version version)
 {
     return(await Task.Factory.StartNew(() =>
     {
         if (version != null)
         {
             try
             {
                 string optionsPath = core.GetVersionOptionsPath(version);
                 if (!File.Exists(optionsPath))
                 {
                     return null;
                 }
                 string[] lines = File.ReadAllLines(optionsPath);
                 List <VersionOption> options = new List <VersionOption>();
                 foreach (var item in lines)
                 {
                     string[] kv = item.Split(':');
                     if (kv.Length != 2)
                     {
                         return null;
                     }
                     options.Add(new VersionOption()
                     {
                         Key = kv[0], Value = kv[1]
                     });
                 }
                 return options;
             }
             catch (Exception)
             {
                 return null;
             }
         }
         else
         {
             return null;
         }
     }));
 }
Beispiel #8
0
 public async static Task SaveOptionsAsync(List <VersionOption> opts, LaunchHandler core, Modules.Version version)
 {
     await Task.Factory.StartNew(() =>
     {
         try
         {
             if (version != null && opts != null)
             {
                 List <string> optLines = new List <string>();
                 foreach (var item in opts)
                 {
                     optLines.Add(item.ToString());
                 }
                 File.WriteAllLines(core.GetVersionOptionsPath(version), optLines.ToArray());
             }
         }
         catch (Exception) {}
     });
 }
Beispiel #9
0
        public Modules.Version JsonToVersion(JObject obj)
        {
            Modules.Version ver = new Modules.Version();
            ver = obj.ToObject <Modules.Version>();
            JObject innerVer = null;

            if (ver.InheritsVersion != null)
            {
                SendDebugLog(string.Format("检测到\"{0}\"继承于\"{1}\"", ver.ID, ver.InheritsVersion));
                string innerJsonStr = GetVersionJsonText(ver.InheritsVersion);
                if (innerJsonStr != null)
                {
                    innerVer = JObject.Parse(innerJsonStr);
                }
            }
            if (obj.ContainsKey("arguments"))
            {
                #region 处理新版本引导

                SendDebugLog(string.Format("检测到\"{0}\"使用新版本启动参数", ver.ID));

                #region 处理版本继承
                if (innerVer != null && innerVer.ContainsKey("arguments"))
                {
                    JObject innerVerArg = (JObject)innerVer["arguments"];
                    if (innerVerArg.ContainsKey("game"))
                    {
                        ver.MinecraftArguments += string.Format("{0} ", ParseGameArgFromJson(innerVerArg["game"]));
                    }
                    if (innerVerArg.ContainsKey("jvm"))
                    {
                        ver.JvmArguments += string.Format("{0} ", ParseJvmArgFromJson(innerVerArg["jvm"]));
                    }
                }
                #endregion

                JObject verArg = (JObject)obj["arguments"];

                #region 游戏参数
                if (verArg.ContainsKey("game"))
                {
                    JToken gameArg = verArg["game"];
                    ver.MinecraftArguments += ParseGameArgFromJson(gameArg);
                }
                #endregion

                #region JVM参数
                if (verArg.ContainsKey("jvm"))
                {
                    JToken jvmArg = verArg["jvm"];
                    ver.JvmArguments += ParseJvmArgFromJson(jvmArg);
                }
                #endregion
            }
            #endregion
            else
            {
                #region 旧版本添加默认JVM参数
                SendDebugLog(string.Format("检测到\"{0}\"使用旧版本启动参数", ver.ID));
                ver.JvmArguments = "-Djava.library.path=${natives_directory} -cp ${classpath}";
                #endregion
            }

            #region 处理依赖
            ver.Libraries = new List <Library>();
            ver.Natives   = new List <Native>();
            var libToken = obj["libraries"];
            foreach (JToken lib in libToken)
            {
                var libObj = lib.ToObject <JLibrary>();

                if (CheckAllowed(libObj.Rules))
                {
                    var parts = libObj.Name.Split(':');

                    string package = parts[0];
                    string name    = parts[1];
                    string version = parts[2];

                    if (libObj.Natives == null)
                    {
                        //不为native
                        Library library = new Library()
                        {
                            Package = package,
                            Name    = name,
                            Version = version
                        };
                        if (!string.IsNullOrWhiteSpace(libObj.Url))
                        {
                            library.Url = libObj.Url;
                        }
                        if (libObj.Downloads?.Artifact != null)
                        {
                            library.LibDownloadInfo = libObj.Downloads.Artifact;
                        }
                        ver.Libraries.Add(library);
                    }
                    else
                    {
                        //为native
                        var native = new Native()
                        {
                            Package      = package,
                            Name         = name,
                            Version      = version,
                            NativeSuffix = libObj.Natives["windows"].Replace("${arch}", SystemTools.GetSystemArch() == ArchEnum.x64 ? "64" : "32")
                        };
                        if (libObj.Extract != null)
                        {
                            native.Exclude = libObj.Extract.Exculde;
                        }
                        if (libObj.Downloads?.Artifact != null)
                        {
                            native.LibDownloadInfo = libObj.Downloads.Artifact;
                        }
                        if (libObj.Downloads?.Classifiers?.Natives != null)
                        {
                            native.NativeDownloadInfo = libObj.Downloads.Classifiers.Natives;
                        }
                        ver.Natives.Add(native);
                    }
                }
            }
            #endregion

            #region 处理版本继承
            if (innerVer != null)
            {
                var iv = JsonToVersion(innerVer);
                if (iv != null)
                {
                    ver.Assets     = iv.Assets;
                    ver.AssetIndex = iv.AssetIndex;
                    ver.Natives.AddRange(iv.Natives);
                    ver.Libraries.AddRange(iv.Libraries);
                    ver.Jar = iv.ID;
                }
            }
            #endregion

            return(ver);
        }
Beispiel #10
0
        public static DownloadTask GetCoreJarDownloadTask(DownloadSource downloadSource, Modules.Version version, LaunchHandler core)
        {
            string       to           = core.GetJarPath(version);
            string       from         = GetCoreJarDownloadURL(downloadSource, version);
            DownloadTask downloadTask = new DownloadTask("游戏版本核心Jar文件", from, to);

            if (!string.IsNullOrWhiteSpace(version.Downloads?.Client?.SHA1))
            {
                downloadTask.Checker = new SHA1Checker()
                {
                    CheckSum = version.Downloads.Client.SHA1, FilePath = to
                };
            }
            return(downloadTask);
        }
Beispiel #11
0
        /// <summary>
        /// 获取版本丢失的库文件
        /// </summary>
        /// <param name="core">所使用的启动核心</param>
        /// <param name="version">要检查的版本</param>
        /// <returns>返回Key为路径,value为库实例的集合</returns>
        public static Dictionary <string, Modules.Library> GetLostLibs(LaunchHandler core, Modules.Version version)
        {
            Dictionary <string, Modules.Library> lostLibs = new Dictionary <string, Modules.Library>();

            foreach (var item in version.Libraries)
            {
                string path = core.GetLibraryPath(item);
                if (lostLibs.ContainsKey(path))
                {
                    continue;
                }
                else if (!File.Exists(path))
                {
                    lostLibs.Add(path, item);
                }
            }

            return(lostLibs);
        }