Exemplo n.º 1
0
        /// <summary>
        /// Updates the Index view window content
        /// </summary>
        private void UpdateIndexList()
        {
            if (_indexDetails == null)
            {
                _indexDetails = new ObservableImmutableList <IndexItem>();
            }

            _indexDetails.Clear();

            var tempList = EterFilesDal.ReadIndexFile(
                Path.Combine(MainWindowVm.Instance.SelectedWorkingProfile.WorkingDirectory, Filename),
                MainWindowVm.Instance.SelectedWorkingProfile.IndexKey,
                DisplayName);

            foreach (var item in tempList)
            {
                _indexDetails.Add(item);
            }

            NumberOfFiles = IndexDetails.Count;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes virtual view
        /// </summary>
        private async void InitializeVirtualView()
        {
            await Task.Run(() =>
            {
                // Clear list
                VirtualTreeViewItems.Clear();

                // Create first item
                VirtualTreeViewItems.Add(new TreeItemFolderVm(null)
                {
                    DisplayName = "Virtual view"
                });

                // Get all files
                var files = IOHelper.GetAllFilesFromDir(_workingDir)
                            .Where(x => String.Equals(x.Extension, _indexExtension, StringComparison.CurrentCultureIgnoreCase)).Reverse();

                // File counters
                double fileCounter    = 0;
                double totalFileCount = files.Count();

                // Loop through all files
                foreach (var file in files)
                {
                    // Get all items
                    var items = EterFilesDal.ReadIndexFile(file.FullName, _indexKey,
                                                           Path.GetFileNameWithoutExtension(file.Name));

                    if (items == null)
                    {
                        continue;
                    }

                    // Loop through all items of the index file
                    foreach (var item in items)
                    {
                        // Replace all backslashes with forward slashes
                        var path = item.Filename.Replace("\\", "/");

                        // Split by slash
                        var tokens = path.Split(new[] { '/' });

                        var currentTreeItem = VirtualTreeViewItems.First() as TreeItemFolderVm;

                        // If first layer item
                        if (tokens.Count() == 1)
                        {
                            currentTreeItem.Children.Add(new TreeItemFileVm()
                            {
                                DisplayName    = item.Filename,
                                Parent         = currentTreeItem,
                                EterFileParent = item.ParentFile,
                                Fullname       = item.Filename
                            });
                        }
                        else
                        {
                            // Token counter
                            int counter = 0;

                            // Holds a reference to the current full path
                            string currentFullpath = "";

                            // Loop through tokens
                            foreach (var token in tokens)
                            {
                                counter++;
                                currentFullpath += token + "/";

                                // Check if item already exists
                                var itemInTreeView =
                                    currentTreeItem.Children.FirstOrDefault(
                                        x =>
                                        String.Equals(token, x.DisplayName,
                                                      StringComparison.CurrentCultureIgnoreCase));

                                // Create item if not already there
                                if (itemInTreeView == null)
                                {
                                    // If last one
                                    if (counter == tokens.Count())
                                    {
                                        currentTreeItem.Children.Add(new TreeItemFileVm()
                                        {
                                            DisplayName    = token,
                                            Parent         = currentTreeItem,
                                            EterFileParent = item.ParentFile,
                                            Fullname       = item.Filename
                                        });
                                    }
                                    else
                                    {
                                        var obj = new TreeItemFolderVm()
                                        {
                                            DisplayName = token,
                                            Parent      = currentTreeItem,
                                            Fullname    = currentFullpath
                                        };

                                        currentTreeItem.Children.Add(obj);

                                        currentTreeItem = obj;
                                    }
                                }
                                else
                                {
                                    currentTreeItem = itemInTreeView as TreeItemFolderVm;
                                }
                            }
                        }
                    }

                    State = String.Format("Processing global hash table... {0}%", Math.Round(fileCounter++ / totalFileCount * 100, 2));
                }

                State = "Sorting list...";

                VirtualTreeViewItems = SortItemsByFolder(VirtualTreeViewItems);

                (VirtualTreeViewItems.First() as TreeItemFolderVm).IsExpanded = true;

                State = "All files have been processed.";
            });
        }