Skip to content

Commit

Permalink
- Fixed comment preservation for instrument and vocal arrangements.
Browse files Browse the repository at this point in the history
- Fixed QuickAdd DLCKey null exception.
  • Loading branch information
cozy1 committed Mar 31, 2017
1 parent 30e024d commit 29da7cc
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 20 deletions.
7 changes: 5 additions & 2 deletions RocksmithTookitGUI/DLCPackageCreator/ArrangementForm.cs
Expand Up @@ -223,6 +223,7 @@ public void LoadArrangementData(string xmlFilePath)
{
//Song XML File
Arrangement.SongXml.File = xmlFilePath;
Arrangement.XmlComments = Song2014.ReadXmlComments(xmlFilePath);

// Song Info
if (!ReferenceEquals(_xmlSong, null))
Expand Down Expand Up @@ -758,9 +759,11 @@ private void ShowTuningForm(ArrangementType selectedType, TuningDefinition tunin
// get the latest comments from the XML to check if previous bass fixed is valid
if (!String.IsNullOrEmpty(Arrangement.SongXml.File))
{
var xmlComments = Song2014.ReadXmlComments(Arrangement.SongXml.File);
var isBassFixed = xmlComments.Any(xComment => xComment.ToString().Contains("Low Bass Tuning Fixed")) || Convert.ToDouble(txtFrequency.Text) == 220.00;
//var xmlComments = Song2014.ReadXmlComments(Arrangement.SongXml.File);
//var isBassFixed = xmlComments.Any(xComment => xComment.ToString().Contains("Low Bass Tuning Fixed")) || Convert.ToDouble(txtFrequency.Text) == 220.00;

var isBassFixed = Arrangement.XmlComments.Any(xComment => xComment.ToString().Contains("Low Bass Tuning Fixed")) || Convert.ToDouble(txtFrequency.Text) == 220.00;

if (isBassFixed && !tuning.UIName.Contains("Fixed"))
{
// UIName may contain spaces, where as Name contains no spaces
Expand Down
14 changes: 7 additions & 7 deletions RocksmithTookitGUI/DLCPackageCreator/DLCPackageCreator.cs
Expand Up @@ -43,7 +43,6 @@ public partial class DLCPackageCreator : UserControl
public static readonly string MESSAGEBOX_CAPTION = "CDLC Package Creator";
private BackgroundWorker bwGenerate = new BackgroundWorker();
private string dlcDestPath;
private string dlcKeyOrg; // used to preserve original
private StringBuilder errorsFound;
private bool fixLowBass;
private bool fixMultiTone;
Expand Down Expand Up @@ -371,8 +370,7 @@ public void LoadTemplateFile(string templatePath)
foreach (var arr in info.Arrangements)
{
// load xml comments
if (arr.ArrangementType == ArrangementType.Bass || arr.ArrangementType == ArrangementType.Guitar)
arr.XmlComments = Song2014.ReadXmlComments(arr.SongXml.File);
arr.XmlComments = Song2014.ReadXmlComments(arr.SongXml.File);

// apply bassfix to template info in case arrangement was changed in EOF
if (arr.ArrangementType == ArrangementType.Bass)
Expand Down Expand Up @@ -781,7 +779,7 @@ private void FillPackageCreatorForm(DLCPackageData info, string filesBaseDir)
var BasePath = Path.GetDirectoryName(filesBaseDir);

// Song INFO
txtDlcKey.Text = dlcKeyOrg = info.Name;
txtDlcKey.Text = info.Name;

PopulateAppIdCombo();
Application.DoEvents();
Expand Down Expand Up @@ -1602,9 +1600,6 @@ public void btnPackageGenerate_Click(object sender = null, EventArgs e = null)

packageData.ToolkitInfo.PackageComment = arrIdComment;
}
else
// maintain use of original DLCKey, as well as, PID
packageData.Name = dlcKeyOrg;
}

// fire up a fake progress bar to show app is alive and well
Expand Down Expand Up @@ -1661,7 +1656,12 @@ public void btnPackageGenerate_Click(object sender = null, EventArgs e = null)

// skip vocal and showlight arrangements
if (arr.ArrangementType == ArrangementType.Vocal || arr.ArrangementType == ArrangementType.ShowLight)
{
if (arr.ArrangementType == ArrangementType.Vocal)
Song2014.WriteXmlComments(arr.SongXml.File, arr.XmlComments);

continue;
}

progress += step;
pbUpdateProgress.Value = (progress > 100 ? 100 : progress);
Expand Down
Binary file modified RocksmithTookitGUI/Resources/BetaInfo.rtf
Binary file not shown.
10 changes: 5 additions & 5 deletions RocksmithToolkitLib/DLCPackage/Arrangement.cs
Expand Up @@ -108,14 +108,14 @@ public Arrangement(Attributes2014 attr, string xmlSongFile, bool fixMultiTone =
this.Id = Guid.Parse(attr.PersistentID);
this.MasterId = attr.MasterID_RDV;

//Filter out showlights\vocals
// Save xml comments
this.XmlComments = Song2014.ReadXmlComments(xmlSongFile);

// Filter out showlights\vocals
if (ArrangementType != ArrangementType.Guitar && ArrangementType != ArrangementType.Bass)
return;

// save xml comments
this.XmlComments = Song2014.ReadXmlComments(xmlSongFile);

//Tones
// Tones
if (attr.Tones == null) // RS2012
{
this.ToneBase = attr.Tone_Base;
Expand Down
13 changes: 8 additions & 5 deletions RocksmithToolkitLib/XML/Song2014.cs
Expand Up @@ -280,7 +280,9 @@ public Song2014(Sng2014HSL.Sng sngData, Attributes2014 attr = null)
}

/// <summary>
/// Reads the xml comments, like EOF and DDC, to keep track of its versions.
/// Reads the EOF, toolkit, and DDC xml comments
/// Used for traceability of version and revisions
/// NOTE: EOF Arrangements and Vocals contain comments
/// </summary>
/// <param name="xmlSongRS2014File">Xml file path.</param>
public static IEnumerable<XComment> ReadXmlComments(string xmlSongRS2014File)
Expand All @@ -299,7 +301,7 @@ public static IEnumerable<XComment> ReadXmlComments(string xmlSongRS2014File)
}

/// <summary>
/// Write the CST\EOF\DDC xml comments
/// Write the CST\EOF\DDC xml arrangement comments
/// </summary>
/// <param name="xmlSongFile"></param>
/// <param name="commentNodes"></param>
Expand All @@ -311,12 +313,13 @@ public static void WriteXmlComments(string xmlSongFile, IEnumerable<XComment> co
const string CST_MAGIC = " CST v";
var sameComment = false;
var sameVersion = false;
var xml = XDocument.Load(xmlSongFile);
var rootnode = xml.Element("song");
var xml = XDocument.Load(xmlSongFile);
var rootElement = xmlSongFile.ToLower().Contains("vocals") ? "vocals" : "song";
var rootnode = xml.Element(rootElement);

if (rootnode == null)
throw new InvalidDataException(xmlSongFile + Environment.NewLine +
"XML file does not contain 'Song' node.");
"XML file does not contain required root node.");

// remove all xml comments
xml.DescendantNodes().OfType<XComment>().Remove();
Expand Down
2 changes: 1 addition & 1 deletion VersionInfo.txt
@@ -1 +1 @@
1315c012
30e024d1

0 comments on commit 29da7cc

Please sign in to comment.