private void btnImport_Click(object sender, EventArgs e) { Sound selectedFile = SearchFile(); String fileout = pluginHost.Get_TempFolder() + Path.DirectorySeparatorChar + Path.GetRandomFileName(); OpenFileDialog o = new OpenFileDialog(); o.CheckFileExists = true; o.AddExtension = true; o.DefaultExt = "wav"; o.Filter = "WAVE audio format (*.wav)|*.wav"; if (o.ShowDialog() != DialogResult.OK) { return; } String filein = o.FileName; sWAV wav = new sWAV(); try { wav = WAV.Read(filein); } catch (Exception ex) { MessageBox.Show(ex.Message); return; } NewAudioOptions dialog = new NewAudioOptions(pluginHost, (selectedFile.type == FormatSound.SWAV ? true : false)); switch (selectedFile.type) { case FormatSound.STRM: sSTRM oldStrm = STRM.Read(SaveFile()); dialog.Compression = oldStrm.head.waveType; dialog.BlockSize = (int)oldStrm.head.blockLen; dialog.Loop = (oldStrm.head.loop != 0 ? true : false); dialog.LoopOffset = (int)oldStrm.head.loopOffset; dialog.SampleRate = (int)wav.wave.fmt.sampleRate; if (dialog.ShowDialog() != DialogResult.OK) { return; } sSTRM strm = STRM.ConvertToSTRM(wav, dialog.Compression); strm.head.loop = (byte)(dialog.Loop ? 0x01 : 0x00); strm.head.loopOffset = (uint)dialog.LoopOffset; STRM.Write(strm, fileout); break; case FormatSound.SWAV: sSWAV oldSwav = SWAV.Read(SaveFile()); dialog.Compression = oldSwav.data.info.nWaveType; dialog.Loop = (oldSwav.data.info.bLoop != 0 ? true : false); dialog.LoopLength = (int)oldSwav.data.info.nNonLoopLen; dialog.LoopOffset = (int)oldSwav.data.info.nLoopOffset; dialog.SampleRate = (int)wav.wave.fmt.sampleRate; if (dialog.ShowDialog() != DialogResult.OK) { return; } sSWAV swav = SWAV.ConvertToSWAV(wav, dialog.Compression, dialog.Volume); swav.data.info.bLoop = (byte)(dialog.Loop ? 0x01 : 0x00); swav.data.info.nLoopOffset = (ushort)dialog.LoopOffset; swav.data.info.nNonLoopLen = (uint)dialog.LoopLength; SWAV.Write(swav, fileout); break; case FormatSound.SSEQ: case FormatSound.SSAR: case FormatSound.SBNK: case FormatSound.SWAR: default: break; } if (!File.Exists(fileout)) { return; } ChangeFile((int)selectedFile.id, fileout); }
private void btnUncompress_Click(object sender, EventArgs e) { System.Xml.Linq.XElement xml = System.Xml.Linq.XElement.Load(Application.StartupPath + Path.DirectorySeparatorChar + "Plugins" + Path.DirectorySeparatorChar + "SDATLang.xml"); xml = xml.Element(pluginHost.Get_Language()); xml = xml.Element("iSDAT"); if (btnUncompress.Text == xml.Element("S07").Value) { #region Unpack SWAR file string swar = SaveFile(); sSWAV[] archivos = SWAR.ConvertToSWAV(SWAR.Read(swar)); string[] swav = new string[archivos.Length]; Folder carpeta = new Folder(); carpeta.name = SearchFile().name; carpeta.files = new List <Sound>(); for (int i = 0; i < archivos.Length; i++) { swav[i] = pluginHost.Get_TempFolder() + '\\' + Path.GetRandomFileName(); SWAV.Write(archivos[i], swav[i]); Sound newSound = new Sound(); newSound.id = lastFileID; lastFileID++; newSound.internalID = newSound.id; newSound.name = "SWAV_" + i.ToString() + ".swav"; newSound.offset = 0x00; newSound.type = FormatSound.SWAV; newSound.path = swav[i]; newSound.size = (uint)new FileInfo(swav[i]).Length; carpeta.files.Add(newSound); } // Lo añadimos al nodo Add_Files(ref carpeta, (int)SearchFile().id); TreeNode selected = treeFiles.SelectedNode; selected = CarpetaToNodo(carpeta); // Agregamos los nodos al árbol TreeNode[] nodos = new TreeNode[selected.Nodes.Count]; selected.Nodes.CopyTo(nodos, 0); treeFiles.SelectedNode.Tag = selected.Tag; selected.Nodes.Clear(); treeFiles.SelectedNode.Nodes.AddRange((TreeNode[])nodos); treeFiles.SelectedNode.Expand(); #endregion btnUncompress.Text = xml.Element("S12").Value; } else { #region Pack SWAR file Folder swar = SearchFolder(Convert.ToInt32(treeFiles.SelectedNode.Tag), sdat.files.root); List <sSWAV> sounds = new List <sSWAV>(); for (int i = 0; i < swar.files.Count; i++) { String tempFile = SaveFile((int)swar.files[i].id); sSWAV swav = SWAV.Read(tempFile); sounds.Add(swav); File.Delete(tempFile); } String fileout = Path.GetTempFileName(); SWAR.Write(sounds.ToArray(), fileout); ChangeFile(Convert.ToInt32(treeFiles.SelectedNode.Tag), fileout); #endregion } }