Example #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(ModPath, refName + ".tmod"));
                    modFile.Read();
                    mod = new LocalMod(modFile);
                    modFile.Close();
                }
                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 Exception(Language.GetTextValue("tModLoader.BuildErrorModReference", refName), ex);
                }
                mods[refName] = mod;
                FindReferencedMods(mod.properties, mods, false);
            }
        }
Example #2
0
        private void FindReferencedMods(BuildProperties properties, Dictionary <string, LocalMod> mods)
        {
            foreach (var refName in properties.RefNames(true))
            {
                if (mods.ContainsKey(refName))
                {
                    continue;
                }

                LocalMod mod;
                try
                {
                    var modFile = new TmodFile(Path.Combine(ModPath, refName + ".tmod"));
                    modFile.Read();
                    mod = new LocalMod(modFile);
                    modFile.Close();
                }
                catch (Exception ex)
                {
                    throw new Exception(Language.GetTextValue("tModLoader.BuildErrorModReference", refName), ex);
                }
                mods[refName] = mod;
                FindReferencedMods(mod.properties, mods);
            }
        }
Example #3
0
        internal static Dictionary <string, List <string> > dependencyCache;    // for some internal features that need to lookup dependencies after load

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

            foreach (string fileName in Directory.GetFiles(ModLoader.ModPath, "*.tmod", SearchOption.TopDirectoryOnly))
            {
                if (Path.GetFileName(fileName) == "temporaryDownload.tmod")
                {
                    continue;
                }
                var lastModified = File.GetLastWriteTime(fileName);
                if (!modsDirCache.TryGetValue(fileName, out var mod) || mod.lastModified != lastModified)
                {
                    try
                    {
                        var modFile = new TmodFile(fileName);
                        modFile.Read();
                        modFile.VerifyCoreFiles();
                        mod = new LocalMod(modFile)
                        {
                            lastModified = lastModified
                        };
                        modFile.Close();
                    }
                    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());
        }
Example #4
0
        internal static void ReceiveMod(BinaryReader reader)
        {
            if (downloadingMod == null)
            {
                return;
            }

            try
            {
                if (downloadingFile == null)
                {
                    Interface.downloadMod.SetDownloading(reader.ReadString());
                    Interface.downloadMod.SetCancel(() =>
                    {
                        downloadingFile?.Close();
                        downloadingMod     = null;
                        Netplay.disconnect = true;
                        Main.menuMode      = 0;
                    });
                    Main.menuMode = Interface.downloadModID;

                    downloadingLength = reader.ReadInt64();
                    downloadingFile   = new FileStream(downloadingMod.path, FileMode.Create);
                    return;
                }

                var bytes = reader.ReadBytes((int)Math.Min(downloadingLength - downloadingFile.Position, CHUNK_SIZE));
                downloadingFile.Write(bytes, 0, bytes.Length);
                Interface.downloadMod.SetProgress(downloadingFile.Position, downloadingLength);

                if (downloadingFile.Position == downloadingLength)
                {
                    downloadingFile.Close();
                    var mod = new TmodFile(downloadingMod.path);
                    mod.Read();
                    mod.Close();

                    if (!downloadingMod.Matches(mod))
                    {
                        throw new Exception(Language.GetTextValue("tModLoader.MPErrorModHashMismatch"));
                    }

                    if (downloadingMod.signed && !mod.ValidModBrowserSignature)
                    {
                        throw new Exception(Language.GetTextValue("tModLoader.MPErrorModNotSigned"));
                    }

                    ModLoader.EnableMod(mod.name);

                    if (downloadQueue.Count > 0)
                    {
                        DownloadNextMod();
                    }
                    else
                    {
                        OnModsDownloaded(true);
                    }
                }
            }
            catch (Exception e)
            {
                try
                {
                    downloadingFile?.Close();
                }
                catch { }

                File.Delete(downloadingMod.path);
                Logging.tML.Error(Language.GetTextValue("tModLoader.MPErrorModDownloadError", downloadingMod.name), e);
                downloadingMod = null;
            }
        }
Example #5
0
        internal static void ReceiveMod(BinaryReader reader)
        {
            if (downloadingMod == null)
            {
                return;
            }

            try {
                if (downloadingFile == null)
                {
                    // TODO migrate to download UI, create new StreamingDownloadRequest
                    // TODO I hope this works fine without UI for the moment...
                    //Interface.downloadMod.SetDownloading(reader.ReadString());
                    //Interface.downloadMod.SetCancel(CancelDownload);
                    Main.menuMode = Interface.downloadModID;

                    ModLoader.GetMod(downloadingMod.name)?.File?.Close();
                    downloadingLength = reader.ReadInt64();
                    downloadingFile   = new FileStream(downloadingMod.path, FileMode.Create);
                    return;
                }

                var bytes = reader.ReadBytes((int)Math.Min(downloadingLength - downloadingFile.Position, CHUNK_SIZE));
                downloadingFile.Write(bytes, 0, bytes.Length);
                //Interface.downloadMod.SetProgress(downloadingFile.Position, downloadingLength);

                if (downloadingFile.Position == downloadingLength)
                {
                    downloadingFile.Close();
                    var mod = new TmodFile(downloadingMod.path);
                    mod.Read();
                    mod.Close();

                    if (!downloadingMod.Matches(mod))
                    {
                        throw new Exception(Language.GetTextValue("tModLoader.MPErrorModHashMismatch"));
                    }

                    if (downloadingMod.signed && !mod.ValidModBrowserSignature)
                    {
                        throw new Exception(Language.GetTextValue("tModLoader.MPErrorModNotSigned"));
                    }

                    ModLoader.EnableMod(mod.name);

                    if (downloadQueue.Count > 0)
                    {
                        DownloadNextMod();
                    }
                    else
                    {
                        OnModsDownloaded(true);
                    }
                }
            }
            catch (Exception e) {
                try {
                    downloadingFile?.Close();
                    File.Delete(downloadingMod.path);
                }
                catch { }

                var msg = Language.GetTextValue("tModLoader.MPErrorModDownloadError", downloadingMod.name);
                Logging.tML.Error(msg, e);
                Interface.errorMessage.Show(msg + e, 0);

                Netplay.disconnect = true;
                downloadingMod     = null;
            }
        }