109 lines
3.4 KiB
C#
109 lines
3.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Windows.ApplicationModel.Payments;
|
|
|
|
namespace RustTools.Editor;
|
|
public class EditorLoad
|
|
{
|
|
/// <summary>
|
|
/// 加载所有的文件 Debug 用
|
|
/// </summary>
|
|
/// <param name="directoryInfo"></param>
|
|
/// <param name="parentItem"></param>
|
|
private void LoadDirectory(DirectoryInfo directoryInfo, ExplorerItem parentItem)
|
|
{
|
|
// 获取当前目录中的所有子目录
|
|
var directories = directoryInfo.GetDirectories();
|
|
foreach (var directory in directories)
|
|
{
|
|
// 创建新的 ExplorerItem 代表当前子目录
|
|
var folderItem = new ExplorerItem
|
|
{
|
|
Name = directory.Name,
|
|
Type = ExplorerItem.ExplorerItemType.Folder
|
|
};
|
|
|
|
// 将这个目录项添加到父级的 Children 集合中
|
|
parentItem.Children.Add(folderItem);
|
|
|
|
// 递归调用,继续加载子目录中的内容
|
|
LoadDirectory(directory, folderItem);
|
|
}
|
|
|
|
// 获取当前目录中的所有文件
|
|
var files = directoryInfo.GetFiles();
|
|
foreach (var file in files)
|
|
{
|
|
// 创建新的 ExplorerItem 代表当前文件
|
|
var fileItem = new ExplorerItem
|
|
{
|
|
Name = file.Name,
|
|
Type = ExplorerItem.ExplorerItemType.File
|
|
};
|
|
|
|
// 将这个文件项添加到父级的 Children 集合中
|
|
parentItem.Children.Add(fileItem);
|
|
}
|
|
}
|
|
|
|
|
|
public ObservableCollection<ExplorerItem> GetData(string dir)
|
|
{
|
|
var list = new ObservableCollection<ExplorerItem>();
|
|
|
|
var directoryInfos = new DirectoryInfo(dir);
|
|
|
|
// 创建根节点 ExplorerItem 根节点不显示防止用户删除
|
|
//var rootItem = new ExplorerItem
|
|
//{
|
|
// Name = directoryInfos.Name,
|
|
// Dir = directoryInfos.FullName,
|
|
// Type = ExplorerItem.ExplorerItemType.Folder,
|
|
//};
|
|
//LoadDirectory(directoryInfos,rootItem);
|
|
foreach (var file in directoryInfos.GetDirectories()) {
|
|
var explorerItem = new ExplorerItem()
|
|
{
|
|
Name = file.Name,
|
|
Dir = file.FullName,
|
|
Type = ExplorerItem.ExplorerItemType.Folder
|
|
};
|
|
list.Add(explorerItem);
|
|
foreach (var a in file.GetDirectories())
|
|
{
|
|
explorerItem.Children.Add(new ExplorerItem()
|
|
{
|
|
Name = a.Name,
|
|
Dir = a.FullName,
|
|
Type = ExplorerItem.ExplorerItemType.Folder
|
|
});
|
|
}
|
|
foreach (var a in file.GetFiles())
|
|
{
|
|
explorerItem.Children.Add(new ExplorerItem()
|
|
{
|
|
Name = a.Name,
|
|
Dir = a.FullName,
|
|
Type = ExplorerItem.ExplorerItemType.File
|
|
});
|
|
}
|
|
}
|
|
foreach (var file in directoryInfos.GetFiles())
|
|
{
|
|
list.Add(new ExplorerItem()
|
|
{
|
|
Name = file.Name,
|
|
Dir = file.FullName,
|
|
Type = ExplorerItem.ExplorerItemType.File
|
|
});
|
|
}
|
|
return list;
|
|
}
|
|
}
|