internal IsoResourceProxy CreateIsoResourceProxy(string key, IFileSystemResourceAccessor isoFileResourceAccessor)
        {
            IsoResourceProxy result = new IsoResourceProxy(key, isoFileResourceAccessor);

            result.Orphaned += OnIsoResourceProxyOrphaned;
            return(result);
        }
 void OnIsoResourceProxyOrphaned(IsoResourceProxy proxy)
 {
   lock (_syncObj)
   {
     if (proxy.UsageCount > 0)
       // Double check if the proxy was reused when the lock was not set
       return;
     _isoUsages.Remove(proxy.Key);
     proxy.Dispose();
   }
 }
 void OnIsoResourceProxyOrphaned(IsoResourceProxy proxy)
 {
     lock (_syncObj)
     {
         if (proxy.UsageCount > 0)
         {
             // Double check if the proxy was reused when the lock was not set
             return;
         }
         _isoUsages.Remove(proxy.Key);
         proxy.Dispose();
     }
 }
Example #4
0
 public void Dispose()
 {
     if (_stream != null)
     {
         _stream.Dispose();
     }
     if (_isoProxy == null)
     {
         return;
     }
     _isoProxy.DecUsage();
     _isoProxy = null;
 }
Example #5
0
        public IsoResourceAccessor(IsoResourceProvider isoProvider, IsoResourceProxy isoProxy, string pathToDirOrFile)
        {
            if (!pathToDirOrFile.StartsWith("/"))
            {
                throw new ArgumentException("Wrong path '{0}': Path in ISO file must start with a '/' character", pathToDirOrFile);
            }
            _isoProxy = isoProxy;
            _isoProxy.IncUsage();
            try
            {
                _isoProvider     = isoProvider;
                _pathToDirOrFile = pathToDirOrFile;

                _isDirectory = true;
                _lastChanged = _isoProxy.IsoFileResourceAccessor.LastChanged;
                _size        = -1;

                if (IsEmptyOrRoot)
                {
                    return;
                }
                lock (_isoProxy.SyncObj)
                {
                    string isoPath = ToIsoPath(pathToDirOrFile);
                    if (_isoProxy.DiskFileSystem.FileExists(isoPath))
                    {
                        _isDirectory = false;
                        _size        = _isoProxy.DiskFileSystem.GetFileLength(isoPath);
                        _lastChanged = _isoProxy.DiskFileSystem.GetLastWriteTime(isoPath);
                        return;
                    }
                    if (_isoProxy.DiskFileSystem.DirectoryExists(isoPath))
                    {
                        _isDirectory = true;
                        _size        = -1;
                        _lastChanged = _isoProxy.DiskFileSystem.GetLastWriteTime(isoPath);
                        return;
                    }
                    throw new ArgumentException(string.Format("IsoResourceAccessor cannot access path or file '{0}' in iso-file", isoPath));
                }
            }
            catch (Exception)
            {
                _isoProxy.DecUsage();
                throw;
            }
        }
        public bool IsResource(IFileSystemResourceAccessor baseResourceAccessor, string path)
        {
            string resourceName = baseResourceAccessor.ResourceName;

            if (string.IsNullOrEmpty(resourceName) || !baseResourceAccessor.IsFile)
            {
                return(false);
            }

            // Test if we have already an ISO proxy for that ISO file...
            lock (_syncObj)
            {
                string key = baseResourceAccessor.CanonicalLocalResourcePath.Serialize();
                try
                {
                    IsoResourceProxy proxy;
                    if (_isoUsages.TryGetValue(key, out proxy))
                    {
                        lock (proxy.SyncObj)
                            return(IsoResourceAccessor.IsResource(proxy.DiskFileSystem, path));
                    }
                }
                catch (Exception)
                {
                    return(false);
                }
            }

            // ... if not, test the resource in a new disk file system instance
            using (Stream underlayingStream = baseResourceAccessor.OpenRead())
            {
                try
                {
                    IFileSystem diskFileSystem = IsoResourceProxy.GetFileSystem(underlayingStream);
                    using (diskFileSystem as IDisposable)
                        return(IsoResourceAccessor.IsResource(diskFileSystem, path));
                }
                catch
                {
                    return(false);
                }
            }
        }
    public IsoResourceAccessor(IsoResourceProvider isoProvider, IsoResourceProxy isoProxy, string pathToDirOrFile)
    {
      if (!pathToDirOrFile.StartsWith("/"))
        throw new ArgumentException("Wrong path '{0}': Path in ISO file must start with a '/' character", pathToDirOrFile);
      _isoProxy = isoProxy;
      _isoProxy.IncUsage();
      try
      {
        _isoProvider = isoProvider;
        _pathToDirOrFile = pathToDirOrFile;

        _isDirectory = true;
        _lastChanged = _isoProxy.IsoFileResourceAccessor.LastChanged;
        _size = -1;

        if (IsEmptyOrRoot)
          return;
        lock (_isoProxy.SyncObj)
        {
          string isoPath = ToIsoPath(pathToDirOrFile);
          if (_isoProxy.DiskFileSystem.FileExists(isoPath))
          {
            _isDirectory = false;
            _size = _isoProxy.DiskFileSystem.GetFileLength(isoPath);
            _lastChanged = _isoProxy.DiskFileSystem.GetLastWriteTime(isoPath);
            return;
          }
          if (_isoProxy.DiskFileSystem.DirectoryExists(isoPath))
          {
            _isDirectory = true;
            _size = -1;
            _lastChanged = _isoProxy.DiskFileSystem.GetLastWriteTime(isoPath);
            return;
          }
          throw new ArgumentException(string.Format("IsoResourceAccessor cannot access path or file '{0}' in iso-file", isoPath));
        }
      }
      catch (Exception)
      {
        _isoProxy.DecUsage();
        throw;
      }
    }
 internal IsoResourceProxy CreateIsoResourceProxy(string key, IResourceAccessor isoFileResourceAccessor)
 {
   IsoResourceProxy result = new IsoResourceProxy(key, isoFileResourceAccessor);
   result.Orphaned += OnIsoResourceProxyOrphaned;
   return result;
 }
 public void Dispose()
 {
   if (_stream != null)
     _stream.Dispose();
   if (_isoProxy == null)
     return;
   _isoProxy.DecUsage();
   _isoProxy = null;
 }