using System.Collections.Generic; using System.IO; using System.Linq; namespace UnityEditor.AddressableAssets.Build { /// /// Use to contain files created during a build. /// public class FileRegistry { private readonly HashSet m_FilePaths; /// /// Initializes a new file registry instance. /// public FileRegistry() { m_FilePaths = new HashSet(); } /// /// Retrieves all the stored file paths. /// /// Returns all file paths as an IEnumerable. public IEnumerable GetFilePaths() { return new HashSet(m_FilePaths); } /// /// Adds a file path to our set of file paths. /// /// The file path. public void AddFile(string path) { m_FilePaths.Add(path); } /// /// Removes a file path from our set of file paths. /// /// The file path. public void RemoveFile(string path) { m_FilePaths.Remove(path); } /// /// Given a bundle name, determine the file path for the bundle. /// /// The name of the bundle. /// The full file path. public string GetFilePathForBundle(string bundleName) { bundleName = Path.GetFileNameWithoutExtension(bundleName); return m_FilePaths.FirstOrDefault((entry) => entry.Contains(bundleName)); } /// /// Replace an entry in the File Registry with a new bundle name. /// /// The bundle name to replace. /// The new file registry bundle name. /// Returns true if a successful replacement occured. public bool ReplaceBundleEntry(string bundleName, string newFileRegistryEntry) { if (!m_FilePaths.Contains(newFileRegistryEntry)) { m_FilePaths.RemoveWhere((entry) => entry.Contains(bundleName)); AddFile(newFileRegistryEntry); return true; } return false; } } }