|
|
@ -41,7 +41,7 @@ namespace ICSharpCode.Decompiler.CSharp |
|
|
|
{ |
|
|
|
{ |
|
|
|
#region Settings
|
|
|
|
#region Settings
|
|
|
|
DecompilerSettings settings = new DecompilerSettings(); |
|
|
|
DecompilerSettings settings = new DecompilerSettings(); |
|
|
|
|
|
|
|
|
|
|
|
public DecompilerSettings Settings { |
|
|
|
public DecompilerSettings Settings { |
|
|
|
get { |
|
|
|
get { |
|
|
|
return settings; |
|
|
|
return settings; |
|
|
@ -52,16 +52,16 @@ namespace ICSharpCode.Decompiler.CSharp |
|
|
|
settings = value; |
|
|
|
settings = value; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// The MSBuild ProjectGuid to use for the new project.
|
|
|
|
/// The MSBuild ProjectGuid to use for the new project.
|
|
|
|
/// <c>null</c> to automatically generate a new GUID.
|
|
|
|
/// <c>null</c> to automatically generate a new GUID.
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
public Guid? ProjectGuid { get; set; } |
|
|
|
public Guid? ProjectGuid { get; set; } |
|
|
|
|
|
|
|
|
|
|
|
public int MaxDegreeOfParallelism { get; set; } = Environment.ProcessorCount; |
|
|
|
public int MaxDegreeOfParallelism { get; set; } = Environment.ProcessorCount; |
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
// per-run members
|
|
|
|
// per-run members
|
|
|
|
HashSet<string> directories = new HashSet<string>(Platform.FileNameComparer); |
|
|
|
HashSet<string> directories = new HashSet<string>(Platform.FileNameComparer); |
|
|
|
|
|
|
|
|
|
|
@ -73,7 +73,7 @@ namespace ICSharpCode.Decompiler.CSharp |
|
|
|
/// can access it.
|
|
|
|
/// can access it.
|
|
|
|
/// </remarks>
|
|
|
|
/// </remarks>
|
|
|
|
protected string targetDirectory; |
|
|
|
protected string targetDirectory; |
|
|
|
|
|
|
|
|
|
|
|
public void DecompileProject(ModuleDefinition moduleDefinition, string targetDirectory, CancellationToken cancellationToken = default(CancellationToken)) |
|
|
|
public void DecompileProject(ModuleDefinition moduleDefinition, string targetDirectory, CancellationToken cancellationToken = default(CancellationToken)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
string projectFileName = Path.Combine(targetDirectory, CleanUpFileName(moduleDefinition.Assembly.Name.Name) + ".csproj"); |
|
|
|
string projectFileName = Path.Combine(targetDirectory, CleanUpFileName(moduleDefinition.Assembly.Name.Name) + ".csproj"); |
|
|
@ -81,7 +81,7 @@ namespace ICSharpCode.Decompiler.CSharp |
|
|
|
DecompileProject(moduleDefinition, targetDirectory, writer, cancellationToken); |
|
|
|
DecompileProject(moduleDefinition, targetDirectory, writer, cancellationToken); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void DecompileProject(ModuleDefinition moduleDefinition, string targetDirectory, TextWriter projectFileWriter, CancellationToken cancellationToken = default(CancellationToken)) |
|
|
|
public void DecompileProject(ModuleDefinition moduleDefinition, string targetDirectory, TextWriter projectFileWriter, CancellationToken cancellationToken = default(CancellationToken)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (string.IsNullOrEmpty(targetDirectory)) { |
|
|
|
if (string.IsNullOrEmpty(targetDirectory)) { |
|
|
@ -99,7 +99,7 @@ namespace ICSharpCode.Decompiler.CSharp |
|
|
|
None, |
|
|
|
None, |
|
|
|
Portable |
|
|
|
Portable |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#region WriteProjectFile
|
|
|
|
#region WriteProjectFile
|
|
|
|
void WriteProjectFile(TextWriter writer, IEnumerable<Tuple<string, string>> files, ModuleDefinition module) |
|
|
|
void WriteProjectFile(TextWriter writer, IEnumerable<Tuple<string, string>> files, ModuleDefinition module) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -248,7 +248,7 @@ namespace ICSharpCode.Decompiler.CSharp |
|
|
|
w.WriteEndDocument(); |
|
|
|
w.WriteEndDocument(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected virtual bool IsGacAssembly(AssemblyNameReference r, AssemblyDefinition asm) |
|
|
|
protected virtual bool IsGacAssembly(AssemblyNameReference r, AssemblyDefinition asm) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return false; |
|
|
|
return false; |
|
|
@ -272,7 +272,7 @@ namespace ICSharpCode.Decompiler.CSharp |
|
|
|
decompiler.AstTransforms.Add(new RemoveCLSCompliantAttribute()); |
|
|
|
decompiler.AstTransforms.Add(new RemoveCLSCompliantAttribute()); |
|
|
|
return decompiler; |
|
|
|
return decompiler; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
IEnumerable<Tuple<string, string>> WriteAssemblyInfo(DecompilerTypeSystem ts, CancellationToken cancellationToken) |
|
|
|
IEnumerable<Tuple<string, string>> WriteAssemblyInfo(DecompilerTypeSystem ts, CancellationToken cancellationToken) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var decompiler = CreateDecompiler(ts); |
|
|
|
var decompiler = CreateDecompiler(ts); |
|
|
@ -293,7 +293,7 @@ namespace ICSharpCode.Decompiler.CSharp |
|
|
|
IEnumerable<Tuple<string, string>> WriteCodeFilesInProject(ModuleDefinition module, CancellationToken cancellationToken) |
|
|
|
IEnumerable<Tuple<string, string>> WriteCodeFilesInProject(ModuleDefinition module, CancellationToken cancellationToken) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var files = module.Types.Where(IncludeTypeWhenDecompilingProject).GroupBy( |
|
|
|
var files = module.Types.Where(IncludeTypeWhenDecompilingProject).GroupBy( |
|
|
|
delegate(TypeDefinition type) { |
|
|
|
delegate (TypeDefinition type) { |
|
|
|
string file = CleanUpFileName(type.Name) + ".cs"; |
|
|
|
string file = CleanUpFileName(type.Name) + ".cs"; |
|
|
|
if (string.IsNullOrEmpty(type.Namespace)) { |
|
|
|
if (string.IsNullOrEmpty(type.Namespace)) { |
|
|
|
return file; |
|
|
|
return file; |
|
|
@ -301,7 +301,7 @@ namespace ICSharpCode.Decompiler.CSharp |
|
|
|
string dir = CleanUpFileName(type.Namespace); |
|
|
|
string dir = CleanUpFileName(type.Namespace); |
|
|
|
if (directories.Add(dir)) |
|
|
|
if (directories.Add(dir)) |
|
|
|
Directory.CreateDirectory(Path.Combine(targetDirectory, dir)); |
|
|
|
Directory.CreateDirectory(Path.Combine(targetDirectory, dir)); |
|
|
|
return Path.Combine(targetDirectory, dir, file); |
|
|
|
return Path.Combine(dir, file); |
|
|
|
} |
|
|
|
} |
|
|
|
}, StringComparer.OrdinalIgnoreCase).ToList(); |
|
|
|
}, StringComparer.OrdinalIgnoreCase).ToList(); |
|
|
|
DecompilerTypeSystem ts = new DecompilerTypeSystem(module); |
|
|
|
DecompilerTypeSystem ts = new DecompilerTypeSystem(module); |
|
|
@ -311,7 +311,7 @@ namespace ICSharpCode.Decompiler.CSharp |
|
|
|
MaxDegreeOfParallelism = this.MaxDegreeOfParallelism, |
|
|
|
MaxDegreeOfParallelism = this.MaxDegreeOfParallelism, |
|
|
|
CancellationToken = cancellationToken |
|
|
|
CancellationToken = cancellationToken |
|
|
|
}, |
|
|
|
}, |
|
|
|
delegate(IGrouping<string, TypeDefinition> file) { |
|
|
|
delegate (IGrouping<string, TypeDefinition> file) { |
|
|
|
using (StreamWriter w = new StreamWriter(Path.Combine(targetDirectory, file.Key))) { |
|
|
|
using (StreamWriter w = new StreamWriter(Path.Combine(targetDirectory, file.Key))) { |
|
|
|
CSharpDecompiler decompiler = CreateDecompiler(ts); |
|
|
|
CSharpDecompiler decompiler = CreateDecompiler(ts); |
|
|
|
decompiler.CancellationToken = cancellationToken; |
|
|
|
decompiler.CancellationToken = cancellationToken; |
|
|
@ -322,7 +322,7 @@ namespace ICSharpCode.Decompiler.CSharp |
|
|
|
return files.Select(f => Tuple.Create("Compile", f.Key)).Concat(WriteAssemblyInfo(ts, cancellationToken)); |
|
|
|
return files.Select(f => Tuple.Create("Compile", f.Key)).Concat(WriteAssemblyInfo(ts, cancellationToken)); |
|
|
|
} |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region WriteResourceFilesInProject
|
|
|
|
#region WriteResourceFilesInProject
|
|
|
|
protected virtual IEnumerable<Tuple<string, string>> WriteResourceFilesInProject(ModuleDefinition module) |
|
|
|
protected virtual IEnumerable<Tuple<string, string>> WriteResourceFilesInProject(ModuleDefinition module) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -358,7 +358,7 @@ namespace ICSharpCode.Decompiler.CSharp |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected virtual IEnumerable<Tuple<string, string>> WriteResourceToFile(string fileName, string resourceName, Stream entryStream) |
|
|
|
protected virtual IEnumerable<Tuple<string, string>> WriteResourceToFile(string fileName, string resourceName, Stream entryStream) |
|
|
|
{ |
|
|
|
{ |
|
|
|
using (FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write)) { |
|
|
|
using (FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write)) { |
|
|
@ -366,7 +366,7 @@ namespace ICSharpCode.Decompiler.CSharp |
|
|
|
} |
|
|
|
} |
|
|
|
yield return Tuple.Create("EmbeddedResource", fileName); |
|
|
|
yield return Tuple.Create("EmbeddedResource", fileName); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
string GetFileNameForResource(string fullName) |
|
|
|
string GetFileNameForResource(string fullName) |
|
|
|
{ |
|
|
|
{ |
|
|
|
string[] splitName = fullName.Split('.'); |
|
|
|
string[] splitName = fullName.Split('.'); |
|
|
@ -393,7 +393,7 @@ namespace ICSharpCode.Decompiler.CSharp |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Cleans up a node name for use as a file name.
|
|
|
|
/// Cleans up a node name for use as a file name.
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
@ -410,7 +410,7 @@ namespace ICSharpCode.Decompiler.CSharp |
|
|
|
text = text.Replace(c, '-'); |
|
|
|
text = text.Replace(c, '-'); |
|
|
|
return text; |
|
|
|
return text; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static string GetPlatformName(ModuleDefinition module) |
|
|
|
public static string GetPlatformName(ModuleDefinition module) |
|
|
|
{ |
|
|
|
{ |
|
|
|
switch (module.Architecture) { |
|
|
|
switch (module.Architecture) { |
|
|
|