private static EntityModel FindOrCreateFolder(FolderModel rootFolder, string path) { string[] pathItems = path.Split('\\'); if (pathItems.Length > 1) { EntityModel parentFolder = rootFolder; for (int i = 0; i < pathItems.Length - 1; i++) { bool found = false; foreach (EntityModel subFolder in parentFolder.Entities) { if (subFolder.Type == "Folder") { if (subFolder.Name == pathItems[i]) { found = true; parentFolder = subFolder; } } } if (!found) { var childFolder = new FolderModel(pathItems[i]); parentFolder.Entities.Add(childFolder); parentFolder = childFolder; } } return(parentFolder); } return(rootFolder); }
public static EntityModel Load(Torrent torrent) { var root = new FolderModel(torrent.Name); foreach (TorrentFile file in torrent.Files) { var folder = FindOrCreateFolder(root, file.Path); folder.Entities.Add(new FileModel(file)); } return(root); }
public static EntityModel Load(string title, LocateResult result) { var root = new FolderModel(title); foreach (TorrentFileLink file in result.TorrentFileLinks) { var folder = FindOrCreateFolder(root, file.TorrentFile.Path); var fileModel = new FileModel(file.TorrentFile); fileModel.Located = file.State == LinkState.Located; folder.Entities.Add(fileModel); } return(root); }
public static EntityModel Load(string path) { if (!Directory.Exists(path)) { return(null); } var folderModel = new FolderModel(Path.GetFileName(path)); folderModel.FullName = path; foreach (var file in Directory.GetFiles(path)) { folderModel.Entities.Add(new FileModel(file)); } foreach (var subFolder in Directory.GetDirectories(path)) { folderModel.Entities.Add(Load(subFolder)); } return(folderModel); }
public static EntityModel Load(string path) { if (!Directory.Exists(path)) { return null; } var folderModel = new FolderModel(Path.GetFileName(path)); folderModel.FullName = path; foreach (var file in Directory.GetFiles(path)) { folderModel.Entities.Add(new FileModel(file)); } foreach (var subFolder in Directory.GetDirectories(path)) { folderModel.Entities.Add(Load(subFolder)); } return folderModel; }
private static EntityModel FindOrCreateFolder(FolderModel rootFolder, string path) { string[] pathItems = path.Split('\\'); if (pathItems.Length > 1) { EntityModel parentFolder = rootFolder; for (int i = 0; i < pathItems.Length - 1; i++) { bool found = false; foreach (EntityModel subFolder in parentFolder.Entities) { if (subFolder.Type == "Folder") { if (subFolder.Name == pathItems[i]) { found = true; parentFolder = subFolder; } } } if (!found) { var childFolder = new FolderModel(pathItems[i]); parentFolder.Entities.Add(childFolder); parentFolder = childFolder; } } return parentFolder; } return rootFolder; }
public static EntityModel Load(string title, LocateResult result) { var root = new FolderModel(title); foreach (TorrentFileLink file in result.TorrentFileLinks) { var folder = FindOrCreateFolder(root, file.TorrentFile.Path); var fileModel = new FileModel(file.TorrentFile); fileModel.Located = file.State == LinkState.Located; folder.Entities.Add(fileModel); } return root; }
public static EntityModel Load(Torrent torrent) { var root = new FolderModel(torrent.Name); foreach (TorrentFile file in torrent.Files) { var folder = FindOrCreateFolder(root, file.Path); folder.Entities.Add(new FileModel(file)); } return root; }