Пример #1
0
        public static HashMapping CreateMapping(string inputPath, string outputPath)
        {
            HashMapping map = new HashMapping();

            map.Input  = ComputeHashFromFile(inputPath);
            map.Output = ComputeHashFromFile(outputPath);
            return(map);
        }
Пример #2
0
        private void EncodeAudio(FusedSong song)
        {
            string mapPath = GetFilePath("hashes.json");

            // Imports existing mappings if found
            AudioHashMappings audioMap = File.Exists(mapPath)
                ? AudioHashMappings.Import(mapPath)
                : new AudioHashMappings();

            string GetPackageFilePath(string relativePath) =>
            Path.Combine(_packageManager.CurrentPackageDirectory + "\\songs\\", song.Identifier.Replace(".", "\\") + "\\" + relativePath);

            bool IsCeltFile(string path)
            {
                string ext = Path.GetExtension(path);

                return(ext.Equals(".clt", StringComparison.CurrentCultureIgnoreCase));
            }

            HashMapping EncodeAudio(string input, string output, HashMapping oldMap)
            {
                if (!File.Exists(input))
                {
                    // Delete if no input
                    if (File.Exists(output))
                    {
                        File.Delete(output);
                    }

                    return(oldMap);
                }
                else if (!File.Exists(output))
                {
                    // Encodes audio (Import from celt supported)
                    Celt celt = IsCeltFile(input) ? Celt.FromFile(input) : Celt.FromAudio(input);
                    celt.Export(output);

                    // Updates hashes
                    return(HashMapping.CreateMapping(input, output));
                }

                HashMapping newMap = HashMapping.CreateMapping(input, output);

                if (newMap.Input != oldMap.Input || newMap.Output != oldMap.Output)
                {
                    // Encodes audio
                    Celt celt = IsCeltFile(input) ? Celt.FromFile(input) : Celt.FromAudio(input);
                    celt.Export(output);

                    // Updates output hash
                    newMap.Output = HashMapping.ComputeHashFromFile(output);
                }
                // Else means they're equal, no need to re-encode

                // Returns new hashes
                return(newMap);
            }

            audioMap.Preview      = EncodeAudio(GetFilePath(song.AudioPaths.Preview), GetPackageFilePath("preview\\audio.clt"), audioMap.Preview);
            audioMap.Backing      = EncodeAudio(GetFilePath(song.AudioPaths.Backing), GetPackageFilePath("gamestems\\back\\audio.clt"), audioMap.Backing);
            audioMap.Bass         = EncodeAudio(GetFilePath(song.AudioPaths.Bass), GetPackageFilePath("gamestems\\bass\\audio.clt"), audioMap.Bass);
            audioMap.Drums        = EncodeAudio(GetFilePath(song.AudioPaths.Drums), GetPackageFilePath("gamestems\\drums\\audio.clt"), audioMap.Drums);
            audioMap.LeadGuitar   = EncodeAudio(GetFilePath(song.AudioPaths.LeadGuitar), GetPackageFilePath("gamestems\\gtr1\\audio.clt"), audioMap.LeadGuitar);
            audioMap.RhythmGuitar = EncodeAudio(GetFilePath(song.AudioPaths.RhythmGuitar), GetPackageFilePath("gamestems\\gtr2\\audio.clt"), audioMap.RhythmGuitar);
            audioMap.Vox          = EncodeAudio(GetFilePath(song.AudioPaths.Vox), GetPackageFilePath("gamestems\\vox\\audio.clt"), audioMap.Vox);

            audioMap.Export(mapPath);
        }