private static int Main(string[] args) { BasicConfigurator.Configure(); var cfg = ConfigurationManager.AppSettings; int res; using (var parser = Parser.Default) { res = parser.ParseArguments <UnsignOptions, PatchOptions, PurifyOptions, SipOptions, IsleOptions, AdoptOptions, WeaveOptions, InvertOptions, UsagesOptions>(args).MapResult( (UnsignOptions opts) => Signer.Unsign(opts), (PatchOptions opts) => Patcher.Modify(opts), (PurifyOptions opts) => Purifier.Clean(opts), (SipOptions opts) => Searcher.Find(opts), (IsleOptions opts) => Island.Replace(opts), (AdoptOptions opts) => Adopter.Force(opts), (WeaveOptions opts) => Weaver.Web(opts), (InvertOptions opts) => Purger.Invert(opts), (UsagesOptions opts) => Usager.Poll(opts), errs => 1); } return(res); }
internal static int Invert(InvertOptions opts) { var report = new DependencyReport(); Usager.Poll(opts, report); Log.Info($"{report.Files.Count} file(s) read for metadata."); var tempDir = Path.GetFullPath(opts.TempDir); Directory.CreateDirectory(tempDir); Log.Info($"Temporary directory is '{tempDir}'."); var reportFile = Path.Combine(tempDir, "report.json"); Usager.WriteToJson(report, reportFile); Log.Info($"Report is in '{reportFile}'."); var outDir = Path.GetFullPath(opts.OutputDir); Directory.CreateDirectory(outDir); Log.Info($"Output directory is '{outDir}'."); var generated = GenerateNamespaces(report); var files = generated.GroupBy(g => g.Key).ToArray(); Log.Info($"Generating {files.Length} package(s)..."); var newLine = Environment.NewLine + Environment.NewLine; var names = report.ManagedRefs.Keys.Concat(report.NativeRefs.Keys).Distinct().ToArray(); var toCompile = new List <string>(); foreach (var file in files) { var key = file.Key; var meta = CreateMetadata(key, names.First(n => Compare(n, key))); var nsps = new object[] { meta }.Concat(file.Select(f => f.Value)).ToArray(); var code = string.Join(newLine, nsps.Select(n => n.ToString())); var filePath = Path.Combine(tempDir, key); Log.Info($"'{ToRelativePath(tempDir, filePath)}' [{nsps.Length} namespace(s)]"); File.WriteAllText(filePath, code, Encoding.UTF8); toCompile.Add(filePath); } IFileCopier copier = new FileCopier(); var workDir = Path.GetFullPath(opts.WorkDir); copier.CopyFolder(workDir, outDir); Log.Info($"Compiling {toCompile.Count} package(s)..."); var toInject = new List <string>(); foreach (var package in toCompile) { var bytes = (new FileInfo(package)).Length; Log.Info($"'{ToRelativePath(tempDir, package)}' [{bytes} bytes]"); var name = Path.GetFileNameWithoutExtension(package); var ass = CreateAssembly(tempDir, name, new[] { package }); if (ass == null) { Log.Error("Sorry, I could not compile everything ;-("); return(-1); } Log.Info($" --> '{ass.FullName}'"); toInject.Add(copier.CopyFile(ass.Location, outDir)); } var oneFileOrMore = report.Files.Count >= 1 && files.Length >= 1; if (oneFileOrMore) { Log.Info($"Ensuring dependencies in '{outDir}'..."); Log.InfoFormat(" added '{0}'!", CopyTypeRef <IVessel>(outDir)); Log.InfoFormat(" added '{0}'!", CopyTypeRef <DefaultVessel>(outDir)); Log.InfoFormat(" added '{0}'!", CopyTypeRef <MoqContainer>(outDir)); Log.InfoFormat(" added '{0}'!", CopyTypeRef <AutofacContainer>(outDir)); } if (oneFileOrMore) { Log.Info($"Processing {report.Files.Count} file(s)..."); ProcessMarkedFiles(workDir, report, toInject, outDir); } Log.Info("Done."); return(0); }