示例#1
0
        /// <summary>
        /// Generate the file package.
        /// Creates the package header:
        /// - Header
        /// - Map of language strings
        /// - Map of soundbank titles
        /// - Soundbank files LUT
        /// - Streamed audio files LUT
        /// Writes the header to file.
        /// Concatenates files referenced in the LUTs.
        /// </summary>
        /// <param name="in_soundbanksInfo">Soundbank data model.</param>
        /// <param name="in_settings">Generation settings.</param>
        /// <param name="in_writer">Binary writer.</param>
        /// <returns>Returns true when no files are missing.</returns>
        private IEnumerable <NamedAction> GeneratePackage(
            Context.GlobalInfo globalInfo,
            Context.PackageInfo packageInfo,
            FilePackageWriter in_writer,
            Results results)
        {
            List <NamedAction> actions = new List <NamedAction>();

            // Header chunk.
            Header header = new Header();

            // Language names map.
            // NOTE: As of Wwise 2009.1, language names are stored as ANSI strings when not on Windows (sync with type AkOSChar).
            bool bLanguageMapUsesAsciiStrings = true;

            switch (globalInfo.BasePlatform)
            {
            case AK.Wwise.InfoFile.SoundBanksInfoBasePlatform.Windows:
            case AK.Wwise.InfoFile.SoundBanksInfoBasePlatform.XboxOne:
                bLanguageMapUsesAsciiStrings = false;
                break;

            default:
                bLanguageMapUsesAsciiStrings = true;
                break;
            }

            IEnumerable <AK.Wwise.InfoFile.FileDescriptorType>            descriptors = packageInfo.Files.Where(f => f.Descriptor != null).Select(f => f.Descriptor);
            IEnumerable <FilePackageGenerator.Context.ExternalSourceInfo> externals   = packageInfo.Files.Where(f => f.ExternalSourceInfo != null).Select(f => f.ExternalSourceInfo);

            Dictionary <string, uint> mapLanguageIDs = FindAllLanguages(descriptors);
            LanguagesMap langMap = new LanguagesMap(mapLanguageIDs, bLanguageMapUsesAsciiStrings);

            // Add Banks files to LUT.
            FileLUT banksLUT = new FileLUT(globalInfo.SoundBanksRoot, packageInfo.BlockSize, typeof(UInt32));

            foreach (AK.Wwise.InfoFile.FileDescriptorType soundbank in descriptors.OfType <AK.Wwise.InfoFile.SoundBanksInfoSoundBanksSoundBank>())
            {
                if (!banksLUT.Add(soundbank, mapLanguageIDs))
                {
                    NotifyLogMsg("Missing soundbank: " + soundbank.ShortName + " (" + soundbank.Path + ")", Severity.Warning);
                    results.HasMissingFiles = true;
                }
            }
            banksLUT.Sort();

            // Add Steamed files to LUT.
            FileLUT streamsLUT = new FileLUT(globalInfo.SourceFilesRoot, packageInfo.BlockSize, typeof(UInt32));

            foreach (AK.Wwise.InfoFile.FileDescriptorType stream in descriptors.Where(fd => (fd is AK.Wwise.InfoFile.SoundBanksInfoStreamedFilesFile ||
                                                                                             fd is AK.Wwise.InfoFile.SoundBanksInfoMediaFilesNotInAnyBankFile)))
            {
                if (!streamsLUT.Add(stream, mapLanguageIDs))
                {
                    NotifyLogMsg("Missing streamed or loose media file: " + stream.ShortName + " (" + stream.Path + ")", Severity.Warning);
                    results.HasMissingFiles = true;
                }
            }
            streamsLUT.Sort();

            // Add External Source files to LUT.
            FileLUT externalLUT = new FileLUT(globalInfo.SourceFilesRoot, packageInfo.BlockSize, typeof(UInt64));

            foreach (FilePackageGenerator.Context.ExternalSourceInfo external in externals)
            {
                if (!externalLUT.Add(external, mapLanguageIDs))
                {
                    NotifyLogMsg("Missing external file: " + external.Name + " (" + external.Path + ")", Severity.Warning);
                    results.HasMissingFiles = true;
                }
            }
            externalLUT.Sort();

            // Find the header size.
            uint uHeaderSize =
                BaseHeaderSize +
                langMap.TotalSize +
                banksLUT.TotalSize +
                streamsLUT.TotalSize +
                externalLUT.TotalSize;

            // Prepare files for ordered concatenation.
            FileOrganizer organizer = new FileOrganizer();

            organizer.AddLUT(FileOrganizer.FileCategory.SoundBank, banksLUT);
            organizer.AddLUT(FileOrganizer.FileCategory.MediaFile, streamsLUT);
            organizer.AddLUT(FileOrganizer.FileCategory.ExternalSource, externalLUT);
            organizer.OrganizeFiles(uHeaderSize, packageInfo.Files, mapLanguageIDs, this);

            // Set header size.
            header.HeaderSize = uHeaderSize;


            // Write to output file:
            actions.Add(new NamedAction("Writing header", delegate()
            {
                // Header.
                header.Write(in_writer);
                in_writer.Write(langMap.TotalSize);
                in_writer.Write(banksLUT.TotalSize);
                in_writer.Write(streamsLUT.TotalSize);
                in_writer.Write(externalLUT.TotalSize);

                langMap.Write(in_writer);
                banksLUT.Write(in_writer);
                streamsLUT.Write(in_writer);
                externalLUT.Write(in_writer);
            }));

            // Concatenated files.
            return(actions.Concat(organizer.ConcatenateFiles(in_writer, this)));
        }
示例#2
0
        private void Generate(Context.GlobalInfo globalInfo, Context.PackageInfo packageInfo, Results results)
        {
            // Open output file.
            try
            {
                // Make sure the target directory exist
                string directory = Path.GetDirectoryName(packageInfo.FilePackageFilename);
                if (!Directory.Exists(directory))
                {
                    Directory.CreateDirectory(directory);
                }

                using (FileStream file = new FileStream(packageInfo.FilePackageFilename, FileMode.Create))
                {
                    // Create the writer for data.
                    FilePackageWriter.Endianness eEndianness;
                    switch (globalInfo.BasePlatform)
                    {
                    case AK.Wwise.InfoFile.SoundBanksInfoBasePlatform.Windows:
                    case AK.Wwise.InfoFile.SoundBanksInfoBasePlatform.Mac:
                    case AK.Wwise.InfoFile.SoundBanksInfoBasePlatform.VitaSW:
                    case AK.Wwise.InfoFile.SoundBanksInfoBasePlatform.VitaHW:
                    case AK.Wwise.InfoFile.SoundBanksInfoBasePlatform.Item3DS:
                    case AK.Wwise.InfoFile.SoundBanksInfoBasePlatform.iOS:
                    case AK.Wwise.InfoFile.SoundBanksInfoBasePlatform.Android:
                    case AK.Wwise.InfoFile.SoundBanksInfoBasePlatform.PS4:
                    case AK.Wwise.InfoFile.SoundBanksInfoBasePlatform.XboxOne:
                    case AK.Wwise.InfoFile.SoundBanksInfoBasePlatform.Linux:
                    case AK.Wwise.InfoFile.SoundBanksInfoBasePlatform.WindowsPhone:
                    case AK.Wwise.InfoFile.SoundBanksInfoBasePlatform.Emscripten:
                    case AK.Wwise.InfoFile.SoundBanksInfoBasePlatform.Switch:
                        eEndianness = FilePackageWriter.Endianness.LittleEndian;
                        break;

                    default:
                        eEndianness = FilePackageWriter.Endianness.BigEndian;
                        break;
                    }

                    FilePackageWriter writer = new FilePackageWriter(file, eEndianness);

                    // Generate the file package.
                    IEnumerable <NamedAction> actions = GeneratePackage(globalInfo, packageInfo, writer, results);

                    // Notify about this package
                    if (GeneratingPackage != null)
                    {
                        GeneratingPackage(this, new GeneratingPackageEventArgs()
                        {
                            NumSteps    = actions.Count(),
                            PackageName = packageInfo.FilePackageFilename
                        });
                    }

                    // Notify about missing files
                    foreach (string missingFile in packageInfo.MissingFiles)
                    {
                        NotifyLogMsg("Package '" + packageInfo.FilePackageFilename + "' contains a missing file: " + missingFile, Severity.Warning);
                    }

                    // Notify about missing from package files
                    foreach (string missingFile in packageInfo.MissingFromPackageFiles)
                    {
                        NotifyLogMsg("Layout for package '" + packageInfo.FilePackageFilename + "' contains a file not present in package: " + missingFile, Severity.Warning);
                    }

                    // Execute the actions
                    foreach (NamedAction action in actions)
                    {
                        if (StopRequested)
                        {
                            break;
                        }

                        // Notify about this step
                        if (PackageStep != null)
                        {
                            PackageStep(this, new PackageStepEventArgs()
                            {
                                StepName = action.Name
                            });
                        }

                        // Execute the step
                        action.Action();
                    }

                    writer.Close();
                    file.Close();
                }
            }
            catch (Exception e)
            {
                NotifyLogMsg("Error writing package \"" + packageInfo.FilePackageFilename + "\":" + e.Message, Severity.Error);
            }
        }