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); } } }
public PackageSystem(List <string> packages) { _rootNode = new PackageNode() { Name = "root", Directory = true }; HLLib.hlInitialize(); foreach (var package in packages) { if (Directory.Exists(package)) { FindDirFiles(package, _rootNode); continue; } HLLib.HLPackageType type = HLLib.hlGetPackageTypeFromName(package); uint packagePointer; if (!HLLib.hlCreatePackage(type, out packagePointer)) { throw new Exception("Can't load package: " + HLLib.hlGetString(HLLib.HLOption.HL_ERROR_SHORT_FORMATED)); } HLLib.hlBindPackage(packagePointer); if (!HLLib.hlPackageOpenFile(package, (uint)HLLib.HLFileMode.HL_MODE_READ)) { throw new Exception("Can't load package: " + HLLib.hlGetString(HLLib.HLOption.HL_ERROR_SHORT_FORMATED)); } _rootNode.FileSize = 0; var rootItems = HLLib.hlFolderGetCount(HLLib.hlPackageGetRoot()); for (uint i = 0; i < rootItems; i++) { var item = HLLib.hlFolderGetItem(HLLib.hlPackageGetRoot(), i); uint size; HLLib.hlItemGetSize(item, out size); _rootNode.FileSize += size; } FindFiles(HLLib.hlPackageGetRoot(), _rootNode, packagePointer); //HLLib.hlPackageClose(); } }
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); } } }