//Add full path (one selected folder/file) with all items to tree private FolderMenuItem AddPathToMenuItemTree(FolderMenuItem item, string path) { string pr = Directory.GetDirectoryRoot(path); var parentPath = Directory.GetParent(path); if (parentPath != null) { string name = parentPath.FullName; var parent = AddPathToMenuItemTree(item, name); var found = parent.ChildFolderMenuItems.FirstOrDefault(i => String.Compare(i.Path, path, true) == 0); if (found == null) { FileAttributes attr = File.GetAttributes(path); var newItem = new BackupFolderMenuItem() { IsFolder = true, Attributes = attr, Path = path, Name = path, ParentItem = parent, Selected = false }; parent.ChildFolderMenuItems.Add(newItem); return(newItem); } else { UpdateChildItemsInMenuItem(found); return(found); } } else { return(item); } }
//protected void AddFilesToFolderMenuItemBaseXXX(FolderMenuItem item, string itemPath, BackupSessionHistory history) //{ // var fileList = m_IStorage.GetFiles(itemPath); // foreach (var file in fileList.Where(f => !IsPathExistsInPathList(f, item.ChildFolderMenuItems))) // { // //var filePath = m_IStorage.Combine(item.Path, file); // var fileName = m_IStorage.GetFileName(file); // FileAttributes attr = File.GetAttributes(file); // if (!IsHidden(attr)) // { // bool bSelected = false; // var rp = m_IStorage.Combine(item.RelativePath, fileName); // item.ChildFolderMenuItems.Add(CreateMenuItem(m_IStorage.IsFolder(file), bSelected, file, rp, fileName, item, attr)); // } // } //} //---------- protected void UpdateSelectedFolders(BackupProfileData profile, FolderMenuItem item) { SelectItemDown(item); SelectItemUp(item); UpdateSelectedFolderList(profile); }
void AddFoldersToFolderMenuItem(FolderMenuItem item, string overridePath = null, BackupSessionHistory history = null) { var path = overridePath == null ? item.Path : overridePath; if (!m_IStorage.DirectoryExists(path)) { return; } var subdirectoryList = m_IStorage.GetDirectoriesNames(path); foreach (string subdirectory in subdirectoryList) { string newPath = m_IStorage.Combine(path, subdirectory); FileAttributes attr = m_IStorage.GetFileAttributes(newPath); if (!IsHidden(attr) && !IsNameExistsInNameList(subdirectory, item.ChildFolderMenuItems)) { HistoryTypeEnum?historyType = GetFolderHistoryType(m_IStorage.Combine(item.RelativePath, subdirectory)); //if (history == null)// || history.SessionHistoryIndex == 1 || historyType == HistoryTypeEnum.Deleted) { bool bSelected = item.Selected == true; var rp = m_IStorage.Combine(item.RelativePath, subdirectory); Application.Current.Dispatcher.Invoke(new Action(() => { item.ChildFolderMenuItems.Add(CreateMenuItem(m_IStorage.IsFolder(newPath), bSelected, newPath, rp, subdirectory, item, attr, historyType)); })); } } } }
public void FolderTreeClick(FolderMenuItem item, bool bSelected) { if (item != null) { DirtyFlag = true; item.Selected = bSelected; UpdateSelectedFolders(ProjectData.CurrentBackupProfile, item); } }
void SelectItemDown(FolderMenuItem item) { if (item != null) { foreach (var subItem in item.ChildFolderMenuItems) { subItem.Selected = item.Selected; SelectItemDown(subItem); } } }
FolderMenuItem GetMenuItemTree(FolderMenuItem item) { if (item.RelativePath == item.RelativePath) { return(item); } foreach (var childItem in item.ChildFolderMenuItems) { return(GetMenuItemTree(childItem)); } return(null); }
protected FolderMenuItem GetExistingMenuItem(bool isFolder, bool isSelected, string path, string relativePath, string name, FolderMenuItem parentItem, FileAttributes attr) { FolderMenuItem menuItem = null; foreach (var item in FolderMenuItemTree) { menuItem = GetMenuItemTree(item); if (menuItem != null) { return(menuItem); } } return(menuItem); }
//Add and update all subitems protected void UpdateChildItemsInMenuItem(FolderMenuItem item, string overridePath = null, BackupSessionHistory history = null) { var path = overridePath == null ? item.Path : overridePath; //Add all folders under item.Path if (item.IsFolder)// && (m_IStorage.DirectoryExists(path) || ) { //Add folders AddFoldersToFolderMenuItem(item, overridePath, history); //Add files AddFilesToFolderMenuItem(item, path, history); } }
protected override void AddFilesToFolderMenuItem(FolderMenuItem item, string itemPath, BackupSessionHistory history) { // AddFilesToFolderMenuItemBaseXXX(item, itemPath, history); var fileList = m_IStorage.GetFiles(itemPath); foreach (var file in fileList.Where(f => !IsPathExistsInPathList(f, item.ChildFolderMenuItems))) { //var filePath = m_IStorage.Combine(item.Path, file); var fileName = m_IStorage.GetFileName(file); FileAttributes attr = File.GetAttributes(file); if (!IsHidden(attr)) { bool bSelected = false; var rp = m_IStorage.Combine(item.RelativePath, fileName); item.ChildFolderMenuItems.Add(CreateMenuItem(m_IStorage.IsFolder(file), bSelected, file, rp, fileName, item, attr)); } } }
void SelectItemUp(FolderMenuItem item) { if (item != null) { var parent = item.ParentItem; if (parent != null) { bool?bValue = false; foreach (var parentItem in parent.ChildFolderMenuItems) { if (parentItem.Selected != false) { bValue = null; break; } } parent.Selected = bValue; SelectItemUp(parent); } item.IsExpanded = item.Selected == null; } }
protected override FolderMenuItem CreateMenuItem(bool isFolder, bool isSelected, string path, string relativePath, string name, FolderMenuItem parentItem, FileAttributes attr, HistoryTypeEnum?historyType = null) { var menuItem = new BackupFolderMenuItem() { IsFolder = isFolder, HistoryType = historyType, Attributes = attr, Path = path, RelativePath = relativePath, Name = name, ParentItem = parentItem, Selected = isSelected, }; return(menuItem); }
protected override void AddFilesToFolderMenuItem(FolderMenuItem item, string itemPath, BackupSessionHistory history) { var profile = ProjectData.CurrentBackupProfile; if ((profile.BackupType != BackupTypeEnum.Differential) || (RestoreActionType == RestoreActionTypeEnum.LatestVersion)) { var fileList = m_IStorage.GetFiles(itemPath); foreach (var file in fileList.Where(f => !IsPathExistsInPathList(f, item.ChildFolderMenuItems))) { //var filePath = m_IStorage.Combine(item.Path, file); var fileName = m_IStorage.GetFileName(file); FileAttributes attr = File.GetAttributes(file); if (!IsHidden(attr)) { bool bSelected = false; var rp = m_IStorage.Combine(item.RelativePath, fileName); item.ChildFolderMenuItems.Add(CreateMenuItem(m_IStorage.IsFolder(file), bSelected, file, rp, fileName, item, attr)); } } } else { ////History Items if (history != null) { foreach (var historyItem in history.HistoryData?.HistoryItemList) { //var filePath = m_IStorage.Combine(item.Path, file); if ((m_IStorage.GetDirectoryName(historyItem.TargetPath) == itemPath) || (historyItem.HistoryType == HistoryTypeEnum.Deleted && (m_IStorage.GetDirectoryName(historyItem.SourcePath) == itemPath))) { var fileName = m_IStorage.GetFileName(historyItem.TargetPath); { bool bSelected = false; var rp = m_IStorage.Combine(item.RelativePath, fileName); var foundItem = item.ChildFolderMenuItems.Where(i => i.Name == fileName).FirstOrDefault(); var timeDate = history?.HistoryData?.TimeStamp; HistoryTypeEnum historyType = historyItem.HistoryType; if (foundItem == null) { var newItem = CreateMenuItem(historyItem.HistoryItemType == HistoryItemTypeEnum.Directory, bSelected, historyItem.TargetPath, rp, fileName, item, 0, historyType); Application.Current.Dispatcher.Invoke(new Action(() => { item.ChildFolderMenuItems.Add(newItem); })); foundItem = newItem; } var newMenuItem = CreateMenuItem(historyItem.HistoryItemType == HistoryItemTypeEnum.Directory, bSelected, historyItem.TargetPath, rp, timeDate.ToString(), foundItem, 0, historyType); Application.Current.Dispatcher.Invoke(new Action(() => { foundItem.ChildFolderMenuItems.Add(newMenuItem); })); } } } } //Latest items if (m_IStorage.DirectoryExists(itemPath)) { var fileList = m_IStorage.GetFiles(itemPath); foreach (var file in fileList) { //var filePath = m_IStorage.Combine(item.Path, file); var fileName = m_IStorage.GetFileName(file); FileAttributes attr = File.GetAttributes(file); if (!IsHidden(attr)) { bool bSelected = false; var rp = m_IStorage.Combine(item.RelativePath, fileName); var foundItem = item.ChildFolderMenuItems.Where(i => i.Name == fileName).FirstOrDefault(); bool bDeletedItem = false; HistoryTypeEnum historyType = HistoryTypeEnum.NoChange; bool bCreatedNew = false; if (foundItem == null) { if (history?.HistoryData?.SessionHistoryIndex > 1) { bDeletedItem = true; historyType = HistoryTypeEnum.Deleted; } var newItem = CreateMenuItem(m_IStorage.IsFolder(file), bSelected, file, rp, fileName, item, attr, historyType); Application.Current.Dispatcher.Invoke(new Action(() => { item.ChildFolderMenuItems.Add(newItem); })); foundItem = newItem; bCreatedNew = true; } if (bCreatedNew || foundItem.ChildFolderMenuItems.Where(i => i.Path == file).FirstOrDefault() == null) { if (bDeletedItem) { historyType = HistoryTypeEnum.Deleted; } else { historyType = HistoryTypeEnum.Changed; } var timeDate = history?.HistoryData?.TimeStamp; var newMenuItem = CreateMenuItem(m_IStorage.IsFolder(file), bSelected, file, rp, timeDate.ToString(), foundItem, attr, historyType); Application.Current.Dispatcher.Invoke(new Action(() => { foundItem.ChildFolderMenuItems.Add(newMenuItem); })); } } } } } }
protected abstract FolderMenuItem CreateMenuItem(bool isFolder, bool isSelected, string path, string relativePath, string name, FolderMenuItem parentItem, FileAttributes attr, HistoryTypeEnum?historyType = null);
protected abstract void AddFilesToFolderMenuItem(FolderMenuItem item, string itemPath, BackupSessionHistory history);