private bool ExtractRBA(string rba) { if (backgroundWorker1.CancellationPending) { return(false); } thumbnail = ""; basesongname = Path.GetFileNameWithoutExtension(rba).Replace(" ", "").Trim(); if (basesongname.Length > 26) { basesongname = basesongname.Substring(0, 26); } try { using (var bReadRba = new BinaryReader(File.Open(rba, FileMode.Open))) { var signature = bReadRba.ReadChars(4); if ((signature[0] != 'R') || (signature[1] != 'B') || (signature[2] != 'S') || (signature[3] != 'F')) { Log("Unknown file format, can't convert file " + Path.GetFileName(rba)); return(false); } var rba_header_values = new int[(int)RBA_HEADER_INDEX.HEADER_INDEX_COUNT]; for (var i = 0; i < (int)RBA_HEADER_INDEX.HEADER_INDEX_COUNT; i++) { var v = bReadRba.ReadInt32(); rba_header_values[i] = v; } if (rba_header_values[(int)RBA_HEADER_INDEX.OFFSET_SONGS_DTA] != 0) { var offset = rba_header_values[(int)RBA_HEADER_INDEX.OFFSET_SONGS_DTA]; var len = rba_header_values[(int)RBA_HEADER_INDEX.LENGTH_SONGS_DTA]; bReadRba.BaseStream.Seek(offset, SeekOrigin.Begin); var data = bReadRba.ReadBytes(len); var fname = tempfolder + "songs.dta.raw"; using (var bWrite = new BinaryWriter(File.Open(fname, FileMode.Create))) { bWrite.Write(data); bWrite.Dispose(); } RBAPatchSongsDta(Path.GetExtension(rba).ToLowerInvariant() == ".rbs"); } if (rba_header_values[(int)RBA_HEADER_INDEX.OFFSET_MID] != 0) { var offset = rba_header_values[(int)RBA_HEADER_INDEX.OFFSET_MID]; var len = rba_header_values[(int)RBA_HEADER_INDEX.LENGTH_MID]; bReadRba.BaseStream.Seek(offset, SeekOrigin.Begin); var data = bReadRba.ReadBytes(len); var fname = tempfolder + basesongname + ".mid"; using (var bWrite = new BinaryWriter(File.Open(fname, FileMode.Create))) { bWrite.Write(data); bWrite.Dispose(); } } if (rba_header_values[(int)RBA_HEADER_INDEX.OFFSET_MOGG] != 0) { var offset = rba_header_values[(int)RBA_HEADER_INDEX.OFFSET_MOGG]; var len = rba_header_values[(int)RBA_HEADER_INDEX.LENGTH_MOGG]; bReadRba.BaseStream.Seek(offset, SeekOrigin.Begin); var data = bReadRba.ReadBytes(len); var fname = tempfolder + basesongname + ".mogg"; using (var bWrite = new BinaryWriter(File.Open(fname, FileMode.Create))) { bWrite.Write(data); bWrite.Dispose(); } } if (rba_header_values[(int)RBA_HEADER_INDEX.OFFSET_MILO_XBOX] != 0) { var offset = rba_header_values[(int)RBA_HEADER_INDEX.OFFSET_MILO_XBOX]; var len = rba_header_values[(int)RBA_HEADER_INDEX.LENGTH_MILO_XBOX]; bReadRba.BaseStream.Seek(offset, SeekOrigin.Begin); var data = bReadRba.ReadBytes(len); var fname = tempfolder + basesongname + ".milo_xbox"; using (var bWrite = new BinaryWriter(File.Open(fname, FileMode.Create))) { bWrite.Write(data); bWrite.Dispose(); } } if (rba_header_values[(int)RBA_HEADER_INDEX.OFFSET_BMP] != 0) { var offset = rba_header_values[(int)RBA_HEADER_INDEX.OFFSET_BMP]; var len = rba_header_values[(int)RBA_HEADER_INDEX.LENGTH_BMP]; bReadRba.BaseStream.Seek(offset, SeekOrigin.Begin); var data = bReadRba.ReadBytes(len); var fname = tempfolder + basesongname + (Path.GetExtension(rba).ToLowerInvariant() == ".rbs" ? "_keep.png_xbox" : ".bmp"); using (var bWrite = new BinaryWriter(File.Open(fname, FileMode.Create))) { bWrite.Write(data); bWrite.Dispose(); } if (Path.GetExtension(rba).ToLowerInvariant() == ".rba") { var xboxfile = fname.Replace(".bmp", "_keep.png_xbox"); Tools.DeleteFile(xboxfile); Tools.TextureSize = 256; Tools.ConvertImagetoRB(fname, xboxfile); thumbnail = fname.Replace(".bmp", ".png"); Tools.DeleteFile(thumbnail); Tools.ResizeImage(fname, 64, "png", thumbnail); if (!File.Exists(thumbnail)) { thumbnail = ""; } } } if (rba_header_values[(int)RBA_HEADER_INDEX.OFFSET_WEIGHTS] != 0) { var offset = rba_header_values[(int)RBA_HEADER_INDEX.OFFSET_WEIGHTS]; var len = rba_header_values[(int)RBA_HEADER_INDEX.LENGTH_WEIGHTS]; bReadRba.BaseStream.Seek(offset, SeekOrigin.Begin); var data = bReadRba.ReadBytes(len); var fname = tempfolder + basesongname + ".bin"; using (var bWrite = new BinaryWriter(File.Open(fname, FileMode.Create))) { bWrite.Write(data); bWrite.Close(); } } bReadRba.Dispose(); return(true); } } catch (Exception e) { Log("Error extracting RBA file " + Path.GetFileName(rba)); Log(e.ToString()); return(false); } }
private void GetImage(String file, PictureBox box) { if (picWorking.Visible) { return; } try { string contentImage = null; //if not passed a string path for the image //show dialog box to find one if (string.IsNullOrWhiteSpace(file)) { var openFileDialog1 = new OpenFileDialog { Filter = "Image Files|*.bmp;*.jpg;*.jpeg;*.png", Title = "Select an image", InitialDirectory = Application.StartupPath + "\\res\\thumbs" }; if (openFileDialog1.ShowDialog() == DialogResult.OK) { contentImage = openFileDialog1.FileName; Tools.CurrentFolder = Path.GetDirectoryName(openFileDialog1.FileName); } } else { //if file is not blank, then use that for the image if ((file.Contains(".jpg") || file.Contains(".bmp") || file.Contains(".png") || file.Contains(".jpeg")) && !file.Contains(".png_xbox") && !file.Contains(".png_wii")) { contentImage = file; } else { return; } } if (string.IsNullOrWhiteSpace(contentImage)) { return; } var thumbnail = Tools.NemoLoadImage(contentImage); if (thumbnail.Width == 64 && thumbnail.Height == 64) { box.Image = thumbnail; return; } var newimage = Path.GetTempPath() + Path.GetFileNameWithoutExtension(contentImage) + ".png"; Tools.ResizeImage(contentImage, 64, "png", newimage); if (File.Exists(newimage)) { box.Image = Tools.NemoLoadImage(newimage); } Tools.DeleteFile(newimage); } catch (Exception iSuck) { MessageBox.Show("Error: " + iSuck.Message); } }
private void getImage(String file, PictureBox box) { if (picWorking.Visible) { return; } try { string contentImage; //if not passed a string path for the image //show dialog box to find one if (string.IsNullOrWhiteSpace(file)) { var openFileDialog1 = new OpenFileDialog { Filter = "Image Files|*.bmp;*.jpg;*.jpeg;*.png", Title = "Select a Package image", InitialDirectory = Application.StartupPath + "\\res\\thumbs" }; if (openFileDialog1.ShowDialog() != DialogResult.OK) { return; } contentImage = openFileDialog1.FileName; Tools.CurrentFolder = Path.GetDirectoryName(openFileDialog1.FileName); } else { //if file is not blank, then use that for the image if ((file.Contains(".jpg") || file.Contains(".bmp") || file.Contains(".png") || file.Contains(".jpeg")) && !file.Contains(".png_xbox") && !file.Contains(".png_wii")) { contentImage = file; } else { Log("That's not a valid image file"); return; } } if (string.IsNullOrWhiteSpace(contentImage)) { return; } var thumbnail = Tools.NemoLoadImage(contentImage); if (thumbnail.Width == 64 && thumbnail.Height == 64) { box.Image = thumbnail; Log(box.Name.Replace("pic", "") + " Image changed successfully"); xPackage.Header.ContentImageBinary = picContent.Image.ImageToBytes(ImageFormat.Png); xPackage.Header.PackageImageBinary = picPackage.Image.ImageToBytes(ImageFormat.Png); ShowChanges(true); return; } var newimage = Path.GetTempPath() + Path.GetFileNameWithoutExtension(contentImage) + ".png"; Tools.ResizeImage(contentImage, 64, "png", newimage); if (File.Exists(newimage)) { box.Image = Tools.NemoLoadImage(newimage); xPackage.Header.ContentImageBinary = picContent.Image.ImageToBytes(ImageFormat.Png); xPackage.Header.PackageImageBinary = picPackage.Image.ImageToBytes(ImageFormat.Png); } Tools.DeleteFile(newimage); Log(box.Name.Replace("pic", "") + " Image changed successfully"); ShowChanges(true); } catch { Log("Error loading image ... try again."); } }