예제 #1
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);
        }