예제 #1
0
        /// <summary>
        /// Users can create an additional custom manifest file for manually created mod files. If available, it's loaded with this method.
        /// </summary>
        /// <returns></returns>
        public static bool TryLoadCustomModManifestFile(out ModsManifest customModsManifest)
        {
            customModsManifest = null;
            string filePath = FileService.GetJsonPath(FileService.ValuesFolder, FileService.ModsManifestCustom);

            if (!File.Exists(filePath))
            {
                return(false);
            }

            if (FileService.LoadJsonFile(filePath, out ModsManifest tmpV, out string errorMessage))
            {
                // set format versions
                // if an entry has no specific format version, it is the general format version of the manifest file
                foreach (var mi in tmpV.modsByFiles)
                {
                    if (string.IsNullOrEmpty(mi.Value.format))
                    {
                        mi.Value.format = tmpV.DefaultFormatVersion;
                    }
                }

                customModsManifest = tmpV;
                return(true);
            }

            throw new SerializationException(errorMessage);
        }
        /// <summary>
        /// Users can create an additional custom manifest file for manually created mod files. If available, it's loaded with this method.
        /// </summary>
        /// <returns></returns>
        public static bool TryLoadCustomModManifestFile(out ModsManifest customModsManifest)
        {
            customModsManifest = null;
            string filePath = FileService.GetJsonPath(FileService.ValuesFolder, FileService.ModsManifestCustom);

            if (!File.Exists(filePath))
            {
                return(false);
            }

            if (FileService.LoadJsonFile(filePath, out ModsManifest tmpV, out string errorMessage))
            {
                customModsManifest = tmpV;
                return(true);
            }

            throw new SerializationException(errorMessage);
        }
예제 #3
0
 /// <summary>
 /// Merges two mod manifests (while for duplicate entries the manifest2 item will be kept) and returns the combined one. This is used to combine the official manifest with the custom created manifest.
 /// </summary>
 /// <param name="manifest1"></param>
 /// <param name="manifest2"></param>
 /// <returns></returns>
 internal static ModsManifest MergeModsManifest(ModsManifest manifest1, ModsManifest manifest2)
 => new ModsManifest()
 {
     DefaultFormatVersion = manifest1.DefaultFormatVersion,
     modsByFiles          = manifest2.modsByFiles.Concat(manifest1.modsByFiles.Where(m1 => !manifest2.modsByFiles.ContainsKey(m1.Key))).ToDictionary(m => m.Key, m => m.Value)
 };