Esempio n. 1
0
        /// <summary>
        /// Function to determine if a physical file system can be read by this provider.
        /// </summary>
        /// <param name="physicalPath">Path to the packed file containing the file system.</param>
        /// <returns><b>true</b> if the provider can read the packed file, <b>false</b> if not.</returns>
        /// <exception cref="ArgumentNullException">Thrown when the <paramref name="physicalPath"/> parameter is <b>null</b>.</exception>
        /// <exception cref="ArgumentEmptyException">Thrown when the <paramref name="physicalPath"/> parameter is an empty string.</exception>
        /// <remarks>
        /// <para>
        /// This will test a physical file system (e.g. a Zip file) to see if the provider can open it or not. If used with a directory on an operating system file system, this method should always return
        /// <b>false</b>.
        /// </para>
        /// <para>
        /// When used with a <see cref="IGorgonFileSystemProvider"/> that supports a non operating system based physical file system, such as the <see cref="GorgonFileSystemRamDiskProvider"/>, then this
        /// method should compare the <paramref name="physicalPath"/> with its <see cref="IGorgonFileSystemProvider.Prefix"/> to ensure that the <see cref="IGorgonFileSystem"/> requesting the provider is using the correct provider.
        /// </para>
        /// <para>
        /// Implementors of a <see cref="GorgonFileSystemProvider"/> should override this method to determine if a packed file can be read by reading the header of the file specified in <paramref name="physicalPath"/>.
        /// </para>
        /// </remarks>
        protected override bool OnCanReadFile(string physicalPath)
        {
            string header;

            using (var reader = new GorgonBinaryReader(File.Open(physicalPath, FileMode.Open, FileAccess.Read, FileShare.Read)))
            {
                // If the length of the stream is less or equal to the header size, it's unlikely that we can read this file.
                if (reader.BaseStream.Length <= GorPackHeader.Length)
                {
                    return(false);
                }

                reader.ReadByte();
                header = new string(reader.ReadChars(GorPackHeader.Length));
            }

            return(string.Equals(header, GorPackHeader));
        }
Esempio n. 2
0
        /// <summary>
        /// Function to determine if a file can be read by this provider.
        /// </summary>
        /// <param name="physicalPath">Path to the file containing the file system.</param>
        /// <returns>
        /// TRUE if the provider can read the packed file, FALSE if not.
        /// </returns>
        /// <remarks>This method is applicable to packed files only.
        /// <para>Implementors must use this method to determine if a packed file can be read by reading the header of the file.</para>
        /// </remarks>
        /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="physicalPath"/> parameter is NULL (Nothing in VB.Net).</exception>
        /// <exception cref="System.ArgumentException">Thrown when the <paramref name="physicalPath"/> parameter is an empty string.</exception>
        public override bool CanReadFile(string physicalPath)
        {
            string header;

            if (physicalPath == null)
            {
                throw new ArgumentNullException("physicalPath");
            }

            if (string.IsNullOrWhiteSpace(physicalPath))
            {
                throw new ArgumentException(Resources.GORFS_PARAMETER_MUST_NOT_BE_EMPTY, "physicalPath");
            }

            using (var reader = new GorgonBinaryReader(File.Open(physicalPath, FileMode.Open, FileAccess.Read, FileShare.Read), false))
            {
                reader.ReadByte();
                header = new string(reader.ReadChars(GorgonGorPackPlugIn.GorPackHeader.Length));
            }

            return(string.Equals(header, GorgonGorPackPlugIn.GorPackHeader));
        }