diff --git a/ILSpy/CommandLineArguments.cs b/ILSpy/CommandLineArguments.cs index 4ee5c1af2..0c4aa3e4c 100644 --- a/ILSpy/CommandLineArguments.cs +++ b/ILSpy/CommandLineArguments.cs @@ -30,6 +30,8 @@ namespace ICSharpCode.ILSpy public string Search; public string Language; public bool NoActivate; + public Guid? FixedGuid; + public string SaveDirectory; public CommandLineArguments(IEnumerable arguments) { @@ -49,6 +51,15 @@ namespace ICSharpCode.ILSpy this.Language = arg.Substring("/language:".Length); else if (arg.Equals("/noActivate", StringComparison.OrdinalIgnoreCase)) this.NoActivate = true; + else if (arg.StartsWith("/fixedGuid:", StringComparison.OrdinalIgnoreCase)) { + string guid = arg.Substring("/fixedGuid:".Length); + if (guid.Length < 32) + guid = guid + new string('0', 32 - guid.Length); + Guid fixedGuid; + if (Guid.TryParse(guid, out fixedGuid)) + this.FixedGuid = fixedGuid; + } else if (arg.StartsWith("/saveDir:", StringComparison.OrdinalIgnoreCase)) + this.SaveDirectory = arg.Substring("/saveDir:".Length); } else { this.AssembliesToLoad.Add(arg); } diff --git a/ILSpy/Languages/CSharpLanguage.cs b/ILSpy/Languages/CSharpLanguage.cs index 558c567f4..369cf2e84 100644 --- a/ILSpy/Languages/CSharpLanguage.cs +++ b/ILSpy/Languages/CSharpLanguage.cs @@ -321,6 +321,7 @@ namespace ICSharpCode.ILSpy { const string ns = "http://schemas.microsoft.com/developer/msbuild/2003"; string platformName = GetPlatformName(module); + Guid guid = App.CommandLineArguments.FixedGuid ?? Guid.NewGuid(); using (XmlTextWriter w = new XmlTextWriter(writer)) { w.Formatting = Formatting.Indented; w.WriteStartDocument(); @@ -329,7 +330,7 @@ namespace ICSharpCode.ILSpy w.WriteAttributeString("DefaultTargets", "Build"); w.WriteStartElement("PropertyGroup"); - w.WriteElementString("ProjectGuid", Guid.NewGuid().ToString("B").ToUpperInvariant()); + w.WriteElementString("ProjectGuid", guid.ToString("B").ToUpperInvariant()); w.WriteStartElement("Configuration"); w.WriteAttributeString("Condition", " '$(Configuration)' == '' "); diff --git a/ILSpy/MainWindow.xaml.cs b/ILSpy/MainWindow.xaml.cs index 53ae49979..fa4028e2c 100644 --- a/ILSpy/MainWindow.xaml.cs +++ b/ILSpy/MainWindow.xaml.cs @@ -300,9 +300,33 @@ namespace ICSharpCode.ILSpy SearchPane.Instance.SearchTerm = args.Search; SearchPane.Instance.Show(); } + if (!string.IsNullOrEmpty(args.SaveDirectory)) { + foreach (var x in commandLineLoadedAssemblies) { + x.ContinueWhenLoaded( (Task moduleTask) => { + OnExportAssembly(moduleTask, args.SaveDirectory); + }, TaskScheduler.FromCurrentSynchronizationContext()); + } + } commandLineLoadedAssemblies.Clear(); // clear references once we don't need them anymore } + void OnExportAssembly(Task moduleTask, string path) + { + AssemblyTreeNode asmNode = assemblyListTreeNode.FindAssemblyNode(moduleTask.Result); + if (asmNode != null) { + string file = DecompilerTextView.CleanUpName(asmNode.LoadedAssembly.ShortName); + Language language = sessionSettings.FilterSettings.Language; + DecompilationOptions options = new DecompilationOptions(); + options.FullDecompilation = true; + options.SaveAsProjectDirectory = Path.Combine(App.CommandLineArguments.SaveDirectory, file); + if (!Directory.Exists(options.SaveAsProjectDirectory)) { + Directory.CreateDirectory(options.SaveAsProjectDirectory); + } + string fullFile = Path.Combine(options.SaveAsProjectDirectory, file + language.ProjectFileExtension); + TextView.SaveToDisk(language, new[] { asmNode }, options, fullFile); + } + } + void MainWindow_Loaded(object sender, RoutedEventArgs e) { ILSpySettings spySettings = this.spySettings; diff --git a/ILSpy/VB/VBLanguage.cs b/ILSpy/VB/VBLanguage.cs index addb2d768..4c200b2db 100644 --- a/ILSpy/VB/VBLanguage.cs +++ b/ILSpy/VB/VBLanguage.cs @@ -127,6 +127,7 @@ namespace ICSharpCode.ILSpy.VB { const string ns = "http://schemas.microsoft.com/developer/msbuild/2003"; string platformName = CSharpLanguage.GetPlatformName(module); + Guid guid = App.CommandLineArguments.FixedGuid ?? Guid.NewGuid(); using (XmlTextWriter w = new XmlTextWriter(writer)) { w.Formatting = Formatting.Indented; w.WriteStartDocument(); @@ -135,7 +136,7 @@ namespace ICSharpCode.ILSpy.VB w.WriteAttributeString("DefaultTargets", "Build"); w.WriteStartElement("PropertyGroup"); - w.WriteElementString("ProjectGuid", Guid.NewGuid().ToString("B").ToUpperInvariant()); + w.WriteElementString("ProjectGuid", guid.ToString("B").ToUpperInvariant()); w.WriteStartElement("Configuration"); w.WriteAttributeString("Condition", " '$(Configuration)' == '' ");