Exemplo n.º 1
0
        /// <inheritdoc />
        public byte[] GetXmlModList()
        {
            var strFileName = Path.GetRandomFileName() + ".xml";
            var strTempPath = Path.Combine(Path.GetTempPath(), strFileName);
            var docVirtual  = new XDocument();
            var xelRoot     = new XElement("virtualModActivator", new XAttribute("fileVersion", VirtualModActivator.CurrentVersion.ToString()));

            docVirtual.Add(xelRoot);

            var xelModList = new XElement("modList");

            xelRoot.Add(xelModList);
            _fileOwner = new Dictionary <string, IMod>();

            foreach (var mod in _activeModRegistry.Registrations.Where(x => !(x.Key is DummyMod)))
            {
                //List<InstalledItemDictionary<string, object>.ItemInstallers> lstItems = _installedFiles.Where(x => CheckFileKeyValuePair(x) && (GetCurrentFileOwnerLogged(x.Item) != null) && (GetCurrentFileOwnerLogged(x.Item).Filename.ToLowerInvariant() == mod.Key.Filename.ToLowerInvariant())).ToList();
                var lstItems = _installedFiles.Where(x => GetCurrentFileOwnerLogged(x.Item) != null && GetCurrentFileOwnerLogged(x.Item).Filename.ToLowerInvariant() == mod.Key.Filename.ToLowerInvariant()).ToList();

                if (lstItems.Count > 0)
                {
                    var modFileName = mod.Key.Filename;

                    if (string.IsNullOrEmpty(modFileName))
                    {
                        throw new Exception($"Could not determine filename of mod \"{mod.Key.ModName}\".");
                    }

                    var xelMod = new XElement("modInfo",
                                              new XAttribute("modId", mod.Key.Id ?? string.Empty),
                                              new XAttribute("modName", mod.Key.ModName),
                                              new XAttribute("modFileName", Path.GetFileName(modFileName)),
                                              new XAttribute("modFilePath", Path.GetDirectoryName(modFileName)));
                    xelModList.Add(xelMod);

                    foreach (var item in lstItems)
                    {
                        var xelFile = new XElement("fileLink",
                                                   new XAttribute("realPath", Path.Combine(Path.GetFileNameWithoutExtension(modFileName), GameMode.GetModFormatAdjustedPath(mod.Key.Format, item.Item, mod.Key, true))),
                                                   new XAttribute("virtualPath", GameMode.GetModFormatAdjustedPath(mod.Key.Format, item.Item, mod.Key, true)),
                                                   new XElement("linkPriority", "0"),
                                                   new XElement("isActive", "true"));
                        xelMod.Add(xelFile);
                    }
                }
            }

            docVirtual.Save(strTempPath);

            var document = new XmlDocument();

            document.Load(strTempPath);
            FileUtil.ForceDelete(strTempPath);
            _fileOwner = null;

            return(Encoding.UTF8.GetBytes(document.OuterXml));
        }