Exemplo n.º 1
0
        private void FindReferencedMods(BuildProperties properties, Dictionary <string, LocalMod> mods, bool requireWeak)
        {
            foreach (var refName in properties.RefNames(true))
            {
                if (mods.ContainsKey(refName))
                {
                    continue;
                }

                bool     isWeak = properties.weakReferences.Any(r => r.mod == refName);
                LocalMod mod;
                try {
                    var modFile = new TmodFile(Path.Combine(ModLoader.ModPath, refName + ".tmod"));
                    using (modFile.Open())
                        mod = new LocalMod(modFile);
                }
                catch (FileNotFoundException) when(isWeak && !requireWeak)
                {
                    // don't recursively require weak deps, if the mod author needs to compile against them, they'll have them installed
                    continue;
                }
                catch (Exception ex) {
                    throw new BuildException(Language.GetTextValue("tModLoader.BuildErrorModReference", refName), ex);
                }
                mods[refName] = mod;
                FindReferencedMods(mod.properties, mods, false);
            }
        }
Exemplo n.º 2
0
        internal static BuildProperties ReadBuildFile(string modDir)
        {
            string          propertiesFile  = modDir + Path.DirectorySeparatorChar + "build.txt";
            string          descriptionfile = modDir + Path.DirectorySeparatorChar + "description.txt";
            BuildProperties properties      = new BuildProperties();

            if (!File.Exists(propertiesFile))
            {
                return(properties);
            }
            if (File.Exists(descriptionfile))
            {
                properties.description = File.ReadAllText(descriptionfile);
            }
            foreach (string line in File.ReadAllLines(propertiesFile))
            {
                if (string.IsNullOrWhiteSpace(line))
                {
                    continue;
                }
                int    split    = line.IndexOf('=');
                string property = line.Substring(0, split).Trim();
                string value    = line.Substring(split + 1).Trim();
                if (value.Length == 0)
                {
                    continue;
                }
                switch (property)
                {
                case "dllReferences":
                    properties.dllReferences = ReadList(value).ToArray();
                    break;

                case "modReferences":
                    properties.modReferences = ReadList(value).Select(ModReference.Parse).ToArray();
                    break;

                case "weakReferences":
                    properties.weakReferences = ReadList(value).Select(ModReference.Parse).ToArray();
                    break;

                case "sortBefore":
                    properties.sortBefore = ReadList(value).ToArray();
                    break;

                case "sortAfter":
                    properties.sortAfter = ReadList(value).ToArray();
                    break;

                case "author":
                    properties.author = value;
                    break;

                case "version":
                    properties.version = new Version(value);
                    break;

                case "displayName":
                    properties.displayName = value;
                    break;

                case "homepage":
                    properties.homepage = value;
                    break;

                case "noCompile":
                    properties.noCompile = string.Equals(value, "true", StringComparison.OrdinalIgnoreCase);
                    break;

                case "hideCode":
                    properties.hideCode = string.Equals(value, "true", StringComparison.OrdinalIgnoreCase);
                    break;

                case "hideResources":
                    properties.hideResources = string.Equals(value, "true", StringComparison.OrdinalIgnoreCase);
                    break;

                case "includeSource":
                    properties.includeSource = string.Equals(value, "true", StringComparison.OrdinalIgnoreCase);
                    break;

                case "includePDB":
                    properties.includePDB = string.Equals(value, "true", StringComparison.OrdinalIgnoreCase);
                    break;

                case "buildIgnore":
                    properties.buildIgnores = value.Split(',').Select(s => s.Trim().Replace('\\', Path.DirectorySeparatorChar).Replace('/', Path.DirectorySeparatorChar)).Where(s => s.Length > 0).ToArray();
                    break;

                case "side":
                    if (!Enum.TryParse(value, true, out properties.side))
                    {
                        throw new Exception("side is not one of (Both, Client, Server, NoSync): " + value);
                    }
                    break;
                }
            }

            var refs = properties.RefNames(true).ToList();

            if (refs.Count != refs.Distinct().Count())
            {
                throw new Exception("Duplicate mod/weak reference");
            }

            //add (mod|weak)References that are not in sortBefore to sortAfter
            properties.sortAfter = properties.RefNames(true).Where(dep => !properties.sortBefore.Contains(dep))
                                   .Concat(properties.sortAfter).Distinct().ToArray();

            return(properties);
        }