Exemple #1
0
        public static CabFileInfo[] GetCabinetFiles(string path)
        {
            var cab = new CabInfo(path);

            var result = cab.GetFiles();

            return(result.Select(c => c).ToArray());
        }
Exemple #2
0
        public void OpenFile(string path)
        {
            textBoxFilePath.Text = path;
            cab      = new CabInfo(path);
            cabFiles = cab.GetFiles();
            Files    = new List <EFile>();

            string xml;

            using (StreamReader streamreader = new StreamReader(cab.OpenRead("_setup.xml"), Encoding.UTF8))
            {
                xml = streamreader.ReadToEnd();
            }



            XmlDocument setupxml = new XmlDocument();

            setupxml.LoadXml(xml);



            XmlNodeList xnList = setupxml.SelectNodes("/wap-provisioningdoc/characteristic/characteristic/characteristic");

            foreach (XmlNode xn in xnList)
            {
                foreach (XmlNode cxn in xn.ChildNodes)
                {
                    if (cxn.Attributes["type"].Value.ToString() == "Extract")
                    {
                        foreach (XmlNode xnFile in cxn.ChildNodes)
                        {
                            if (xnFile.Attributes["name"].Value.ToString() == "Source")
                            {
                                CabFileInfo cabfileinfo = cabFiles.Where(x => x.Name == xnFile.Attributes["value"].Value.ToString()).FirstOrDefault();
                                EFile       file        = new EFile();
                                file.Source     = xnFile.Attributes["value"].Value.ToString();
                                file.FileName   = xn.Attributes["type"].Value.ToString();
                                file.LastUpDate = cabfileinfo.LastWriteTime;
                                file.Lenght     = cabfileinfo.Length;
                                file.FileIcon   = FileIconLoader.GetFileIcon(file.FileName, false);


                                Files.Add(file);
                            }
                        }
                    }
                }
            }

            BindDataGrid();
            buttonExtract.Enabled     = true;
            buttonInsertFiles.Enabled = true;
        }
Exemple #3
0
        public override ArcFile TryOpen(ArcView file)
        {
            if (VFS.IsVirtual)
            {
                throw new NotSupportedException("Cabinet files inside archives not supported");
            }
            var info = new CabInfo(file.Name);
            var dir  = info.GetFiles().Select(f => new CabEntry(f) as Entry);

            return(new ArcFile(file, this, dir.ToList()));
        }
Exemple #4
0
        private void InitializeManifest()
        {
            if (_infoPathManifest != null)
            {
                return;
            }

            // get the files named manifest.xsf (there should be one)
            IList <CabFileInfo> cbInfos = CabInfo.GetFiles("manifest.xsf");

            if (cbInfos.Count != 1)
            {
                throw new ArgumentException("Invalid InfoPath xsn");
            }
            _infoPathManifest = InfoPathManifest.Create(cbInfos[0]);
        }
Exemple #5
0
        private SummaryWsmBinary GetSummaryWsmBinary()
        {
            var cabInfo         = new CabInfo(_scenarioCabFile.FullName);
            var summaryWsmFiles = cabInfo.GetFiles()
                                  .Where(e => e.Name.Equals("Summary.wsm"))
                                  .OrderBy(e => e.FullName);

            if (!summaryWsmFiles.Any())
            {
                throw new FileNotFoundException("Summary.wsm file not found");
            }

            var summaryFile = summaryWsmFiles.ElementAt(0);

            return(new SummaryWsmBinary(GetBinaryData(summaryFile), GetSummaryMetaData(summaryFile)));
        }
Exemple #6
0
        private void InitializeViews()
        {
            if (_infoPathViews != null)
            {
                return;
            }
            _infoPathViews = new List <InfoPathView>();

            foreach (string name in InfoPathManifest.ViewNames)
            {
                IList <CabFileInfo> cbInfos = CabInfo.GetFiles(name);
                if (cbInfos.Count != 1)
                {
                    throw new ArgumentException(String.Format("Malformed template file: view {0} not found", name));
                }
                InfoPathView viewFile = InfoPathView.Create(cbInfos[0]);
                _infoPathViews.Add(viewFile);
            }
        }
        /// <summary>
        ///     Finds packages given a locally-accessible filename
        ///     Package information must be returned using <c>request.YieldPackage(...)</c> function.
        /// </summary>
        /// <param name="file">the full path to the file to determine if it is a package</param>
        /// <param name="id">
        ///     if this is greater than zero (and the number should have been generated using <c>StartFind(...)</c>,
        ///     the core is calling this multiple times to do a batch search request. The operation can be delayed until
        ///     <c>CompleteFind(...)</c> is called
        /// </param>
        /// <param name="request">
        ///     An object passed in from the CORE that contains functions that can be used to interact with
        ///     the CORE and HOST
        /// </param>
        public void FindPackageByFile(string file, int id, Request request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }
            if (string.IsNullOrWhiteSpace(file))
            {
                throw new ArgumentNullException("file");
            }

            // Nice-to-have put a debug message in that tells what's going on.
            request.Debug("Calling '{0}::FindPackageByFile' '{1}','{2}'", ProviderName, file, id);

            if (file.FileExists())
            {
                var info = new CabInfo(file);

                request.YieldSoftwareIdentity(file, info.Name, null, null, null, null, null, file, info.Name);

                var files = info.GetFiles();
                foreach (var i in files)
                {
                    // read the properties file
                    if (i.FullNameExtension == ".txt")
                    {
                        request.Debug("Reading properties file {0}", i.FullName);
                        using (var reader = i.OpenText())
                        {
                            var contents = reader.ReadToEnd();
                            Dictionary <string, string> keyValuePairs = contents.Split('\n').Select(line => line.Split('=')).Where(v => v.Count() == 2).ToDictionary(pair => pair[0], pair => pair[1]);

                            foreach (var pair in keyValuePairs)
                            {
                                request.AddMetadata(pair.Key.Replace(' ', '_'), pair.Value.Replace("\"", "").Replace("\r", ""));
                            }
                        }
                    }
                }
            }
        }
Exemple #8
0
        /// <summary>
        /// Method:         dsCabFile
        /// Description:    This method is used to handle various functions like list a cab file contents,
        ///                 create a cab file from a directory containing files, or even extract files from
        ///                 a cab file.
        /// </summary>
        /// <param name="cabFileName"></param>
        /// <param name="cabFileLocation"></param>
        /// <param name="cabFlag"></param>
        public static void dsCabFile(string cabFileName, string cabFileLocation, int cabFlag)
        {
            if (cabFlag == 0)
            {
                Program.copyrightBanner();
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("The cabinet file {0} has the following files embedded within it: ", cabFileName);
                CabInfo CabFile = new CabInfo(cabFileName);
                Console.WriteLine("\nCab FileName" + "\t" + "Cab FileSize (KB)");
                foreach (CabFileInfo CabIndvFile in CabFile.GetFiles())
                {
                    Console.WriteLine(CabIndvFile.Name + "\t" + CabIndvFile.Length);
                }
                Console.ResetColor();
            }

            else if (cabFlag == 1)
            {
                Program.copyrightBanner();
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("Cab File {0} is being created. The following files are being added now: \n", cabFileName);
                ArchiveInfo cabFile = CompressedFileType(cabFileName);
                cabFile.Pack(cabFileLocation, true, CompressionLevel.Max, cabProgress);
                Console.WriteLine("\nThe Cab File {0} is successfully created.", cabFileName);
                Console.ResetColor();
            }

            else if (cabFlag == 2)
            {
                Program.copyrightBanner();
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("Cab File {0} is being extracted. The following files are being extracted now: \n", cabFileName);
                ArchiveInfo cabFile = CompressedFileType(cabFileName);
                cabFile.Unpack(cabFileLocation, cabProgress);
                Console.WriteLine("\nThe cab file {0} is extracted to {1}", cabFileName, cabFileLocation);
                Console.ResetColor();
            }
        }
Exemple #9
0
        /// <summary>
        ///     Finds packages given a locally-accessible filename
        ///     Package information must be returned using <c>request.YieldPackage(...)</c> function.
        /// </summary>
        /// <param name="file">the full path to the file to determine if it is a package</param>
        /// <param name="id">
        ///     if this is greater than zero (and the number should have been generated using <c>StartFind(...)</c>,
        ///     the core is calling this multiple times to do a batch search request. The operation can be delayed until
        ///     <c>CompleteFind(...)</c> is called
        /// </param>
        /// <param name="request">
        ///     An object passed in from the CORE that contains functions that can be used to interact with
        ///     the CORE and HOST
        /// </param>
        public void FindPackageByFile(string file, int id, Request request)
        {
            if( request == null ) {
                throw new ArgumentNullException("request");
            }
            if( string.IsNullOrWhiteSpace(file) ) {
                throw new ArgumentNullException("file");
            }

            // Nice-to-have put a debug message in that tells what's going on.
            request.Debug("Calling '{0}::FindPackageByFile' '{1}','{2}'", ProviderName, file, id);

            if (file.FileExists())
            {
                var info = new CabInfo(file);

                request.YieldSoftwareIdentity(file, info.Name, null, null, null, null, null, file, info.Name);

                var files = info.GetFiles();
                foreach (var i in files) {
                    // read the properties file
                    if (i.FullNameExtension == ".txt")
                    {
                        request.Debug("Reading properties file {0}", i.FullName);
                        using (var reader = i.OpenText())
                        {
                            var contents = reader.ReadToEnd();
                            Dictionary<string, string> keyValuePairs = contents.Split('\n').Select(line => line.Split('=')).Where(v => v.Count() == 2).ToDictionary(pair => pair[0], pair => pair[1]);

                            foreach (var pair in keyValuePairs)
                            {
                                request.AddMetadata(pair.Key.Replace(' ', '_'), pair.Value.Replace("\"", "").Replace("\r", ""));
                            }
                        }
                    }
                }
            }
        }
Exemple #10
0
        /// <summary>
        ///     Finds packages given a locally-accessible filename
        ///     Package information must be returned using <c>request.YieldPackage(...)</c> function.
        /// </summary>
        /// <param name="file">the full path to the file to determine if it is a package</param>
        /// <param name="id">
        ///     if this is greater than zero (and the number should have been generated using <c>StartFind(...)</c>,
        ///     the core is calling this multiple times to do a batch search request. The operation can be delayed until
        ///     <c>CompleteFind(...)</c> is called
        /// </param>
        /// <param name="request">
        ///     An object passed in from the CORE that contains functions that can be used to interact with
        ///     the CORE and HOST
        /// </param>
        public void FindPackageByFile(string file, int id, Request request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }
            if (string.IsNullOrWhiteSpace(file))
            {
                throw new ArgumentNullException("file");
            }

            // Nice-to-have put a debug message in that tells what's going on.
            request.Debug("Calling '{0}::FindPackageByFile' '{1}','{2}'", ProviderName, file, id);
            if (file.FileExists())
            {
                var info  = new CabInfo(file);
                var files = info.GetFiles();
                foreach (var i in files)
                {
                    request.Verbose("File {0}", i.FullName);
                }
            }
        }
Exemple #11
0
 /// <summary>
 ///     Finds packages given a locally-accessible filename
 ///     Package information must be returned using <c>request.YieldPackage(...)</c> function.
 /// </summary>
 /// <param name="file">the full path to the file to determine if it is a package</param>
 /// <param name="id">
 ///     if this is greater than zero (and the number should have been generated using <c>StartFind(...)</c>,
 ///     the core is calling this multiple times to do a batch search request. The operation can be delayed until
 ///     <c>CompleteFind(...)</c> is called
 /// </param>
 /// <param name="requestObject">
 ///     An object passed in from the CORE that contains functions that can be used to interact with
 ///     the CORE and HOST
 /// </param>
 public void FindPackageByFile(string file, int id, IRequestObject requestObject)
 {
     try {
         // create a strongly-typed request object.
         using (var request = requestObject.As <Request>()) {
             // Nice-to-have put a debug message in that tells what's going on.
             request.Debug("Calling '{0}::FindPackageByFile' '{1}','{2}'", ProviderName, file, id);
             if (file.FileExists())
             {
                 var info  = new CabInfo(file);
                 var files = info.GetFiles();
                 foreach (var i in files)
                 {
                     request.Verbose("File {0}", i.FullName);
                 }
             }
         }
     } catch (Exception e) {
         // We shoudn't throw exceptions from here, it's not-optimal. And if the exception class wasn't properly Serializable, it'd cause other issues.
         // Really this is just here as a precautionary to behave correctly.
         // At the very least, we'll write it to the system debug channel, so a developer can find it if they are looking for it.
         Debug.WriteLine("Unexpected Exception thrown in '{0}::FindPackageByFile' -- {1}\\{2}\r\n{3}", ProviderName, e.GetType().Name, e.Message, e.StackTrace);
     }
 }
        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);
        }
Exemple #13
0
        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);
            }
        }
 private static IEnumerable <CabFileInfo> GetSummaryXmlFiles(CabInfo cabInfo)
 {
     return(cabInfo.GetFiles()
            .Where(e => e.Name.Equals("Summary.xml"))
            .OrderBy(e => e.FullName));
 }