Esempio n. 1
0
        /// <summary>
        /// Adds music files that are placed in the vanilla directories to the vanilla channels
        /// </summary>
        private void ExtendVanillaContent()
        {
            if (!ModOptions.Instance.EnableAddingContentToVanillaStations)
            {
                return;
            }
            if (!ModOptions.Instance.AddVanillaSongsToMusicMix)
            {
                return;
            }

            for (uint i = 0; i < PrefabCollection <RadioChannelInfo> .PrefabCount(); ++i)
            {
                RadioChannelInfo info = PrefabCollection <RadioChannelInfo> .GetPrefab(i);

                if (info == null)
                {
                    continue;
                }

                if (!UserRadioContainer.m_UserRadioDict.ContainsKey(info))
                {
                    // Collect existing radio content
                    HashSet <string> existing = new HashSet <string>();

                    for (uint j = 0; j < PrefabCollection <RadioContentInfo> .PrefabCount(); ++j)
                    {
                        RadioContentInfo content = PrefabCollection <RadioContentInfo> .GetPrefab(j);

                        if (content == null)
                        {
                            continue;
                        }
                        if (content.m_radioChannels == null)
                        {
                            continue;
                        }

                        if (content.m_radioChannels.Contains(info))
                        {
                            string text = Path.Combine(DataLocation.gameContentPath, "Radio");
                            text = Path.Combine(text, content.m_contentType.ToString());
                            text = Path.Combine(text, content.m_folderName);
                            text = Path.Combine(text, content.m_fileName);

                            existing.Add(text);
                        }
                    }

                    HashSet <string> validcollectionnames = new HashSet <string>();
                    foreach (RadioContentInfo.ContentType type in Enum.GetValues(typeof(RadioContentInfo.ContentType)))
                    {
                        validcollectionnames.Add(type + ": " + info.name);
                    }

                    // Check our collection for non-existing files
                    foreach (UserRadioContent usercontent in UserRadioContainer.m_Songs.Values)
                    {
                        if (!existing.Contains(usercontent.m_FileName) && validcollectionnames.Contains(usercontent.m_Collection))
                        {
                            CSLMusicMod.Log("[ExtendedVanillaContent] Adding " + usercontent.m_FileName + " to vanilla station " + info.name);

                            List <RadioChannelInfo> v = GenericHelper.CopyOrCreateList <RadioChannelInfo>(usercontent.m_VanillaContentInfo.m_radioChannels);
                            v.Add(info);
                            usercontent.m_VanillaContentInfo.m_radioChannels = v.ToArray();
                        }
                    }
                }
            }
        }