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
{
///
/// 加载所有的文件 Debug 用
///
///
///
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 GetData(string dir)
{
var list = new ObservableCollection();
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;
ExplorerItem folder1 = new ExplorerItem()
{
Name = "Work Documents",
Type = ExplorerItem.ExplorerItemType.Folder,
Children =
{
new ExplorerItem()
{
Name = "Functional Specifications",
Type = ExplorerItem.ExplorerItemType.Folder,
Children =
{
new ExplorerItem()
{
Name = "TreeView spec",
Type = ExplorerItem.ExplorerItemType.File,
}
}
},
new ExplorerItem()
{
Name = "Feature Schedule",
Type = ExplorerItem.ExplorerItemType.File,
},
new ExplorerItem()
{
Name = "Overall Project Plan",
Type = ExplorerItem.ExplorerItemType.File,
},
new ExplorerItem()
{
Name = "Feature Resources Allocation",
Type = ExplorerItem.ExplorerItemType.File,
}
}
};
ExplorerItem folder2 = new ExplorerItem()
{
Name = "Personal Folder",
Type = ExplorerItem.ExplorerItemType.Folder,
Children =
{
new ExplorerItem()
{
Name = "Home Remodel Folder",
Type = ExplorerItem.ExplorerItemType.Folder,
Children =
{
new ExplorerItem()
{
Name = "Contractor Contact Info",
Type = ExplorerItem.ExplorerItemType.File,
},
new ExplorerItem()
{
Name = "Paint Color Scheme",
Type = ExplorerItem.ExplorerItemType.File,
},
new ExplorerItem()
{
Name = "Flooring Woodgrain type",
Type = ExplorerItem.ExplorerItemType.File,
},
new ExplorerItem()
{
Name = "Kitchen Cabinet Style",
Type = ExplorerItem.ExplorerItemType.File,
}
}
}
}
};
list.Add(folder1);
list.Add(folder2);
return list;
}
}