SevenZip/LibraryManager.cs
/// <summary>
///   Gets IInArchive interface to extract 7-zip archives.
/// </summary>
/// <param name = "format">Archive format.</param>
/// <param name = "user">Archive format user.</param>
Gets IInArchive interface to extract 7-zip archives.
Gets IInArchive interface to extract 7 - zip archives .
public static IInArchive InArchive(InArchiveFormat format, object user)
        {
#if !WINCE && !MONO
            lock (_libraryFileName)
            {
#endif
                if (_inArchives[user][format] == null)
                {
#if !WINCE && !MONO
                    var sp = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);
                    sp.Demand();
                    if (_modulePtr == IntPtr.Zero)
                    {
                        LoadLibrary(user, format);
                        if (_modulePtr == IntPtr.Zero)
                        {
                            throw new SevenZipLibraryException();
                        }
                    }
                    var createObject = (NativeMethods.CreateObjectDelegate)
                                       Marshal.GetDelegateForFunctionPointer(
                                           NativeMethods.GetProcAddress(_modulePtr, "CreateObject"),
                                           typeof (NativeMethods.CreateObjectDelegate));
                    if (createObject == null)
                    {
                        throw new SevenZipLibraryException();
                    }
#endif
                    object result;
                    Guid interfaceId =
#if !WINCE && !MONO
                        typeof (IInArchive).GUID;
#else
                new Guid(((GuidAttribute)typeof(IInArchive).GetCustomAttributes(typeof(GuidAttribute), false)[0]).Value);
#endif
                    Guid classID = Formats.InFormatGuids[format];
                    try
                    {
#if !WINCE && !MONO
                        createObject(ref classID, ref interfaceId, out result);
#elif !MONO
                    	NativeMethods.CreateCOMObject(ref classID, ref interfaceId, out result);
#else
						result = SevenZip.Mono.Factory.CreateInterface<IInArchive>(user, classID, interfaceId);
#endif
                    }
                    catch (Exception)
                    {
                        throw new SevenZipLibraryException("Your 7-zip library does not support this archive type.");
                    }
                    InitUserInFormat(user, format);
                    _inArchives[user][format] = result as IInArchive;
                }
#if !WINCE && !MONO
            }
#endif
            return _inArchives[user][format];
        }
public static IInArchive InArchive ( InArchiveFormat format , object user ) { if ! WINCE && ! MONO lock ( _libraryFileName ) { endif if ( _inArchives [ user ] [ format ] == null ) { if ! WINCE && ! MONO var sp = new SecurityPermission ( SecurityPermissionFlag . UnmanagedCode ) ; sp . Demand ( ) ; if ( _modulePtr == IntPtr . Zero ) { LoadLibrary ( user , format ) ; if ( _modulePtr == IntPtr . Zero ) { throw new SevenZipLibraryException ( ) ; } } var createObject = ( NativeMethods . CreateObjectDelegate ) Marshal . GetDelegateForFunctionPointer ( NativeMethods . GetProcAddress ( _modulePtr , " " ) , typeof ( NativeMethods . CreateObjectDelegate ) ) ; if ( createObject == null ) { throw new SevenZipLibraryException ( ) ; } endif object result ; Guid interfaceId = if ! WINCE && ! MONO typeof ( IInArchive ) . GUID ; else new Guid ( ( ( GuidAttribute ) typeof ( IInArchive ) . GetCustomAttributes ( typeof ( GuidAttribute ) , false ) [ 0 ] ) . Value ) ; endif Guid classID = Formats . InFormatGuids [ format ] ; try { if ! WINCE && ! MONO createObject ( ref classID , ref interfaceId , out result ) ; elif ! MONO NativeMethods . CreateCOMObject ( ref classID , ref interfaceId , out result ) ; else result = SevenZip . Mono . Factory . CreateInterface < IInArchive > ( user , classID , interfaceId ) ; endif } catch ( Exception ) { throw new SevenZipLibraryException ( " " ) ; } InitUserInFormat ( user , format ) ; _inArchives [ user ] [ format ] = result as IInArchive ; } if ! WINCE && ! MONO } endif return _inArchives [ user ] [ format ] ; }
Gets IInArchive interface to extract 7-zip archives.
Gets IInArchive interface to extract 7 - zip archives .
format
InArchiveFormat
None
user
object
Archive format user.
Archive format user .