Exemple #1
0
        static void ExportXml(List <string> inputFiles, CmdOptions options)
        {
            Score  score      = new Score();
            string identifier = "none";

            foreach (var xmlFile in inputFiles)
            {
                Console.WriteLine("Processing {0} ...", xmlFile);
                Song2014 arrangement = null;
                try
                {
                    arrangement = Song2014.LoadFromFile(xmlFile);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Failed to parse XML input file: " + e.Message);
                }

                if (arrangement != null)
                {
                    // xml files should be named "songidentifier_arrangement.xml",
                    // extract the arrangement identifier, which we use to set
                    // the track name and track color as well as output file name
                    string baseFileName = Path.GetFileNameWithoutExtension(xmlFile);
                    var    identifiers  = baseFileName.Split(new char[] { '_' });
                    string arr          = "";
                    if (identifiers.Length >= 2)
                    {
                        arr = identifiers.Last();
                    }
                    identifier = identifiers.First();

                    ExportArrangement(score, arrangement, arr, options.DifficultyLevel, xmlFile, null);
                    if (options.SplitArrangements)
                    {
                        baseFileName = CleanFileName(
                            ConstructFileName(options.FileNameFormat, score, identifier, identifier, null));
                        baseFileName += " (" + arr + ")";
                        SaveScore(score, baseFileName, options.OutputDirectory, options.OutputFormat);
                        // remember to remove the track from the score again
                        score.Tracks.Clear();
                    }
                }
            }

            if (!options.SplitArrangements)
            {
                score.SortTracks();
                string baseFileName = CleanFileName(
                    ConstructFileName(options.FileNameFormat, score, identifier, identifier, null));
                SaveScore(score, baseFileName, options.OutputDirectory, options.OutputFormat);
            }
        }
Exemple #2
0
        static void Main(string[] args)
        {
            // parse command line arguments
            var options = new CmdOptions();

            if (CommandLine.Parser.Default.ParseArguments(args, options))
            {
                if (options.InputFiles == null || options.InputFiles.Count == 0)
                {
                    Console.Write(options.GetUsage());
                    return;
                }

                // collect a full file list from the inputs by doing a simple glob style
                // file search.
                List <string> inputFiles = new List <string>();
                foreach (var input in options.InputFiles)
                {
                    inputFiles.AddRange(SimpleGlob(input));
                }

                // create output dir, if necessary
                Directory.CreateDirectory(options.OutputDirectory);

                if (!options.XmlMode)
                {
                    for (int i = 0; i < inputFiles.Count; ++i)
                    {
                        Console.WriteLine("[{1}/{2}] Opening archive {0} ...", Path.GetFileName(inputFiles[i]), i + 1, inputFiles.Count);
                        ExportPsarc(inputFiles[i], options);
                    }
                }
                else
                {
                    ExportXml(inputFiles, options);
                }
            }
        }
Exemple #3
0
        static void ExportPsarc(string psarcFile, CmdOptions options)
        {
            var archiveName = Path.GetFileNameWithoutExtension(psarcFile);

            try
            {
                var browser = new PsarcBrowser(psarcFile);

                var songList    = browser.GetSongList();
                var toolkitInfo = browser.GetToolkitInfo();

                if (options.ListSongs)
                {
                    foreach (var song in songList)
                    {
                        Console.WriteLine("[{0}] {1} - {2}  ({3}, {4})   {{{5}}}", song.Identifier,
                                          song.Artist, song.Title, song.Album, song.Year,
                                          string.Join(", ", song.Arrangements));
                    }
                    return;
                }

                // collect all songs to convert
                var toConvert = new List <SongInfo>();
                if (options.Tracks == null || options.Tracks.Count == 0)
                {
                    // if nothing was specified, convert all songs
                    toConvert = toConvert.Concat(songList).ToList();
                }
                else
                {
                    foreach (var songId in options.Tracks)
                    {
                        var songInfo = songList.FirstOrDefault(x => x.Identifier == songId);
                        if (songInfo != null)
                        {
                            toConvert.Add(songInfo);
                        }
                    }
                }

                for (int i = 0; i < toConvert.Count; ++i)
                {
                    var song  = toConvert[i];
                    var score = new Score();
                    // figure out which arrangements to convert
                    var arrangements = song.Arrangements;
                    if (options.Arrangements != null && options.Arrangements.Count > 0)
                    {
                        arrangements = arrangements.Intersect(options.Arrangements).ToList();
                    }

                    Console.WriteLine("({1}/{2}) Converting song {0} ...", song.Identifier, i + 1, toConvert.Count);
                    foreach (var arr in arrangements)
                    {
                        var arrangement = browser.GetArrangement(song.Identifier, arr);
                        if (arrangement == null)
                        {
                            Console.WriteLine(" Failed to get arrangement {0}", arr);
                            continue;
                        }
                        if (arrangement.ArrangementProperties.Metronome == 1)
                        {
                            // CDLC feature: optional arrangements can be generated which feature only
                            // metronome ticks, no music. However, the tab is identical to the normal
                            // track, so we don't need this unless it was explicitly requested.
                            if (options.Arrangements == null || options.Arrangements.Count == 0)
                            {
                                Console.WriteLine(" Arrangement {0} is a metronome track, ignore.", arr);
                                continue;
                            }
                        }
                        ExportArrangement(score, arrangement, arr, options.DifficultyLevel, psarcFile, toolkitInfo);

                        if (options.SplitArrangements)
                        {
                            string baseFileName = ConstructFileName(options.FileNameFormat, score, song.Identifier,
                                                                    archiveName, toolkitInfo);
                            baseFileName = CleanFileName(string.Format("{0} ({1})", baseFileName, arr));
                            SaveScore(score, baseFileName, options.OutputDirectory, options.OutputFormat);
                            // remember to remove the track from the score again
                            score.Tracks.Clear();
                        }
                    }

                    if (!options.SplitArrangements)
                    {
                        score.SortTracks();
                        string baseFileName = CleanFileName(
                            ConstructFileName(options.FileNameFormat, score, song.Identifier, archiveName, toolkitInfo));
                        SaveScore(score, baseFileName, options.OutputDirectory, options.OutputFormat);
                    }
                }
                Console.WriteLine();
            }
            catch (IOException e)
            {
                Console.WriteLine("Error encountered:");
                Console.WriteLine(e.Message);
            }
        }
Exemple #4
0
        static void Main(string[] args)
        {
            // parse command line arguments
            var options = new CmdOptions();

            if (CommandLine.Parser.Default.ParseArguments(args, options))
            {
                if (options.InputFiles == null || options.InputFiles.Count == 0)
                {
                    Console.Write(options.GetUsage());
                    return;
                }

                // collect a full file list from the inputs by doing a simple glob style
                // file matching or by scanning a given directory for eligible files
                List <string> inputFiles = new List <string>();
                foreach (var input in options.InputFiles)
                {
                    if (Directory.Exists(input))
                    {
                        inputFiles.AddRange(ScanDirectory(input, options.Recursive));
                    }
                    else
                    {
                        inputFiles.AddRange(SimpleGlob(input));
                    }
                }

                // create output dir, if necessary
                Directory.CreateDirectory(options.OutputDirectory);

                if (!options.XmlMode)
                {
                    if (options.Incremental)
                    {
                        // only process files which were modified since the last run, we do this
                        // by comparing their last modified date against a timestamp file we store
                        // in the output directory
                        inputFiles = FilterOldFiles(inputFiles, options.OutputDirectory);
                    }

                    for (int i = 0; i < inputFiles.Count; ++i)
                    {
                        Console.WriteLine("[{1}/{2}] Opening archive {0} ...", Path.GetFileName(inputFiles[i]), i + 1, inputFiles.Count);
                        ExportPsarc(inputFiles[i], options);
                    }

                    if (inputFiles.Count == 0)
                    {
                        Console.WriteLine("All files up to date. Nothing to do :)");
                    }
                    else
                    {
                        // finally, create a timestamp file in the output directory for future reference
                        var stream = File.CreateText(Path.Combine(options.OutputDirectory, ".rs2tab.timestamp"));
                        stream.Write(System.DateTime.UtcNow);
                        stream.Close();
                    }
                }
                else
                {
                    ExportXml(inputFiles, options);
                }
            }
        }
Exemple #5
0
        static void ExportXml(List<string> inputFiles, CmdOptions options)
        {
            Score score = new Score();
            string identifier = "none";
            foreach (var xmlFile in inputFiles)
            {
                Console.WriteLine("Processing {0} ...", xmlFile);
                Song2014 arrangement = null;
                try
                {
                    arrangement = Song2014.LoadFromFile(xmlFile);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Failed to parse XML input file: " + e.Message);
                }

                if (arrangement != null)
                {
                    // xml files should be named "songidentifier_arrangement.xml", 
                    // extract the arrangement identifier, which we use to set
                    // the track name and track color as well as output file name
                    string baseFileName = Path.GetFileNameWithoutExtension(xmlFile);
                    var identifiers = baseFileName.Split(new char[] { '_' });
                    string arr = "";
                    if (identifiers.Length >= 2)
                        arr = identifiers.Last();
                    identifier = identifiers.First();

                    ExportArrangement(score, arrangement, arr, options.DifficultyLevel, xmlFile, null);
                    if (options.SplitArrangements)
                    {
                        baseFileName = CleanFileName(
                            ConstructFileName(options.FileNameFormat, score, identifier, identifier, null));
                        baseFileName += " (" + arr + ")";
                        SaveScore(score, baseFileName, options.OutputDirectory, options.OutputFormat);
                        // remember to remove the track from the score again
                        score.Tracks.Clear();
                    }
                }
            }

            if (!options.SplitArrangements)
            {
                score.SortTracks();
                string baseFileName = CleanFileName(
                    ConstructFileName(options.FileNameFormat, score, identifier, identifier, null));
                SaveScore(score, baseFileName, options.OutputDirectory, options.OutputFormat);
            }
        }
Exemple #6
0
        static void ExportPsarc(string psarcFile, CmdOptions options)
        {
            var archiveName = Path.GetFileNameWithoutExtension(psarcFile);
            try
            {
                var browser = new PsarcBrowser(psarcFile);

                var songList = browser.GetSongList();
                var toolkitInfo = browser.GetToolkitInfo();

                if (options.ListSongs)
                {
                    foreach (var song in songList)
                    {
                        Console.WriteLine("[{0}] {1} - {2}  ({3}, {4})   {{{5}}}", song.Identifier,
                            song.Artist, song.Title, song.Album, song.Year,
                            string.Join(", ", song.Arrangements));
                    }
                    return;
                }

                // collect all songs to convert
                var toConvert = new List<SongInfo>();
                if (options.Tracks == null || options.Tracks.Count == 0)
                {
                    // if nothing was specified, convert all songs
                    toConvert = toConvert.Concat(songList).ToList();
                }
                else
                {
                    foreach (var songId in options.Tracks)
                    {
                        var songInfo = songList.FirstOrDefault(x => x.Identifier == songId);
                        if (songInfo != null)
                            toConvert.Add(songInfo);
                    }
                }

                for (int i = 0; i < toConvert.Count; ++i)
                {
                    var song = toConvert[i];
                    var score = new Score();
                    // figure out which arrangements to convert
                    var arrangements = song.Arrangements;
                    if (options.Arrangements != null && options.Arrangements.Count > 0)
                        arrangements = arrangements.Intersect(options.Arrangements).ToList();

                    Console.WriteLine("({1}/{2}) Converting song {0} ...", song.Identifier, i+1, toConvert.Count);
                    foreach (var arr in arrangements)
                    {
                        var arrangement = browser.GetArrangement(song.Identifier, arr);
                        if (arrangement == null)
                        {
                            Console.WriteLine(" Failed to get arrangement {0}", arr);
                            continue;
                        }
                        if (arrangement.ArrangementProperties.Metronome == 1)
                        {
                            // CDLC feature: optional arrangements can be generated which feature only
                            // metronome ticks, no music. However, the tab is identical to the normal
                            // track, so we don't need this unless it was explicitly requested.
                            if (options.Arrangements == null || options.Arrangements.Count == 0)
                            {
                                Console.WriteLine(" Arrangement {0} is a metronome track, ignore.", arr);
                                continue;
                            }
                        }
                        ExportArrangement(score, arrangement, arr, options.DifficultyLevel, psarcFile, toolkitInfo);

                        if (options.SplitArrangements)
                        {
                            string baseFileName = ConstructFileName(options.FileNameFormat, score, song.Identifier,
                                archiveName, toolkitInfo);
                            baseFileName = CleanFileName(string.Format("{0} ({1})", baseFileName, arr));
                            SaveScore(score, baseFileName, options.OutputDirectory, options.OutputFormat);
                            // remember to remove the track from the score again
                            score.Tracks.Clear();
                        }
                    }

                    if (!options.SplitArrangements)
                    {
                        score.SortTracks();
                        string baseFileName = CleanFileName(
                            ConstructFileName(options.FileNameFormat, score, song.Identifier, archiveName, toolkitInfo));
                        SaveScore(score, baseFileName, options.OutputDirectory, options.OutputFormat);
                    }
                }
                Console.WriteLine();
            }
            catch (IOException e)
            {
                Console.WriteLine("Error encountered:");
                Console.WriteLine(e.Message);
            }

        }
Exemple #7
0
        static void Main(string[] args)
        {
            // parse command line arguments
            var options = new CmdOptions();
            if (CommandLine.Parser.Default.ParseArguments(args, options))
            {
                if (options.InputFiles == null || options.InputFiles.Count == 0)
                {
                    Console.Write(options.GetUsage());
                    return;
                }

                // collect a full file list from the inputs by doing a simple glob style
                // file matching or by scanning a given directory for eligible files
                List<string> inputFiles = new List<string>();
                foreach (var input in options.InputFiles)
                {
                    if (Directory.Exists(input))
                        inputFiles.AddRange(ScanDirectory(input, options.Recursive));
                    else
                        inputFiles.AddRange(SimpleGlob(input));
                }

                // create output dir, if necessary
                Directory.CreateDirectory(options.OutputDirectory);

                if (!options.XmlMode)
                {
                    if (options.Incremental)
                    {
                        // only process files which were modified since the last run, we do this
                        // by comparing their last modified date against a timestamp file we store
                        // in the output directory
                        inputFiles = FilterOldFiles(inputFiles, options.OutputDirectory);
                    }

                    for (int i = 0; i < inputFiles.Count; ++i)
                    {
                        Console.WriteLine("[{1}/{2}] Opening archive {0} ...", Path.GetFileName(inputFiles[i]), i+1, inputFiles.Count);
                        ExportPsarc(inputFiles[i], options);
                    }

                    if (inputFiles.Count == 0)
                    {
                        Console.WriteLine("All files up to date. Nothing to do :)");
                    }
                    else
                    {
                        // finally, create a timestamp file in the output directory for future reference
                        var stream = File.CreateText(Path.Combine(options.OutputDirectory, ".rs2tab.timestamp"));
                        stream.Write(System.DateTime.UtcNow);
                        stream.Close();
                    }
                }
                else
                {
                    ExportXml(inputFiles, options);
                }

            }
        }
Exemple #8
0
        static void Main(string[] args)
        {
            // parse command line arguments
            var options = new CmdOptions();
            if (CommandLine.Parser.Default.ParseArguments(args, options))
            {
                if (options.InputFiles == null || options.InputFiles.Count == 0)
                {
                    Console.Write(options.GetUsage());
                    return;
                }

                // collect a full file list from the inputs by doing a simple glob style
                // file search.
                List<string> inputFiles = new List<string>();
                foreach (var input in options.InputFiles)
                {
                    inputFiles.AddRange(SimpleGlob(input));
                }

                // create output dir, if necessary
                Directory.CreateDirectory(options.OutputDirectory);

                if (!options.XmlMode)
                {
                    for (int i = 0; i < inputFiles.Count; ++i)
                    {
                        Console.WriteLine("[{1}/{2}] Opening archive {0} ...", Path.GetFileName(inputFiles[i]), i+1, inputFiles.Count);
                        ExportPsarc(inputFiles[i], options);
                    }
                }
                else
                {
                    ExportXml(inputFiles, options);
                }
            }
        }