Esempio n. 1
0
        /// <summary>
        /// Loads all the chords and notes for the arrangement
        /// </summary>
        public ArrangementObject LoadArrangement(Arrangement arrangment)
        {
            XmlDocument document = new XmlDocument();

            using (var inputStream = File.OpenRead(source))
            {
                var psarc = new PlayStationArchive();
                psarc.Read(inputStream, true);

                try
                {
                    foreach (var entry in psarc.TOC)
                    {
                        if (entry.Name.Contains("songs") && entry.Name.Contains("arr") && entry.Name.EndsWith("_" + arrangment.ToString() + ".xml"))
                        {
                            psarc.InflateEntry(entry);
                            using (var reader = new StreamReader(entry.Data, Encoding.UTF8))
                            {
                                document.LoadXml(reader.ReadToEnd());
                            }
                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
                finally
                {
                    if (psarc != null)
                    {
                        psarc.Dispose();
                        psarc = null;
                    }
                }
            }

            float averageTempo = float.Parse(document.GetElementsByTagName("averageTempo")[0].InnerText, CultureInfo.InvariantCulture);

            XmlNode node       = document.GetElementsByTagName("transcriptionTrack")[0];
            int     noteCount  = int.Parse(node["notes"].GetAttribute("count"));
            int     chordCount = int.Parse(node["chords"].GetAttribute("count"));

            if (noteCount <= 0 && chordCount <= 0)
            {
                node       = document.GetElementsByTagName("level")[0];
                noteCount  = int.Parse(node["notes"].GetAttribute("count"));
                chordCount = int.Parse(node["chords"].GetAttribute("count"));
            }

            ArrangementObject newArrangement = new ArrangementObject(averageTempo,
                                                                     noteCount, node["notes"].GetElementsByTagName("note"),
                                                                     chordCount, node["chords"].GetElementsByTagName("chord"));

            return(newArrangement);
        }
Esempio n. 2
0
        private static SongObject UnpackArchive(string archivePath, Stream inputStream, GraphicsDevice graphics)
        {
            var psarc = new PlayStationArchive();

            psarc.Read(inputStream, true);
            SongObject newSong = new SongObject(archivePath);

            try
            {
                // InflateEntries - compatible with RS1 and RS2014 files
                foreach (var entry in psarc.TOC)
                {
                    if (entry.Name.Contains("manifests") && entry.Name.EndsWith(".hsan"))
                    {
                        psarc.InflateEntry(entry);
                        using (var reader = new StreamReader(entry.Data, Encoding.UTF8))
                        {
                            JProperty json = JObject.Parse(reader.ReadToEnd()).Property("Entries");

                            JContainer lead   = FindArrangment("Lead", json);
                            JContainer rhythm = FindArrangment("Rhythm", json);

                            if (lead == null && rhythm == null)
                            {
                                newSong = null;
                                break;
                            }

                            foreach (JProperty property in lead.Values())
                            {
                                if (property.Name.Equals("AlbumName"))
                                {
                                    newSong.album = property.Value.ToString();
                                }
                                else if (property.Name.Equals("ArtistName"))
                                {
                                    newSong.artist = property.Value.ToString();
                                }
                                else if (property.Name.Equals("SongLength"))
                                {
                                    float seconds;
                                    bool  success = float.TryParse(property.Value.ToString(), out seconds);
                                    newSong.length = seconds;
                                }
                                else if (property.Name.Equals("SongName"))
                                {
                                    newSong.title = property.Value.ToString();
                                }
                                else if (property.Name.Equals("SongYear"))
                                {
                                    newSong.year = property.Value.ToString();
                                }
                                else if (property.Name.Equals("Tuning"))
                                {
                                    int count = 0;
                                    newSong.tuningLead = new sbyte[6];
                                    foreach (JProperty attribute in property.Values())
                                    {
                                        newSong.tuningLead[count] = sbyte.Parse(attribute.Value.ToString());
                                        count++;
                                    }
                                }
                            }

                            foreach (JProperty property in rhythm.Values())
                            {
                                if (property.Name.Equals("Tuning"))
                                {
                                    int count = 0;
                                    newSong.tuningRhythm = new sbyte[6];
                                    foreach (JProperty attribute in property.Values())
                                    {
                                        newSong.tuningRhythm[count] = sbyte.Parse(attribute.Value.ToString());
                                        count++;
                                    }
                                }
                            }
                        }
                    }
                    // Close
                    if (entry.Data != null)
                    {
                        entry.Data.Dispose();
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            finally
            {
                if (psarc != null)
                {
                    psarc.Dispose();
                    psarc = null;
                }
            }

            if (newSong != null && !albumImages.ContainsKey(newSong.artist + "+" + newSong.album))
            {
                albumImages.Add(newSong.artist + "+" + newSong.album, new AlbumImage(spotify, newSong.artist + "+" + newSong.album, graphics));
            }
            return(newSong);
        }