public override TexturePackage CreatePackage(string package) { var tp = new TexturePackage(package, this); var list = new List<TextureItem>(); try { HLLib.Initialize(); using (var pack = new HLLib.Package(package)) { var folder = pack.GetRootFolder(); var items = folder.GetItems(); list.AddRange(items .Select(item => new HLLib.WADFile(item)) .Where(wad => IsValidLumpType(wad.GetLumpType())) .Select(wad => new TextureItem(tp, StripExtension(wad.Name), wad.Width, wad.Height))); } } finally { HLLib.Shutdown(); } foreach (var ti in list) { tp.AddTexture(ti); } return tp; }
public override void LoadTextures(IEnumerable<TextureItem> items) { var list = items.ToList(); var packages = list.Select(x => x.Package).Distinct(); try { HLLib.Initialize(); foreach (var package in packages) { var p = package; using (var pack = new HLLib.Package(p.PackageFile)) { var folder = pack.GetRootFolder(); foreach (var ti in list.Where(x => x.Package == p)) { var item = folder.GetItemByName(ti.Name + ".bmp", HLLib.FindType.Files); if (!item.Exists) continue; using (var stream = pack.CreateStream(item)) { var bmp = new Bitmap(new MemoryStream(stream.ReadAll())); bool hasTransparency; bmp = PostProcessBitmap(ti.Name, bmp, out hasTransparency); TextureHelper.Create(ti.Name.ToLowerInvariant(), bmp, hasTransparency); bmp.Dispose(); } } } } } finally { HLLib.Shutdown(); } }
public WadStreamSource(IEnumerable<TexturePackage> packages) { _texturePackages = new List<TexturePackage>(); _packages = new Dictionary<string, Tuple<HLLib.Package, HLLib.Folder>>(); HLLib.Initialize(); foreach (var tp in packages) { if (_packages.ContainsKey(tp.PackageFile)) continue; var pack = new HLLib.Package(tp.PackageFile); _texturePackages.Add(tp); _packages.Add(tp.PackageFile, Tuple.Create(pack, pack.GetRootFolder())); } }