Exemplo n.º 1
0
        static void ConvertProject(String input, String output)
        {
            XapFile xapFile = new XapFile();
            String  content = File.ReadAllText(input);

            xapFile.Open(content);
            xapFile.ContentVersion = "44";
            xapFile.Release        = "March 2008";

            ElementCollection presets = xapFile.GetElements("Compression Preset");

            if (presets.Count > 0)
            {
                /*
                 * Change
                 * Compression Preset
                 * {
                 *      Name = Compression Preset;
                 *      Xbox Format Tag = 357;
                 *      Target Sample Rate = 48000;
                 *      Quality = 65;
                 *      Find Best Quality = 0;
                 *      High Freq Cut = 0;
                 *      Loop = 0;
                 *      PC Format Tag = 2;
                 *      Samples Per Block = 128;
                 * }
                 * to
                 * Compression Preset
                 * {
                 *      Name = Compression Preset;
                 *      Xbox Format Tag = 357;
                 *      Target Sample Rate = 48000;
                 *      XMA Quality = 65;
                 *      Find Best Quality = 0;
                 *      High Freq Cut = 0;
                 *      Loop = 0;
                 *      PC Format Tag = 353;
                 *      WMA Quality = 65;
                 * }
                 */

                // Add WMA format to all compression presets that define XMA compression,
                // using the same quality setting
                for (int c = 0; c < presets.Count; c++)
                {
                    SectionElement preset             = presets[c] as SectionElement;
                    ScalarElement  xboxFormatTag      = preset.Value["Xbox Format Tag"] as ScalarElement;
                    int            xboxFormatTagValue = 0;
                    if (Int32.TryParse(xboxFormatTag.Value, out xboxFormatTagValue) == true &&
                        (CompressionFormat)xboxFormatTagValue == CompressionFormat.XMA)
                    {
                        preset.Value["PC Format Tag"].Value = String.Format("{0}", (int)CompressionFormat.WMA);
                        ScalarElement xmaQuality = preset.Value["Quality"] as ScalarElement;
                        preset.Value["Samples Per Block"] = null;
                        preset.Value.Add(new ScalarElement("WMA Quality", xmaQuality.Value));
                        //REVIEW: Check Wave size: file too small to encode, must have at least 352256 bytes of data
                        //REVIEW: Rename "Quality" element to "XMA Quality"?
                    }
                }
            }

            using (FileStream outputStream = new FileStream(output, FileMode.Create))
            {
                xapFile.Save(outputStream);
            }
        }