Esempio n. 1
0
 public void RecompressXap(UpdateableXapFile xap)
 {
     xap.Load();
     Tuple<long, long> recompressed = xap.Recompress();
     if (recompressed.Item1 > recompressed.Item2)
     {
         _console.WriteLine(Output.RecompressSucceeded,
             StorageUtil.PrettyPrintBytes(recompressed.Item1),
             StorageUtil.PrettyPrintBytes(recompressed.Item1 - recompressed.Item2));
     }
     else
     {
         _console.WriteLine(Output.RecompressCanceled);
     }
 }
Esempio n. 2
0
        public void ReduceXap(Options options)
        {
            long oldSize = _fileSystem.FileSize(options.Input);

            WritableXapFile xap;

            if (options.Output != null)
            {
                xap = new RecreatedXapFile(options.Input, options.Output, _fileSystem);
            }
            else
            {
                xap = new UpdateableXapFile(options.Input, _fileSystem);
            }

            using (xap)
            {
                // Get a list of redundant assemblies: identical files that exist in both input and source XAPs
                List<AssemblyPartInfo> redundantAssemblyParts = GetRedundantAssemblyParts(options.Sources, xap).ToList();

                // Get satellite assemblies (resources) for redundant assemblies
                var redundantResources = redundantAssemblyParts.SelectMany(ap => GetResourceAssemblyParts(ap, xap)).ToList();

                // Merge the two lists. Note that it can contain duplicates when a resource file exists in both
                // input and source XAPs, while at the same time the main assembly is also redundant.
                redundantAssemblyParts = redundantAssemblyParts.Union(redundantResources).ToList();

                _console.WriteLine(Output.RedundantAssemblyParts, redundantAssemblyParts.Count);
                _console.Write(Environment.NewLine);

                RemoveAssemblyParts(xap, redundantAssemblyParts);
                xap.Save();
                xap.Close();

                long newSize = _fileSystem.FileSize(options.Input);

                _console.Write(Environment.NewLine);
                _console.WriteLine(Program.ReportFileSizeReduction(oldSize, newSize));

                if (options.Recompress)
                {
                    RecompressXap((UpdateableXapFile)xap);
                }
            }
        }