private bool TryLoadSkinPicture(string path, out Image picture) { Image img = null; Action <Stream> getStream = (Stream stream) => { img = Image.FromStream(stream); }; if (WotPkg.TryExtractFile(Path.Combine(gamePath, @"res\packages\gui-part1.pkg"), path, getStream, verbose: false) && img != null) { picture = img; return(true); } if (WotPkg.TryExtractFile(Path.Combine(gamePath, @"res\packages\gui-part2.pkg"), path, getStream, verbose: false) && img != null) { picture = img; return(true); } picture = null; return(false); }
static int Extract(ExtractOptions opts) { if (string.IsNullOrWhiteSpace(opts.Output)) { opts.Output = opts.File; } return(WotPkg.TryExtractFile(opts.Input, opts.File, (Stream stream) => { Directory.CreateDirectory(Path.GetDirectoryName(opts.Output)); if (opts.Decode) { if (WotXml.TryDecodeXml(opts.File, stream, out var decodedXml)) { File.WriteAllText(opts.Output, decodedXml); } } else { using (var fileStream = File.OpenWrite(opts.Output)) { stream.CopyTo(fileStream); } } }) ? 0 : 1); }
public List <Skin> GetSkins() { List <Skin> result = new List <Skin>(); if (!WotPkg.TryExtractFile(Path.Combine(gamePath, @"res\packages\scripts.pkg"), StylesListXmlPath, FetchDecodedXml)) { throw new Exception("Failed to extract styles list from pkg"); } Dictionary <string, Image> images = new Dictionary <string, Image>(StringComparer.InvariantCultureIgnoreCase); WotPkg.TryExtractDirectory( Path.Combine(gamePath, @"res\packages\gui-part1.pkg"), "gui/maps/vehicles/styles/", (stream, entry) => { if (entry.Name.EndsWith(".png", StringComparison.InvariantCultureIgnoreCase)) { var img = Image.FromStream(stream); images[entry.FullName] = img; } }); WotPkg.TryExtractDirectory( Path.Combine(gamePath, @"res\packages\gui-part2.pkg"), "gui/maps/vehicles/styles/", (stream, entry) => { if (entry.Name.EndsWith(".png", StringComparison.InvariantCultureIgnoreCase)) { var img = Image.FromStream(stream); images[entry.FullName] = img; } }); var xmlrefNode = ListXMLDocument.DocumentElement.SelectSingleNode("/list.xml/xmlref"); if (xmlrefNode != null) { ListXMLDocument.DocumentElement.RemoveChild(xmlrefNode); } int n = 0; foreach (XmlNode itemGroup in ListXMLDocument.DocumentElement.SelectNodes("/list.xml/itemGroup/style")) { n++; try { var skin = new Skin() { Id = int.Parse(itemGroup.SelectSingleNode("id").InnerText), Texture = itemGroup.SelectSingleNode("texture").InnerText, Name = itemGroup.SelectSingleNode("userString").InnerText, //TODO load translations? }; //some special style have no pictures if (!string.IsNullOrWhiteSpace(skin.Texture)) { //if (!TryLoadSkinPicture(skin.Texture, out var picture)) //{ // throw new Exception($"Failed to load picture '{skin.Texture}'"); //} //skin.Picture = picture; if (images.TryGetValue(skin.Texture, out var img)) { skin.Picture = img; } } result.Add(skin); } catch (Exception ex) { throw new Exception($"Failed to parse itemGroup #{n}", ex); } } foreach (var unusedImg in images.Where(i => !result.Any(r => r.Picture == i.Value))) { unusedImg.Value.Dispose(); } return(result); }