示例#1
0
        /// <summary>
        /// Get the wave data from a file path.
        /// </summary>
        /// <returns>Wave data.</returns>
        public Wave GetWave()
        {
            string wavePath = GetWavePath();

            if (wavePath == "")
            {
                return(null);
            }

            //Extension.
            string ext = Path.GetExtension(wavePath).ToLower();

            //RIFF.
            if (ext.StartsWith(".w"))
            {
                RiffWave r = new RiffWave();
                r.Load(System.IO.File.ReadAllBytes(wavePath));
                return(new Wave()
                {
                    Wav = WaveFactory.CreateWave(r, true, forceWavMaj, forceWavMin, forceWavRev)
                });
            }

            //Wave.
            else if (ext.EndsWith("wav"))
            {
                b_wav b = new b_wav();
                b.Load(System.IO.File.ReadAllBytes(wavePath));
                return(new Wave()
                {
                    Wav = b
                });
            }

            //Stream.
            else if (ext.EndsWith("stm"))
            {
                b_stm s = new b_stm();
                s.Load(System.IO.File.ReadAllBytes(wavePath));
                return(new Wave()
                {
                    Wav = WaveFactory.CreateWave(s, forceWavMaj, forceWavMin, forceWavRev)
                });
            }

            //Null.
            return(null);
        }
示例#2
0
        /// <summary>
        /// Import files.
        /// </summary>
        public override void WarBatchImport()
        {
            //File open check.
            if (!FileTest(null, null, false, true))
            {
                return;
            }

            //Safety.
            string path = GetFolderPath();

            if (path == "")
            {
                return;
            }

            //Sort files.
            List <string> files = Directory.EnumerateFiles(path).ToList();

            for (int i = files.Count - 1; i >= 0; i--)
            {
                if (!files[i].Contains("wav"))
                {
                    files.RemoveAt(i);
                }
            }

            //Read each file.
            foreach (string d in files)
            {
                if (Path.GetExtension(d).ToLower().Contains(".wav"))
                {
                    byte[] b = System.IO.File.ReadAllBytes(d);
                    if (b.Length > 0)
                    {
                        RiffWave r = new RiffWave();
                        r.Load(b);
                        (File as SoundWaveArchive).Add(new Wave()
                        {
                            Wav = WaveFactory.CreateWave(r, true, forceWavMaj, forceWavMin, forceWavRev)
                        });
                    }
                    else
                    {
                        (File as SoundWaveArchive).Add(null);
                    }
                }
                else
                {
                    byte[] b = System.IO.File.ReadAllBytes(d);
                    if (b.Length > 0)
                    {
                        Wave a = new Wave();
                        a.Wav = new b_wav();
                        a.Wav.Load(b);
                        (File as SoundWaveArchive).Add(a);
                    }
                    else
                    {
                        (File as SoundWaveArchive).Add(null);
                    }
                }
            }

            //Update.
            UpdateNodes();
            DoInfoStuff();
        }