/// <summary> /// Adds a package group node to the game explorer view /// </summary> /// <param name="groupReference">PackageGroup reference.</param> public void AddPackageGroupNode(FileReference groupReference) { // Add the group node Pixbuf packageGroupIcon = IconManager.GetIcon("user-home"); TreeIter packageGroupNode = this.FiletreeStore.AppendValues(packageGroupIcon, groupReference.PackageGroup.GroupName, "", "Virtual file tree", (int)NodeType.PackageGroup); groupReference.ReferenceIter = packageGroupNode; this.PackageNodeItemMapping.Add(packageGroupNode, groupReference); VirtualFileReference virtualGroupReference = groupReference as VirtualFileReference; if (virtualGroupReference != null) { this.PackageGroupVirtualNodeMapping.Add(groupReference.PackageGroup, virtualGroupReference); } // Add the package folder subnode Pixbuf packageFolderIcon = IconManager.GetIcon("applications-other"); TreeIter packageFolderNode = this.FiletreeStore.AppendValues(packageGroupNode, packageFolderIcon, "Packages", "", "Individual packages", (int)NodeType.PackageFolder); groupReference.ChildReferences.First().ReferenceIter = packageFolderNode; this.PackageNodeItemMapping.Add(packageFolderNode, groupReference.ChildReferences.First()); }
/// <summary> /// Enumerates the files and subfolders in the specified package, starting at /// the provided root path. /// </summary> /// <param name="parentReferenceObject">Parent reference where the search should start.</param> private void EnumerateFilesAndFolders(object parentReferenceObject) { if (!this.ShouldProcessWork) { // Early drop out return; } FileReference parentReference = parentReferenceObject as FileReference; if (parentReference != null) { VirtualFileReference virtualParentReference = parentReference as VirtualFileReference; if (virtualParentReference != null) { EnumerateHardReference(virtualParentReference.HardReference); for (int i = 0; i < virtualParentReference.OverriddenHardReferences.Count; ++i) { EnumerateHardReference(virtualParentReference.OverriddenHardReferences[i]); } virtualParentReference.State = ReferenceState.Enumerated; } else { EnumerateHardReference(parentReference); // TODO: Probable issue, no assignment of state } } }
/// <summary> /// Adds a file reference to the game explorer view, attached to its parent reference /// </summary> /// <param name="childReference">Child file reference.</param> public void AddFileNode(FileReference childReference) { if (childReference.ParentReference.HasBeenAddedToTheUI() && !childReference.HasBeenAddedToTheUI()) { childReference.ParentReference.ChildReferences.Add(childReference); TreeIter parentIter = childReference.ParentReference.ReferenceIter; TreeIter node = CreateFileTreeNode(parentIter, childReference); childReference.ReferenceIter = node; this.PackageNodeItemMapping.Add(node, childReference); } // Now, let's add (or append to) the virtual node VirtualFileReference virtualParentReference = GetVirtualReference(childReference.ParentReference); if (virtualParentReference != null) { if (virtualParentReference.HasBeenAddedToTheUI()) { VirtualFileReference virtualChildReference = GetVirtualReference(childReference); if (virtualChildReference != null) { // Append this directory reference as an additional overridden hard reference virtualChildReference.OverriddenHardReferences.Add(childReference); } else { virtualChildReference = new VirtualFileReference(virtualParentReference, childReference.PackageGroup, childReference); if (!virtualParentReference.ChildReferences.Contains(virtualChildReference)) { virtualParentReference.ChildReferences.Add(virtualChildReference); // Create a new virtual reference and a node that maps to it. TreeIter virtualParentNode = virtualParentReference.ReferenceIter; TreeIter node = CreateFileTreeNode(virtualParentNode, virtualChildReference); virtualChildReference.ReferenceIter = node; this.PackageNodeItemMapping.Add(node, virtualChildReference); AddVirtualMapping(childReference, virtualChildReference); } } } } }
/// <summary> /// Adds a virtual mapping. /// </summary> /// <param name="hardReference">Hard reference.</param> /// <param name="virtualReference">Virtual reference.</param> private void AddVirtualMapping(FileReference hardReference, VirtualFileReference virtualReference) { PackageGroup referenceGroup = hardReference.PackageGroup; if (this.VirtualReferenceMappings.ContainsKey(referenceGroup)) { if (!this.VirtualReferenceMappings[referenceGroup].ContainsKey(hardReference.FilePath)) { this.VirtualReferenceMappings[referenceGroup].Add(hardReference.FilePath, virtualReference); } } else { Dictionary <string, VirtualFileReference> groupDictionary = new Dictionary <string, VirtualFileReference>(); groupDictionary.Add(hardReference.FilePath, virtualReference); this.VirtualReferenceMappings.Add(referenceGroup, groupDictionary); } }
/// <summary> /// Loads all packages in the currently selected game directory. This function does not enumerate files /// and directories deeper than one to keep the UI responsive. /// </summary> private void Reload_Implementation() { if (!HasPackageDirectoryChanged()) { return; } this.CachedPackageDirectories = GamePathStorage.Instance.GamePaths; this.PackageGroups.Clear(); if (this.CachedPackageDirectories.Count > 0) { this.WorkQueue.Clear(); this.NodeStorage.Clear(); } foreach (string packageDirectory in this.CachedPackageDirectories) { if (!Directory.Exists(packageDirectory)) { continue; } // Create the package group and add it to the available ones string folderName = Path.GetFileName(packageDirectory); PackageGroup packageGroup = new PackageGroup(folderName, packageDirectory); // TODO: Creating a package group is real slow. Speed it up this.PackageGroups.Add(folderName, packageGroup); // Create a virtual item reference that points to the package group VirtualFileReference packageGroupReference = new VirtualFileReference(packageGroup, new FileReference(packageGroup)) { State = ReferenceState.Enumerating }; // Create a virtual package folder for the individual packages under the package group FileReference packageGroupPackagesFolderReference = new FileReference(packageGroup, packageGroupReference, ""); // Add the package folder as a child to the package group node packageGroupReference.ChildReferences.Add(packageGroupPackagesFolderReference); // Send the package group node to the UI this.PackageGroupAddedArgs = new ReferenceEnumeratedEventArgs(packageGroupReference); RaisePackageGroupAdded(); // Add the packages in the package group as nodes to the package folder foreach (KeyValuePair <string, List <string> > packageListFile in packageGroup.PackageListfiles) { if (packageListFile.Value == null) { continue; } string packageName = Path.GetFileName(packageListFile.Key); FileReference packageReference = new FileReference(packageGroup, packageGroupPackagesFolderReference, packageName, ""); // Send the package node to the UI this.PackageEnumeratedArgs = new ReferenceEnumeratedEventArgs(packageReference); RaisePackageEnumerated(); // Submit the package as a work order, enumerating the topmost directories SubmitWork(packageReference); } } this.IsReloading = false; this.ArePackageGroupsLoaded = true; }
/// <summary> /// Initializes a new instance of the <see cref="VirtualFileReference"/> class, /// where the reference has a parent <see cref="VirtualFileReference"/>. /// </summary> /// <param name="parentVirtualReference">Parent virtual reference.</param> /// <param name="inPackageGroup">In group.</param> /// <param name="inHardReference">In hard reference.</param> public VirtualFileReference(VirtualFileReference parentVirtualReference, PackageGroup inPackageGroup, FileReference inHardReference) : this(inPackageGroup, inHardReference) { this.ParentReference = parentVirtualReference; }