/// <summary>
        ///     Called when the engine is shutting down.
        /// </summary>
        protected override void dispose(bool disposeManagedResources)
        {
            if (!isDisposed)
            {
                if (disposeManagedResources)
                {
                    // Unload & delete resources in turn
                    foreach (KeyValuePair <string, Archive> arch in _archives)
                    {
                        // Unload
                        arch.Value.Unload();

                        // Find factory to destroy
                        ArchiveFactory fac = _factories[arch.Value.Type];
                        if (fac == null)
                        {
                            // Factory not found
                            throw ExceptionFactory.CreateFatalException("Cannot find an archive factory to deal with archive of type {0}", arch.Value.Type);
                        }
                        Archive tmp = arch.Value;
                        fac.DestroyInstance(ref tmp);
                    }

                    // Empty the list
                    _archives.Clear();
                }

                // There are no unmanaged resources to release, but
                // if we add them, they need to be released here.
            }

            // If it is available, make the call to the
            // base class's Dispose(Boolean) method
            base.dispose(disposeManagedResources);
        }
예제 #2
0
        /// <summary>
        ///     Retrieves a log managed by this class.
        /// </summary>
        /// <param name="name">Name of the log to retrieve.</param>
        /// <returns>Log with the specified name.</returns>
        public Log GetLog(string name)
        {
            if (logList[name] == null)
            {
                throw ExceptionFactory.CreateFatalException("Log with the name '{0}' not found.", name);
            }

            return((Log)logList[name]);
        }
        /// <summary>
        /// Add an archive factory to the list
        /// </summary>
        /// <param name="type">The type of the factory (zip, file, etc.)</param>
        /// <param name="factory">The factory itself</param>
        public void AddArchiveFactory(ArchiveFactory factory)
        {
            if (_factories.ContainsKey(factory.Type) == true)
            {
                throw ExceptionFactory.CreateFatalException("Attempted to add the {0} factory to ArchiveManager more than once.", factory.Type);
            }

            _factories.Add(factory.Type, factory);
            LogManager.Instance.Write("ArchiveFactory for archive type {0} registered.", factory.Type);
        }
        /// <summary>
        ///  Unloads an archive.
        ///  </summary>
        ///  <remarks>
        /// You must ensure that this archive is not being used before removing it.
        ///  </remarks>
        /// <param name="arch">The Archive to unload</param>
        public void Unload(string filename)
        {
            Archive arch = _archives[filename];

            if (arch != null)
            {
                arch.Unload();

                ArchiveFactory fac = _factories[arch.Type];
                if (fac == null)
                {
                    throw ExceptionFactory.CreateFatalException("Cannot find an archive factory to deal with archive of type {0}", arch.Type);
                }
                _archives.Remove(arch.Name);
                fac.DestroyInstance(ref arch);
            }
        }
        /// <summary>
        /// Opens an archive for file reading.
        /// </summary>
        /// <remarks>
        /// The archives are created using class factories within
        /// extension libraries.
        /// </remarks>
        /// <param name="filename">The filename that will be opened</param>
        /// <param name="archiveType">The library that contains the data-handling code</param>
        /// <returns>
        /// If the function succeeds, a valid pointer to an Archive object is returned.
        /// <para/>
        /// If the function fails, an exception is thrown.
        /// </returns>
        public Archive Load(string filename, string archiveType)
        {
            Archive arch = null;

            if (!_archives.TryGetValue(filename, out arch))
            {
                // Search factories
                ArchiveFactory fac = null;
                if (!_factories.TryGetValue(archiveType, out fac))
                {
                    throw ExceptionFactory.CreateFatalException("Cannot find an archive factory to deal with archive of type {0}", archiveType);
                }

                arch = fac.CreateInstance(filename);
                arch.Load();
                _archives.Add(filename, arch);
            }
            return(arch);
        }
예제 #6
0
 /// <summary>
 /// Delete a named file.
 /// </summary>
 /// <remarks>If the archive is read-only then this method will fail.</remarks>
 /// <param name="filename">The fully qualified name of the file</param>
 virtual public void Remove(string filename)
 {
     throw ExceptionFactory.CreateFatalException("This archive does not support removal of files.");
 }
예제 #7
0
 /// <summary>
 /// Create a new file (or overwrite one already there).
 /// </summary>
 /// <remarks>If the archive is read-only then this method will fail.</remarks>
 /// <param name="filename">The fully qualified name of the file</param>
 /// <param name="overwrite">True to overwrite an existing file.</param>
 /// <returns>A Stream which can be used to read / write the file.</returns>
 virtual public Stream Create(string filename, bool overwrite)
 {
     throw ExceptionFactory.CreateFatalException("This archive does not support creation of files.");
 }