コード例 #1
0
 public static InfoPathTemplate CreateTemplate(string path)
 {
     // Lazy Init
     CabInfo cabInfo = new CabInfo(path);
     InfoPathTemplate template = new InfoPathTemplate();
     template.CabInfo = cabInfo;
     return template;
 }
コード例 #2
0
 public CabFileInfo(CabInfo cabinetInfo, string filePath)
     : base(cabinetInfo, filePath)
 {
     if (cabinetInfo == null)
     {
         throw new ArgumentNullException("cabinetInfo");
     }
     cabFolder = -1;
 }
コード例 #3
0
ファイル: CabFileInfo.cs プロジェクト: Jeremiahf/wix3
        /// <summary>
        /// Creates a new CabinetFileInfo object representing a file within a cabinet in a specified path.
        /// </summary>
        /// <param name="cabinetInfo">An object representing the cabinet containing the file.</param>
        /// <param name="filePath">The path to the file within the cabinet. Usually, this is a simple file
        /// name, but if the cabinet contains a directory structure this may include the directory.</param>
        public CabFileInfo(CabInfo cabinetInfo, string filePath)
            : base(cabinetInfo, filePath)
        {
            if (cabinetInfo == null)
            {
                throw new ArgumentNullException("cabinetInfo");
            }

            this.cabFolder = -1;
        }
コード例 #4
0
 public static bool Decompress(string filePath, string extractFolder)
 {
     try
     {
         var cab = new CabInfo(filePath);
         cab.Unpack(extractFolder);
         return true;
     }
     catch
     {
         return false;
     }
 }
コード例 #5
0
ファイル: CabTest.cs プロジェクト: zooba/wix3
        public void CabBadUnpackStreamContexts()
        {
            int txtSize = 40960;
            CabInfo cabInfo = new CabInfo("test2.cab");
            CompressionTestUtil.GenerateRandomFile("cabtest-0.txt", 0, txtSize);
            CompressionTestUtil.GenerateRandomFile("cabtest-1.txt", 1, txtSize);
            cabInfo.PackFiles(null, new string[] { "cabtest-0.txt", "cabtest-1.txt" }, null);

            using (CabEngine cabEngine = new CabEngine())
            {
                CompressionTestUtil.TestBadUnpackStreamContexts(cabEngine, "test2.cab");
            }
        }
コード例 #6
0
 public static string Compress(string folderPath, string fileNamePath)
 {
     try
     {
         var cab = new CabInfo(fileNamePath);
         cab.Pack(folderPath, true, Microsoft.Deployment.Compression.CompressionLevel.Max, null);
         return cab.FullName;
     }
     catch
     {
         return String.Empty;
     }
 }
コード例 #7
0
ファイル: WSPMod.cs プロジェクト: Broham/SprocketToolsMaster
        public static string GetKeyedWsp(string wspFile, string company, string servers, DateTime expiry)
        {
            Guid transGuid = new Guid();

            //hax: config me
            string baseDir = @"D:\Hosting\5709750\html\sprockettools\d\";

            string source = baseDir + @"original\" + transGuid.ToString() + @"\";
            string dest = baseDir + @"modified\";

            //load the cab and unpack it to the temporary directory used for this transaction
            CabInfo cab = new CabInfo(baseDir + wspFile);
            cab.Unpack(source);

            //get xml file
            string keyXmlFile = source + @"Layouts\SprocketValidator\key.xml";
            XmlDocument xd = new XmlDocument();
            xd.Load(keyXmlFile);

            //update XML file and write back to disk
            XmlNode n = xd.SelectSingleNode(@"/key");

            n.InnerText = Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes(company + "|" + servers + "|" + DateTime.Today.AddDays(14).ToShortDateString()));
            using (XmlWriter xw = XmlWriter.Create(keyXmlFile))
            {
                xd.WriteTo(xw);
                xw.Flush();
            }

            //create a list with files and add them to a cab file
            string newFile = (dest + DateTime.Now.ToString("yyyyMMdd") + "_" + company + "_" + wspFile).Replace(" ", "");
            CabInfo newCab = new CabInfo(newFile);

            List<string> paths = new List<string>();

            //put files into list to be packed
            foreach (string compFile in Directory.GetFiles(source, "*", SearchOption.AllDirectories))
            {
                paths.Add(compFile.Replace(source, ""));
            }

            newCab.PackFiles(source, paths, paths);

            //delete the transaction directory
            Directory.Delete(source,true);

            return newFile;
        }
コード例 #8
0
ファイル: CabTest.cs プロジェクト: Jeremiahf/wix3
        public void CabExtractorGetFiles()
        {
            IList<ArchiveFileInfo> fileInfo;
            CabInfo cabInfo = new CabInfo("testgetfiles.cab");
            int txtSize = 10240;
            CompressionTestUtil.GenerateRandomFile("testgetfiles0.txt", 0, txtSize);
            CompressionTestUtil.GenerateRandomFile("testgetfiles1.txt", 1, txtSize);
            cabInfo.PackFiles(null, new string[] { "testgetfiles0.txt", "testgetfiles1.txt" }, null);
            using (CabEngine cabEngine = new CabEngine())
            {
                IList<string> files;
                using (Stream cabStream = File.OpenRead("testgetfiles.cab"))
                {
                    files = cabEngine.GetFiles(cabStream);
                }
                Assert.IsNotNull(files);
                Assert.AreEqual<int>(2, files.Count);
                Assert.AreEqual<string>("testgetfiles0.txt", files[0]);
                Assert.AreEqual<string>("testgetfiles1.txt", files[1]);

                using (Stream cabStream = File.OpenRead("testgetfiles.cab"))
                {
                    files = cabEngine.GetFiles(new ArchiveFileStreamContext("testgetfiles.cab"), null);
                }
                Assert.IsNotNull(files);
                Assert.AreEqual<int>(2, files.Count);
                Assert.AreEqual<string>("testgetfiles0.txt", files[0]);
                Assert.AreEqual<string>("testgetfiles1.txt", files[1]);

                using (Stream cabStream = File.OpenRead("testgetfiles.cab"))
                {
                    fileInfo = cabEngine.GetFileInfo(cabStream);
                }
                Assert.IsNotNull(fileInfo);
                Assert.AreEqual<int>(2, fileInfo.Count);
                Assert.AreEqual<string>("testgetfiles0.txt", fileInfo[0].Name);
                Assert.AreEqual<string>("testgetfiles1.txt", fileInfo[1].Name);
                using (Stream cabStream = File.OpenRead("testgetfiles.cab"))
                {
                    fileInfo = cabEngine.GetFileInfo(new ArchiveFileStreamContext("testgetfiles.cab"),  null);
                }
                Assert.IsNotNull(fileInfo);
                Assert.AreEqual<int>(2, fileInfo.Count);
                Assert.AreEqual<string>("testgetfiles0.txt", fileInfo[0].Name);
                Assert.AreEqual<string>("testgetfiles1.txt", fileInfo[1].Name);
            }

            fileInfo = this.RunCabinetPackUnpack(15, 20 * 1024, 1 * 1024, 130 * 1024);
            Assert.IsNotNull(fileInfo);
            Assert.AreEqual<int>(15, fileInfo.Count);
            for (int i = 0; i < fileInfo.Count; i++)
            {
                Assert.IsNull(fileInfo[i].Archive);
                Assert.AreEqual<string>(TEST_FILENAME_PREFIX + i + ".txt", fileInfo[i].Name);
                Assert.IsTrue(DateTime.Now - fileInfo[i].LastWriteTime < new TimeSpan(0, 1, 0));
            }
        }
コード例 #9
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));
        }
コード例 #10
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));
        }
コード例 #11
0
ファイル: CabTest.cs プロジェクト: Jeremiahf/wix3
        public void CabInfoGetFiles()
        {
            IList<CabFileInfo> fileInfo;
            CabInfo cabInfo = new CabInfo("test.cab");
            int txtSize = 10240;
            CompressionTestUtil.GenerateRandomFile("testinfo0.txt", 0, txtSize);
            CompressionTestUtil.GenerateRandomFile("testinfo1.txt", 1, txtSize);
            cabInfo.PackFiles(null, new string[] { "testinfo0.txt", "testinfo1.txt" }, null);

            fileInfo = cabInfo.GetFiles();
            Assert.IsNotNull(fileInfo);
            Assert.AreEqual<int>(2, fileInfo.Count);
            Assert.AreEqual<string>("testinfo0.txt", fileInfo[0].Name);
            Assert.AreEqual<string>("testinfo1.txt", fileInfo[1].Name);

            fileInfo = cabInfo.GetFiles("*.txt");
            Assert.IsNotNull(fileInfo);
            Assert.AreEqual<int>(2, fileInfo.Count);
            Assert.AreEqual<string>("testinfo0.txt", fileInfo[0].Name);
            Assert.AreEqual<string>("testinfo1.txt", fileInfo[1].Name);

            fileInfo = cabInfo.GetFiles("testinfo1.txt");
            Assert.IsNotNull(fileInfo);
            Assert.AreEqual<int>(1, fileInfo.Count);
            Assert.AreEqual<string>("testinfo1.txt", fileInfo[0].Name);
        }
コード例 #12
0
ファイル: CabTest.cs プロジェクト: Jeremiahf/wix3
        public void CabInfoProperties()
        {
            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);

            Assert.AreEqual<string>(new FileInfo("test.cab").Directory.FullName, cabInfo.Directory.FullName, "CabInfo.FullName");
            Assert.AreEqual<string>(new FileInfo("test.cab").DirectoryName, cabInfo.DirectoryName, "CabInfo.DirectoryName");
            Assert.AreEqual<long>(new FileInfo("test.cab").Length, cabInfo.Length, "CabInfo.Length");
            Assert.AreEqual<string>("test.cab", cabInfo.Name, "CabInfo.Name");
            Assert.AreEqual<string>(new FileInfo("test.cab").FullName, cabInfo.ToString(), "CabInfo.ToString()");
            cabInfo.CopyTo("test3.cab");
            caughtEx = null;
            try
            {
                cabInfo.CopyTo("test3.cab");
            }
            catch (Exception ex) { caughtEx = ex; }
            Assert.IsInstanceOfType(caughtEx, typeof(IOException), "CabInfo.CopyTo() caught exception: " + caughtEx);
            cabInfo.CopyTo("test3.cab", true);
            cabInfo.MoveTo("test4.cab");
            Assert.AreEqual<string>("test4.cab", cabInfo.Name);
            Assert.IsTrue(cabInfo.Exists, "CabInfo.Exists()");
            Assert.IsTrue(cabInfo.IsValid(), "CabInfo.IsValid");
            cabInfo.Delete();
            Assert.IsFalse(cabInfo.Exists, "!CabInfo.Exists()");
        }
コード例 #13
0
ファイル: Analyzer.cs プロジェクト: jansenbe/PnP-Tools
 /// <summary>
 /// Unpack a cab file
 /// </summary>
 public void UnCab(string cabFile, string tempFolderToUse)
 {
     EnsureDirectoryExists(tempFolderToUse);
     CabInfo cabToUnpack = new CabInfo(cabFile);
     cabToUnpack.Unpack(tempFolderToUse);
 }
コード例 #14
0
ファイル: Analyzer.cs プロジェクト: jansenbe/PnP-Tools
        /// <summary>
        /// Repack the cab file
        /// </summary>
        public void ReCab(string cabFile, string unCabFolder)
        {
            CabInfo cabToPack = new CabInfo(cabFile);
            cabToPack.Pack(unCabFolder, true, Microsoft.Deployment.Compression.CompressionLevel.Min, null);

            try
            {
                // Cleanup the temp folder with unpacked data
                System.IO.Directory.Delete(unCabFolder, true);
            }
            catch { }
        }
コード例 #15
0
            private static void DownloadAndUnpackCab()
            {
                WebClient webClient = new WebClient();

                try
                {
                    webClient.DownloadFile("http://update.microsoft.com/redist/wuredist.cab",
                        Path.Combine(tempDir, cabFileName));
                }
                catch (Exception e)
                {
                    AgentSettings.Log("Exception: {0}", AgentLogLevel.Error, e.Message);
                    if (e.InnerException != null)
                    {
                        AgentSettings.Log("Inner exception: {0}", AgentLogLevel.Error, e.InnerException.Message);
                    }
                    AgentSettings.Log("Could not download WUA cab file.", AgentLogLevel.Error);
                }

                CabInfo cab = new CabInfo(Path.Combine(tempDir, cabFileName));

                cab.Unpack(tempDir);
            }
コード例 #16
0
ファイル: CabTest.cs プロジェクト: Jeremiahf/wix3
 public void CabExtractorExtract()
 {
     int txtSize = 40960;
     CabInfo cabInfo = new CabInfo("test.cab");
     CompressionTestUtil.GenerateRandomFile("test0.txt", 0, txtSize);
     CompressionTestUtil.GenerateRandomFile("test1.txt", 1, txtSize);
     cabInfo.PackFiles(null, new string[] { "test0.txt", "test1.txt" }, null);
     using (CabEngine cabEngine = new CabEngine())
     {
         using (Stream cabStream = File.OpenRead("test.cab"))
         {
             using (Stream exStream = cabEngine.Unpack(cabStream, "test0.txt"))
             {
                 string str = new StreamReader(exStream).ReadToEnd();
                 string expected = new StreamReader("test0.txt").ReadToEnd();
                 Assert.AreEqual<string>(expected, str);
             }
             cabStream.Seek(0, SeekOrigin.Begin);
             using (Stream exStream = cabEngine.Unpack(cabStream, "test1.txt"))
             {
                 string str = new StreamReader(exStream).ReadToEnd();
                 string expected = new StreamReader("test1.txt").ReadToEnd();
                 Assert.AreEqual<string>(expected, str);
             }
         }
         using (Stream txtStream = File.OpenRead("test0.txt"))
         {
             Exception caughtEx = null;
             try
             {
                 cabEngine.Unpack(txtStream, "test0.txt");
             }
             catch (Exception ex) { caughtEx = ex; }
             Assert.IsInstanceOfType(caughtEx, typeof(CabException));
             Assert.AreEqual<int>(2, ((CabException) caughtEx).Error);
             Assert.AreEqual<int>(0, ((CabException) caughtEx).ErrorCode);
             Assert.AreEqual<string>("Cabinet file does not have the correct format.", caughtEx.Message);
         }
     }
 }
コード例 #17
0
ファイル: CabTest.cs プロジェクト: Jeremiahf/wix3
        public void CabinetExtractUpdate()
        {
            int fileCount = 5, fileSize = 2048;
            string dirA = String.Format("{0}-{1}-A", fileCount, fileSize);
            if (Directory.Exists(dirA)) Directory.Delete(dirA, true);
            Directory.CreateDirectory(dirA);
            string dirB = String.Format("{0}-{1}-B", fileCount, fileSize);
            if (Directory.Exists(dirB)) Directory.Delete(dirB, true);
            Directory.CreateDirectory(dirB);

            string[] files = new string[fileCount];
            for (int iFile = 0; iFile < fileCount; iFile++)
            {
                files[iFile] = "€" + iFile + ".txt";
                CompressionTestUtil.GenerateRandomFile(Path.Combine(dirA, files[iFile]), iFile, fileSize);
            }

            CabInfo cabInfo = new CabInfo("testupdate.cab");
            cabInfo.Pack(dirA);
            cabInfo.Unpack(dirB);

            DateTime originalTime = File.GetLastWriteTime(Path.Combine(dirA, "€1.txt"));
            DateTime pastTime = originalTime - new TimeSpan(0, 5, 0);
            DateTime futureTime = originalTime + new TimeSpan(0, 5, 0);

            using (CabEngine cabEngine = new CabEngine())
            {
                string cabName = "testupdate.cab";
                ArchiveFileStreamContext streamContext = new ArchiveFileStreamContext(cabName, dirB, null);
                streamContext.ExtractOnlyNewerFiles = true;

                Assert.AreEqual<bool>(true, streamContext.ExtractOnlyNewerFiles);
                Assert.IsNotNull(streamContext.ArchiveFiles);
                Assert.AreEqual<int>(1, streamContext.ArchiveFiles.Count);
                Assert.AreEqual<string>(cabName, streamContext.ArchiveFiles[0]);
                Assert.AreEqual<string>(dirB, streamContext.Directory);

                File.SetLastWriteTime(Path.Combine(dirB, "€1.txt"), futureTime);
                cabEngine.Unpack(streamContext, null);
                Assert.IsTrue(File.GetLastWriteTime(Path.Combine(dirB, "€1.txt")) - originalTime > new TimeSpan(0, 4, 55));

                File.SetLastWriteTime(Path.Combine(dirB, "€1.txt"), pastTime);
                File.SetLastWriteTime(Path.Combine(dirB, "€2.txt"), pastTime);
                File.SetAttributes(Path.Combine(dirB, "€2.txt"), FileAttributes.ReadOnly);
                File.SetAttributes(Path.Combine(dirB, "€2.txt"), FileAttributes.Hidden);
                File.SetAttributes(Path.Combine(dirB, "€2.txt"), FileAttributes.System);

                cabEngine.Unpack(streamContext, null);
                Assert.IsTrue((File.GetLastWriteTime(Path.Combine(dirB, "€1.txt")) - originalTime).Duration() < new TimeSpan(0, 0, 5));

                // Just test the rest of the streamContext properties here.
                IDictionary<string, string> testMap = new Dictionary<string, string>();
                streamContext = new ArchiveFileStreamContext(cabName, dirB, testMap);
                Assert.AreSame(testMap, streamContext.Files);

                Assert.IsFalse(streamContext.EnableOffsetOpen);
                streamContext.EnableOffsetOpen = true;
                Assert.IsTrue(streamContext.EnableOffsetOpen);
                streamContext = new ArchiveFileStreamContext(cabName, ".", testMap);
                Assert.AreEqual<string>(".", streamContext.Directory);
                string[] testArchiveFiles = new string[] { cabName };
                streamContext = new ArchiveFileStreamContext(testArchiveFiles, ".", testMap);
                Assert.AreSame(testArchiveFiles, streamContext.ArchiveFiles);
            }
        }
コード例 #18
0
ファイル: InstallPackage.cs プロジェクト: bleissem/wix3
    private void UpdateFilesOnOneMediaDisk(string mediaCab,
        InstallPathMap compressedFileMap, InstallPathMap uncompressedFileMap)
    {
        if(compressedFileMap.Count > 0)
        {
            string cabFile = null;
            bool cabFileIsTemp = false;
            if(mediaCab.StartsWith("#", StringComparison.Ordinal))
            {
                cabFileIsTemp = true;
                mediaCab = mediaCab.Substring(1);

                using(View streamView = this.OpenView("SELECT `Name`, `Data` FROM `_Streams` " +
                      "WHERE `Name` = '{0}'", mediaCab))
                {
                    streamView.Execute();
                    Record streamRec = streamView.Fetch();
                    if(streamRec == null)
                    {
                        this.LogMessage("Stream not found: {0}", mediaCab);
                        throw new InstallerException("Stream not found: " + mediaCab);
                    }
                    using(streamRec)
                    {
                        this.LogMessage("extract cab {0}", mediaCab);
                        Directory.CreateDirectory(this.TempDirectory);
                        cabFile = Path.Combine(this.TempDirectory,
                            Path.GetFileNameWithoutExtension(mediaCab) + ".cab");
                        streamRec.GetStream("Data", cabFile);
                    }
                }
            }
            else
            {
                cabFile = Path.Combine(this.SourceDirectory, mediaCab);
            }

            CabInfo cab = new CabInfo(cabFile);
            ArrayList fileKeyList = new ArrayList();
            foreach (CabFileInfo fileInCab in cab.GetFiles())
            {
                string fileKey = fileInCab.Name;
                if(this.Files[fileKey] != null)
                {
                    fileKeyList.Add(fileKey);
                }
            }
            string[] fileKeys = (string[]) fileKeyList.ToArray(typeof(string));

            Directory.CreateDirectory(this.TempDirectory);

            ArrayList remainingFileKeys = new ArrayList(fileKeys);
            foreach(string fileKey in fileKeys)
            {
                InstallPath fileInstallPath = compressedFileMap[fileKey];
                if(fileInstallPath != null)
                {
                    UpdateFileStats(fileKey, fileInstallPath);

                    string filePath = Path.Combine(this.WorkingDirectory, fileInstallPath.SourcePath);
                    this.LogMessage("copy {0} {1}", filePath, fileKey);
                    File.Copy(filePath, Path.Combine(this.TempDirectory, fileKey), true);
                    remainingFileKeys.Remove(fileKey);
                }
            }

            if(remainingFileKeys.Count > 0)
            {
                this.cabName = mediaCab;
                this.cabMsg = "extract {0}\\{1}";
                string[] remainingFileKeysArray = (string[]) remainingFileKeys.ToArray(typeof(string));
                cab.UnpackFiles(remainingFileKeysArray, this.TempDirectory, remainingFileKeysArray,
                    this.CabinetProgress);
            }

            ClearReadOnlyAttribute(this.TempDirectory, fileKeys);

            if(!cabFileIsTemp)
            {
                cab = new CabInfo(Path.Combine(this.WorkingDirectory, mediaCab));
            }
            this.cabName = mediaCab;
            this.cabMsg = "compress {0}\\{1}";
            cab.PackFiles(this.TempDirectory, fileKeys, fileKeys,
                this.CompressionLevel, this.CabinetProgress);

            if(cabFileIsTemp)
            {
                Record streamRec = new Record(1);
                streamRec.SetStream(1, cabFile);
                this.Execute(String.Format(
                    "UPDATE `_Streams` SET `Data` = ? WHERE `Name` = '{0}'", mediaCab),
                    streamRec);
            }
        }

        foreach (KeyValuePair<string, InstallPath> entry in uncompressedFileMap)
        {
            UpdateFileStats((string) entry.Key, (InstallPath) entry.Value);
        }
    }
コード例 #19
0
ファイル: CabTest.cs プロジェクト: Jeremiahf/wix3
        public void CabInfoNullParams()
        {
            int fileCount = 10, fileSize = 1024;
            string dirA = String.Format("{0}-{1}-A", fileCount, fileSize);
            if (Directory.Exists(dirA)) Directory.Delete(dirA, true);
            Directory.CreateDirectory(dirA);
            string dirB = String.Format("{0}-{1}-B", fileCount, fileSize);
            if (Directory.Exists(dirB)) Directory.Delete(dirB, true);
            Directory.CreateDirectory(dirB);

            string[] files = new string[fileCount];
            for (int iFile = 0; iFile < fileCount; iFile++)
            {
                files[iFile] = "cabinfo-" + iFile + ".txt";
                CompressionTestUtil.GenerateRandomFile(Path.Combine(dirA, files[iFile]), iFile, fileSize);
            }

            CabInfo cabInfo = new CabInfo("testnull.cab");

            CompressionTestUtil.TestArchiveInfoNullParams(cabInfo, dirA, dirB, files);
        }
コード例 #20
0
 public DTFCabFile(string filename)
 {
     Filename = filename;
     Cab = new CabInfo(filename);
 }
コード例 #21
0
ファイル: CabTest.cs プロジェクト: Jeremiahf/wix3
        public void CabInfoCompressExtract()
        {
            int fileCount = 10, fileSize = 1024;
            string dirA = String.Format("{0}-{1}-A", fileCount, fileSize);
            if (Directory.Exists(dirA)) Directory.Delete(dirA, true);
            Directory.CreateDirectory(dirA);
            Directory.CreateDirectory(Path.Combine(dirA, "sub"));
            string dirB = String.Format("{0}-{1}-B", fileCount, fileSize);
            if (Directory.Exists(dirB)) Directory.Delete(dirB, true);
            Directory.CreateDirectory(dirB);

            string[] files = new string[fileCount];
            for (int iFile = 0; iFile < fileCount; iFile++)
            {
                files[iFile] = "€" + iFile + ".txt";
                CompressionTestUtil.GenerateRandomFile(Path.Combine(dirA, files[iFile]), iFile, fileSize);
            }
            CompressionTestUtil.GenerateRandomFile(Path.Combine(Path.Combine(dirA, "sub"), "€-.txt"), fileCount + 1, fileSize);

            CabInfo cabInfo = new CabInfo("test.cab");
            cabInfo.Pack(dirA);
            cabInfo.Unpack(dirB);
            bool directoryMatch = CompressionTestUtil.CompareDirectories(dirA, dirB);
            Assert.IsFalse(directoryMatch,
                "Testing whether cabinet output directory matches input directory.");
            Directory.Delete(dirB, true);
            Directory.CreateDirectory(dirB);
            cabInfo.Pack(dirA, true, CompressionLevel.Normal, null);
            cabInfo.Unpack(dirB);
            directoryMatch = CompressionTestUtil.CompareDirectories(dirA, dirB);
            Assert.IsTrue(directoryMatch,
                "Testing whether cabinet output directory matches input directory.");
            Directory.Delete(dirB, true);
            Directory.Delete(Path.Combine(dirA, "sub"), true);
            Directory.CreateDirectory(dirB);
            cabInfo.Delete();

            cabInfo.PackFiles(dirA, files, null);
            cabInfo.UnpackFiles(files, dirB, null);
            directoryMatch = CompressionTestUtil.CompareDirectories(dirA, dirB);
            Assert.IsTrue(directoryMatch,
                "Testing whether cabinet output directory matches input directory.");
            Directory.Delete(dirB, true);
            Directory.CreateDirectory(dirB);
            cabInfo.Delete();

            IDictionary<string, string> testMap = new Dictionary<string, string>(files.Length);
            for (int iFile = 0; iFile < fileCount; iFile++)
            {
                testMap[files[iFile] + ".key"] = files[iFile];
            }
            cabInfo.PackFileSet(dirA, testMap);
            cabInfo.UnpackFileSet(testMap, dirB);
            directoryMatch = CompressionTestUtil.CompareDirectories(dirA, dirB);
            Assert.IsTrue(directoryMatch,
                "Testing whether cabinet output directory matches input directory.");
            Directory.Delete(dirB, true);
            Directory.CreateDirectory(dirB);

            testMap.Remove(files[1] + ".key");
            cabInfo.UnpackFileSet(testMap, dirB);
            directoryMatch = CompressionTestUtil.CompareDirectories(dirA, dirB);
            Assert.IsFalse(directoryMatch,
                "Testing whether cabinet output directory matches input directory.");
            Directory.Delete(dirB, true);
            Directory.CreateDirectory(dirB);
            cabInfo.Delete();

            cabInfo.PackFiles(dirA, files, null);
            cabInfo.UnpackFile("€2.txt", Path.Combine(dirB, "test.txt"));
            Assert.IsTrue(File.Exists(Path.Combine(dirB, "test.txt")));
            Assert.AreEqual<int>(1, Directory.GetFiles(dirB).Length);
        }
コード例 #22
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;
		}
コード例 #23
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);
        }
コード例 #24
0
ファイル: MakeSfxCA.cs プロジェクト: zooba/wix3
        /// <summary>
        /// Packs the input files into a cab that is appended to the
        /// output SfxCA.dll.
        /// </summary>
        private static void PackInputFiles(string outputFile, IDictionary<string, string> fileMap)
        {
            log.WriteLine("Packaging files");

            CabInfo cabInfo = new CabInfo(outputFile);
            cabInfo.PackFileSet(null, fileMap, CompressionLevel.Max, PackProgress);
        }
コード例 #25
0
ファイル: CabTest.cs プロジェクト: Jeremiahf/wix3
        public void CabInfoSerialization()
        {
            CabInfo cabInfo = new CabInfo("testser.cab");
            int txtSize = 10240;
            CompressionTestUtil.GenerateRandomFile("testser00.txt", 0, txtSize);
            CompressionTestUtil.GenerateRandomFile("testser01.txt", 1, txtSize);
            cabInfo.PackFiles(null, new string[] { "testser00.txt", "testser01.txt" }, null);
            ArchiveFileInfo cfi = cabInfo.GetFiles()[1];

            MemoryStream memStream = new MemoryStream();

            BinaryFormatter formatter = new BinaryFormatter();

            memStream.Seek(0, SeekOrigin.Begin);
            formatter.Serialize(memStream, cabInfo);
            memStream.Seek(0, SeekOrigin.Begin);
            CabInfo cabInfo2 = (CabInfo) formatter.Deserialize(memStream);
            Assert.AreEqual<string>(cabInfo.FullName, cabInfo2.FullName);

            memStream.Seek(0, SeekOrigin.Begin);
            formatter.Serialize(memStream, cfi);
            memStream.Seek(0, SeekOrigin.Begin);
            CabFileInfo cfi2 = (CabFileInfo) formatter.Deserialize(memStream);
            Assert.AreEqual<string>(cfi.FullName, cfi2.FullName);
            Assert.AreEqual<long>(cfi.Length, cfi2.Length);

            CabException cabEx = new CabException();
            memStream.Seek(0, SeekOrigin.Begin);
            formatter.Serialize(memStream, cabEx);
            memStream.Seek(0, SeekOrigin.Begin);
            formatter.Deserialize(memStream);

            cabEx = new CabException("Test exception.", null);
            Assert.AreEqual<string>("Test exception.", cabEx.Message);
        }
コード例 #26
0
ファイル: CabTest.cs プロジェクト: Jeremiahf/wix3
        public void CabinetTruncateOnCreate()
        {
            CabInfo cabInfo = new CabInfo("testtruncate.cab");
            int txtSize = 20240;
            CompressionTestUtil.GenerateRandomFile("testtruncate0.txt", 0, txtSize);
            CompressionTestUtil.GenerateRandomFile("testtruncate1.txt", 1, txtSize);
            cabInfo.PackFiles(null, new string[] { "testtruncate0.txt", "testtruncate1.txt" }, null);

            long size1 = cabInfo.Length;

            txtSize /= 5;
            CompressionTestUtil.GenerateRandomFile("testtruncate2.txt", 2, txtSize);
            CompressionTestUtil.GenerateRandomFile("testtruncate3.txt", 3, txtSize);
            cabInfo.PackFiles(null, new string[] { "testtruncate2.txt", "testtruncate3.txt" }, null);

            // The newly created cab file should be smaller than before.
            Assert.AreNotEqual<long>(size1, cabInfo.Length, "Checking that cabinet file got truncated when creating a smaller cab in-place.");
        }
コード例 #27
0
ファイル: WUA.cs プロジェクト: cengonurozkan/vFenseAgent-win
        private static void DownloadAndUnpackCab()
        {
            var webClient = new WebClient();

            try
            {
                if (Settings.Proxy != null)
                    webClient.Proxy = Settings.Proxy;
                webClient.DownloadFile("http://update.microsoft.com/redist/wuredist.cab",
                                       Path.Combine(TempDir, CabFileName));
            }
            catch (Exception e)
            {
                Logger.Log("Could not download WUA cab file.", LogLevel.Error);
                Logger.LogException(e);
            }

            var cab = new CabInfo(Path.Combine(TempDir, CabFileName));

            cab.Unpack(TempDir);
        }
コード例 #28
0
ファイル: CabTest.cs プロジェクト: Jeremiahf/wix3
        public void CabTruncatedArchive()
        {
            CabInfo cabInfo = new CabInfo("test-t.cab");
            CompressionTestUtil.GenerateRandomFile("cabtest-0.txt", 0, 5);
            CompressionTestUtil.GenerateRandomFile("cabtest-1.txt", 1, 5);
            cabInfo.PackFiles(null, new string[] { "cabtest-0.txt", "cabtest-1.txt" }, null);

            CompressionTestUtil.TestTruncatedArchive(cabInfo, typeof(CabException));
        }