protected virtual HierarchyNode AddNodeIfTargetExistInStorage(HierarchyNode parentNode, string name,
string targetPath)
{
if (parentNode == null)
{
return null;
}
var newNode = parentNode;
// If the file/directory exist, add a node for it
if (File.Exists(targetPath))
{
var result = new VSADDRESULT[1];
ErrorHandler.ThrowOnFailure(AddItem(parentNode.ID, VSADDITEMOPERATION.VSADDITEMOP_OPENFILE, name, 1,
new[] {targetPath}, IntPtr.Zero, result));
if (result[0] != VSADDRESULT.ADDRESULT_Success)
throw new Exception();
newNode = FindChild(targetPath);
if (newNode == null)
throw new Exception();
}
else if (Directory.Exists(targetPath))
{
newNode = CreateFolderNodes(targetPath);
}
return newNode;
}