SevenZip/LibraryManager.cs
/// <summary>
///   Removes user from reference list and frees the 7-zip library if it becomes empty
/// </summary>
/// <param name = "user">Caller of the function</param>
/// <param name = "format">Archive format</param>
Removes user from reference list and frees the 7-zip library if it becomes empty
Removes user from reference list and frees the 7 - zip library if it becomes empty
public static void FreeLibrary(object user, Enum format)
        {
#if !WINCE && !MONO
            var sp = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);
            sp.Demand();
#endif
            if (_modulePtr != IntPtr.Zero)
            {
                if (format is InArchiveFormat)
                {
                    if (_inArchives != null && _inArchives.ContainsKey(user) &&
                        _inArchives[user].ContainsKey((InArchiveFormat) format) &&
                        _inArchives[user][(InArchiveFormat) format] != null)
                    {
                        try
                        {
                            Marshal.ReleaseComObject(_inArchives[user][(InArchiveFormat) format]);
                        }
                        catch (InvalidComObjectException)
                        {
                        }
                        _inArchives[user].Remove((InArchiveFormat) format);
                        _totalUsers--;
                        if (_inArchives[user].Count == 0)
                        {
                            _inArchives.Remove(user);
                        }
                    }
                }
#if COMPRESS
                if (format is OutArchiveFormat)
                {
                    if (_outArchives != null && _outArchives.ContainsKey(user) &&
                        _outArchives[user].ContainsKey((OutArchiveFormat) format) &&
                        _outArchives[user][(OutArchiveFormat) format] != null)
                    {
                        try
                        {
                            Marshal.ReleaseComObject(_outArchives[user][(OutArchiveFormat) format]);
                        }
                        catch (InvalidComObjectException)
                        {
                        }
                        _outArchives[user].Remove((OutArchiveFormat) format);
                        _totalUsers--;
                        if (_outArchives[user].Count == 0)
                        {
                            _outArchives.Remove(user);
                        }
                    }
                }
#endif
                if ((_inArchives == null || _inArchives.Count == 0)
#if COMPRESS
                    && (_outArchives == null || _outArchives.Count == 0)
#endif
                    )
                {
                    _inArchives = null;
#if COMPRESS
                    _outArchives = null;
#endif
                    if (_totalUsers == 0)
                    {
#if !WINCE && !MONO
                        NativeMethods.FreeLibrary(_modulePtr);
#endif
                        _modulePtr = IntPtr.Zero;
                    }
                }
            }
        }
public static void FreeLibrary ( object user , Enum format ) { if ! WINCE && ! MONO var sp = new SecurityPermission ( SecurityPermissionFlag . UnmanagedCode ) ; sp . Demand ( ) ; endif if ( _modulePtr != IntPtr . Zero ) { if ( format is InArchiveFormat ) { if ( _inArchives != null && _inArchives . ContainsKey ( user ) && _inArchives [ user ] . ContainsKey ( ( InArchiveFormat ) format ) && _inArchives [ user ] [ ( InArchiveFormat ) format ] != null ) { try { Marshal . ReleaseComObject ( _inArchives [ user ] [ ( InArchiveFormat ) format ] ) ; } catch ( InvalidComObjectException ) { } _inArchives [ user ] . Remove ( ( InArchiveFormat ) format ) ; _totalUsers -- ; if ( _inArchives [ user ] . Count == 0 ) { _inArchives . Remove ( user ) ; } } } if COMPRESS if ( format is OutArchiveFormat ) { if ( _outArchives != null && _outArchives . ContainsKey ( user ) && _outArchives [ user ] . ContainsKey ( ( OutArchiveFormat ) format ) && _outArchives [ user ] [ ( OutArchiveFormat ) format ] != null ) { try { Marshal . ReleaseComObject ( _outArchives [ user ] [ ( OutArchiveFormat ) format ] ) ; } catch ( InvalidComObjectException ) { } _outArchives [ user ] . Remove ( ( OutArchiveFormat ) format ) ; _totalUsers -- ; if ( _outArchives [ user ] . Count == 0 ) { _outArchives . Remove ( user ) ; } } } endif if ( ( _inArchives == null || _inArchives . Count == 0 ) if COMPRESS && ( _outArchives == null || _outArchives . Count == 0 ) endif ) { _inArchives = null ; if COMPRESS _outArchives = null ; endif if ( _totalUsers == 0 ) { if ! WINCE && ! MONO NativeMethods . FreeLibrary ( _modulePtr ) ; endif _modulePtr = IntPtr . Zero ; } } } }
Removes user from reference list and frees the 7-zip library if it becomes empty
Removes user from reference list and frees the 7 - zip library if it becomes empty
user
object
Caller of the function
Caller of the function
format
Enum
None