Exemple #1
0
        SoundFile FillDuration(SoundFile sound)
        {
            if (sound.duration == 0)
            {
                var size = sound.file.Size;
                switch (this.GetExtensionFromPath(sound.name))
                {
                case ".ogg":
                    sound.duration = (0.0002 * size) - 0.3996;
                    break;

                case ".mp3":
                    sound.duration = (0.00005 * size) + 1.1362;
                    break;

                default:
                    //throw new Exception(string.Format("Can not determine duration of type {0}.", GetExtensionFromPath(sound.name)));
                    //Console.WriteLine(string.Format("Can not determine duration of type {0}.", GetExtensionFromPath(sound.name)));
                    sound.duration = (0.0005 * size);
                    break;
                }
            }
            progressFunc();
            return(sound);
        }
        void CreateSubfoldersFromUnderscore(Folder folder)
        {
            List <SoundFile> SoundsToRemove = new List <SoundFile>();

            foreach (SoundFile sound in folder.sounds)
            {
                if (sound.name.Contains("_"))
                {
                    int    splitI     = sound.name.IndexOf("_") + 1;
                    string newSubName = sound.name.Substring(0, splitI);

                    SoundFile newSound = new SoundFile();
                    newSound.name     = sound.name.Substring(splitI);
                    newSound.duration = sound.duration;

                    Folder newFolder = GetSubfolder(folder, newSubName);
                    newFolder.sounds.Add(newSound);
                    SoundsToRemove.Add(sound);
                }
            }
            foreach (SoundFile sound in SoundsToRemove)
            {
                folder.sounds.Remove(sound);
            }

            foreach (Folder subFolder in folder.folders)
            {
                CreateSubfoldersFromUnderscore(subFolder);
            }
        }
Exemple #3
0
 private void AddSoundToFolderSystem(Folder folder, MpqFile file, int offset)
 {
     if (file.Name.IndexOf("\\", offset) >= 0)
     {
         var splitOffset = file.Name.IndexOf("\\", offset);
         var folderName  = file.Name.Substring(offset, splitOffset - offset);
         var subFolder   = folder.folders.Where(f => f.name == folderName).FirstOrDefault();
         if (subFolder == null)
         {
             subFolder      = new Folder();
             subFolder.name = folderName + "\\\\";
             folder.folders.Add(subFolder);
         }
         var remainingPath = file.Name.Substring(file.Name.IndexOf("\\") + 1);
         AddSoundToFolderSystem(subFolder, file, splitOffset + 1);
     }
     else
     {
         var soundFile = new SoundFile();
         soundFile.name = file.Name.Substring(offset);
         soundFile.file = file;
         folder.sounds.Add(soundFile);
         soundsFound++;
     }
 }
        void OptimizeFolder(Folder folder)
        {
            List <Folder> foldersToRemove = new List <Folder>();

            for (int i = 0; i < folder.folders.Count; i++)
            {
                Folder subFolder = folder.folders[i];

                if (subFolder.folders.Count == 1 && subFolder.sounds.Count == 0)
                {
                    Folder newSubfolder = subFolder.folders[0];
                    newSubfolder.name = subFolder.name + newSubfolder.name;
                    folder.folders[i] = newSubfolder;
                }

                subFolder = folder.folders[i];
                OptimizeFolder(subFolder);

                if (subFolder.folders.Count == 0 && subFolder.sounds.Count == 1)
                {
                    SoundFile soundFile = subFolder.sounds[0];
                    soundFile.name = subFolder.name + soundFile.name;
                    folder.sounds.Add(soundFile);
                    foldersToRemove.Add(subFolder);
                }
            }
            foreach (Folder subFolder in foldersToRemove)
            {
                folder.folders.Remove(subFolder);
            }
        }
 string SoundFileToString(SoundFile sound)
 {
     return(string.Format(CultureInfo.InvariantCulture, "[\"{0}\"] = {1:00.00},", sound.name, sound.duration));
 }