示例#1
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);
                }
            }
        }
示例#2
0
        public static Options ParseCommandLine(string[] args, TextWriter helpWriter)
        {
            var options = new Options();
            var parser = new Parser(settings =>
            {
                settings.HelpWriter = helpWriter;
                settings.IgnoreUnknownArguments = false;
            });

            Action onFail = () =>
            {
                HelpText.AutoBuild(options);
                options.Exit = true;
            };

            if (parser.ParseArgumentsStrict(args, options, onFail))
            {
                return options;
            }

            return options;
        }
示例#3
0
        internal static int CheckCommandLineOptions(Options options, IFileSystem fileSystem)
        {
            if (!fileSystem.FileExists(options.Input))
            {
                Console.WriteLine(Res.Errors.InputFileDoesNotExist, options.Input);
                return 2;
            }

            if (options.Sources == null || options.Sources.Length == 0)
            {
                Console.WriteLine(Res.Errors.AtLeastOneSourceFileRequired);
                return 1;
            }

            var missingFiles = options.Sources.Where(f => !fileSystem.FileExists(f)).ToList();
            if (missingFiles.Count > 0 && !options.IgnoreMissing)
            {
                Console.WriteLine(Res.Errors.SourceFilesMissing, @"  " + String.Join("  \r\n", missingFiles));
                return 3;
            }

            return 0;
        }