Ejemplo n.º 1
0
        /// <summary>Get a raw data record.</summary>
        /// <param name="manifest">The mod manifest whose fields to match.</param>
        /// <param name="displayName">The mod's default display name.</param>
        /// <param name="record">The raw mod record.</param>
        private bool TryGetRaw(IManifest manifest, out string displayName, out ModDataRecord record)
        {
            if (manifest != null)
            {
                foreach (var entry in this.Records)
                {
                    displayName = entry.Key;
                    record      = entry.Value;

                    // try main ID
                    if (record.ID != null && record.ID.Equals(manifest.UniqueID, StringComparison.InvariantCultureIgnoreCase))
                    {
                        return(true);
                    }

                    // try former IDs
                    if (record.FormerIDs != null)
                    {
                        foreach (string part in record.FormerIDs.Split('|'))
                        {
                            // packed field snapshot
                            if (part.StartsWith("{"))
                            {
                                FieldSnapshot snapshot = JsonConvert.DeserializeObject <FieldSnapshot>(part);
                                bool          isMatch  =
                                    (snapshot.ID == null || snapshot.ID.Equals(manifest.UniqueID, StringComparison.InvariantCultureIgnoreCase)) &&
                                    (snapshot.EntryDll == null || snapshot.EntryDll.Equals(manifest.EntryDll, StringComparison.InvariantCultureIgnoreCase)) &&
                                    (
                                        snapshot.Author == null ||
                                        snapshot.Author.Equals(manifest.Author, StringComparison.InvariantCultureIgnoreCase) ||
                                        (manifest.ExtraFields != null && manifest.ExtraFields.ContainsKey("Authour") && snapshot.Author.Equals(manifest.ExtraFields["Authour"].ToString(), StringComparison.InvariantCultureIgnoreCase))
                                    ) &&
                                    (snapshot.Name == null || snapshot.Name.Equals(manifest.Name, StringComparison.InvariantCultureIgnoreCase));

                                if (isMatch)
                                {
                                    return(true);
                                }
                            }

                            // plain ID
                            else if (part.Equals(manifest.UniqueID, StringComparison.InvariantCultureIgnoreCase))
                            {
                                return(true);
                            }
                        }
                    }
                }
            }

            displayName = null;
            record      = null;
            return(false);
        }
Ejemplo n.º 2
0
        /*********
        ** Private models
        *********/
        /// <summary>Get a raw data record.</summary>
        /// <param name="id">The mod ID to match.</param>
        /// <param name="displayName">The mod's default display name.</param>
        /// <param name="record">The raw mod record.</param>
        private bool TryGetRaw(string id, out string displayName, out ModDataRecord record)
        {
            foreach (var entry in this.Records)
            {
                if (entry.Value.ID != null && entry.Value.ID.Equals(id, StringComparison.InvariantCultureIgnoreCase))
                {
                    displayName = entry.Key;
                    record      = entry.Value;
                    return(true);
                }
            }

            displayName = null;
            record      = null;
            return(false);
        }