Example #1
0
        /// <summary>
        /// Initializes a new content file using an already existing file from an addon as storage.
        /// </summary>
        /// <param name="reader">The reader of the addon.</param>
        /// <param name="index">The index of the file to use.</param>
        public ContentFile(Reader reader, Reader.IndexEntry index)
        {
            Path = index.Path;

            Storage          = ContentStorageType.AddonInstance;
            AssociatedReader = reader;
            ReaderFileEntry  = index.FileNumber;
        }
Example #2
0
        /// <summary>
        /// Initializes a new content file using pure content as storage.
        /// </summary>
        /// <param name="path">The path of the file WITHIN the addon.</param>
        /// <param name="content">The array of bytes containing the already set content.</param>
        public ContentFile(string path, byte[] content)
        {
            Storage = ContentStorageType.Filesystem;
            Path    = path;

            ExternalFile = new FileStream(ContentFile.GenerateExternalPath(path), FileMode.CreateNew, FileAccess.ReadWrite, FileShare.None);

            Content = content;
        }
Example #3
0
        /// <summary>
        /// Switches the current ContentFile to represent a file saved into an addon.
        /// Used after saving addons so that previous externally-saved entries are dropped in time.
        /// </summary>
        /// <param name="reader">The reader of the addon.</param>
        /// <param name="index">The index of the file to use.</param>
        public void SwitchToAddonInstance(Reader reader, Reader.IndexEntry index)
        {
            if (Storage == ContentStorageType.Filesystem)
            {
                AssociatedReader = reader;
                ReaderFileEntry  = index.FileNumber;
                DisposeExternal();

                Storage = ContentStorageType.AddonInstance;
            }
            else if (Storage == ContentStorageType.AddonInstance)
            {
                // Update the entry itself. There is no need to touch files on disk.
                AssociatedReader = reader;
                ReaderFileEntry  = index.FileNumber;
            }
        }
Example #4
0
        /// <summary>
        /// Switches the current ContentFile to represent a file saved into an addon.
        /// Used after saving addons so that previous externally-saved entries are dropped in time.
        /// </summary>
        /// <param name="reader">The reader of the addon.</param>
        /// <param name="index">The index of the file to use.</param>
        public void SwitchToAddonInstance(Reader reader, Reader.IndexEntry index)
        {
            switch (_storage)
            {
            case ContentStorageType.Filesystem:
                _associatedReader = reader;
                _readerFileEntry  = index.FileNumber;
                DisposeExternal();

                _storage = ContentStorageType.AddonInstance;
                break;

            case ContentStorageType.AddonInstance:
                // Update the entry itself. There is no need to touch files on disk.
                _associatedReader = reader;
                _readerFileEntry  = index.FileNumber;
                break;
            }
        }
Example #5
0
        /// <summary>
        /// Switches the current ContentFile to represent a file saved into an addon.
        /// Used after saving addons so that previous externally-saved entries are dropped in time.
        /// </summary>
        /// <param name="reader">The reader of the addon.</param>
        /// <param name="index">The index of the file to use.</param>
        public void SwitchToAddonInstance(Reader reader, Reader.IndexEntry index)
        {
            if (Storage == ContentStorageType.Filesystem)
            {
                AssociatedReader = reader;
                ReaderFileEntry = index.FileNumber;
                DisposeExternal();

                Storage = ContentStorageType.AddonInstance;
            }
            else if (Storage == ContentStorageType.AddonInstance)
            {
                // Update the entry itself. There is no need to touch files on disk.
                AssociatedReader = reader;
                ReaderFileEntry = index.FileNumber;
            }
        }
Example #6
0
        /// <summary>
        /// Initializes a new content file using pure content as storage.
        /// </summary>
        /// <param name="path">The path of the file WITHIN the addon.</param>
        /// <param name="content">The array of bytes containing the already set content.</param>
        public ContentFile(string path, byte[] content)
        {
            Storage = ContentStorageType.Filesystem;
            Path = path;

            ExternalFile = new FileStream(ContentFile.GenerateExternalPath(path), FileMode.CreateNew, FileAccess.ReadWrite, FileShare.None);

            Content = content;
        }
Example #7
0
        /// <summary>
        /// Initializes a new content file using an already existing file from an addon as storage.
        /// </summary>
        /// <param name="reader">The reader of the addon.</param>
        /// <param name="index">The index of the file to use.</param>
        public ContentFile(Reader reader, Reader.IndexEntry index)
        {
            Path = index.Path;

            Storage = ContentStorageType.AddonInstance;
            AssociatedReader = reader;
            ReaderFileEntry = index.FileNumber;
        }