コード例 #1
0
        public static void SetVersions(List <ModMetaHeader> metaHeaders)
        {
            if (xdoc == null)
            {
                throw new Exception("Invoke BeginReading before using this method");
            }

            var meta            = xdoc.Root.Element("meta");
            var modVersionsNode = GetElementWithForceCreation(meta, MOD_META_DATAS);

            modVersionsNode.RemoveAll();

            if (meta.Element(MOD_META_DATAS) == null)
            {
                throw new Exception("F");
            }

            for (int i = 0; i < metaHeaders.Count; i++)
            {
                var data   = metaHeaders[i];
                var liNode = new XElement("li");
                liNode.Add(new XElement(MOD_IDENTIFIER_NODENAME)
                {
                    Value = data.Identifier
                });
                liNode.Add(new XElement(VERSION_NODENAME)
                {
                    Value = data.Version
                });
                SimpleLog.Log($"Writing {data.Identifier} {data.Version} to versionNode");
                modVersionsNode.Add(liNode);
            }
        }
コード例 #2
0
 public static void EndReading()
 {
     xdoc.Save(CurrnetUsingFilePath);
     SimpleLog.Log("Saving xdoc");
     xdoc = null;
     CurrnetUsingFilePath = null;
     isVersionDictDirty   = true;
 }
コード例 #3
0
        public static bool isVersionSame(List <Madeline.ModMismatchFormatter.Mod> saveMods, List <Madeline.ModMismatchFormatter.Mod> activeMods)
        { // saveMods와 activeMods는 길이가 무조건 같음
            SimpleLog.Log("Checking version difference...");
            if (saveMods.Count != activeMods.Count)
            {
                string ListOfSaveMods   = string.Join(", ", saveMods.Select(mod => mod.Identifier));
                string ListOfActiveMods = string.Join(", ", activeMods.Select(mod => mod.Identifier));

                StringBuilder exceptionMessage = new StringBuilder();

                exceptionMessage.AppendLine("saveMods length and activeMods length are different.");
                exceptionMessage.AppendLine($"Save Mod Count : {saveMods.Count} Active Mods Count : {activeMods.Count}");
                exceptionMessage.AppendLine("Active Mods List");
                exceptionMessage.AppendLine(ListOfActiveMods);
                exceptionMessage.AppendLine("Save Mods List");
                exceptionMessage.AppendLine(ListOfSaveMods);

                throw new Exception(exceptionMessage.ToString());
            }

            int length = saveMods.Count;

            for (int i = 0; i < length; i++)
            {
                var save   = saveMods[i];
                var active = activeMods[i];

                SimpleLog.Log($"Comparing {save.Identifier} ({save.Version}) - {active.Identifier} ({active.Version})");

                if (save.Identifier != active.Identifier)
                {
                    string ListOfSaveMods   = string.Join(", ", saveMods.Select(mod => mod.Identifier));
                    string ListOfActiveMods = string.Join(", ", activeMods.Select(mod => mod.Identifier));

                    StringBuilder exceptionMessage = new StringBuilder();

                    exceptionMessage.AppendLine($"two mod's identifier is different while comparing version, save mod identifier : {save.Identifier}, active mod identifier : {active.Identifier}");
                    exceptionMessage.AppendLine($"Save Mod Count : {saveMods.Count} Active Mods Count : {activeMods.Count}");
                    exceptionMessage.AppendLine("Active Mods List");
                    exceptionMessage.AppendLine(ListOfActiveMods);
                    exceptionMessage.AppendLine("Save Mods List");
                    exceptionMessage.AppendLine(ListOfSaveMods);

                    throw new Exception(exceptionMessage.ToString());
                }

                if (save.Version != active.Version)
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #4
0
 public static void BeginReading(string filePath)
 {
     if (xdoc != null || string.IsNullOrEmpty(CurrnetUsingFilePath))
     {
         Log.Warning("xdoc is still open. force-closing");
         xdoc = null;
         CurrnetUsingFilePath = null;
     }
     SimpleLog.Log($"Trying to load {filePath}");
     xdoc = XDocument.Load(filePath);
     CurrnetUsingFilePath = filePath;
 }
コード例 #5
0
        static void RebuildVersionDict()
        {
            SimpleLog.Log("Rebuilding VersionDict");
            isVersionDictDirty = false;
            versionDict.Clear();

            if (xdoc == null)
            {
                Log.Error($"invoke BeginReading before calling {nameof(RebuildVersionDict)}");
                return;
            }

            try
            {
                var ModMetaHeaders = xdoc.Root.Element("meta")?.Element(MOD_META_DATAS);
                if (ModMetaHeaders == null)
                {
                    return;
                }

                var elements = ModMetaHeaders.Elements();
                foreach (var node in elements)
                {
                    var Identifier = node.Element(MOD_IDENTIFIER_NODENAME)?.Value;
                    var Version    = node.Element(VERSION_NODENAME)?.Value;

                    if (Identifier == null || Version == null) // variable sanity check
                    {
                        continue;
                    }

                    versionDict[Identifier] = Version;

                    SimpleLog.Log($"Set {Identifier} {Version}");
                }
            }
            catch (Exception ex)
            {
                Log.Error($"Exception while rebuilding VersionDict, exception : {ex.Message}");
                return;
            }
        }
コード例 #6
0
        public static void UpdateModVersionMetaHeader()
        {
            string rawFilePath = SaveFilePathCache;
            string filePath    = GenFilePaths.FilePathForSavedGame(rawFilePath);

            MetaHeaderUtility.BeginReading(filePath);
            List <ModMetaHeader> metaHeaders = new List <ModMetaHeader>();

            foreach (var modContentPack in LoadedModManager.RunningMods)
            {
                // var metadata = modContentPack.GetMetaData();
                var version = MetaHeaderUtility.GetVersionFromManifestFile(modContentPack);
                metaHeaders.Add(new ModMetaHeader()
                {
                    Identifier = modContentPack.PackageId, Version = version
                });
                SimpleLog.Log($"Add metadata to metaHeaders list : {modContentPack.PackageId}, {version}");
            }
            MetaHeaderUtility.SetVersions(metaHeaders);
            MetaHeaderUtility.EndReading();
        }