Beispiel #1
0
        private static int CheckForDupDllFiles(Mod mod, Mod otherMod, XmlFile xmlFile, XmlFile otherXmlFile)
        {
            var totalConflicts = 0;

            if ((xmlFile.XmlFileInfo != null) && (otherXmlFile.XmlFileInfo != null))
            {
                if (xmlFile.XmlFileInfo.FullName.ContainsAll("\\Assemblies\\", ".dll")) //rare. 1/mod at most. Only care if its a DLL in the assemblies folder.
                {
                    //Logger.Instance.Log(xmlFile.XmlFileInfo.FullName + " vs " + otherXmlFile.XmlFileInfo.FullName);
                    if (otherXmlFile.XmlFileInfo.FullName.ContainsAll("\\Assemblies\\", ".dll")) //rare. 1/mod at most. Only care if its a DLL in the assemblies folder.
                    {
                        if (xmlFile.XmlFileInfo.Name == otherXmlFile.XmlFileInfo.Name)           //semi rare. 1+ per mod
                        {
                            //if (xmlFile.XmlFileInfo.FullName != otherXmlFile.XmlFileInfo.FullName) //happens when a mod compares against itself.
                            //{
                            var xmlsize      = new FileInfo(xmlFile.XmlFileInfo.FullName).Length;
                            var xmldate      = new FileInfo(xmlFile.XmlFileInfo.FullName).LastWriteTime;
                            var otherXmlsize = new FileInfo(otherXmlFile.XmlFileInfo.FullName).Length;
                            var otherXmldate = new FileInfo(otherXmlFile.XmlFileInfo.FullName).LastWriteTime;
                            // Get the file version for the notepad.
                            // FileVersionInfo xmlversion = FileVersionInfo.GetVersionInfo(xmlFile.XmlFileInfo.FullName);
                            var xmlversion = FileVersionInfo.GetVersionInfo(xmlFile.XmlFileInfo.FullName);
                            // FileVersionInfo otherXmlversion = FileVersionInfo.GetVersionInfo(otherXmlFile.XmlFileInfo.FullName);
                            var otherXmlversion = FileVersionInfo.GetVersionInfo(otherXmlFile.XmlFileInfo.FullName);
                            if (mod.ModRank > otherMod.ModRank)
                            {
                                Logger.Instance.LogDll(otherXmlFile.XmlFileInfo.FullName, otherMod.ModRank, otherXmlsize, xmlversion.FileVersion, otherXmldate);
                                Logger.Instance.LogDll(xmlFile.XmlFileInfo.FullName, mod.ModRank, xmlsize, otherXmlversion.FileVersion, xmldate);
                            }
                            else
                            {
                                Logger.Instance.LogDll(xmlFile.XmlFileInfo.FullName, mod.ModRank, xmlsize, xmlversion.FileVersion, xmldate);
                                Logger.Instance.LogDll(otherXmlFile.XmlFileInfo.FullName, otherMod.ModRank, otherXmlsize, otherXmlversion.FileVersion, otherXmldate);
                            }
                            totalConflicts++;
                            //}
                        }
                    }
                }
            }
            return(totalConflicts);
        }
Beispiel #2
0
        private static int CheckForFileConflicts(XmlFile xmlFile, XmlFile otherXmlFile, Mod mod, Mod otherMod)
        {
            var totalConflicts = 0;


            //RimworldXmlLoader.weapons.Add(weapon);
            //weapons.Add(weapon);
            //if (((mod.ModEnabled == true) && (otherMod.ModEnabled == true)) && ((xmlFile.XmlDocument != null) && (otherXmlFile.XmlDocument != null) && xmlFile.XmlFileInfo.Name.Contains(".xml") && otherXmlFile.XmlFileInfo.Name.Contains(".xml")))
            if (((xmlFile.XmlDocument != null) && (otherXmlFile.XmlDocument != null) && xmlFile.XmlFileInfo.Name.Contains(".xml") && otherXmlFile.XmlFileInfo.Name.Contains(".xml")))
            {
                if (xmlFile.XmlDocument.Root != null)
                {
                    foreach (var element in xmlFile.XmlDocument.Root.Elements())
                    {
                        //string thingDefNameValue = element.Element("ThingDef")?.Value;
                        var thingDefNameValue = element.Name.ToString();           //the element text
                        var defNameValue      = element.Element("defName")?.Value; //the value of the defName element (only works when on this element)
                        var thisculture       = CultureInfo.CurrentCulture;

                        //element defName is null, then no point in doing this element (likely because we're not on the deName element!)
                        if (string.IsNullOrWhiteSpace(defNameValue))
                        {
                            continue;
                        }

                        //we're in a ThingDef
                        if (Program.Dps)
                        {
                            foreach (var element2 in element.Elements())
                            {
                                var weapon             = new Weapon();
                                var thingDefNameValue2 = element2.Name.ToString(); //the element text
                                if (thisculture.CompareInfo.IndexOf(thingDefNameValue2, "statBases", CompareOptions.IgnoreCase) >= 0)
                                {
                                    foreach (var element3 in element2.Elements())
                                    {
                                        var thingDefNameValue3 = element3.Name.ToString(); //the element text
                                        var defNameValue3      = element3.Value;
                                        //the value of the defName element (only works when on this element)
                                        //if (thisculture.CompareInfo.IndexOf(thingDefNameValue3, "RangedWeapon_Cooldown", CompareOptions.IgnoreCase) >= 0)
                                        //{
                                        //match
                                        //weapon.RangedWeapon_Cooldown = float.Parse(element3.Value, CultureInfo.InvariantCulture.NumberFormat);
                                        //}
                                        weapon.RangedWeaponCooldown = string.IsNullOrWhiteSpace(element3.Element("RangedWeapon_Cooldown")?.Value) ? 0f : float.Parse(element3.Element("RangedWeapon_Cooldown")?.Value, CultureInfo.InvariantCulture.NumberFormat); //crashes if null
                                    }
                                }
                            }
                        }

                        if (otherXmlFile.XmlDocument.Root != null)
                        {
                            foreach (var otherElement in otherXmlFile.XmlDocument.Root.Elements())
                            {
                                var otherDefNameValue = otherElement.Element("defName")?.Value;

                                //if null then no point in doing this element
                                if (string.IsNullOrWhiteSpace(otherDefNameValue))
                                {
                                    continue;
                                }

                                if (string.Equals(defNameValue, otherDefNameValue)) //do the elements match?
                                {
                                    //We have a conflict print some useful information about the conflict
                                    //SimpleLogger.Instance.Log("Conflict found with xml tag " + defNameValue + " in the file " + xmlFile.XmlFileInfo.Name + " in mod " + DirName + " and the file " + otherXmlFile.XmlFileInfo.Name + " in mod " + otherMod.DirName);
                                    var rootValue      = xmlFile.XmlDocument.Root.Name.ToString();
                                    var otherRootValue = otherXmlFile.XmlDocument.Root.Name.ToString();
                                    //string otherThingDefNameValue = otherElement.Element("ThingDef")?.Value;
                                    var otherThingDefNameValue = otherElement.Name.ToString();
                                    //var thisculture = CultureInfo.CurrentCulture;
                                    //Console.WriteLine(rootValue);
                                    //Console.WriteLine(otherRootValue);

                                    if (string.Equals(thingDefNameValue, otherThingDefNameValue))
                                    {
                                        //entire defnames are replaced by mods further down in the load order, so no need to check params
                                        long xmlsize      = 0;
                                        long otherXmlsize = 0;
                                        try
                                        {
                                            xmlsize      = new FileInfo(xmlFile.XmlFileInfo.FullName).Length;
                                            otherXmlsize = new FileInfo(otherXmlFile.XmlFileInfo.FullName).Length;
                                        }
                                        catch (Exception ex)
                                        {
                                            Logger.Instance.LogError("Unable to read file.", ex);
                                            //Utils.LogException("XmlReader Error", ex);
                                        }
                                        var    modenabled      = "";
                                        var    othermodenabled = "";
                                        var    linenum         = 1;
                                        var    otherlinenum    = 1;
                                        string line;
                                        string otherline;
                                        var    modposition      = mod.ModRank;
                                        var    othermodposition = otherMod.ModRank;
                                        //if (modposition == 0)
                                        if (!mod.ModEnabled)
                                        {
                                            modenabled = "(Not Enabled)";
                                        }
                                        //if (othermodposition == 0)
                                        if (!otherMod.ModEnabled)
                                        {
                                            othermodenabled = "(Not Enabled)";
                                        }
                                        using (var file = new StreamReader(xmlFile.XmlFileInfo.FullName))
                                        {
                                            while ((line = file.ReadLine()) != null)
                                            {
                                                if (
                                                    thisculture.CompareInfo.IndexOf(line, "<defName>" + defNameValue + "</defName>", CompareOptions.IgnoreCase) >= 0)
                                                {
                                                    break;
                                                }
                                                linenum++;
                                            }
                                            //file.Close();
                                            using (var otherfile = new StreamReader(otherXmlFile.XmlFileInfo.FullName))
                                            {
                                                while ((otherline = otherfile.ReadLine()) != null)
                                                {
                                                    if (thisculture.CompareInfo.IndexOf(otherline, "<defName>" + defNameValue + "</defName>", CompareOptions.IgnoreCase) >= 0)
                                                    {
                                                        break;
                                                    }
                                                    otherlinenum++;
                                                }
                                                //otherfile.Close();
                                                //foreach (var match in File.ReadLines(@xmlFile.XmlFileInfo.FullName)
                                                //    .Select((text, index) => new { text, lineNumber = index + 1 })
                                                //    .Where(x => x.text.Contains(defNameValue)))
                                                //{
                                                //    Console.WriteLine("{0}: {1}", match.lineNumber, match.text);
                                                //}
                                                //var match = File.ReadLines(@xmlFile.XmlFileInfo.FullName).Select((text, index) => new { text, lineNumber = index + 1 }).Where(x => x.text.Contains(defNameValue));
                                                //SimpleLogger.Instance.DumpConflict(modposition, xmlsize, 0, rootValue, thingDefNameValue, defNameValue, xmlFile.XmlFileInfo.FullName);
                                                //SimpleLogger.Instance.DumpConflict(othermodposition, otherXmlsize, 0, otherRootValue, otherThingDefNameValue, defNameValue, otherXmlFile.XmlFileInfo.FullName);
                                                if (modposition < othermodposition)
                                                {
                                                    Logger.Instance.Log("Conflicting Mods: " + mod.ModXmlDetails.ModName + " " + modenabled + " &  " + otherMod.ModXmlDetails.ModName + " " + othermodenabled);
                                                    Logger.Instance.Log(xmlFile.XmlFileInfo.FullName);
                                                    Logger.Instance.Log(otherXmlFile.XmlFileInfo.FullName);
                                                    Logger.Instance.DumpConflict(mod.ModXmlDetails.ModName, modposition, xmlsize, linenum, rootValue, thingDefNameValue, defNameValue);
                                                    Logger.Instance.DumpConflict(otherMod.ModXmlDetails.ModName, othermodposition, otherXmlsize, otherlinenum, otherRootValue, otherThingDefNameValue, defNameValue);
                                                    Logger.Instance.Log("");
                                                }
                                                else
                                                {
                                                    Logger.Instance.Log("Conflicting Mods: " + otherMod.ModXmlDetails.ModName + " " + othermodenabled + "  &  " + mod.ModXmlDetails.ModName + " " + modenabled);
                                                    Logger.Instance.Log(otherXmlFile.XmlFileInfo.FullName);
                                                    Logger.Instance.Log(xmlFile.XmlFileInfo.FullName);
                                                    Logger.Instance.DumpConflict(otherMod.ModXmlDetails.ModName, othermodposition, otherXmlsize, otherlinenum, otherRootValue, otherThingDefNameValue, defNameValue);
                                                    Logger.Instance.DumpConflict(mod.ModXmlDetails.ModName, modposition, xmlsize, linenum, rootValue, thingDefNameValue, defNameValue);
                                                    Logger.Instance.Log("");
                                                }
                                                totalConflicts++;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(totalConflicts);
        }