Skip to content

Commit

Permalink
icsharpcode#1942: WholeProjectDecompiler: Do not use filenames that c…
Browse files Browse the repository at this point in the history
…ollide with names of special devices. Note: this changes the PDB structure from multi-level folders per namespace to "dotted name" folders.
  • Loading branch information
siegfriedpammer committed Mar 5, 2020
1 parent 0a983ec commit 70b087b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
36 changes: 35 additions & 1 deletion ICSharpCode.Decompiler/CSharp/WholeProjectDecompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,41 @@ public static string CleanUpFileName(string text)
}
if (b.Length == 0)
b.Append('-');
return b.ToString();
string name = b.ToString();
if (IsReservedFileSystemName(name))
return name + "_";
return name;
}

static bool IsReservedFileSystemName(string name)
{
switch (name.ToUpperInvariant()) {
case "AUX":
case "COM1":
case "COM2":
case "COM3":
case "COM4":
case "COM5":
case "COM6":
case "COM7":
case "COM8":
case "COM9":
case "CON":
case "LPT1":
case "LPT2":
case "LPT3":
case "LPT4":
case "LPT5":
case "LPT6":
case "LPT7":
case "LPT8":
case "LPT9":
case "NUL":
case "PRN":
return true;
default:
return false;
}
}

public static string GetPlatformName(Metadata.PEFile module)
Expand Down
3 changes: 2 additions & 1 deletion ICSharpCode.Decompiler/DebugInfo/PortablePdbWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ public static void WritePdb(PEFile file, CSharpDecompiler decompiler, Decompiler

lock (metadata) {
var sourceBlob = WriteSourceToBlob(metadata, sourceText, out var sourceCheckSum);
var name = metadata.GetOrAddDocumentName(type.GetFullTypeName(reader).ReflectionName.Replace('.', Path.DirectorySeparatorChar) + ".cs");
var typeName = type.GetFullTypeName(reader).TopLevelTypeName;
var name = metadata.GetOrAddDocumentName(Path.Combine(WholeProjectDecompiler.CleanUpFileName(typeName.Namespace), WholeProjectDecompiler.CleanUpFileName(typeName.Name) + ".cs"));

// Create Document(Handle)
var document = metadata.AddDocument(name,
Expand Down

0 comments on commit 70b087b

Please sign in to comment.