Inheritance: INotifyPropertyChanged
Ejemplo n.º 1
0
        private void PatternScan(byte[] blockData)
        {
            var magic   = "CWAV".Select(c => (byte)c).ToArray();
            var indexes = ScanBuffer(blockData, magic);

            foreach (int index in indexes)
            {
                var sz = BitConverter.ToInt32(blockData, index + 0x0C);

                // Probably a Mismatch
                // Or an invalid CWAV File Header
                // Read to End of Block and pray
                if (index + sz > blockData.Length)
                {
                    sz = blockData.Length - index;
                }

                byte[] fileData = new byte[sz];
                Buffer.BlockCopy(blockData, index, fileData, 0, sz);
                var cwav = new CwavFile(fileData)
                {
                    Tag = "0x" + index.ToString("X8")
                };
                Scanned.Add(cwav);
            }
        }
 private void Remove_Execute(CwavKind obj)
 {
     Import_PostExecute(new ImportResults()
     {
         CWAV   = CwavFile.Empty(),
         Target = obj,
         Loaded = true
     });
 }
Ejemplo n.º 3
0
        public CwavBlock()
        {
            Sounds = new SoundDictionary
            {
                { CwavKind.Cursor, CwavFile.Empty() },
                { CwavKind.Launch, CwavFile.Empty() },
                { CwavKind.Folder, CwavFile.Empty() },
                { CwavKind.Close, CwavFile.Empty() },
                { CwavKind.Frame0, CwavFile.Empty() },
                { CwavKind.Frame1, CwavFile.Empty() },
                { CwavKind.Frame2, CwavFile.Empty() },
                { CwavKind.OpenLid, CwavFile.Empty() },
            };
            Scanned = new List <CwavFile>(7);

            foreach (var pair in Sounds)
            {
                pair.Value.PropertyChanged += SoundEffectOnPropertyChanged;
            }
        }
        private Task <ImportResults> Import_Execute(CwavKind cwavKind)
        {
            return(Task <ImportResults> .Factory.StartNew(() =>
            {
                var result = new ImportResults
                {
                    Loaded = false,
                    Target = cwavKind
                };
                OpenFileDialog opfd = new OpenFileDialog
                {
                    Filter = ThirdPartyTools.CtrWaveConveter.Present
                                 ? "Supported Files|*.wav;*.bcwav|DSP ADCPM Audio|*.bcwav|PCM Audio|*.wav"
                                 : "Supported Files|*.bcwav|DSP ADCPM Audio|*.bcwav"
                };
                var dlg = opfd.ShowDialog();
                if (dlg.HasValue && dlg.Value)
                {
                    try
                    {
                        switch (opfd.FilterIndex)
                        {
                        case 1:
                            {
                                if (opfd.FileName.EndsWith(".bcwav", StringComparison.OrdinalIgnoreCase))
                                {
                                    goto case 2;
                                }
                                if (opfd.FileName.EndsWith(".wav", StringComparison.OrdinalIgnoreCase))
                                {
                                    goto case 3;
                                }
                                break;
                            }

                        case 2:
                            {
                                // Read CWAV
                                var cwavData = File.ReadAllBytes(opfd.FileName);
                                result.Loaded = true;
                                result.CWAV = new CwavFile(cwavData);
                                break;
                            }

                        case 3:
                            {
                                // Convert Wav
                                var wavData = File.ReadAllBytes(opfd.FileName);
                                byte[] cwavData = CwavFile.EncodeCwav(wavData);
                                if (cwavData.Length == 3)
                                {
                                    return result;
                                }
                                result.Loaded = true;
                                result.CWAV = new CwavFile(cwavData);
                                break;
                            }
                        }
                    }
                    catch
                    {
                        // Ignore
                    }
                }
                return result;
            }));
        }