Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search for includes in the directory of currently processed file #107

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions Obfuscar/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private static bool AssemblyIsSigned (AssemblyDefinition def)
return def.Name.PublicKeyToken.Length != 0;
}

public static AssemblyInfo FromXml (Project project, XmlReader reader, Variables vars)
public static AssemblyInfo FromXml (string currentFilePath, Project project, XmlReader reader, Variables vars)
{
Debug.Assert (reader.NodeType == XmlNodeType.Element && reader.Name == "Module");

Expand All @@ -100,13 +100,13 @@ public static AssemblyInfo FromXml (Project project, XmlReader reader, Variables
}

if (!reader.IsEmptyElement) {
FromXmlReadNode(reader, project, vars, info);
FromXmlReadNode(currentFilePath, reader, project, vars, info);
}

return info;
}

private static void FromXmlReadNode(XmlReader reader, Project project, Variables vars, AssemblyInfo info)
private static void FromXmlReadNode(string currentFilePath, XmlReader reader, Project project, Variables vars, AssemblyInfo info)
{
string val;
while (reader.Read())
Expand Down Expand Up @@ -145,7 +145,7 @@ private static void FromXmlReadNode(XmlReader reader, Project project, Variables
{
case "Include":
{
Project.ReadIncludeTag(reader, project, (includeReader, proj) => FromXmlReadNode(includeReader, proj, vars, info));
Project.ReadIncludeTag(currentFilePath, reader, project, (path, includeReader, proj) => FromXmlReadNode(path, includeReader, proj, vars, info));
break;
}
case "SkipNamespace":
Expand Down
19 changes: 12 additions & 7 deletions Obfuscar/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,12 @@ public static Project FromXml (XmlReader reader, string projectFileDirectory)

project.vars.Add (SPECIALVAR_PROJECTFILEDIRECTORY, string.IsNullOrEmpty (projectFileDirectory) ? "." : projectFileDirectory);

FromXmlReadNode(reader, project);
FromXmlReadNode(project.vars.GetValue(SPECIALVAR_PROJECTFILEDIRECTORY, "."), reader, project);

return project;
}

private static void FromXmlReadNode(XmlReader reader, Project project)
private static void FromXmlReadNode(string currentFilePath, XmlReader reader, Project project)
{
while (reader.Read())
{
Expand All @@ -166,7 +166,7 @@ private static void FromXmlReadNode(XmlReader reader, Project project)
break;
}
case "Module":
AssemblyInfo info = AssemblyInfo.FromXml(project, reader, project.vars);
AssemblyInfo info = AssemblyInfo.FromXml(currentFilePath, project, reader, project.vars);
if (info.Exclude) {
project.copyAssemblyList.Add(info);
break;
Expand All @@ -181,15 +181,15 @@ private static void FromXmlReadNode(XmlReader reader, Project project)
break;
}
case "Include": {
ReadIncludeTag(reader, project, FromXmlReadNode);
ReadIncludeTag(currentFilePath, reader, project, FromXmlReadNode);
break;
}
}
}
}
}

internal static void ReadIncludeTag(XmlReader parentReader, Project project, Action<XmlReader, Project> readAction)
internal static void ReadIncludeTag(string currentFilePath, XmlReader parentReader, Project project, Action<string, XmlReader, Project> readAction)
{
if (parentReader == null)
throw new ArgumentNullException("parentReader");
Expand All @@ -198,8 +198,13 @@ internal static void ReadIncludeTag(XmlReader parentReader, Project project, Act
throw new ArgumentNullException("readAction");

string path = Environment.ExpandEnvironmentVariables(project.vars.Replace(Helper.GetAttribute(parentReader, "path")));
if (!File.Exists(path))
{
path = Path.Combine(currentFilePath, Path.GetFileName(path));
}
FileStream fileStream = File.OpenRead(path);
XmlReaderSettings includeReaderSettings = Obfuscator.GetReaderSettings();
using (XmlReader includeReader = XmlReader.Create(File.OpenRead(path), includeReaderSettings))
using (XmlReader includeReader = XmlReader.Create(fileStream, includeReaderSettings))
{
// Start reading
includeReader.Read();
Expand All @@ -212,7 +217,7 @@ internal static void ReadIncludeTag(XmlReader parentReader, Project project, Act

Debug.Assert(includeReader.NodeType == XmlNodeType.Element && includeReader.Name == "Include");

readAction(includeReader, project);
readAction(path, includeReader, project);
}
}

Expand Down