Esempio n. 1
0
        protected void ReleaseOpenedZipEntry(string path)
        {
            OpenedZipEntry zipEntry = null;

            lock (zipEntries)
            {
                zipEntry = zipEntries[path];
            }
            lock (zipEntry)
            {
                zipEntry.OpenCount--;
            }
            lock (zipEntry)
            {
                if (zipEntry.OpenCount == 0)
                {
                    lock (zipEntryCache)
                    {
                        int      lastAccessed = -1;
                        DateTime lastAccess   = DateTime.Now;
                        int      emptyIndex   = -1;
                        for (int i = 0; i < zipEntryCache.Length; i++)
                        {
                            if (zipEntryCache[i] == null)
                            {
                                emptyIndex = i;
                                break;
                            }
                            if (zipEntryCache[i].LastAccess < lastAccess)
                            {
                                lastAccessed = i;
                                lastAccess   = zipEntryCache[i].LastAccess;
                            }
                        }
                        if (emptyIndex < 0)
                        {
                            if (zipEntryCache[lastAccessed].Stream != null)
                            {
                                zipEntryCache[lastAccessed].Stream.Close();
                            }
                            zipEntryCache[lastAccessed].Stream = null;
                            zipEntryCache[lastAccessed].Data   = null;
                            if (zipEntryCache[lastAccessed].ZipFile != null)
                            {
                                ReleaseZipFileReference(zipEntryCache[lastAccessed].ZipFile.Path);
                            }
                            zipEntryCache[lastAccessed].ZipFile = null;
                            zipEntryCache[lastAccessed]         = null;
                            emptyIndex = lastAccessed;
                        }
                        zipEntryCache[emptyIndex] = zipEntry;
                        lock (zipEntries)
                        {
                            zipEntries.Remove(path);
                        }
                        zipEntry.LastAccess = DateTime.Now;
                    }
                }
            }
        }
Esempio n. 2
0
        protected OpenedZipEntry LockOpenedZipEntryFromCache(string path)
        {
            OpenedZipEntry zipEntry = null;

            lock (zipEntryCache)
            {
                int cacheIndex = -1;
                for (int i = 0; i < zipEntryCache.Length; i++)
                {
                    if ((zipEntryCache[i] != null) && (zipEntryCache[i].Path == path))
                    {
                        cacheIndex = i;
                        break;
                    }
                }
                zipEntry = zipEntryCache[cacheIndex];
                lock (zipEntries)
                {
                    zipEntries.Add(path, zipEntry);
                }
                zipEntryCache[cacheIndex] = null;
            }
            lock (zipEntry)
            {
                zipEntry.OpenCount++;
            }
            return(zipEntry);
        }
Esempio n. 3
0
        protected OpenedZipEntry LockOpenedZipEntry(string path)
        {
            OpenedZipEntry zipEntry = null;

            lock (zipEntries)
            {
                zipEntry = zipEntries[path];
            }
            lock (zipEntry)
            {
                zipEntry.OpenCount++;
            }
            return(zipEntry);
        }
Esempio n. 4
0
        protected OpenedZipEntry CreateOpenedZipEntry(ZipFileReference zipFile, string fullPath, string path)
        {
            OpenedZipEntry entry = new OpenedZipEntry();

            entry.Path     = fullPath;
            entry.ZipFile  = zipFile;
            entry.ZipEntry = zipFile.ZipFile.GetEntry(path);
            entry.Stream   = zipFile.ZipFile.GetInputStream(entry.ZipEntry);
            entry.Data     = new byte[entry.ZipEntry.Size];
            entry.OpenCount++;
            entry.LastAccess = DateTime.Now;
            lock (zipEntries)
            {
                zipEntries.Add(fullPath, entry);
            }
            return(entry);
        }
Esempio n. 5
0
 void ReadToPosition(OpenedZipEntry entry, long position)
 {
     position = Math.Min(entry.Data.LongLength, position);
     if (entry.Position == entry.Data.LongLength)
     {
         return;
     }
     while (position > entry.Position)
     {
         int read = entry.Stream.Read(entry.Data, (int)entry.Position, (int)(position - entry.Position));
         entry.Position += read;
     }
     if (entry.Position == entry.Data.LongLength)
     {
         entry.Stream.Close();
         entry.Stream   = null;
         entry.ZipEntry = null;
         ReleaseZipFileReference(entry.ZipFile.Path);
         entry.ZipFile = null;
     }
 }
Esempio n. 6
0
        protected override Errno OnReadHandle(string file, OpenedPathInfo info, byte[] buf, long offset, out int bytesWritten)
        {
            OpenedZipEntry entry = null;

            lock (zipEntries)
            {
                entry = zipEntries[file];
            }
            lock (entry)
            {
                if (entry.Position < offset + buf.LongLength)
                {
                    ReadToPosition(entry, offset + buf.LongLength);
                }
            }
            long maxRead = Math.Min(entry.Data.LongLength - offset, buf.LongLength);

            Array.Copy(entry.Data, offset, buf, 0, maxRead);
            bytesWritten = (int)maxRead;
            return(0);
        }
Esempio n. 7
0
 protected OpenedZipEntry CreateOpenedZipEntry(ZipFileReference zipFile, string fullPath, string path)
 {
     OpenedZipEntry entry = new OpenedZipEntry();
     entry.Path = fullPath;
     entry.ZipFile = zipFile;
     entry.ZipEntry = zipFile.ZipFile.GetEntry(path);
     entry.Stream = zipFile.ZipFile.GetInputStream(entry.ZipEntry);
     entry.Data = new byte[entry.ZipEntry.Size];
     entry.OpenCount++;
     entry.LastAccess = DateTime.Now;
     lock (zipEntries)
     {
         zipEntries.Add(fullPath, entry);
     }
     return entry;
 }
Esempio n. 8
0
 void ReadToPosition(OpenedZipEntry entry, long position)
 {
     position = Math.Min(entry.Data.LongLength, position);
     if (entry.Position == entry.Data.LongLength)
         return;
     while (position > entry.Position)
     {
         int read = entry.Stream.Read(entry.Data, (int)entry.Position, (int)(position - entry.Position));
         entry.Position += read;
     }
     if (entry.Position == entry.Data.LongLength)
     {
         entry.Stream.Close();
         entry.Stream = null;
         entry.ZipEntry = null;
         ReleaseZipFileReference(entry.ZipFile.Path);
         entry.ZipFile = null;
     }
 }