public void RecursiveBuildFromVPK(ref ProjectFolder folder, IntPtr currentFolder) { uint folderCount = HLLib.hlFolderGetCount(currentFolder); for (uint i = 0; i < folderCount; i++) { IntPtr subItem = HLLib.hlFolderGetItem(currentFolder, i); string name = HLLib.hlItemGetName(subItem); if (HLLib.hlItemGetType(subItem) == HLLib.HLDirectoryItemType.HL_ITEM_FOLDER) { DomNode sf = new DomNode(DotaObjectsSchema.FolderType.Type); sf.SetAttribute(DotaObjectsSchema.FolderType.NameAttribute, name); sf.SetAttribute(DotaObjectsSchema.FolderType.PathAttribute, folder.Path + "/" + name); sf.SetAttribute(DotaObjectsSchema.FolderType.InGCFAttribute, true); DomNode par = folder.As <DomNode>(); par.GetChildList(DotaObjectsSchema.FolderType.FilesChild).Add(sf); ProjectFolder subFolder = sf.As <ProjectFolder>(); RecursiveBuildFromVPK(ref subFolder, subItem); } if (HLLib.hlItemGetType(subItem) == HLLib.HLDirectoryItemType.HL_ITEM_FILE) { string ext = name.Substring(name.LastIndexOf('.')); ProjectFile f; if (ProjectLoader.FileTypes.ContainsKey(ext)) { ProjectLoader.FileTypeResolver resolver = ProjectLoader.FileTypes[ext]; f = (ProjectFile)(new DomNode(resolver.DomNodeType)).As(resolver.WrapperType); } else { f = (new DomNode(DotaObjectsSchema.FileType.Type)).As <ProjectFile>(); } f.Name = name; f.Path = folder.Path + "/" + name; f.InGCF = true; folder.Files.Add(f); } } }
private void FindFiles(IntPtr dir, PackageNode node, uint package) { uint count = HLLib.hlFolderGetCount(dir); for (uint i = 0; i < count; i++) { var item = HLLib.hlFolderGetItem(dir, i); var itemNode = new PackageNode(); itemNode.Name = HLLib.hlItemGetName(item).ToLower(); itemNode.Directory = HLLib.hlItemGetType(item) == HLLib.HLDirectoryItemType.HL_ITEM_FOLDER; var pathPtr = Marshal.AllocHGlobal(255); HLLib.hlItemGetPath(item, pathPtr, 255); var pathBuffer = new byte[255]; Marshal.Copy(pathPtr, pathBuffer, 0, 255); itemNode.Path = Encoding.ASCII.GetString(pathBuffer).TrimEnd('\0').ToLower(); uint filesize; HLLib.hlItemGetSize(item, out filesize); itemNode.FileSize = filesize; if (itemNode.Directory) { if (node.Directories.ContainsKey(itemNode.Name)) { FindFiles(item, node.Directories[itemNode.Name], package); } else { FindFiles(item, itemNode, package); node.Directories[itemNode.Name] = itemNode; } } else { itemNode.FilePtr = item; itemNode.FilePackage = package; node.Files[itemNode.Name] = itemNode; } } }
protected void RecursivePopulateFromVPK(ref TreeNode parent, IntPtr CurrentFolder) { uint folderCount = HLLib.hlFolderGetCount(CurrentFolder); for (uint i = 0; i < folderCount; i++) { IntPtr subItem = HLLib.hlFolderGetItem(CurrentFolder, i); string name = HLLib.hlItemGetName(subItem); if (HLLib.hlItemGetType(subItem) == HLLib.HLDirectoryItemType.HL_ITEM_FOLDER) { TreeNode folder = new TreeNode() { Name = name, Text = name, ImageIndex = 2, SelectedImageIndex = 2, Tag = ((string)parent.Tag) + name + "/", ContextMenu = folder_context_menu, }; parent.Nodes.Add(folder); RecursivePopulateFromVPK(ref folder, subItem); } else if (HLLib.hlItemGetType(subItem) == HLLib.HLDirectoryItemType.HL_ITEM_FILE) { TreeNode folder = new TreeNode() { Name = name, Text = name, ImageIndex = 0, Tag = ((string)parent.Tag) + name, ContextMenu = file_context_menu, }; parent.Nodes.Add(folder); } } }