示例#1
0
        /// <summary>
        /// Generate a file package.
        /// </summary>
        /// <param name="in_soundbanksInfo">Soundbanks data model.</param>
        /// <param name="in_settings">Generation settings.</param>
        /// <param name="in_szOutputFileName">Full path of the file package to be created.</param>
        /// <returns>Returns true when no files are missing.</returns>
        public bool Generate(SoundBanksInfo in_soundbanksInfo, PackageSettings in_settings, List <OrderedFile> in_listOrderedFiles)
        {
            // Open output file.
            FileStream file = new FileStream(in_settings.szFilePackageFilename, FileMode.Create);

            // Create the writer for data.
            FilePackageWriter.Endianness eEndianness;
            switch (in_soundbanksInfo.Platform)
            {
            case Platform.Windows:
                eEndianness = FilePackageWriter.Endianness.LittleEndian;
                break;

            default:
                eEndianness = FilePackageWriter.Endianness.BigEndian;
                break;
            }
            FilePackageWriter writer = new FilePackageWriter(file, eEndianness);

            // Generate the file package.
            bool bAllFilesExist = GeneratePackage(in_soundbanksInfo, in_settings, writer, in_listOrderedFiles);

            writer.Close();
            file.Close();

            return(bAllFilesExist);
        }
示例#2
0
 /// <summary>
 /// File helper: Write a certain amount of padding zeros to file.
 /// </summary>
 /// <param name="in_writer">Binary writer.</param>
 /// <param name="in_uPadSize">Number of zeroed bytes to be written.</param>
 internal static void Pad(FilePackageWriter in_writer, uint in_uPadSize)
 {
     if (in_uPadSize > 0)
     {
         byte[] padding = new byte[in_uPadSize];
         in_writer.Write(padding);
     }
 }
示例#3
0
        /// <summary>
        /// Write header to file.
        /// </summary>
        /// <param name="in_writer">Binary writer.</param>
        public void Write(FilePackageWriter in_writer)
        {
            // Header ID.
            in_writer.WriteAscii("AKPK");

            // Header size.
            in_writer.Write((uint)m_uHeaderSize);

            // Version.
            in_writer.Write((uint)AK_FILE_PACKAGE_VERSION);
        }
示例#4
0
        /// <summary>
        /// Write LUT to file.
        /// NOTE: If there are 0 files, the method writes 4 zeroed bytes.
        /// </summary>
        /// <param name="in_writer">Binary writer.</param>
        public void Write(FilePackageWriter in_writer)
        {
            ulong uPositionBefore = in_writer.Position;

            in_writer.Write(NumFiles);
            foreach (FileEntry file in m_arFiles)
            {
                in_writer.Write(file.uFileID);
                in_writer.Write(file.uBlockSize);
                in_writer.Write(file.uFileSize);
                in_writer.Write(file.uStartingBlock);
                in_writer.Write(file.uLanguageID);
            }
            
            System.Diagnostics.Debug.Assert(TotalSize == in_writer.Position - uPositionBefore);
        }
示例#5
0
        public void ConcatenateFiles(FilePackageWriter in_writer, IProgressNotificationsDispatcher in_notifDispatcher)
        {
            foreach (FileLUT.IncludedFile file in m_arOrganizedFileEntries)
            {
                // Add padding so that next file falls on a block boundary.
                PadToBlock(in_writer, file.uBlockSize, in_writer.Position);

                // At this point we know the file exists.
                System.Diagnostics.Debug.Assert(file.szPath.Length > 0 && System.IO.File.Exists(file.szPath));

                in_notifDispatcher.NotifyLogMsg("Copying file " + file.szPath);

                // Copy file.
                in_writer.Write(System.IO.File.ReadAllBytes(file.szPath));

                in_notifDispatcher.NotifySubstep();
            }
        }
示例#6
0
        /// <summary>
        /// Write string map to file.
        /// </summary>
        /// <param name="in_writer">Binary writer.</param>
        public void Write(FilePackageWriter in_writer)
        {
            ulong uPositionBefore = in_writer.Position;

            in_writer.Write((uint)m_hashStrings.Count);
            List <string> sortedKeys = GetSortedKeys();

            foreach (string szKey in sortedKeys)
            {
                in_writer.Write(m_hashStrings[szKey].Offset);
                in_writer.Write(m_hashStrings[szKey].ID);
            }
            foreach (string szKey in sortedKeys)
            {
                in_writer.Write(szKey);
            }

            System.Diagnostics.Debug.Assert(TotalSize == in_writer.Position - uPositionBefore);
        }
示例#7
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>
        internal bool GeneratePackage(SoundBanksInfo in_soundbanksInfo, PackageSettings in_settings, FilePackageWriter in_writer, List <OrderedFile> in_listOrderedFiles)
        {
            bool bNoFilesMissing = true;

            const int    kNumSubStepsHeader = 6;
            const string kHeaderStepName    = "Generating header";

            OnStepChange(kNumSubStepsHeader, kHeaderStepName);

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

            OnSubStep();

            // Language names map.
            Dictionary <string, uint> mapLanguageIDs = FindAllLanguages(in_soundbanksInfo);
            LanguagesMap langMap = new LanguagesMap(mapLanguageIDs);

            OnSubStep();

            // Banks LUT.
            FileLUT banksLUT = new FileLUT(in_settings.uDefaultBlockSize);

            foreach (FileDescriptorType soundbank in in_soundbanksInfo.SoundBanks.SoundBankCollection)
            {
                if (!banksLUT.Add(soundbank, mapLanguageIDs))
                {
                    bNoFilesMissing = false;
                }
            }
            banksLUT.Sort();
            OnSubStep();

            // Steamed files LUT.
            FileLUT streamsLUT = new FileLUT(in_settings.uDefaultBlockSize);

            foreach (FileDescriptorType stream in in_soundbanksInfo.StreamedFiles.FileCollection)
            {
                if (!streamsLUT.Add(stream, mapLanguageIDs))
                {
                    bNoFilesMissing = false;
                }
            }
            streamsLUT.Sort();
            OnSubStep();

            // Find the header size.
            uint uHeaderSize =
                header.SizeOnDisk +
                langMap.MapSizeSize +
                banksLUT.LUTSizeSize +
                streamsLUT.LUTSizeSize +
                langMap.TotalSize +
                banksLUT.TotalSize +
                streamsLUT.TotalSize;

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

            organizer.AddLUT(AK.Wwise.FilePackager.PackageLayout.Type.SoundBank, banksLUT);
            organizer.AddLUT(AK.Wwise.FilePackager.PackageLayout.Type.StreamedAudio, streamsLUT);
            organizer.OrganizeFiles(uHeaderSize, in_listOrderedFiles, mapLanguageIDs, this);
            OnSubStep();


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


            // Write to output file:

            // Header.
            header.Write(in_writer);
            in_writer.Write(langMap.TotalSize);
            in_writer.Write(banksLUT.TotalSize);
            in_writer.Write(streamsLUT.TotalSize);

            langMap.Write(in_writer);
            banksLUT.Write(in_writer);
            streamsLUT.Write(in_writer);
            OnSubStep();


            // Concatenated files.
            const string kConcatenateStepName = "Concatenating files";

            OnStepChange((int)(banksLUT.NumFiles + streamsLUT.NumFiles), kConcatenateStepName);
            organizer.ConcatenateFiles(in_writer, this);

            return(bNoFilesMissing);
        }
示例#8
0
 /// <summary>
 /// File helper: Write padding zeros to file to meet the required alignment.
 /// </summary>
 /// <param name="in_writer">Binary writer.</param>
 /// <param name="in_uBlockSize">Required alignment.</param>
 /// <param name="in_uOffset">Current offset.</param>
 internal static void PadToBlock(FilePackageWriter in_writer, uint in_uBlockSize, ulong in_uOffset)
 {
     Pad(in_writer, ComputePaddingSize(in_uBlockSize, in_uOffset));
 }