private void OpenIMG(string path) { var img = BCLIM.MakeBMP(path, CHK_PNG.Checked); if (img == null) { try { var flim = new BFLIM(path); if (!flim.Footer.Valid) { return; } img = flim.GetBitmap(); } catch (Exception ree) { Console.WriteLine(ree.Message); return; } if (CHK_PNG.Checked) { var dir = Path.GetDirectoryName(path); var fn = Path.GetFileNameWithoutExtension(path); var outpath = Path.Combine(dir, $"{fn}.png"); img.Save(outpath); } } PB_BCLIM.Size = new Size(img.Width + 2, img.Height + 2); PB_BCLIM.BackgroundImage = img; int leftpad = PB_BCLIM.Location.X; int suggestedWidth = (leftpad * 2) + PB_BCLIM.Width + 10; if (Width < suggestedWidth) { Width = suggestedWidth; } int suggestedHeight = PB_BCLIM.Location.Y + PB_BCLIM.Height + leftpad + 30; if (Height < suggestedHeight) { Height = suggestedHeight; } }
public Dictionary <string, STGenericTexture> GetTextures() { Dictionary <string, STGenericTexture> textures = new Dictionary <string, STGenericTexture>(); if (File.Exists(FilePath)) { string folder = Path.GetDirectoryName(FilePath); foreach (var file in Directory.GetFiles(folder)) { try { if (Utils.GetExtension(file) == ".bflim") { BFLIM bflim = (BFLIM)STFileLoader.OpenFileFormat(file); if (!textures.ContainsKey(bflim.FileName)) { textures.Add(bflim.FileName, bflim); } } if (Utils.GetExtension(file) == ".bntx") { BNTX bntx = (BNTX)STFileLoader.OpenFileFormat(file); foreach (var tex in bntx.Textures) { if (!textures.ContainsKey(tex.Key)) { textures.Add(tex.Key, tex.Value); } } string fileName = Path.GetFileName(file); if (!header.TextureManager.BinaryContainers.ContainsKey(fileName)) { header.TextureManager.BinaryContainers.Add(fileName, bntx); } } } catch (Exception ex) { STErrorDialog.Show($"Failed to load texture {file}. ", "Layout Editor", ex.ToString()); } } } foreach (var archive in PluginRuntime.SarcArchives) { foreach (var file in archive.Files) { try { if (Utils.GetExtension(file.FileName) == ".bntx") { BNTX bntx = (BNTX)file.OpenFile(); file.FileFormat = bntx; foreach (var tex in bntx.Textures) { if (!textures.ContainsKey(tex.Key)) { textures.Add(tex.Key, tex.Value); } } if (!header.TextureManager.BinaryContainers.ContainsKey($"{archive.FileName}.bntx")) { header.TextureManager.BinaryContainers.Add($"{archive.FileName}.bntx", bntx); } } if (Utils.GetExtension(file.FileName) == ".bflim") { BFLIM bflim = (BFLIM)file.OpenFile(); string name = bflim.FileName; if (archive is SARC) { if (((SARC)archive).sarcData.HashOnly) { var sarcEntry = file as SARC.SarcEntry; //Look through all textures and find a hash match name = sarcEntry.TryGetHash(header.Textures, "timg"); name = Path.GetFileName(name); } } file.FileFormat = bflim; if (!textures.ContainsKey(bflim.FileName)) { textures.Add(name, bflim); } } } catch (Exception ex) { STErrorDialog.Show($"Failed to load texture {file.FileName}. ", "Layout Editor", ex.ToString()); } } if (!header.TextureManager.ArchiveFile.ContainsKey(archive.FileName)) { header.TextureManager.ArchiveFile.Add(archive.FileName, archive); } } return(textures); }
public List <STGenericTexture> AddTextures() { List <STGenericTexture> textures = new List <STGenericTexture>(); switch (Platform) { case PlatformType.WiiU: { var archive = ArchiveParent; if (archive == null) { return(null); } var matches = archive.Files.Where(p => p.FileName.Contains("bflim")).ToList(); string textureFolder = "timg"; if (matches.Count > 0) { textureFolder = System.IO.Path.GetDirectoryName(matches[0].FileName); } var bflim = BFLIM.CreateNewFromImage(); if (bflim == null) { return(textures); } textures.Add(bflim); var mem = new System.IO.MemoryStream(); bflim.Save(mem); archive.AddFile(new ArchiveFileInfo() { FileData = mem.ToArray(), FileName = System.IO.Path.Combine(textureFolder, bflim.Text).Replace('\\', '/'), }); } break; case PlatformType.Switch: { BNTX bntx = null; if (BinaryContainers.Count == 0) { //Create a new one if none exist //Method for saving these will come in the save dialog bntx = new BNTX(); bntx.IFileInfo = new IFileInfo(); bntx.FileName = "textures"; bntx.Load(new System.IO.MemoryStream(BNTX.CreateNewBNTX("textures"))); BinaryContainers.Add("textures", bntx); } else { //Use first container for now as archives only use one bntx = BinaryContainers.Values.FirstOrDefault(); } var importedTextures = bntx.ImportTexture(); //Load all the additional textues for (int i = 0; i < importedTextures.Count; i++) { textures.Add(importedTextures[i]); } } break; } return(textures); }