Exemplo n.º 1
0
        private void ExportSong(string currentDir, SongInfo cur)
        {
            string srcName = Path.GetFileNameWithoutExtension(cur.File.Name);
            Song   song    = songEditor.ReadSong(srcName);

            if (song == null)
            {
                Log("Skipped unknown song: " + cur.File.FullName);
                return;
            }

            string vol = "0";

            if (song.DefaultVolume.HasValue)
            {
                vol = song.DefaultVolume.Value.ToString();
            }

            string title        = FileOperations.SantizeFilename(song.DefaultName);
            string destFilename = srcName + "." + vol + "." + title + cur.File.Extension;
            string dest         = Path.Combine(currentDir, destFilename);

            if (cur.File.Exists)
            {
                File.Copy(cur.File.FullName, dest, true);
            }
            else
            {
                // Create an empty placeholder file.
                File.Create(dest).Dispose();
            }
        }
Exemplo n.º 2
0
        private void ImportSong(FileInfo file)
        {
            Match match = filenameRegex.Match(file.Name);

            if (!match.Success)
            {
                Warn("Skipped file due to incorrect filename format: " + file.FullName);
                return;
            }

            if (file.Length == 0)
            {
                Log("Skipped empty file: " + file.FullName);
                return;
            }

            string filename   = match.Groups[1].Value;
            byte   fileVolume = byte.Parse(match.Groups[2].Value);
            string title      = match.Groups[3].Value;

            Song defSong = songEditor.GetDefaultSong(filename);
            Song curSong = songEditor.ReadSong(filename);

            if (defSong == null)
            {
                Log("Skipped unknown song: " + file.FullName);
                return;
            }

            if (importedSongs.ContainsKey(filename))
            {
                string first = importedSongs[filename];
                Warn("Song file '" + filename + "' has already been imported from '"
                     + first + "'. Skipping subsequent file: " + file.Name);
                return;
            }

            importedSongs.Add(filename, file.Name);

            if (FileOperations.SantizeFilename(curSong.DefaultName) == title)
            {
                title = curSong.DefaultName;
            }

            if (fileVolume > 127)
            {
                Warn("Volume decreased to maximum of 127 for file: " + file.FullName);
                fileVolume = 127;
            }

            byte?volume = fileVolume;

            if (fileVolume == 0)
            {
                Log("Ignoring 0 volume for: " + file.FullName);
                volume = null;
            }
            else if (defSong.DefaultVolume.HasValue &&
                     defSong.DefaultVolume.Value == fileVolume)
            {
                volume = null;
            }

            Song song = new Song(title, filename, defSong.ID, volume, defSong.InfoPacIndex);

            songEditor.WriteSong(song);

            File.Copy(file.FullName, new SongInfo(song.Filename).File.FullName, true);
        }