Example #1
0
 protected virtual void ClearItemList()
 {
     Application.Current.Dispatcher.Invoke(new Action(() =>
     {
         FolderMenuItemTree?.Clear();
     }));
 }
        protected override void AddRootItemsToTree()
        {
            var profile = ProjectData.CurrentBackupProfile;

            ClearItemList();
            //m_BackupSetPathCacheList.Clear();

            m_LastSetPathCache = BackupBase.GetLastBackupSetPath_(profile);
            if (m_LastSetPathCache == null)
            {
                return;
            }

            //var lastSetARchivePath = m_IStorage.Combine(lastSetPath, BackupProfileData.TargetBackupBaseDirectoryName);

            var historyItem = SelectedHistoryItem;

            if (historyItem == null)
            {
                return;
            }

            var lastSetPath = m_IStorage.Combine(profile.GetTargetBackupFolder(), m_LastSetPathCache);

            string targetPath = null;

            if (historyItem.HistoryData?.HistoryItemList.Count() > 0)
            {
                string path     = historyItem.HistoryData?.HistoryItemList[0].TargetPath;
                string lastPath = path;
                while ((path != null) && (path != string.Empty) && (path != historyItem.HistoryData?.TargetPath))
                {
                    lastPath = path;
                    path     = m_IStorage.GetDirectoryName(path);
                }

                if ((path != null) && (path != string.Empty))
                {
                    targetPath = m_IStorage.Combine(lastPath, BackupProfileData.TargetBackupBaseDirectoryName);
                }
            }


            foreach (var item in profile.BackupFolderList.Where(i => i.IsAvailable))
            {
                var directoryName = m_IStorage.GetFileName(item.Path);
                var restorePath   = m_IStorage.Combine(lastSetPath, item.Name);

                var rootItem = CreateMenuItem(m_IStorage.IsFolder(restorePath), false, restorePath, directoryName, directoryName, null, 0);

                UpdateChildItemsInMenuItem(rootItem);

                Application.Current.Dispatcher.Invoke(new Action(() =>
                {
                    FolderMenuItemTree.Add(rootItem);
                }));
            }
        }
        protected override void AddRootItemsToTree()
        {
            var ProfileData = ProjectData.CurrentBackupProfile;

            ClearItemList();


            DriveInfo[] drives = DriveInfo.GetDrives();

            //Add all available drives to list
            foreach (var drive in drives)
            {
                DirectoryInfo dInfo = drive.RootDirectory;

                var            name = drive.Name;
                FileAttributes attr = 0;
                try
                {
                    attr = File.GetAttributes(drive.Name);
                    name = $"{drive.VolumeLabel} ({drive.DriveType}) ({drive.Name})";
                }
                catch (IOException)
                {
                    name = name + " [Not Ready]";
                }

                var rootItem = new BackupFolderMenuItem()
                {
                    IsFolder     = true,
                    Attributes   = attr,
                    Path         = drive.Name,
                    RelativePath = drive.Name,
                    Name         = name,
                };

                try
                {
                    UpdateChildItemsInMenuItem(rootItem);
                }
                catch (Exception) { }

                Application.Current.Dispatcher.Invoke(new Action(() =>
                {
                    FolderMenuItemTree.Add(rootItem);
                }));
            }

            //Add selected folders to tree list
            var itemList = new List <FolderMenuItem>();

            //        Application.Current.Dispatcher.Invoke(new Action(() =>
            //        {
            foreach (var folder in SelectedItemList)
            {
                string pr    = Directory.GetDirectoryRoot(folder.Path);
                var    match = FolderMenuItemTree.FirstOrDefault(f => String.Compare(f.Path, pr, true) == 0);

                if (match != null)
                {
                    try
                    {
                        var item = AddPathToMenuItemTree(match, folder.Path);
                        itemList.Add(item);
                    }
                    catch (FileNotFoundException)
                    {
                        ProfileData.Logger.Writeln($"***Warning: Backup item not available: {folder.Path}");
                    }
                }
            }
            //           }));

            //After we added the folders, we need update selected folders root items to mark the correct selection
            foreach (var item in itemList)
            {
                item.Selected = true;
                Application.Current.Dispatcher.Invoke(new Action(() =>
                {
                    UpdateSelectedFolders(ProfileData, item);
                }));
            }
        }
        protected override void AddRootItemsToTree()
        {
            var profile = ProjectData.CurrentBackupProfile;

            ClearItemList();
            //m_BackupSetPathCacheList.Clear();

            m_LastSetPathCache = BackupBase.GetLastBackupSetPath_(profile);

            if (m_LastSetPathCache == null)
            {
                return;
            }

            switch (profile.BackupType)
            {
            case BackupTypeEnum.Snapshot:
            case BackupTypeEnum.Incremental:
            {
                var lastSetPath = m_IStorage.Combine(profile.GetTargetBackupFolder(), m_LastSetPathCache);

                foreach (var item in profile.BackupFolderList.Where(i => i.IsAvailable))
                {
                    var directoryName = m_IStorage.GetFileName(item.Path);
                    var restorePath   = m_IStorage.Combine(lastSetPath, item.Name);

                    if (m_IStorage.DirectoryExists(restorePath) || m_IStorage.FileExists(restorePath))
                    {
                        var rootItem = CreateMenuItem(m_IStorage.IsFolder(restorePath), false, restorePath, directoryName, directoryName, null, 0);

                        UpdateChildItemsInMenuItem(rootItem);

                        Application.Current.Dispatcher.Invoke(new Action(() =>
                            {
                                FolderMenuItemTree.Add(rootItem);
                            }));
                    }
                    else
                    {
                        profile.Logger.Writeln($"Skipping restore item, Item not found: {restorePath}");
                    }
                }
            }

            break;

            case BackupTypeEnum.Differential:
            {
                var backSetList = BackupBase.GetBackupSetList_(profile);
                //var lastSetName = BackupBase.GetLastBackupSetPath_(profile);

                //foreach (var setPath in backSetList.Where(p => p != m_LastSetPathCache))
                //{
                //    m_BackupSetPathCacheList.Add(m_IStorage.Combine(profile.GetTargetBackupFolder(), setPath));
                //}

                m_RootFolderMenuItemTree.ParentItem   = null;
                m_RootFolderMenuItemTree.IsFolder     = true;
                m_RootFolderMenuItemTree.Path         = profile.GetTargetBackupFolder();
                m_RootFolderMenuItemTree.RelativePath = string.Empty;
                m_RootFolderMenuItemTree.Name         = "BACKUP";

                int iSessionIndex = 0;
                foreach (var setPath in backSetList)
                {
                    iSessionIndex++;
                    var sessionHistory = BackupSessionHistory.LoadHistory(profile.GetTargetBackupFolder(), setPath);
                    if (sessionHistory == null)
                    {
                        Trace.WriteLine("Error, Select Restore Differential Items, History is null");
                    }
                    else
                    {
                        sessionHistory.HistoryData.SessionHistoryIndex = iSessionIndex;

                        var lastSetPath = m_IStorage.Combine(m_IStorage.Combine(profile.GetTargetBackupFolder(), setPath), BackupProfileData.TargetBackupBaseDirectoryName);

                        m_RootFolderMenuItemTree.Path = lastSetPath;

                        //update add root items
                        UpdateChildItemsInMenuItem(m_RootFolderMenuItemTree, lastSetPath, sessionHistory);

                        foreach (var subItem in m_RootFolderMenuItemTree.ChildFolderMenuItems)
                        {
                            var newPath = m_IStorage.Combine(lastSetPath, subItem.RelativePath);
                            UpdateChildItemsInMenuItem(subItem, newPath, sessionHistory);
                        }
                    }
                }
            }
            break;

            default:
                break;
            }
        }