示例#1
0
        /// <summary>
        /// Attempt to find a bundle by the given ID.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="bundle"></param>
        /// <returns><code>true</code> on success, <code>false</code> on failure.</returns>
        public bool FindBundle(Guid id, out VfsBundle bundle)
        {
            var result = ScanMountsForBundle(id, _mounts.Values);

            bundle = result;

            return(result != null);
        }
示例#2
0
        /// <summary>
        /// Unmount a bundle.
        /// </summary>
        /// <param name="bundle"></param>
        public void UnmountBundle(VfsBundle bundle)
        {
            if (!Bundles.Exists(b => b.ID == bundle.ID))
            {
                throw new Exception($"Bundle [{bundle.ID}] is not mounted to [{Path}].");
            }

            UnmountBundle(bundle.ID);
        }
示例#3
0
        /// <summary>
        /// Mount a bundle.
        /// </summary>
        /// <param name="bundle"></param>
        public void MountBundle(VfsBundle bundle)
        {
            if (Bundles.Exists(b => b.ID == bundle.ID))
            {
                throw new Exception($"Bundle [{bundle.ID}] is already mounted to [{Path}].");
            }

            Bundles.Add(bundle);
        }
示例#4
0
        /// <summary>
        /// Mount a bundle to the bundle. Yes, seriously.
        /// </summary>
        /// <param name="bundle"></param>
        public VfsBundle MountBundle(VfsBundle bundle)
        {
            if (Bundles.Exists(b => b.ID == bundle.ID))
            {
                throw new Exception($"Bundle [{bundle.ID}] is already mounted to bundle {Name}.");
            }

            Bundles.Add(bundle);

            return(Bundles.Find(b => b.ID == bundle.ID));
        }
示例#5
0
        /// <summary>
        /// Mounts a bundle to the VFS.
        /// </summary>
        /// <param name="location">The mount location. Example: /bundles</param>
        /// <param name="bundle"></param>
        public void MountBundle(string location, VfsBundle bundle)
        {
            if (location.Length == 0)
            {
                throw new ArgumentException("Location cannot be empty", nameof(location));
            }

            // Make sure the root mount exists
            if (!FindMount("/", out var rootMount))
            {
                throw new Exception("Failed to access root mount.");
            }

            var parts = location.Split('/').Skip(1).ToList();

            if (parts.Count == 1)
            {
                if (string.IsNullOrWhiteSpace(parts[0]))
                {
                    // Trying to mount to root
                    rootMount.MountBundle(bundle);
                }
                else
                {
                    if (rootMount.SubMounts.Exists(m => m.Path == $"/{parts[0]}"))
                    {
                        rootMount.SubMounts.Find(m => m.Path == $"/{parts[0]}")
                        .MountBundle(bundle);
                    }
                    else
                    {
                        // Create a sub-mount under root
                        rootMount.SubMounts.Add(new VfsMount
                        {
                            Path    = $"/{parts[0]}",
                            Bundles = { bundle }
                        });
                    }
                }
            }
            else
            {
                var lastMount = rootMount;
                var partQueue = new Queue <string>(parts);
                var builtPath = "/";

                while (partQueue.Count > 0)
                {
                    var part = partQueue.Dequeue();

                    if (lastMount.Path == rootMount.Path)
                    {
                        builtPath += part;

                        if (!rootMount.SubMounts.Exists(m => m.Path == builtPath))
                        {
                            rootMount.SubMounts.Add(new VfsMount
                            {
                                Path = builtPath
                            });
                        }

                        lastMount = rootMount.SubMounts.Find(m => m.Path == builtPath);
                    }
                    else
                    {
                        builtPath += $"/{part}";

                        if (!lastMount.SubMounts.Exists(m => m.Path == builtPath))
                        {
                            lastMount.SubMounts.Add(new VfsMount
                            {
                                Path = builtPath
                            });
                        }

                        lastMount = lastMount.SubMounts.Find(m => m.Path == builtPath);
                    }
                }

                lastMount.MountBundle(bundle);
            }

            _mounts["/"] = rootMount;
        }