Ejemplo n.º 1
0
        /// <summary>
        /// Appends specified cabinet to this one, forming or extending a cabinet set.
        /// </summary>
        /// <param name="nextCabinet">The cab to append to this one.</param>
        public void Append(MSCabinet nextCabinet)
        {
            var result = NativeMethods.mspack_invoke_mscab_decompressor_append(_pDecompressor, _pNativeCabinet, nextCabinet._pNativeCabinet);

            if (result != NativeMethods.MSPACK_ERR.MSPACK_ERR_OK)
            {
                throw new Exception(string.Format("Error '{0}' appending cab '{1}' to {2}.", result, nextCabinet._cabinetFilename, _cabinetFilename));
            }

            // after a successul append remarshal over the nativeCabinet struct5ure as it now represents the combined state.
            _nativeCabinet             = (NativeMethods.mscabd_cabinet)Marshal.PtrToStructure(_pNativeCabinet, typeof(NativeMethods.mscabd_cabinet));
            nextCabinet._nativeCabinet = (NativeMethods.mscabd_cabinet)Marshal.PtrToStructure(nextCabinet._pNativeCabinet, typeof(NativeMethods.mscabd_cabinet));
        }
Ejemplo n.º 2
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));
        }
Ejemplo n.º 3
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));
        }