Exemplo n.º 1
0
        // Constructor
        public PK3Reader(DataLocation dl) : base(dl)
        {
            General.WriteLogLine("Opening PK3 resource '" + location.location + "'");

            if (!File.Exists(location.location))
            {
                throw new FileNotFoundException("Could not find the file \"" + location.location + "\"", location.location);
            }

            // Open the zip file
            ZipInputStream zipstream = OpenPK3File();

            // Make list of all files
            List <DirectoryFileEntry> fileentries = new List <DirectoryFileEntry>();
            ZipEntry entry = zipstream.GetNextEntry();

            while (entry != null)
            {
                if (entry.IsFile)
                {
                    fileentries.Add(new DirectoryFileEntry(entry.Name));
                }

                // Next
                entry = zipstream.GetNextEntry();
            }

            // Make files list
            files = new DirectoryFilesList(fileentries);

            // Done with the zip file
            zipstream.Close();
            zipstream.Dispose();

            // Initialize without path (because we use paths relative to the PK3 file)
            Initialize();

            // We have no destructor
            GC.SuppressFinalize(this);
        }
 // Call this to initialize this class
 protected virtual void Initialize()
 {
     // [ZZ] we can have wad files already. dispose if any.
     if (wads != null)
     {
         foreach (WADReader wr in wads)
         {
             wr.Dispose();
         }
     }
     // Load all WAD files in the root as WAD resources
     string[] wadfiles = GetWadFiles();
     wads = new List <WADReader>(wadfiles.Length);
     foreach (string w in wadfiles)
     {
         string       tempfile = CreateTempFile(w);
         DataLocation wdl      = new DataLocation(DataLocation.RESOURCE_WAD, tempfile, Path.Combine(location.GetDisplayName(), Path.GetFileName(w)), false, false, true);
         wads.Add(new WADReader(wdl, location.type != DataLocation.RESOURCE_DIRECTORY)
         {
             ParentResource = this
         });
     }
 }
Exemplo n.º 3
0
        // Constructor
        public WADReader(DataLocation dl) : base(dl)
        {
            General.WriteLogLine("Opening WAD resource '" + location.location + "'");

            // Initialize
            file           = new WAD(location.location, true);
            is_iwad        = (file.Type == WAD.TYPE_IWAD);
            strictpatches  = dl.option1;
            patchranges    = new List <LumpRange>();
            spriteranges   = new List <LumpRange>();
            flatranges     = new List <LumpRange>();
            textureranges  = new List <LumpRange>();
            colormapranges = new List <LumpRange>();

            // Find ranges
            FindRanges(patchranges, General.Map.Config.PatchRanges, "patches");
            FindRanges(spriteranges, General.Map.Config.SpriteRanges, "sprites");
            FindRanges(flatranges, General.Map.Config.FlatRanges, "flats");
            FindRanges(textureranges, General.Map.Config.TextureRanges, "textures");
            FindRanges(colormapranges, General.Map.Config.ColormapRanges, "colormaps");

            // We have no destructor
            GC.SuppressFinalize(this);
        }
Exemplo n.º 4
0
 // Constructor
 public DataReader(DataLocation dl)
 {
     // Keep information
     location   = dl;
     textureset = new ResourceTextureSet(GetTitle(), dl);
 }
        }                                                              //mxd

        #endregion

        #region ================== Constructor / Disposer

        // Constructor
        protected PK3StructuredReader(DataLocation dl, bool asreadonly) : base(dl, asreadonly)
        {
            // Initialize
            this.roottextures = dl.option1;
            this.rootflats    = dl.option2;
        }
 // Constructor
 public PK3StructuredReader(DataLocation dl) : base(dl)
 {
     // Initialize
     this.roottextures = dl.option1;
     this.rootflats    = dl.option2;
 }
        private void LoadFrom(DataLocation dl, bool asreadonly)
        {
			FileAccess access;
			FileShare share;

			isreadonly = asreadonly;

			// Determine if opening for read only
			if (isreadonly)
			{
				// Read only
				access = FileAccess.Read;
				share = FileShare.ReadWrite;
			}
			else
			{
				// Private access
				access = FileAccess.ReadWrite;
				share = FileShare.Read;
			}

			General.WriteLogLine("Opening " + Path.GetExtension(location.location).ToUpper().Replace(".", "") + " resource \"" + location.location + "\"");

            if (!File.Exists(location.location))
                throw new FileNotFoundException("Could not find the file \"" + location.location + "\"", location.location);

            // Make list of all files
            List<DirectoryFileEntry> fileentries = new List<DirectoryFileEntry>();

			// Take the detour with a FileStream because SharpCompress doesn't directly support opening files as read-only
			filestream = File.Open(location.location, FileMode.OpenOrCreate, access, share);

			// Create archive
			archive = ArchiveFactory.Open(filestream);
            archivetype = archive.Type;

            // Random access of 7z archives works TERRIBLY slow in SharpCompress
            if (archivetype == ArchiveType.SevenZip)
            {
                isreadonly = true; // Unsaveable...
                sevenzipentries = new Dictionary<string, byte[]>(StringComparer.Ordinal);

                IReader reader = archive.ExtractAllEntries();
                while (reader.MoveToNextEntry())
                {
                    if (reader.Entry.IsDirectory || !CheckInvalidPathChars(reader.Entry.Key)) continue;

                    MemoryStream s = new MemoryStream();
                    reader.WriteEntryTo(s);
                    sevenzipentries.Add(reader.Entry.Key.ToLowerInvariant(), s.ToArray());
                    fileentries.Add(new DirectoryFileEntry(reader.Entry.Key));
                }
			}
            else
            {
                foreach (IArchiveEntry entry in archive.Entries)
                {
                    if (!entry.IsDirectory && CheckInvalidPathChars(entry.Key))
                        fileentries.Add(new DirectoryFileEntry(entry.Key));
                }
            }

            // Get rid of archive
            archive.Dispose();
            archive = null;

			filestream.Dispose();
			filestream = null;

            // Make files list
            files = new DirectoryFilesList(dl.GetDisplayName(), fileentries);

            // Initialize without path (because we use paths relative to the PK3 file)
            Initialize();

            // We have no destructor
            GC.SuppressFinalize(this);
        }
		// Constructor
		public PK3Reader(DataLocation dl, bool asreadonly) : base(dl, asreadonly)
		{
            LoadFrom(dl, asreadonly);
		}