Exemplo n.º 1
0
        internal ArrangementData ExtractArrangementData(Attributes2014 attr)
        {
            string sngFilePath = $"songs/bin/generic/{attr.SongXml.Substring(20)}.sng";
            var    entry       = _archive.TOC.Where(x => x.Name.Equals(sngFilePath)).FirstOrDefault();

            if (entry == null)
            {
                throw new Exception($"Could not find arrangement sng {_filePath}/{sngFilePath}");
            }

            ArrangementData data = null;

            _archive.InflateEntry(entry);
            entry.Data.Position = 0;

            var sng = Sng2014File.ReadSng(entry.Data, new RocksmithToolkitLib.Platform(RocksmithToolkitLib.GamePlatform.Pc, RocksmithToolkitLib.GameVersion.RS2014));

            if (sng == null)
            {
                throw new Exception($"Could not read sng {_filePath}{sngFilePath}");
            }

            data = new ArrangementData(sng);

            entry.Dispose();

            return(data);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Reads psarc file from filepath and populates details with information
        /// </summary>
        /// <param name="filepath"></param>
        /// <param name="details"></param>
        internal static Dictionary <string, SongDetails> ReadPSARCHeaderData(FileInfo fileInfo)
        {
            //Wait for the file to exist
            WaitForFile(fileInfo);

            if (!fileInfo.Exists)
            {
                Logger.LogError("Warning! Psarc file {0} does not exist!", fileInfo.FullName);
                return(null);
            }

            var sw = new Stopwatch();

            sw.Start();

            string fileHash = GetFileHash(fileInfo);

            var detailsDict = new Dictionary <string, SongDetails>();

            using (PsarcFile loader = new PsarcFile(fileInfo))
            {
                //Extract toolkit info
                var tkInfo = loader.ExtractToolkitInfo();

                List <SongArrangement> manifests;

                try
                {
                    manifests = loader.ExtractArrangementManifests();
                }
                catch (Exception e)
                {
                    Logger.LogError("Warning! Could not parse psarc file {0}: {1}", fileInfo.Name, e.Message);
                    return(null);
                }

                //Extract all arrangements
                foreach (var v in manifests)
                {
                    if (v == null)
                    {
                        Logger.LogError("Unable to process JSON manifest for {0}", fileInfo.Name);
                        continue;
                    }

                    var arrangement    = v.Attributes;
                    var arrangement_id = arrangement.PersistentID;

                    var             arrangementSng  = loader.InflateEntry <SngAsset>(a => a.Path.Equals($"songs/bin/generic/{arrangement.SongXml.Substring(20)}.sng"));
                    ArrangementData arrangementData = new ArrangementData(arrangementSng);

                    if (arrangement.Phrases != null)
                    {
                        if (!detailsDict.ContainsKey(arrangement.SongKey))
                        {
                            detailsDict[arrangement.SongKey] = new SongDetails();
                        }

                        SongDetails details = detailsDict[arrangement.SongKey];

                        if (details.albumArt == null)
                        {
                            try
                            {
                                details.albumArt = loader.ExtractAlbumArt(arrangement).Bitmap;
                            }
                            catch (Exception e)
                            {
                                Logger.LogError("Warning: couldn't extract album art for {0}", arrangement.SongName);
#if DEBUG
                                Logger.LogException(e);
#endif

                                details.albumArt = new Bitmap(1, 1);
                            }
                        }

                        //Get a list of all sections
                        var sections = new List <ArrangementDetails.SectionDetails>();
                        Dictionary <string, int> sectionCounts = new Dictionary <string, int>();

                        foreach (var sect in arrangement.Sections)
                        {
                            if (!sectionCounts.ContainsKey(sect.Name))
                            {
                                sectionCounts[sect.Name] = 1;
                            }

                            var sectionDetails = new ArrangementDetails.SectionDetails
                            {
                                name      = $"{sect.Name} {sectionCounts[sect.Name]}",
                                startTime = sect.StartTime,
                                endTime   = sect.EndTime
                            };

                            sections.Add(sectionDetails);

                            sectionCounts[sect.Name]++;
                        }


                        //Get a list of all phraseIterations
                        var phraseIterations = new List <ArrangementDetails.PhraseIterationDetails>();
                        Dictionary <string, int> phraseIterationCounts = new Dictionary <string, int>();

                        foreach (var phrI in arrangement.PhraseIterations)
                        {
                            if (!phraseIterationCounts.ContainsKey(phrI.Name))
                            {
                                phraseIterationCounts[phrI.Name] = 1;
                            }

                            var phraseIterationDetails = new ArrangementDetails.PhraseIterationDetails
                            {
                                name          = $"{phrI.Name} {phraseIterationCounts[phrI.Name]}",
                                phraseId      = phrI.PhraseIndex,
                                maxDifficulty = phrI.MaxDifficulty,
                                startTime     = phrI.StartTime,
                                endTime       = phrI.EndTime
                            };

                            phraseIterations.Add(phraseIterationDetails);

                            phraseIterationCounts[phrI.Name]++;
                        }

                        //Build arrangement details
                        var arrangementDetails = new ArrangementDetails
                        {
                            name                   = arrangement.ArrangementName,
                            arrangementID          = arrangement_id,
                            sections               = sections,
                            phraseIterations       = phraseIterations,
                            data                   = arrangementData,
                            isBonusArrangement     = (arrangement.ArrangementProperties.BonusArr == 1),
                            isAlternateArrangement = (arrangement.ArrangementProperties.Represent == 0)
                        };

                        //Determine path type
                        if (arrangement.ArrangementProperties.PathLead == 1)
                        {
                            arrangementDetails.type = "Lead";
                        }
                        else if (arrangement.ArrangementProperties.PathRhythm == 1)
                        {
                            arrangementDetails.type = "Rhythm";
                        }
                        else if (arrangement.ArrangementProperties.PathBass == 1)
                        {
                            arrangementDetails.type = "Bass";
                        }

                        arrangementDetails.tuning = new ArrangementTuning(arrangement.Tuning, (int)arrangement.CentOffset, (int)arrangement.CapoFret);


                        //file hash
                        details.psarcFileHash = fileHash;

                        //Get general song information
                        details.songID     = arrangement.SongKey;
                        details.songLength = arrangement.SongLength;
                        details.songName   = arrangement.SongName;
                        details.artistName = arrangement.ArtistName;
                        details.albumName  = arrangement.AlbumName;
                        details.albumYear  = arrangement.SongYear;
                        details.arrangements.Add(arrangementDetails);

                        //Apply toolkit information
                        details.toolkit = new ToolkitDetails
                        {
                            version         = tkInfo.PackageVersion,
                            author          = tkInfo.PackageAuthor,
                            comment         = tkInfo.PackageComment,
                            package_version = tkInfo.PackageVersion
                        };
                    }
                }

                sw.Stop();

                Logger.Log("Parsed {0} ({1}mb) in {2}ms and found {3} songs", fileInfo.Name, fileInfo.Length / 1024 / 1024, sw.ElapsedMilliseconds, detailsDict.Count);

                return(detailsDict);
            }
        }