Ejemplo 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);
            }
        }
Ejemplo n.º 2
0
        private static List <string> readFailures = new List <string>();       // TODO: Reflect these skipped Mods in the UI somehow.

        internal static LocalMod[] FindMods()
        {
            Directory.CreateDirectory(ModLoader.ModPath);
            var mods = new List <LocalMod>();

            DeleteTemporaryFiles();

            foreach (string fileName in Directory.GetFiles(ModLoader.ModPath, "*.tmod", SearchOption.TopDirectoryOnly))
            {
                var lastModified = File.GetLastWriteTime(fileName);
                if (!modsDirCache.TryGetValue(fileName, out var mod) || mod.lastModified != lastModified)
                {
                    try {
                        var modFile = new TmodFile(fileName);
                        using (modFile.Open())
                            mod = new LocalMod(modFile)
                            {
                                lastModified = lastModified
                            };
                    }
                    catch (Exception e) {
                        if (!readFailures.Contains(fileName))
                        {
                            Logging.tML.Warn("Failed to read " + fileName, e);
                        }
                        else
                        {
                            readFailures.Add(fileName);
                        }
                        continue;
                    }
                    modsDirCache[fileName] = mod;
                }
                mods.Add(mod);
            }
            return(mods.OrderBy(x => x.Name, StringComparer.InvariantCulture).ToArray());
        }