static void OnProjectFileCreated(object sender, ProjectFileCreated e) { count++; CommandLineManager.SetForegroundColor(ConsoleColor.DarkGray); string generationErrors = ""; if (e.HasErrors) { generationErrors = " ... error generating."; Console.ForegroundColor = ConsoleColor.Red; } CommandLineManager.WriteLine(" " + count + "." + e.Name + generationErrors); CommandLineManager.ResetColor(); }
public virtual void Run(GeneratorProjectInfo projectInfo) { //"lang:scharp", //@"/target C:\Work\Behemoth\Trunk\Source\Binaries\Telerik.Windows.Controls.dll", //string[] testArgs = new string[] {"/target" @"C:\Work\Behemoth\Trunk\Source\Binaries\Telerik.Windows.Controls.dll", @"/out", "c:\\dir" }; #if ENGINEONLYBUILD if (projectInfo == null) { projectInfo = new GeneratorProjectInfo(new CommandLineHelpError()); } #endif if (projectInfo == null) { CommandLineManager.WriteLineColor(ConsoleColor.Red, "args = null"); CommandLineManager.ResetColor(); return; } try { // If there is an error, there is no need to create output directory, because there will not be any project generation at all. if (projectInfo.Error == null) { try { this.CreateOutputDirectory(projectInfo); } catch (Exception ex) { if (ex is IOException || ex is UnauthorizedAccessException || ex is ArgumentException || ex is PathTooLongException || ex is DirectoryNotFoundException || ex is NotSupportedException) { projectInfo.Error = new CommandLineError(CommandLineManager.InvalidDirectoryPathError + ex.Message); } else { throw; } } } if (projectInfo.Error == null) { CommandLineManager.WriteLine(); CommandLineManager.WriteLineColor(ConsoleColor.White, description); CommandLineManager.WriteLineColor(ConsoleColor.White, new string(Enumerable.Range(0, description.Length).Select(i => '=').ToArray())); Console.WriteLine(); Console.WriteLine("Generates MS Visual Studio(r) Project from .NET assembly."); CommandLineManager.WriteLine(); if (!CLRHelper.IsValidClrFile(projectInfo.Target)) { CommandLineManager.WriteLineColor(ConsoleColor.Red, "The target assembly is not a valid CLR assembly."); return; } AssemblyDefinition assembly = Telerik.JustDecompiler.Decompiler.Utilities.GetAssembly(projectInfo.Target); ProjectGenerationSettings settings = this.GetSettings(projectInfo); if (!settings.VisualStudioSupportedProjectType) { CommandLineManager.WriteLineColor(ConsoleColor.Red, this.ReplaceRegisteredTrademarkSymbol(settings.ErrorMessage)); return; } else if (!settings.JustDecompileSupportedProjectType) { CommandLineManager.WriteLineColor(ConsoleColor.Yellow, this.ReplaceRegisteredTrademarkSymbol(settings.ErrorMessage)); CommandLineManager.WriteLine(); } else if (!projectInfo.IsDefaultFrameworkVersion) { AssemblyInfo assemblyInfo = NoCacheAssemblyInfoService.Instance.GetAssemblyInfo(assembly, new ConsoleFrameworkResolver(projectInfo.FrameworkVersion)); if (assemblyInfo.ModulesFrameworkVersions[assembly.MainModule] != projectInfo.FrameworkVersion) { CommandLineManager.WriteLineColor(ConsoleColor.Yellow, "JustDecompile managed to determine the target assembly framework. The fallback target framework version command line option is ignored."); CommandLineManager.WriteLine(); } } if (!projectInfo.DecompileDangerousResources) { CommandLineManager.WriteLineColor(ConsoleColor.Yellow, "By default JustDecompile's command-line project generataion does not decompile dangerous resources, which may contain malicious code. Decompilation of such resources will result in execution of that malicious code. Check the help [/?] for information how to turn on decompilation of such resources. WARNING: Use with trusted assemblies only."); CommandLineManager.WriteLine(); } CommandLineManager.WriteLineColor(ConsoleColor.White, "Project Creation:"); CommandLineManager.WriteLineColor(ConsoleColor.White, "============================"); TimeSpan projectGenerationTime = RunInternal(assembly, projectInfo, settings); CommandLineManager.WriteLine(); CommandLineManager.WriteLineColor(ConsoleColor.White, "============================"); CommandLineManager.WriteLineColor(ConsoleColor.White, string.Format("Finished in {0:0.0} seconds.", projectGenerationTime.TotalSeconds)); count = 0; } else { projectInfo.Error.PrintError(); } } catch (Exception ex) { CommandLineManager.WriteLine(); CommandLineManager.WriteLineColor(ConsoleColor.Red, ex.Message); OnExceptionThrown(ex); } finally { CommandLineManager.WriteLine(); CommandLineManager.ResetColor(); } }