working
This commit is contained in:
@@ -1,14 +1,22 @@
|
||||
namespace SharpIDE.Application.Features.SolutionDiscovery;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace SharpIDE.Application.Features.SolutionDiscovery;
|
||||
|
||||
public class Folder
|
||||
{
|
||||
public required string Name { get; set; }
|
||||
public required string FullName { get; set; }
|
||||
public required Folder? ParentFolder { get; set; }
|
||||
public required List<MyFile> Files { get; set; } = [];
|
||||
public required string Path { get; set; }
|
||||
public string Name { get; set; } = null!;
|
||||
public List<Folder> Folders { get; set; } = [];
|
||||
public List<TreeMapFile> Files { get; set; } = [];
|
||||
public bool IsPseudoFolder { get; set; }
|
||||
public int Depth { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public bool Expanded { get; set; }
|
||||
}
|
||||
|
||||
public class MyFile
|
||||
public class TreeMapFile
|
||||
{
|
||||
public required string Path { get; set; }
|
||||
public required string Name { get; set; }
|
||||
}
|
||||
|
||||
@@ -44,35 +44,7 @@ public static class GetNodesInSolution
|
||||
var rootDirectoryOfProject = new DirectoryInfo(Path.GetDirectoryName(projectPath)!);
|
||||
|
||||
var grouped = files.GroupBy(s => s.Directory!.FullName);
|
||||
var folders = grouped.Select(s => new Folder
|
||||
{
|
||||
Name = Path.GetFileName(s.Key),
|
||||
FullName = s.Key,
|
||||
ParentFolder = null,
|
||||
Files = s.Select(f => new MyFile
|
||||
{
|
||||
Name = f.Name
|
||||
}).ToList()
|
||||
}).ToList();
|
||||
|
||||
foreach (var folder in folders)
|
||||
{
|
||||
var directoryInfo = new DirectoryInfo(folder.FullName);
|
||||
if (directoryInfo.FullName == rootDirectoryOfProject.FullName) continue;
|
||||
|
||||
var parent = directoryInfo.Parent;
|
||||
try
|
||||
{
|
||||
var parentFolder = folders.SingleOrDefault(f => f.FullName == parent!.FullName);
|
||||
folder.ParentFolder = parentFolder;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
}
|
||||
}
|
||||
|
||||
return folders;
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace SharpIDE.Application.Features.SolutionDiscovery;
|
||||
|
||||
public static class TreeMapper
|
||||
{
|
||||
public static List<Folder> GetSubFolders(this Folder folder)
|
||||
{
|
||||
var directoryInfo = new DirectoryInfo(folder.Path);
|
||||
|
||||
ConcurrentBag<Folder> subFolders = [];
|
||||
|
||||
var files = GetFiles(directoryInfo);
|
||||
if (files.Count is not 0)
|
||||
{
|
||||
var pseudoFolder = new Folder
|
||||
{
|
||||
Path = folder.Path,
|
||||
Name = "<Files>",
|
||||
IsPseudoFolder = true,
|
||||
Files = files,
|
||||
Depth = folder.Depth + 1
|
||||
};
|
||||
subFolders.Add(pseudoFolder);
|
||||
}
|
||||
|
||||
List<DirectoryInfo> subFolderInfos;
|
||||
try
|
||||
{
|
||||
subFolderInfos = directoryInfo.EnumerateDirectories("*", new EnumerationOptions { IgnoreInaccessible = false, AttributesToSkip = FileAttributes.ReparsePoint}).ToList();
|
||||
}
|
||||
catch (UnauthorizedAccessException)
|
||||
{
|
||||
return subFolders.ToList();
|
||||
}
|
||||
Parallel.ForEach(subFolderInfos, subFolderInfo =>
|
||||
{
|
||||
var subFolder = new Folder
|
||||
{
|
||||
Path = subFolderInfo.FullName,
|
||||
Name = subFolderInfo.Name,
|
||||
Depth = folder.Depth + 1
|
||||
};
|
||||
subFolder.Folders = subFolder.GetSubFolders();
|
||||
subFolders.Add(subFolder);
|
||||
});
|
||||
return subFolders.ToList();
|
||||
}
|
||||
|
||||
public static List<TreeMapFile> GetFiles(DirectoryInfo directoryInfo)
|
||||
{
|
||||
List<FileInfo> fileInfos;
|
||||
try
|
||||
{
|
||||
fileInfos = directoryInfo.EnumerateFiles().ToList();
|
||||
}
|
||||
catch (UnauthorizedAccessException)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
var files = fileInfos.Select(s => new TreeMapFile
|
||||
{
|
||||
Path = s.FullName,
|
||||
Name = s.Name
|
||||
}).ToList();
|
||||
return files;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user