Merge pull request #310 from blowfishpro/AllowEmptyLinesAndCommentsInBlacklist

Allow empty lines and comments in blacklist/whitelist
This commit is contained in:
Chris Adderley 2019-02-06 21:17:35 -08:00 committed by GitHub
commit beaee80138
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 deletions

View File

@ -9,6 +9,7 @@ namespace Restock
[KSPAddon(KSPAddon.Startup.Instantly, true)] [KSPAddon(KSPAddon.Startup.Instantly, true)]
public class ResourceBlacklist : MonoBehaviour public class ResourceBlacklist : MonoBehaviour
{ {
private readonly string[] commentSep = { "//" };
private void Start() private void Start()
{ {
HashSet<UrlDir.UrlFile> blacklist = new HashSet<UrlDir.UrlFile>(); HashSet<UrlDir.UrlFile> blacklist = new HashSet<UrlDir.UrlFile>();
@ -23,7 +24,10 @@ namespace Restock
Debug.Log($"[Restock] Reading blacklist {file.url}.{file.fileExtension}"); Debug.Log($"[Restock] Reading blacklist {file.url}.{file.fileExtension}");
foreach (string line in File.ReadAllLines(file.fullPath)) foreach (string line in File.ReadAllLines(file.fullPath))
{ {
foreach (UrlDir.UrlFile blacklistFile in FindFiles(line, gameData)) string lineBeforeComment = line.Split(commentSep, 2, StringSplitOptions.None)[0].Trim();
if (lineBeforeComment == string.Empty) continue;
foreach (UrlDir.UrlFile blacklistFile in FindFiles(lineBeforeComment, gameData))
{ {
blacklist.Add(blacklistFile); blacklist.Add(blacklistFile);
} }
@ -34,7 +38,10 @@ namespace Restock
Debug.Log($"[Restock] Reading whitelist {file.url}.{file.fileExtension}"); Debug.Log($"[Restock] Reading whitelist {file.url}.{file.fileExtension}");
foreach (string line in File.ReadAllLines(file.fullPath)) foreach (string line in File.ReadAllLines(file.fullPath))
{ {
foreach (UrlDir.UrlFile whitelistFile in FindFiles(line, gameData)) string lineBeforeComment = line.Split(commentSep, 2, StringSplitOptions.None)[0].Trim();
if (lineBeforeComment == string.Empty) continue;
foreach (UrlDir.UrlFile whitelistFile in FindFiles(lineBeforeComment, gameData))
{ {
whitelist.Add(whitelistFile); whitelist.Add(whitelistFile);
} }