/// <summary> /// Converts RS1 Song Object to *.sng File /// </summary> /// <param name="rs1Song"></param> /// <param name="outputPath"></param> /// <returns>Path to binary *.sng file</returns> public string SongToSngFilePath(Song rs1Song, string outputPath) { string rs1XmlPath; using (var obj = new Rs1Converter()) rs1XmlPath = obj.SongToXml(rs1Song, outputPath, true); ArrangementType arrangementType; if (rs1Song.Arrangement.ToLower() == "bass") { arrangementType = ArrangementType.Bass; } else { arrangementType = ArrangementType.Guitar; } var sngFilePath = Path.ChangeExtension(rs1XmlPath, ".sng"); SngFileWriter.Write(rs1XmlPath, sngFilePath, arrangementType, new Platform(GamePlatform.Pc, GameVersion.None)); if (File.Exists(rs1XmlPath)) { File.Delete(rs1XmlPath); } return(sngFilePath); }
private void sngConvertButton_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(InputXmlFile)) { return; } if (string.IsNullOrEmpty(OutputSngFile)) { return; } try { SngFileWriter.Write(InputXmlFile, OutputSngFile, ArrangementType, Platform); MessageBox.Show("Process Complete", "File Creation Process"); } catch (Exception ex) { var errorMessage = ex.Message; if (ex.InnerException != null && !string.IsNullOrEmpty(ex.InnerException.Message)) { errorMessage += "\n" + ex.InnerException.Message; } PSTaskDialog.cTaskDialog.MessageBox("Error", "Conversion has failed.", errorMessage, ex.ToString(), "Click 'show details' for complete exception information.", "", PSTaskDialog.eTaskDialogButtons.OK, PSTaskDialog.eSysIcons.Error, PSTaskDialog.eSysIcons.Information); } }
private void TestSngGeneration(SngFile rsSng, Action <SngFile, StringBuilder> func) { var songKey = rsSng.Metadata.SongTitle + rsSng.Metadata.Arrangement + rsSng.Metadata.SongPart; if (songKey == "0") { return; } string xmlName = null, xmlLocation = null; if (rsXmlMappings.ContainsKey(songKey)) { xmlName = rsXmlMappings[songKey]; if (xmlName == null) { return; } xmlLocation = Path.Combine(@"C:\Projects\RS\RS XML Clean", Path.ChangeExtension(xmlName, "xml")); } if (!File.Exists(xmlLocation)) { xmlName = rsSng.Metadata.SongTitle + " - " + rsSng.Metadata.Arrangement; xmlLocation = Path.Combine(@"C:\Projects\RS\RS XML Clean", Path.ChangeExtension(xmlName, "xml")); } if (!File.Exists(xmlLocation)) { Assert.Fail("Couldn't find XML file for SNG: {0}", songKey); } var tmpSngLocation = Path.GetTempFileName(); var arrangement = rsSng.Metadata.Arrangement == "Bass" ? ArrangementType.Bass : ArrangementType.Guitar; SngFileWriter.Write(xmlLocation, tmpSngLocation, arrangement, new Platform(GamePlatform.Pc, GameVersion.None)); SngFile toolkitSng = new SngFile(tmpSngLocation); StringBuilder sb = new StringBuilder(); func(toolkitSng, sb); try { File.Delete(tmpSngLocation); } catch { } if (sb.Length > 0) { Assert.Fail(sb.ToString()); } }
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 (string.IsNullOrEmpty(arguments.InputFile)) { ShowHelpfulError("Must specify an input file."); return(1); } if (!File.Exists(arguments.InputFile)) { ShowHelpfulError("Specified input file does not exist."); return(1); } if (string.IsNullOrEmpty(arguments.OutputFile)) { arguments.OutputFile = Path.ChangeExtension(arguments.InputFile, "sng"); } } catch (OptionException ex) { ShowHelpfulError(ex.Message); return(1); } SngFileWriter.Write(arguments.InputFile, arguments.OutputFile, arguments.ArrangementType, arguments.Platform); Console.WriteLine(string.Format("Successfully converted XML file to SNG file.")); Console.WriteLine("\tInput: " + arguments.InputFile); Console.WriteLine("\tOutput: " + arguments.OutputFile); return(0); }
private static void UpdateSng(string songDirectory, Platform platform) { var xmlFiles = Directory.EnumerateFiles(Path.Combine(songDirectory, @"GR\Behaviors\Songs")); foreach (var xmlFile in xmlFiles) { if (File.Exists(xmlFile) && Path.GetExtension(xmlFile) == ".xml") { var sngFile = Path.Combine(songDirectory, "GRExports", platform.GetPathName()[1], Path.GetFileNameWithoutExtension(xmlFile) + ".sng"); var arrType = ArrangementType.Guitar; if (Path.GetFileName(xmlFile).ToLower().Contains("vocal")) { arrType = ArrangementType.Vocal; SngFileWriter.Write(xmlFile, sngFile, arrType, platform); } else { Song song = Song.LoadFromFile(xmlFile); if (!Enum.TryParse <ArrangementType>(song.Arrangement, out arrType)) { if (song.Arrangement.ToLower().Contains("bass")) { arrType = ArrangementType.Bass; } } } SngFileWriter.Write(xmlFile, sngFile, arrType, platform); } else { throw new ArgumentException(String.Format("'{0}' is not a valid XML file.", xmlFile)); } } }