예제 #1
0
 public void CreateFciContext(string cabFileName)
 {
     this.error = new NativeHelper.CabError();
     NativeHelper.CompressionInfo cabInfo = new NativeHelper.CompressionInfo(cabFileName);
     this.customData  = new CustomCabData();
     CustomDataHandle = GCHandle.Alloc(this.customData);
     fciContext       = NativeHelper.FCICreate(
         this.error,
         FciFilePlacedMethod,
         FciAllocMemHandler,
         FdiFreeMemHandler,
         FciOpenMethod,
         FciReadMethod,
         FciWriteMethod,
         FciCloseMethod,
         FciSeekMethod,
         FciDlDeleteMethod,
         FciGetTempFileMethod,
         cabInfo,
         (IntPtr)CustomDataHandle);
     if (this.customData.ErrorInfo != null)
     {
         throw this.customData.ErrorInfo;
     }
 }
예제 #2
0
        private static IntPtr GetOpenInfo(
            string fileName,
            ref int date,
            ref int time,
            ref short attributes,
            ref int error,
            IntPtr data)
        {
            CustomCabData userData = (CustomCabData)((GCHandle)data).Target;

            try
            {
                attributes = AttributeFlagsFromFileAttributes(File.GetAttributes(fileName));
                var dateTime = File.GetLastWriteTime(fileName);
                date = ConvertDate(dateTime);
                time = ConvertTime(dateTime);

                var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.None);
                return((IntPtr)GCHandle.Alloc(stream));
            }
            catch (IOException ex)
            {
                userData.ErrorInfo = ex;
                error = 1;
                return(IntPtr.Zero);
            }
        }