/// <summary> /// Parse this structure from the XAP file source. /// </summary> /// <param name="source">The source data.</param> /// <param name="line">The current line, which will change during the Parser.</param> public void Parse( string[] source, ref int line, Project project ) { m_project = project; string propertyName; string value; // Will currently be looking at the structure header, increment to get into structure delimiting brackets ++line; if ( !Parser.TokeniseLine( source[line], out propertyName, out value ) || propertyName != "{" ) { throw new InvalidContentException( "Structure on line " + line.ToString() + " does not open with a curly brace." ); } // Increment again to get into the structure proper ++line; while ( line < source.Length ) { if ( Parser.TokeniseLine( source[line], out propertyName, out value ) ) { switch ( propertyName ) { case "}": return; default: if ( !SetProperty( propertyName, value, source, ref line ) ) { throw new InvalidContentException( "Type " + this.GetType().ToString() + " did not expect property '" + propertyName + "', value '" + value + "', on line " + line.ToString() ); } break; } } ++line; } }
private static void ConvertXactProject( string projectFile, string sourceFolder, string outputFolder, Dictionary <string, object> profileSettings, Dictionary <string, CompressResult> existingJournal, List <CompressResult> journal, Action <string, string, Dictionary <string, object> > logOutput ) { const int CompressVersion = 1; Console.Error.WriteLine("// Processing {0}...", projectFile); var projectSubdir = Path.GetDirectoryName(projectFile); var projectPath = Path.Combine(sourceFolder, projectFile); var projectInfo = new FileInfo(projectPath); var project = new Xap.Project(); project.Parse(File.ReadAllLines(projectPath)); var waveManifest = new Dictionary <string, string>(); var jss = new JavaScriptSerializer(); foreach (var waveBank in project.m_waveBanks) { foreach (var wave in waveBank.m_waves) { var waveFolder = Path.GetDirectoryName(wave.m_fileName); var waveOutputFolder = FixupOutputDirectory(outputFolder, waveFolder); waveManifest[wave.m_name] = FixupOutputDirectory( projectSubdir, wave.m_fileName .Replace(Path.GetExtension(wave.m_fileName), "") ); journal.AddRange(CompressAudioGroup( Path.Combine(projectSubdir, wave.m_fileName), sourceFolder, waveOutputFolder, profileSettings, existingJournal, logOutput )); } } foreach (var soundBank in project.m_soundBanks) { var waveNames = new HashSet <string>(); var soundEntries = (from sound in soundBank.m_sounds select new SoundEntry { Name = sound.m_name, Tracks = ( from track in sound.m_tracks select new TrackEntry { Name = track.m_name, Events = ( from evt in track.m_events select(Dictionary <string, object>) TranslateEvent( evt as dynamic, waveNames ) ).ToArray() } ).ToArray() }).ToArray(); var cueEntries = (from cue in soundBank.m_cues select new CueEntry { Name = cue.m_name, Sounds = ( from se in cue.m_soundEntries select se.m_name ).ToArray() }).ToArray(); var soundBankJson = jss.Serialize( new Dictionary <string, object> { { "Name", soundBank.m_name }, { "Cues", cueEntries }, { "Sounds", soundEntries }, { "Waves", waveManifest } } ); var soundBankPath = Path.Combine(outputFolder, soundBank.m_name + ".soundBank"); File.WriteAllText( soundBankPath, soundBankJson ); journal.Add(MakeCompressResult( CompressVersion, null, soundBankPath, projectPath, projectInfo )); logOutput("SoundBank", soundBankPath, null); } Console.Error.WriteLine("// Done processing {0}.", projectFile); }