Beispiel #1
0
        private void ProcessPsarcFile(string psarcFile)
        {
            //Return if file is already cached
            if (cache.Contains(psarcFile))
            {
                return;
            }

            //Read psarc data
            Dictionary <string, SongDetails> allSongDetails;

            try
            {
                allSongDetails = PSARCUtil.ReadPSARCHeaderData(psarcFile);
            }
            catch
            {
                Logger.LogError("Unable to read {0}", psarcFile);
                return;
            }

            //If loading was successful
            if (allSongDetails != null)
            {
                //Add this CDLC file to the cache
                cache.Add(psarcFile, allSongDetails);
            }
        }
Beispiel #2
0
        private void ProcessPsarcFile(string psarcFile)
        {
            var fileInfo = new FileInfo(psarcFile);

            // Try to hash the psarc file
            string hash;

            try
            {
                hash = PSARCUtil.GetFileHash(fileInfo);
            }
            catch (Exception e)
            {
                Logger.LogError("Unable to calculate hash for {0}", psarcFile);
                Logger.LogException(e);
                PsarcFileProcessingDone(psarcFile, false);
                return;
            }

            //Return if file is already cached
            if (_cache.Contains(psarcFile, hash))
            {
                PsarcFileProcessingDone(psarcFile, false);
                return;
            }

            //Read psarc data
            Dictionary <string, SongDetails> allSongDetails;

            try
            {
                allSongDetails = PSARCUtil.ReadPSARCHeaderData(fileInfo);
            }
            catch (Exception e)
            {
                Logger.LogError("Unable to read {0}", psarcFile);
                Logger.LogException(e);
                PsarcFileProcessingDone(psarcFile, false);
                return;
            }

            //If loading was successful
            if (allSongDetails != null)
            {
                //In case file hash was different
                //or if this is a newer psarc with the same song ids
                //Remove all existing entries
                _cache.Remove(psarcFile, allSongDetails.Keys.ToList());

                //Add this CDLC file to the cache
                _cache.Add(psarcFile, allSongDetails);
            }

            PsarcFileProcessingDone(psarcFile, true);
        }
Beispiel #3
0
        private async Task <bool> UpdateCurrentDetails(string filepath)
        {
            //If the song has not changed, and the details object is valid, no need to update
            //Compare song id's in lowercase because the preview audio name is not guaranteed to match
            if (currentCDLCDetails.IsValid() && currentMemoryReadout.songID.ToLowerInvariant() == currentCDLCDetails.songID.ToLowerInvariant())
            {
                return(true);
            }

            //If songID is empty, we aren't gonna be able to do anything here
            if (currentMemoryReadout.songID == "")
            {
                return(true);
            }

            if (Logger.logSongDetails)
            {
                Logger.Log("Looking for '{0}' in psarc file: {1}", currentMemoryReadout.songID, filepath);
            }

            //Check if this psarc file is cached
            if (cache.Contains(filepath))
            {
                //Load from cache if it is
                currentCDLCDetails = cache.Load(filepath, currentMemoryReadout.songID);

                //If cache failed to load
                if (currentCDLCDetails == null)
                {
                    //Set invalid song details
                    currentCDLCDetails = new SongDetails();

                    //Return false, this is probably not the correct file
                    return(false);
                }

                //Print current details (if debug is enabled) and print warnings about this dlc
                currentCDLCDetails.Print();

                //Invoke event
                OnSongChanged?.Invoke(this, new OnSongChangedArgs()
                {
                    songDetails = currentCDLCDetails
                });

                //Exit function as data was handled from cache
                return(true);
            }

            //Read psarc data into the details object
            var allSongDetails = await Task.Run(() => PSARCUtil.ReadPSARCHeaderData(filepath));

            //If loading failed
            if (allSongDetails == null)
            {
                //Exit function
                return(true);
            }

            //If this is the songs.psarc file, we should merge RS1 DLC into it
            if (filepath.EndsWith("songs.psarc"))
            {
                //Really ugly way to find the rs1 dlc psarc
                string rs1dlcpath = filepath.Replace("songs.psarc", "dlc" + System.IO.Path.DirectorySeparatorChar + "rs1compatibilitydlc_p.psarc");

                //Read the rs1 dlc psarc
                var rs1SongDetails = await Task.Run(() => PSARCUtil.ReadPSARCHeaderData(rs1dlcpath));

                //If we got rs1 dlc arrangements
                if (rs1SongDetails != null)
                {
                    //Combine the two dictionaries
                    allSongDetails = allSongDetails.Concat(rs1SongDetails).ToDictionary(k => k.Key, v => v.Value);
                }
            }

            //If the song detail dictionary contains the song ID we are looking for
            if (allSongDetails.ContainsKey(currentMemoryReadout.songID))
            {
                //Assign current CDLC details
                currentCDLCDetails = allSongDetails[currentMemoryReadout.songID];
            }

            //Add this CDLC file to the cache
            cache.Add(filepath, allSongDetails);

            //Print current details (if debug is enabled) and print warnings about this dlc
            currentCDLCDetails.Print();

            //Invoke event
            OnSongChanged?.Invoke(this, new OnSongChangedArgs()
            {
                songDetails = currentCDLCDetails
            });

            return(true);
        }