Skip to content

Commit

Permalink
Merge pull request #28 from mattantonelli/bgm-search
Browse files Browse the repository at this point in the history
Add search params to SaintCoinach.Cmd BGM command
  • Loading branch information
goaaats authored Sep 30, 2021
2 parents 706029c + 992bcd0 commit 111543b
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions SaintCoinach.Cmd/Commands/BgmCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,26 @@ public class BgmCommand : ActionCommandBase {
private ARealmReversed _Realm;

public BgmCommand(ARealmReversed realm)
: base("bgm", "Export all BGM files.") {
: base("bgm", "Export all BGM files (default), or only those matching specific strings, separated by spaces (e.g. bgm_ride bgm_orch)") {
_Realm = realm;
}

public override async Task<bool> InvokeAsync(string paramList) {
var bgms = _Realm.GameData.GetSheet("BGM");
String[] searchStrings;

if (string.IsNullOrWhiteSpace(paramList))
searchStrings = Array.Empty<String>();
else
searchStrings = paramList.Split(' ');

var successCount = 0;
var failCount = 0;
foreach (Xiv.IXivRow bgm in bgms) {
var filePath = bgm["File"].ToString();

try {

if (string.IsNullOrWhiteSpace(filePath))
if (string.IsNullOrWhiteSpace(filePath) || !IsMatch(searchStrings, filePath))
continue;

if (ExportFile(filePath, null)) {
Expand All @@ -51,7 +56,7 @@ public override async Task<bool> InvokeAsync(string paramList) {
var name = orchestrionInfo["Name"].ToString();
var filePath = path["File"].ToString();

if (string.IsNullOrWhiteSpace(filePath))
if (string.IsNullOrWhiteSpace(filePath) || !IsMatch(searchStrings, filePath))
continue;

try {
Expand Down Expand Up @@ -115,5 +120,9 @@ private bool ExportFile(string filePath, string suffix) {

return true;
}

private bool IsMatch(String[] searchStrings, string filePath) {
return searchStrings.Length == 0 || searchStrings.Any(searchString => filePath.IndexOf(searchString, StringComparison.OrdinalIgnoreCase) > 0);
}
}
}

0 comments on commit 111543b

Please sign in to comment.