예제 #1
0
        // Constructor
        public PK3Reader(DataLocation dl) : base(dl)
        {
            General.WriteLogLine("Opening PK3 resource '" + 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);
        }
예제 #2
0
        // Constructor
        public PK3Reader(DataLocation dl, bool asreadonly) : base(dl, asreadonly)
        {
            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>();

            // Create archive
            archive     = ArchiveFactory.Open(location.location, Options.KeepStreamsOpen);
            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;

            // 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);
        }
예제 #3
0
        // Constructor
        public DirectoryReader(DataLocation dl) : base(dl)
        {
            General.WriteLogLine("Opening directory resource \"" + location.location + "\"");

            // Initialize
            files = new DirectoryFilesList(dl.location, true);
            Initialize();
        }
        // Constructor
        public DirectoryReader(DataLocation dl, bool asreadonly) : base(dl, asreadonly)
        {
            General.WriteLogLine("Opening directory resource \"" + location.location + "\"");

            // Initialize
            files = new DirectoryFilesList(dl.location, true);
            Initialize();

            // We have no destructor
            GC.SuppressFinalize(this);
        }
        // Constructor
        public DirectoryReader(DataLocation dl) : base(dl)
        {
            Logger.WriteLogLine("Opening directory resource '" + location.location + "'");

            // Initialize
            files = new DirectoryFilesList(dl.location, true);
            Initialize();

            // We have no destructor
            GC.SuppressFinalize(this);
        }
        // GET: Document
        public ActionResult ViewDocuments()
        {
            string str = System.Web.HttpContext.Current.User.Identity.Name;

            ViewBag.Message = "Your file page.";
            DirectoryInfo   dirInfo = new DirectoryInfo(@"C:\Users\");
            List <FileInfo> files   = dirInfo.GetFiles().ToList();

            Console.WriteLine(" ");
            //List<DirectoryInfo> directories = dirInfo.GetDirectories().ToList();
            List <DirectoryInfo> dir = dirInfo.GetDirectories().ToList();
            //pass the data trough the "View" method

            DirectoryFilesList naziv = new DirectoryFilesList();

            naziv.dinfo = dir;
            naziv.finfo = files;
            return(View(naziv));
        }
예제 #7
0
        private bool bathmode = true; //mxd

        #endregion

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

        // Constructor
        public PK3Reader(DataLocation dl) : base(dl)
        {
            Logger.WriteLogLine("Opening PK3 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>();

            ReaderOptions options = new ReaderOptions();

            options.LeaveStreamOpen = true;

            // Create archive
            archive = ArchiveFactory.Open(location.location, options);

            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;


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

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

            // We have no destructor
            GC.SuppressFinalize(this);
        }
        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);
        }