コード例 #1
0
ファイル: CabUnpacker.cs プロジェクト: urmas69/Wix3.6Toolset
        private int CabListNotify(NativeMethods.FDI.NOTIFICATIONTYPE notificationType, NativeMethods.FDI.NOTIFICATION notification)
        {
            switch (notificationType)
            {
            case NativeMethods.FDI.NOTIFICATIONTYPE.CABINET_INFO:
            {
                string nextCab = Marshal.PtrToStringAnsi(notification.psz1);
                this.NextCabinetName = (nextCab.Length != 0 ? nextCab : null);
                return(0);         // Continue
            }

            case NativeMethods.FDI.NOTIFICATIONTYPE.PARTIAL_FILE:
            {
                // This notification can occur when examining the contents of a non-first cab file.
                return(0);         // Continue
            }

            case NativeMethods.FDI.NOTIFICATIONTYPE.COPY_FILE:
            {
                //bool execute = (notification.attribs & (ushort) FileAttributes.Device) != 0;  // _A_EXEC

                string name = CabUnpacker.GetFileName(notification);

                if (this.filter == null || this.filter(name))
                {
                    if (this.fileList != null)
                    {
                        FileAttributes attributes = (FileAttributes)notification.attribs &
                                                    (FileAttributes.Archive | FileAttributes.Hidden | FileAttributes.ReadOnly | FileAttributes.System);
                        if (attributes == (FileAttributes)0)
                        {
                            attributes = FileAttributes.Normal;
                        }
                        DateTime lastWriteTime;
                        CompressionEngine.DosDateAndTimeToDateTime(notification.date, notification.time, out lastWriteTime);
                        long length = notification.cb;

                        CabFileInfo fileInfo = new CabFileInfo(
                            name,
                            notification.iFolder,
                            notification.iCabinet,
                            attributes,
                            lastWriteTime,
                            length);
                        this.fileList.Add(fileInfo);
                        this.currentFileNumber   = this.fileList.Count - 1;
                        this.fileBytesProcessed += notification.cb;
                    }
                }

                this.totalFiles++;
                this.totalFileBytes += notification.cb;
                return(0);         // Continue
            }
            }
            return(0);
        }
コード例 #2
0
        private int CabListNotify(NativeMethods.FDI.NOTIFICATIONTYPE notificationType, NativeMethods.FDI.NOTIFICATION notification)
        {
            checked
            {
                switch (notificationType)
                {
                case NativeMethods.FDI.NOTIFICATIONTYPE.CABINET_INFO:
                {
                    string text = Marshal.PtrToStringAnsi(notification.psz1);
                    base.NextCabinetName = ((text.Length != 0) ? text : null);
                    return(0);
                }

                case NativeMethods.FDI.NOTIFICATIONTYPE.PARTIAL_FILE:
                    return(0);

                case NativeMethods.FDI.NOTIFICATIONTYPE.COPY_FILE:
                {
                    string fileName = GetFileName(notification);
                    if ((filter == null || filter(fileName)) && fileList != null)
                    {
                        FileAttributes fileAttributes = unchecked ((FileAttributes)(notification.attribs & 0x27));
                        if (fileAttributes == (FileAttributes)0)
                        {
                            fileAttributes = FileAttributes.Normal;
                        }
                        CompressionEngine.DosDateAndTimeToDateTime(notification.date, notification.time, out var dateTime);
                        long        length = notification.cb;
                        CabFileInfo item   = new CabFileInfo(fileName, notification.iFolder, notification.iCabinet, fileAttributes, dateTime, length);
                        fileList.Add(item);
                        currentFileNumber   = fileList.Count - 1;
                        fileBytesProcessed += notification.cb;
                    }
                    totalFiles++;
                    totalFileBytes += notification.cb;
                    return(0);
                }

                default:
                    return(0);
                }
            }
        }
コード例 #3
0
ファイル: CabTest.cs プロジェクト: Jeremiahf/wix3
        public void CabFileInfoNullParams()
        {
            Exception caughtEx;
            CabInfo cabInfo = new CabInfo("test.cab");
            int txtSize = 10240;
            CompressionTestUtil.GenerateRandomFile("test00.txt", 0, txtSize);
            CompressionTestUtil.GenerateRandomFile("test01.txt", 1, txtSize);
            cabInfo.PackFiles(null, new string[] { "test00.txt", "test01.txt" }, null);
            CabFileInfo cfi = new CabFileInfo(cabInfo, "test01.txt");

            caughtEx = null;
            try
            {
                new CabFileInfo(null, "test00.txt");
            }
            catch (Exception ex) { caughtEx = ex; }
            Assert.IsInstanceOfType(caughtEx, typeof(ArgumentNullException));
            caughtEx = null;
            try
            {
                new CabFileInfo(cabInfo, null);
            }
            catch (Exception ex) { caughtEx = ex; }
            Assert.IsInstanceOfType(caughtEx, typeof(ArgumentNullException));
            caughtEx = null;
            try
            {
                cfi.CopyTo(null);
            }
            catch (Exception ex) { caughtEx = ex; }
            Assert.IsInstanceOfType(caughtEx, typeof(ArgumentNullException));
        }
コード例 #4
0
ファイル: CabTest.cs プロジェクト: Jeremiahf/wix3
        public void CabFileInfoOpenText()
        {
            CabInfo cabInfo = new CabInfo("test.cab");
            int txtSize = 10240;
            CompressionTestUtil.GenerateRandomFile("test00.txt", 0, txtSize);
            CompressionTestUtil.GenerateRandomFile("test01.txt", 1, txtSize);

            string expectedText = File.ReadAllText("test01.txt");
            
            cabInfo.PackFiles(null, new string[] { "test00.txt", "test01.txt" }, null);

            CabFileInfo cfi = new CabFileInfo(cabInfo, "test01.txt");
            using (StreamReader cabFileReader = cfi.OpenText())
            {
                string text = cabFileReader.ReadToEnd();
                Assert.AreEqual(expectedText, text);

                // Check the assumption that the cab can't be deleted while a stream is open.
                Exception caughtEx = null;
                try
                {
                    File.Delete(cabInfo.FullName);
                }
                catch (Exception ex)
                {
                    caughtEx = ex;
                }

                Assert.IsInstanceOfType(caughtEx, typeof(IOException));
            }

            // Ensure all streams are closed after disposing of the StreamReader returned by OpenText.
            File.Delete(cabInfo.FullName);
        }
コード例 #5
0
ファイル: CabTest.cs プロジェクト: Jeremiahf/wix3
        public void CabFileInfoProperties()
        {
            CabInfo cabInfo = new CabInfo("test.cab");
            int txtSize = 10240;
            CompressionTestUtil.GenerateRandomFile("test00.txt", 0, txtSize);
            CompressionTestUtil.GenerateRandomFile("test01.txt", 1, txtSize);
            File.SetAttributes("test01.txt", FileAttributes.ReadOnly | FileAttributes.Archive);
            DateTime testTime = File.GetLastWriteTime("test01.txt");
            cabInfo.PackFiles(null, new string[] { "test00.txt", "test01.txt" }, null);
            File.SetAttributes("test01.txt", FileAttributes.Archive);

            CabFileInfo cfi = new CabFileInfo(cabInfo, "test01.txt");
            Assert.AreEqual(cabInfo.FullName, cfi.CabinetName);
            Assert.AreEqual<int>(0, ((CabFileInfo) cfi).CabinetFolderNumber);
            Assert.AreEqual<string>(Path.Combine(cabInfo.FullName, "test01.txt"), cfi.FullName);
            cfi = new CabFileInfo(cabInfo, "test01.txt");
            Assert.IsTrue(cfi.Exists);
            cfi = new CabFileInfo(cabInfo, "test01.txt");
            Assert.AreEqual<long>(txtSize, cfi.Length);
            cfi = new CabFileInfo(cabInfo, "test00.txt");
            Assert.AreEqual<FileAttributes>(FileAttributes.Archive, cfi.Attributes);
            cfi = new CabFileInfo(cabInfo, "test01.txt");
            Assert.AreEqual<FileAttributes>(FileAttributes.ReadOnly | FileAttributes.Archive, cfi.Attributes);
            cfi = new CabFileInfo(cabInfo, "test01.txt");
            Assert.IsTrue((testTime - cfi.LastWriteTime).Duration() < new TimeSpan(0, 0, 5));
            Assert.AreEqual<string>(Path.Combine(cabInfo.FullName, "test01.txt"), cfi.ToString());
            cfi.CopyTo("testcopy.txt");
            Assert.IsTrue(File.Exists("testCopy.txt"));
            Assert.AreEqual<long>(cfi.Length, new FileInfo("testCopy.txt").Length);

            Exception caughtEx = null;
            try
            {
                cfi.CopyTo("testcopy.txt", false);
            }
            catch (Exception ex) { caughtEx = ex; }
            Assert.IsInstanceOfType(caughtEx, typeof(IOException));
        }
コード例 #6
0
ファイル: CabDiffEngine.cs プロジェクト: Jeremiahf/wix3
		public bool GetDiff(string diffInput1, string diffInput2, string[] options, TextWriter diffOutput, string linePrefix, IDiffEngineFactory diffFactory)
		{
			bool difference = false;
			IComparer caseInsComp = CaseInsensitiveComparer.Default;

			// TODO: Make this faster by extracting the whole cab at once.
			// TODO: Optimize for the match case by first comparing the whole cab files.

            CabInfo cab1 = new CabInfo(diffInput1);
            CabInfo cab2 = new CabInfo(diffInput2);
			IList<CabFileInfo> cabFilesList1 = cab1.GetFiles();
            IList<CabFileInfo> cabFilesList2 = cab2.GetFiles();
            CabFileInfo[] cabFiles1 = new CabFileInfo[cabFilesList1.Count];
            CabFileInfo[] cabFiles2 = new CabFileInfo[cabFilesList2.Count];
            cabFilesList1.CopyTo(cabFiles1, 0);
            cabFilesList2.CopyTo(cabFiles2, 0);
			string[] files1 = new string[cabFiles1.Length];
			string[] files2 = new string[cabFiles2.Length];
			for(int i1 = 0; i1 < cabFiles1.Length; i1++) files1[i1] = cabFiles1[i1].Name;
			for(int i2 = 0; i2 < cabFiles2.Length; i2++) files2[i2] = cabFiles2[i2].Name;
			Array.Sort(files1, cabFiles1, caseInsComp);
			Array.Sort(files2, cabFiles2, caseInsComp);


			for(int i1 = 0, i2 = 0; i1 < files1.Length || i2 < files2.Length; )
			{
				int comp;
				if(i1 == files1.Length)
				{
					comp = 1;
				}
				else if(i2 == files2.Length)
				{
					comp = -1;
				}
				else
				{
					comp = caseInsComp.Compare(files1[i1], files2[i2]);
				}
				if(comp < 0)
				{
					diffOutput.WriteLine("{0}< {1}", linePrefix, files1[i1]);
					i1++;
					difference = true;
				}
				else if(comp > 0)
				{
					diffOutput.WriteLine("{0}> {1}", linePrefix, files2[i2]);
					i2++;
					difference = true;
				}
				else
				{
					string tempFile1 = Path.GetTempFileName();
					string tempFile2 = Path.GetTempFileName();
					cabFiles1[i1].CopyTo(tempFile1, true);
					cabFiles2[i2].CopyTo(tempFile2, true);
					IDiffEngine diffEngine = diffFactory.GetDiffEngine(tempFile1, tempFile2, options);
					StringWriter sw = new StringWriter();
					if(diffEngine.GetDiff(tempFile1, tempFile2, options, sw, linePrefix + "    ", diffFactory))
					{
						diffOutput.WriteLine("{0}{1}", linePrefix, files1[i1]);
						diffOutput.Write(sw.ToString());
						difference = true;
					}

					File.SetAttributes(tempFile1, File.GetAttributes(tempFile1) & ~FileAttributes.ReadOnly);
					File.SetAttributes(tempFile2, File.GetAttributes(tempFile2) & ~FileAttributes.ReadOnly);
					try
					{
						File.Delete(tempFile1);
						File.Delete(tempFile2);
					}
					catch(IOException)
					{
#if DEBUG
						Console.WriteLine("Could not delete temporary files {0} and {1}", tempFile1, tempFile2);
#endif
					}
					i1++;
					i2++;
				}
			}

			return difference;
		}
コード例 #7
0
        private int CabListNotify(NativeMethods.FDI.NOTIFICATIONTYPE notificationType, NativeMethods.FDI.NOTIFICATION notification)
        {
            switch (notificationType)
            {
                case NativeMethods.FDI.NOTIFICATIONTYPE.CABINET_INFO:
                    {
                        string nextCab = Marshal.PtrToStringAnsi(notification.psz1);
                        this.NextCabinetName = (nextCab.Length != 0 ? nextCab : null);
                        return 0;  // Continue
                    }
                case NativeMethods.FDI.NOTIFICATIONTYPE.PARTIAL_FILE:
                    {
                        // This notification can occur when examining the contents of a non-first cab file.
                        return 0;  // Continue
                    }
                case NativeMethods.FDI.NOTIFICATIONTYPE.COPY_FILE:
                    {
                        //bool execute = (notification.attribs & (ushort) FileAttributes.Device) != 0;  // _A_EXEC

                        string name = CabUnpacker.GetFileName(notification);

                        if (this.filter == null || this.filter(name))
                        {
                            if (this.fileList != null)
                            {
                                FileAttributes attributes = (FileAttributes) notification.attribs &
                                    (FileAttributes.Archive | FileAttributes.Hidden | FileAttributes.ReadOnly | FileAttributes.System);
                                if (attributes == (FileAttributes) 0)
                                {
                                    attributes = FileAttributes.Normal;
                                }
                                DateTime lastWriteTime;
                                CompressionEngine.DosDateAndTimeToDateTime(notification.date, notification.time, out lastWriteTime);
                                long length = notification.cb;

                                CabFileInfo fileInfo = new CabFileInfo(
                                    name,
                                    notification.iFolder,
                                    notification.iCabinet,
                                    attributes,
                                    lastWriteTime,
                                    length);
                                this.fileList.Add(fileInfo);
                                this.currentFileNumber = this.fileList.Count - 1;
                                this.fileBytesProcessed += notification.cb;
                            }
                        }

                        this.totalFiles++;
                        this.totalFileBytes += notification.cb;
                        return 0;  // Continue
                    }
            }
            return 0;
        }
コード例 #8
0
 public static InfoPathManifest Create(CabFileInfo cabFileInfo)
 {
     InfoPathManifest manifest = new InfoPathManifest();
     manifest.CabFileInfo = cabFileInfo;
     return manifest;
 }