private static void UpdateSng2014(string songDirectory, Platform platform) { var xmlFiles = Directory.GetFiles(Path.Combine(songDirectory, "songs", "arr"), "*_*.xml", SearchOption.AllDirectories); var sngFolder = Path.Combine(songDirectory, "songs", "bin", platform.GetPathName()[1]); //-3 or more times re-calculation foreach (var xmlFile in xmlFiles) { if (File.Exists(xmlFile)) { var xmlName = Path.GetFileNameWithoutExtension(xmlFile); bool noShowlights = true; //Update Showlights if (xmlName.ToLower().Contains("_showlights")) { updateShl(xmlFile); } else { var sngFile = Path.Combine(sngFolder, xmlName + ".sng"); var arrType = ArrangementType.Guitar; if (Path.GetFileName(xmlFile).ToLower().Contains("vocal")) { arrType = ArrangementType.Vocal; } string fontSng = null; var vocSng = Sng2014File.LoadFromFile(sngFile, platform); if (File.Exists(sngFile) && arrType == ArrangementType.Vocal && vocSng.IsCustomFont()) { fontSng = Path.GetTempFileName(); vocSng.WriteChartData(fontSng, new Platform(GamePlatform.Pc, GameVersion.None)); } using (var fs = new FileStream(sngFile, FileMode.Create)) { Sng2014File sng = Sng2014File.ConvertXML(xmlFile, arrType, fontSng); sng.WriteSng(fs, platform); } if (xmlFiles.Any(x => Path.GetFileName(x).Contains(xmlName.Split('_')[0].ToLower() + "_showlights"))) { noShowlights = false; } //Create Showlights if (noShowlights && arrType != ArrangementType.Vocal) { var shlName = Path.Combine(Path.GetDirectoryName(xmlFile), xmlName.Split('_')[0] + "_showlights.xml"); var shl = new RocksmithToolkitLib.DLCPackage.Showlight.Showlights(); if (shl.PopShList(shl.FixShowlights(shl.Genegate(xmlFile).ShowlightList))) { shl.Count = shl.ShowlightList.Count; using (var fs = new FileStream(shlName, FileMode.Create)) shl.Serialize(fs); } } } } } }
private void convertSngXmlButton_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(ConverterSngXmlFile)) { MessageBox.Show(String.Format("File not found: {0}: ", ConverterSngXmlFile), MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error); sngXmlTB.Focus(); return; } if (sng2xmlRadio.Checked) { if (String.IsNullOrEmpty(ConverterManifestFile)) { MessageBox.Show("No manifest file was entered. The song xml file will be generated without song informations like song title, album, artist, tone names, etc.", MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error); } Attributes2014 att = null; if (ConverterArrangementType != ArrangementType.Vocal && !String.IsNullOrEmpty(ConverterManifestFile)) { att = Manifest2014 <Attributes2014> .LoadFromFile(ConverterManifestFile).Entries.ToArray()[0].Value.ToArray()[0].Value; } var sng = Sng2014File.LoadFromFile(ConverterSngXmlFile, ConverterPlatform); var outputFile = Path.Combine(Path.GetDirectoryName(ConverterSngXmlFile), String.Format("{0}.xml", Path.GetFileNameWithoutExtension(ConverterSngXmlFile))); using (FileStream outputStream = new FileStream(outputFile, FileMode.Create, FileAccess.ReadWrite)) { dynamic xml = null; if (ConverterArrangementType == ArrangementType.Vocal) { xml = new Vocals(sng); } else { xml = new Song2014(sng, att ?? null); } xml.Serialize(outputStream); MessageBox.Show(String.Format("XML file was generated! {0}It was saved on same location of sng file specified.", Environment.NewLine), MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Information); } } else if (xml2sngRadio.Checked) { var outputFile = Path.Combine(Path.GetDirectoryName(ConverterSngXmlFile), String.Format("{0}.sng", Path.GetFileNameWithoutExtension(ConverterSngXmlFile))); using (FileStream outputStream = new FileStream(outputFile, FileMode.Create, FileAccess.ReadWrite)) { Sng2014File sng = Sng2014File.ConvertXML(ConverterSngXmlFile, ConverterArrangementType); sng.WriteSng(outputStream, ConverterPlatform); } MessageBox.Show(String.Format("SNG file was generated! {0}It was saved on same location of xml file specified.", Environment.NewLine), MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Information); } }
static int Main(string[] args) { var arguments = DefaultArguments(); var options = GetOptions(arguments); try { options.Parse(args); if (arguments.ShowHelp) { options.WriteOptionDescriptions(Console.Out); return(0); } if (!arguments.Pack && !arguments.Unpack && !arguments.Sng2Xml && !arguments.Xml2Sng) { ShowHelpfulError("Must especify a primary command as 'pack', 'unpack', 'sng2xml' or 'xml2sng'."); return(1); } if (arguments.Input == null && arguments.Input.Length <= 0) { ShowHelpfulError("Must specify at least one input file."); return(1); } if (arguments.Sng2Xml && arguments.Manifest == null && arguments.Manifest.Length <= 0) { Console.WriteLine("No manifest file was entered. The song xml file will be generated without song informations like song title, album, artist, tone names, etc."); } var srcFiles = new List <string>(); foreach (var name in arguments.Input) { if (name.IsDirectory()) { srcFiles.AddRange(Directory.EnumerateFiles(Path.GetFullPath(name), "*.sng", SearchOption.AllDirectories)); } if (File.Exists(name)) { srcFiles.Add(name); } } var errorCount = 0; var indexCount = 0; foreach (string inputFile in srcFiles) { if (!File.Exists(inputFile)) { Console.WriteLine(String.Format("File '{0}' doesn't exists.", inputFile)); continue; } if (arguments.Unpack || arguments.Sng2Xml) { if (Path.GetExtension(inputFile) != ".sng") { Console.WriteLine(String.Format("File '{0}' is not support. \nOnly *.sng are supported on this command.", inputFile)); continue; } } if (arguments.Pack || arguments.Unpack) { var outputFile = Path.Combine(Path.GetDirectoryName(inputFile), String.Format("{0}_{1}.sng", Path.GetFileNameWithoutExtension(inputFile), (arguments.Unpack) ? "decrypted" : "encrypted")); using (FileStream inputStream = new FileStream(inputFile, FileMode.Open, FileAccess.Read)) using (FileStream outputStream = new FileStream(outputFile, FileMode.Create, FileAccess.ReadWrite)) { if (arguments.Pack) { Sng2014File.PackSng(inputStream, outputStream, new Platform(arguments.Platform, GameVersion.RS2014)); } else if (arguments.Unpack) { Sng2014File.UnpackSng(inputStream, outputStream, new Platform(arguments.Platform, GameVersion.RS2014)); } } } else if (arguments.Sng2Xml) { Attributes2014 att = null; if (arguments.ArrangementType != ArrangementType.Vocal && arguments.Manifest != null && arguments.Manifest.Length > indexCount) { att = Manifest2014 <Attributes2014> .LoadFromFile(arguments.Manifest[indexCount]).Entries.ToArray()[0].Value.ToArray()[0].Value; } var sng = Sng2014File.LoadFromFile(inputFile, new Platform(arguments.Platform, GameVersion.RS2014)); var outputFile = Path.Combine(Path.GetDirectoryName(inputFile), String.Format("{0}.xml", Path.GetFileNameWithoutExtension(inputFile))); using (FileStream outputStream = new FileStream(outputFile, FileMode.Create, FileAccess.ReadWrite)) { dynamic xml = null; if (arguments.ArrangementType == ArrangementType.Vocal) { xml = new Vocals(sng); } else { xml = new Song2014(sng, att ?? null); } xml.Serialize(outputStream); } } else if (arguments.Xml2Sng) { var outputFile = Path.Combine(Path.GetDirectoryName(inputFile), String.Format("{0}.sng", Path.GetFileNameWithoutExtension(inputFile))); using (FileStream outputStream = new FileStream(outputFile, FileMode.Create, FileAccess.ReadWrite)) { Sng2014File sng = Sng2014File.ConvertXML(inputFile, arguments.ArrangementType); sng.WriteSng(outputStream, new Platform(arguments.Platform, GameVersion.RS2014)); } } } if (errorCount == 0) { Console.WriteLine("Process successfully completed!"); } else if (errorCount > 0 && errorCount < srcFiles.Count) { Console.WriteLine("Process completed with errors!"); } else { Console.WriteLine("An error occurred!"); } } catch (OptionException ex) { ShowHelpfulError(ex.Message); return(1); } return(0); }