internal Dir(Feature feature, string targetPath, Project project)
{
this.Feature = feature;
//create nested Dirs on-fly but reuse already existing ones in the project
var nestedDirs = targetPath.Split("\\/".ToCharArray());
Dir lastFound = null;
string lastMatching = null;
string[] flatTree = ToFlatPathTree(targetPath);
foreach (string path in flatTree)
{
var existingDir = project.FindDir(path);
if (existingDir != null)
{
lastFound = existingDir;
lastMatching = path;
}
else
{
if (lastFound != null)
{
Dir currDir = lastFound;
string[] newSubDirs = targetPath.Substring(lastMatching.Length + 1).Split("\\/".ToCharArray());
for (int i = 0; i < newSubDirs.Length; i++)
{
Dir nextSubDir = new Dir(feature, newSubDirs[i]);
currDir.Dirs = new Dir[] { nextSubDir };
currDir = nextSubDir;
}
currDir.Feature = feature;
}
else
{
lastDir = ProcessTargetPath(targetPath, feature);
lastDir.Feature = feature;
}
break;
}
}
}