Exemple #1
0
        public MSCabinet(string cabinetFilename)
        {
            LocalFilePath           = cabinetFilename;
            _pCabinetFilenamePinned = Marshal.StringToCoTaskMemAnsi(LocalFilePath);            // needs to be pinned as we use the address in unmanaged code.
            Decompressor            = MSCabDecompressor.CreateInstance();

            // open cabinet:
            _pNativeCabinet = NativeMethods.mspack_invoke_mscab_decompressor_open(Decompressor, _pCabinetFilenamePinned);
            if (_pNativeCabinet == IntPtr.Zero)
            {
                var lasterror = NativeMethods.mspack_invoke_mscab_decompressor_last_error(Decompressor);
                throw new Exception("Failed to open cabinet. Last error:" + lasterror);
            }
            //Marshal.PtrToStructure(_pNativeCabinet, _nativeCabinet);
            _nativeCabinet = (NativeMethods.mscabd_cabinet)Marshal.PtrToStructure(_pNativeCabinet, typeof(NativeMethods.mscabd_cabinet));
        }
Exemple #2
0
        public MSCabinet(string cabinetFilename)
        {
                        #if NET_CORE
            cabinetFilename = $"\\\\?\\{cabinetFilename}";
                        #else
            cabinetFilename = new Path(cabinetFilename).WithWin32LongPathPrefix();
                        #endif

            _cabinetFilename        = cabinetFilename;
            _pCabinetFilenamePinned = Marshal.StringToCoTaskMemAnsi(_cabinetFilename);            // needs to be pinned as we use the address in unmanaged code.
            _pDecompressor          = MSCabDecompressor.CreateInstance();

            // open cabinet:
            _pNativeCabinet = NativeMethods.mspack_invoke_mscab_decompressor_open(_pDecompressor, _pCabinetFilenamePinned);
            if (_pNativeCabinet == IntPtr.Zero)
            {
                var lasterror = NativeMethods.mspack_invoke_mscab_decompressor_last_error(_pDecompressor);
                throw new Exception("Failed to open cabinet. Last error:" + lasterror);
            }
            //Marshal.PtrToStructure(_pNativeCabinet, _nativeCabinet);
            _nativeCabinet = (NativeMethods.mscabd_cabinet)Marshal.PtrToStructure(_pNativeCabinet, typeof(NativeMethods.mscabd_cabinet));
        }