[Logiqx, Utilities] Use helper methods

This commit is contained in:
Matt Nadareski
2018-01-04 18:14:47 -08:00
parent 616ede6f58
commit e04370b1f1
2 changed files with 34 additions and 175 deletions

View File

@@ -144,51 +144,15 @@ namespace SabreTools.Library.DatFiles
} }
if (xtr.GetAttribute("forcemerging") != null && ForceMerging == ForceMerging.None) if (xtr.GetAttribute("forcemerging") != null && ForceMerging == ForceMerging.None)
{ {
switch (xtr.GetAttribute("forcemerging")) ForceMerging = Utilities.GetForceMerging(xtr.GetAttribute("forcemerging"));
{
case "none":
ForceMerging = ForceMerging.None;
break;
case "split":
ForceMerging = ForceMerging.Split;
break;
case "merged":
ForceMerging = ForceMerging.Merged;
break;
case "nonmerged":
ForceMerging = ForceMerging.NonMerged;
break;
case "full":
ForceMerging = ForceMerging.Full;
break;
}
} }
if (xtr.GetAttribute("forcenodump") != null && ForceNodump == ForceNodump.None) if (xtr.GetAttribute("forcenodump") != null && ForceNodump == ForceNodump.None)
{ {
switch (xtr.GetAttribute("forcenodump")) ForceNodump = Utilities.GetForceNodump(xtr.GetAttribute("forcenodump"));
{
case "obsolete":
ForceNodump = ForceNodump.Obsolete;
break;
case "required":
ForceNodump = ForceNodump.Required;
break;
case "ignore":
ForceNodump = ForceNodump.Ignore;
break;
}
} }
if (xtr.GetAttribute("forcepacking") != null && ForcePacking == ForcePacking.None) if (xtr.GetAttribute("forcepacking") != null && ForcePacking == ForcePacking.None)
{ {
switch (xtr.GetAttribute("forcepacking")) ForcePacking = Utilities.GetForcePacking(xtr.GetAttribute("forcepacking"));
{
case "zip":
ForcePacking = ForcePacking.Zip;
break;
case "unzip":
ForcePacking = ForcePacking.Unzip;
break;
}
} }
xtr.Read(); xtr.Read();
break; break;
@@ -346,51 +310,15 @@ namespace SabreTools.Library.DatFiles
} }
if (headreader.GetAttribute("forcemerging") != null && ForceMerging == ForceMerging.None) if (headreader.GetAttribute("forcemerging") != null && ForceMerging == ForceMerging.None)
{ {
switch (headreader.GetAttribute("forcemerging")) ForceMerging = Utilities.GetForceMerging(headreader.GetAttribute("forcemerging"));
{
case "none":
ForceMerging = ForceMerging.None;
break;
case "split":
ForceMerging = ForceMerging.Split;
break;
case "merged":
ForceMerging = ForceMerging.Merged;
break;
case "nonmerged":
ForceMerging = ForceMerging.NonMerged;
break;
case "full":
ForceMerging = ForceMerging.Full;
break;
}
} }
if (headreader.GetAttribute("forcenodump") != null && ForceNodump == ForceNodump.None) if (headreader.GetAttribute("forcenodump") != null && ForceNodump == ForceNodump.None)
{ {
switch (headreader.GetAttribute("forcenodump")) ForceNodump = Utilities.GetForceNodump(headreader.GetAttribute("forcenodump"));
{
case "obsolete":
ForceNodump = ForceNodump.Obsolete;
break;
case "required":
ForceNodump = ForceNodump.Required;
break;
case "ignore":
ForceNodump = ForceNodump.Ignore;
break;
}
} }
if (headreader.GetAttribute("forcepacking") != null && ForcePacking == ForcePacking.None) if (headreader.GetAttribute("forcepacking") != null && ForcePacking == ForcePacking.None)
{ {
switch (headreader.GetAttribute("forcepacking")) ForcePacking = Utilities.GetForcePacking(headreader.GetAttribute("forcepacking"));
{
case "zip":
ForcePacking = ForcePacking.Zip;
break;
case "unzip":
ForcePacking = ForcePacking.Unzip;
break;
}
} }
headreader.Read(); headreader.Read();
break; break;
@@ -428,49 +356,19 @@ namespace SabreTools.Library.DatFiles
case "forcemerging": case "forcemerging":
if (ForceMerging == ForceMerging.None) if (ForceMerging == ForceMerging.None)
{ {
switch (content) ForceMerging = Utilities.GetForceMerging(content);
{
case "split":
ForceMerging = ForceMerging.Split;
break;
case "none":
ForceMerging = ForceMerging.None;
break;
case "full":
ForceMerging = ForceMerging.Full;
break;
}
} }
break; break;
case "forcenodump": case "forcenodump":
if (ForceNodump == ForceNodump.None) if (ForceNodump == ForceNodump.None)
{ {
switch (content) ForceNodump = Utilities.GetForceNodump(content);
{
case "obsolete":
ForceNodump = ForceNodump.Obsolete;
break;
case "required":
ForceNodump = ForceNodump.Required;
break;
case "ignore":
ForceNodump = ForceNodump.Ignore;
break;
}
} }
break; break;
case "forcepacking": case "forcepacking":
if (ForcePacking == ForcePacking.None) if (ForcePacking == ForcePacking.None)
{ {
switch (content) ForcePacking = Utilities.GetForcePacking(content);
{
case "zip":
ForcePacking = ForcePacking.Zip;
break;
case "unzip":
ForcePacking = ForcePacking.Unzip;
break;
}
} }
break; break;
} }
@@ -540,29 +438,13 @@ namespace SabreTools.Library.DatFiles
// Get the supported value from the reader // Get the supported value from the reader
if (subreader.GetAttribute("supported") != null) if (subreader.GetAttribute("supported") != null)
{ {
switch (subreader.GetAttribute("supported")) supported = Utilities.GetYesNo(subreader.GetAttribute("supported"));
{
case "no":
supported = false;
break;
case "yes":
supported = true;
break;
}
} }
// Get the runnable value from the reader // Get the runnable value from the reader
if (subreader.GetAttribute("runnable") != null) if (subreader.GetAttribute("runnable") != null)
{ {
switch (subreader.GetAttribute("runnable")) machine.Runnable = Utilities.GetYesNo(subreader.GetAttribute("runnable"));
{
case "no":
machine.Runnable = false;
break;
case "yes":
machine.Runnable = true;
break;
}
} }
if (superdat && !keep) if (superdat && !keep)
@@ -705,14 +587,7 @@ namespace SabreTools.Library.DatFiles
bool? defaultrel = null; bool? defaultrel = null;
if (subreader.GetAttribute("default") != null) if (subreader.GetAttribute("default") != null)
{ {
if (subreader.GetAttribute("default") == "yes") defaultrel = Utilities.GetYesNo(subreader.GetAttribute("default"));
{
defaultrel = true;
}
else if (subreader.GetAttribute("default") == "no")
{
defaultrel = false;
}
} }
DatItem relrom = new Release DatItem relrom = new Release
@@ -747,14 +622,7 @@ namespace SabreTools.Library.DatFiles
bool? defaultbios = null; bool? defaultbios = null;
if (subreader.GetAttribute("default") != null) if (subreader.GetAttribute("default") != null)
{ {
if (subreader.GetAttribute("default") == "yes") defaultbios = Utilities.GetYesNo(subreader.GetAttribute("default"));
{
defaultbios = true;
}
else if (subreader.GetAttribute("default") == "no")
{
defaultbios = false;
}
} }
DatItem biosrom = new BiosSet DatItem biosrom = new BiosSet
@@ -851,22 +719,10 @@ namespace SabreTools.Library.DatFiles
string merge = subreader.GetAttribute("merge"); string merge = subreader.GetAttribute("merge");
// If the rom has a status, flag it // If the rom has a status, flag it
its = ItemStatus.None; its = Utilities.GetItemStatus(subreader.GetAttribute("status"));
if (subreader.GetAttribute("flags") == "good" || subreader.GetAttribute("status") == "good") if (its == ItemStatus.None)
{ {
its = ItemStatus.Good; its = Utilities.GetItemStatus(subreader.GetAttribute("flags"));
}
if (subreader.GetAttribute("flags") == "baddump" || subreader.GetAttribute("status") == "baddump")
{
its = ItemStatus.BadDump;
}
if (subreader.GetAttribute("flags") == "nodump" || subreader.GetAttribute("status") == "nodump")
{
its = ItemStatus.Nodump;
}
if (subreader.GetAttribute("flags") == "verified" || subreader.GetAttribute("status") == "verified")
{
its = ItemStatus.Verified;
} }
// If the rom has a Date attached, read it in and then sanitize it // If the rom has a Date attached, read it in and then sanitize it
@@ -1065,21 +921,7 @@ namespace SabreTools.Library.DatFiles
if (flagreader.GetAttribute("name") != null && flagreader.GetAttribute("value") != null) if (flagreader.GetAttribute("name") != null && flagreader.GetAttribute("value") != null)
{ {
string content = flagreader.GetAttribute("value"); string content = flagreader.GetAttribute("value");
switch (flagreader.GetAttribute("name")) its = Utilities.GetItemStatus(flagreader.GetAttribute("name"));
{
case "good":
its = ItemStatus.Good;
break;
case "baddump":
its = ItemStatus.BadDump;
break;
case "nodump":
its = ItemStatus.Nodump;
break;
case "verified":
its = ItemStatus.Verified;
break;
}
} }
break; break;
} }

View File

@@ -813,6 +813,23 @@ namespace SabreTools.Library.Tools
} }
} }
/// <summary>
/// Get bool value from input string
/// </summary>
/// <param name="yesno">String to get value from</param>
/// <returns>Bool corresponding to the string</returns>
public static bool GetYesNo(string yesno)
{
switch (yesno?.ToLowerInvariant())
{
case "yes":
return true;
default:
case "no":
return false;
}
}
#endregion #endregion
#region File Information #region File Information