Browse Source

Add commandline arguments for a fixed guid, and for specifying a directory where decompiled projects will be stored.

all assemblies passed on the commandline are exported to this dir.
pull/535/head
learn_more 10 years ago
parent
commit
83bc512ae2
  1. 14
      ILSpy/CommandLineArguments.cs
  2. 3
      ILSpy/Languages/CSharpLanguage.cs
  3. 24
      ILSpy/MainWindow.xaml.cs
  4. 3
      ILSpy/VB/VBLanguage.cs

14
ILSpy/CommandLineArguments.cs

@ -29,6 +29,8 @@ namespace ICSharpCode.ILSpy @@ -29,6 +29,8 @@ namespace ICSharpCode.ILSpy
public string NavigateTo;
public string Language;
public bool NoActivate;
public Guid? FixedGuid;
public string SaveDirectory;
public CommandLineArguments(IEnumerable<string> arguments)
{
@ -46,6 +48,18 @@ namespace ICSharpCode.ILSpy @@ -46,6 +48,18 @@ 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);
try {
if (guid.Length < 32)
guid = guid + new string('0', 32 - guid.Length);
this.FixedGuid = new Guid(guid);
} catch {
this.FixedGuid = null;
}
}
else if (arg.StartsWith("/saveDir:", StringComparison.OrdinalIgnoreCase))
this.SaveDirectory = arg.Substring("/saveDir:".Length);
} else {
this.AssembliesToLoad.Add(arg);
}

3
ILSpy/Languages/CSharpLanguage.cs

@ -309,6 +309,7 @@ namespace ICSharpCode.ILSpy @@ -309,6 +309,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();
@ -317,7 +318,7 @@ namespace ICSharpCode.ILSpy @@ -317,7 +318,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)' == '' ");

24
ILSpy/MainWindow.xaml.cs

@ -295,9 +295,33 @@ namespace ICSharpCode.ILSpy @@ -295,9 +295,33 @@ namespace ICSharpCode.ILSpy
// Select the newly loaded assembly
JumpToReference(commandLineLoadedAssemblies[0].ModuleDefinition);
}
if (!string.IsNullOrEmpty(args.SaveDirectory)) {
foreach (var x in commandLineLoadedAssemblies) {
x.ContinueWhenLoaded( (Task<ModuleDefinition> moduleTask) => {
OnExportAssembly(moduleTask, args.SaveDirectory);
}, TaskScheduler.FromCurrentSynchronizationContext());
}
}
commandLineLoadedAssemblies.Clear(); // clear references once we don't need them anymore
}
void OnExportAssembly(Task<ModuleDefinition> 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;

3
ILSpy/VB/VBLanguage.cs

@ -126,6 +126,7 @@ namespace ICSharpCode.ILSpy.VB @@ -126,6 +126,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();
@ -134,7 +135,7 @@ namespace ICSharpCode.ILSpy.VB @@ -134,7 +135,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)' == '' ");

Loading…
Cancel
Save