From 06a3c5b19431b6e273d4f4c18ef714ea15fc3a1a Mon Sep 17 00:00:00 2001 From: Bertie2011 <44732286+Bertie2011@users.noreply.github.com> Date: Thu, 21 Jan 2021 21:17:39 +0100 Subject: [PATCH] Added -f switch, string tokenizer (ConsoleHelper) and made all consts PascalCase --- DataPackChecker/ConsoleHelper.cs | 34 +++++++++++++++++++ DataPackChecker/Options.cs | 2 ++ DataPackChecker/Parsers/AdvancementParser.cs | 4 +-- .../Parsers/Dimensions/DimensionParser.cs | 4 +-- .../Parsers/Dimensions/DimensionTypeParser.cs | 4 +-- DataPackChecker/Parsers/FunctionParser.cs | 4 +-- DataPackChecker/Parsers/LootTableParser.cs | 4 +-- DataPackChecker/Parsers/PredicateParser.cs | 4 +-- DataPackChecker/Parsers/RecipeParser.cs | 4 +-- DataPackChecker/Parsers/StructureParser.cs | 4 +-- DataPackChecker/Parsers/TagParser.cs | 4 +-- .../Parsers/WorldGen/BiomeParser.cs | 4 +-- .../WorldGen/ConfiguredCarverParser.cs | 4 +-- .../WorldGen/ConfiguredFeatureParser.cs | 4 +-- .../ConfiguredStructureFeatureParser.cs | 4 +-- .../ConfiguredSurfaceBuilderParser.cs | 4 +-- .../Parsers/WorldGen/NoiseSettingsParser.cs | 4 +-- .../Parsers/WorldGen/ProcessorListParser.cs | 4 +-- .../Parsers/WorldGen/TemplatePoolParser.cs | 4 +-- DataPackChecker/Program.cs | 29 ++++++++++++---- .../Properties/launchSettings.json | 3 +- Shared/Data/Resources/Command.cs | 12 +++---- 22 files changed, 100 insertions(+), 48 deletions(-) diff --git a/DataPackChecker/ConsoleHelper.cs b/DataPackChecker/ConsoleHelper.cs index 7dc9a38..512d24b 100644 --- a/DataPackChecker/ConsoleHelper.cs +++ b/DataPackChecker/ConsoleHelper.cs @@ -1,9 +1,12 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Text; namespace DataPackChecker { static class ConsoleHelper { + private static readonly char[] Quotes = new char[] { '"', '\'' }; + private static readonly char[] Escapable = new char[] { '"', '\'' }; static public void WriteLine(string text, ConsoleColor color = ConsoleColor.White) { Console.ForegroundColor = color; Console.WriteLine(text); @@ -25,5 +28,36 @@ static public void WriteError(Exception e, ConsoleColor color = ConsoleColor.Red if (e.InnerException != null) WriteError(e.InnerException, color, depth + 1); if (depth == 0) Console.ForegroundColor = ConsoleColor.White; } + + static public string[] CreateArgs(string line) { + StringBuilder arg = new StringBuilder(); + char? quote = null; + bool escape = false; + List args = new List(); + for (int i = 0; i < line.Length; i++) { + char c = line[i]; + + // Either process the created argument or record the next character. + if (c == ' ' && quote == null && !escape) { + args.Add(arg.ToString()); + arg.Clear(); + } else if (escape || !Quotes.Any(q => q == c) && c != '\\') { + if (escape && !Escapable.Any(e => e == c)) arg.Append('\\'); + arg.Append(c); + } + + // Change modifiers + if (escape) { + escape = false; + } else if (c == '\\') { + escape = true; + } else if (Quotes.Any(q => q == c)) { + quote = quote == null ? c : (char?)null; + } + } + + if (arg.Length > 0) args.Add(arg.ToString()); + return args.ToArray(); + } } } diff --git a/DataPackChecker/Options.cs b/DataPackChecker/Options.cs index 04cccbb..08766bb 100644 --- a/DataPackChecker/Options.cs +++ b/DataPackChecker/Options.cs @@ -5,6 +5,8 @@ namespace DataPackChecker { class Options { + [Option('f', "arguments-file", HelpText = "Read arguments from a file.", SetName = "Args File")] + public string ArgsPath { get; set; } [Option('o', "keep-open", HelpText = "Keep process running after finishing.")] public bool KeepOpen { get; set; } [Option('d', "data-pack", HelpText = "Path to root folder of data pack, with data folder and pack.mcmeta file inside. Requires -c, --config.", SetName = "Check")] diff --git a/DataPackChecker/Parsers/AdvancementParser.cs b/DataPackChecker/Parsers/AdvancementParser.cs index 0c76033..b868165 100644 --- a/DataPackChecker/Parsers/AdvancementParser.cs +++ b/DataPackChecker/Parsers/AdvancementParser.cs @@ -8,9 +8,9 @@ namespace DataPackChecker.Parsers { static class AdvancementParser { - private static readonly Regex NAMESPACE_PATH_REGEX = new Regex(@"[\\/]advancements([\\/](?.+?))?[\\/](?[^\\/]+)\.json$"); + private static readonly Regex NamespacePathRegex = new Regex(@"[\\/]advancements([\\/](?.+?))?[\\/](?[^\\/]+)\.json$"); static public Advancement TryParse(string absPath, string nsPath) { - var match = NAMESPACE_PATH_REGEX.Match(absPath, nsPath.Length); + var match = NamespacePathRegex.Match(absPath, nsPath.Length); if (!match.Success) return null; var advancement = new Advancement(match.Groups["path"].Value.Replace('\\', '/'), match.Groups["name"].Value); using FileStream fs = new FileStream(absPath, FileMode.Open); diff --git a/DataPackChecker/Parsers/Dimensions/DimensionParser.cs b/DataPackChecker/Parsers/Dimensions/DimensionParser.cs index 215b069..ba19466 100644 --- a/DataPackChecker/Parsers/Dimensions/DimensionParser.cs +++ b/DataPackChecker/Parsers/Dimensions/DimensionParser.cs @@ -8,9 +8,9 @@ namespace DataPackChecker.Parsers.Dimensions { static class DimensionParser { - private static readonly Regex NAMESPACE_PATH_REGEX = new Regex(@"[\\/]dimension([\\/](?.+?))?[\\/](?[^\\/]+)\.json$"); + private static readonly Regex NamespacePathRegex = new Regex(@"[\\/]dimension([\\/](?.+?))?[\\/](?[^\\/]+)\.json$"); static public Dimension TryParse(string absPath, string nsPath) { - var match = NAMESPACE_PATH_REGEX.Match(absPath, nsPath.Length); + var match = NamespacePathRegex.Match(absPath, nsPath.Length); if (!match.Success) return null; var dimension = new Dimension(match.Groups["path"].Value.Replace('\\', '/'), match.Groups["name"].Value); using FileStream fs = new FileStream(absPath, FileMode.Open); diff --git a/DataPackChecker/Parsers/Dimensions/DimensionTypeParser.cs b/DataPackChecker/Parsers/Dimensions/DimensionTypeParser.cs index d40440c..514fff6 100644 --- a/DataPackChecker/Parsers/Dimensions/DimensionTypeParser.cs +++ b/DataPackChecker/Parsers/Dimensions/DimensionTypeParser.cs @@ -8,9 +8,9 @@ namespace DataPackChecker.Parsers.Dimensions { static class DimensionTypeParser { - private static readonly Regex NAMESPACE_PATH_REGEX = new Regex(@"[\\/]dimension_type([\\/](?.+?))?[\\/](?[^\\/]+)\.json$"); + private static readonly Regex NamespacePathRegex = new Regex(@"[\\/]dimension_type([\\/](?.+?))?[\\/](?[^\\/]+)\.json$"); static public DimensionType TryParse(string absPath, string nsPath) { - var match = NAMESPACE_PATH_REGEX.Match(absPath, nsPath.Length); + var match = NamespacePathRegex.Match(absPath, nsPath.Length); if (!match.Success) return null; var dimensionType = new DimensionType(match.Groups["path"].Value.Replace('\\', '/'), match.Groups["name"].Value); using FileStream fs = new FileStream(absPath, FileMode.Open); diff --git a/DataPackChecker/Parsers/FunctionParser.cs b/DataPackChecker/Parsers/FunctionParser.cs index 07d8cb2..bf367bd 100644 --- a/DataPackChecker/Parsers/FunctionParser.cs +++ b/DataPackChecker/Parsers/FunctionParser.cs @@ -5,9 +5,9 @@ namespace DataPackChecker.Parsers { static public class FunctionParser { - private static readonly Regex NAMESPACE_PATH_REGEX = new Regex(@"[\\/]functions([\\/](?.+?))?[\\/](?[^\\/]+)\.mcfunction$"); + private static readonly Regex NamespacePathRegex = new Regex(@"[\\/]functions([\\/](?.+?))?[\\/](?[^\\/]+)\.mcfunction$"); static public Function TryParse(string absPath, string nsPath) { - var match = NAMESPACE_PATH_REGEX.Match(absPath, nsPath.Length); + var match = NamespacePathRegex.Match(absPath, nsPath.Length); if (!match.Success) return null; var function = new Function(match.Groups["path"].Value.Replace('\\', '/'), match.Groups["name"].Value); function.Commands = File.ReadAllLines(absPath).Select((c, i) => new Command(i + 1, c)).ToList(); diff --git a/DataPackChecker/Parsers/LootTableParser.cs b/DataPackChecker/Parsers/LootTableParser.cs index ea346a3..8277f34 100644 --- a/DataPackChecker/Parsers/LootTableParser.cs +++ b/DataPackChecker/Parsers/LootTableParser.cs @@ -8,9 +8,9 @@ namespace DataPackChecker.Parsers { static class LootTableParser { - private static readonly Regex NAMESPACE_PATH_REGEX = new Regex(@"[\\/]loot_tables([\\/](?.+?))?[\\/](?[^\\/]+)\.json$"); + private static readonly Regex NamespacePathRegex = new Regex(@"[\\/]loot_tables([\\/](?.+?))?[\\/](?[^\\/]+)\.json$"); static public LootTable TryParse(string absPath, string nsPath) { - var match = NAMESPACE_PATH_REGEX.Match(absPath, nsPath.Length); + var match = NamespacePathRegex.Match(absPath, nsPath.Length); if (!match.Success) return null; var lootTable = new LootTable(match.Groups["path"].Value.Replace('\\', '/'), match.Groups["name"].Value); using FileStream fs = new FileStream(absPath, FileMode.Open); diff --git a/DataPackChecker/Parsers/PredicateParser.cs b/DataPackChecker/Parsers/PredicateParser.cs index a409d6c..b7fdd1f 100644 --- a/DataPackChecker/Parsers/PredicateParser.cs +++ b/DataPackChecker/Parsers/PredicateParser.cs @@ -8,9 +8,9 @@ namespace DataPackChecker.Parsers { static class PredicateParser { - private static readonly Regex NAMESPACE_PATH_REGEX = new Regex(@"[\\/]predicates([\\/](?.+?))?[\\/](?[^\\/]+)\.json$"); + private static readonly Regex NamespacePathRegex = new Regex(@"[\\/]predicates([\\/](?.+?))?[\\/](?[^\\/]+)\.json$"); static public Predicate TryParse(string absPath, string nsPath) { - var match = NAMESPACE_PATH_REGEX.Match(absPath, nsPath.Length); + var match = NamespacePathRegex.Match(absPath, nsPath.Length); if (!match.Success) return null; var predicate = new Predicate(match.Groups["path"].Value.Replace('\\', '/'), match.Groups["name"].Value); using FileStream fs = new FileStream(absPath, FileMode.Open); diff --git a/DataPackChecker/Parsers/RecipeParser.cs b/DataPackChecker/Parsers/RecipeParser.cs index d456352..691376e 100644 --- a/DataPackChecker/Parsers/RecipeParser.cs +++ b/DataPackChecker/Parsers/RecipeParser.cs @@ -8,9 +8,9 @@ namespace DataPackChecker.Parsers { static class RecipeParser { - private static readonly Regex NAMESPACE_PATH_REGEX = new Regex(@"[\\/]recipes([\\/](?.+?))?[\\/](?[^\\/]+)\.json$"); + private static readonly Regex NamespacePathRegex = new Regex(@"[\\/]recipes([\\/](?.+?))?[\\/](?[^\\/]+)\.json$"); static public Recipe TryParse(string absPath, string nsPath) { - var match = NAMESPACE_PATH_REGEX.Match(absPath, nsPath.Length); + var match = NamespacePathRegex.Match(absPath, nsPath.Length); if (!match.Success) return null; var recipe = new Recipe(match.Groups["path"].Value.Replace('\\', '/'), match.Groups["name"].Value); using FileStream fs = new FileStream(absPath, FileMode.Open); diff --git a/DataPackChecker/Parsers/StructureParser.cs b/DataPackChecker/Parsers/StructureParser.cs index 6b4c0c5..ec0ca07 100644 --- a/DataPackChecker/Parsers/StructureParser.cs +++ b/DataPackChecker/Parsers/StructureParser.cs @@ -8,9 +8,9 @@ namespace DataPackChecker.Parsers { static class StructureParser { - private static readonly Regex NAMESPACE_PATH_REGEX = new Regex(@"[\\/]structures([\\/](?.+?))?[\\/](?[^\\/]+)\.nbt$"); + private static readonly Regex NamespacePathRegex = new Regex(@"[\\/]structures([\\/](?.+?))?[\\/](?[^\\/]+)\.nbt$"); static public Structure TryParse(string absPath, string nsPath) { - var match = NAMESPACE_PATH_REGEX.Match(absPath, nsPath.Length); + var match = NamespacePathRegex.Match(absPath, nsPath.Length); if (!match.Success) return null; return new Structure(match.Groups["path"].Value.Replace('\\', '/'), match.Groups["name"].Value); } diff --git a/DataPackChecker/Parsers/TagParser.cs b/DataPackChecker/Parsers/TagParser.cs index 82aea1b..f351c53 100644 --- a/DataPackChecker/Parsers/TagParser.cs +++ b/DataPackChecker/Parsers/TagParser.cs @@ -8,9 +8,9 @@ namespace DataPackChecker.Parsers { static class TagParser { - private static readonly Regex NAMESPACE_PATH_REGEX = new Regex(@"[\\/]tags[\\/](?[^\\/]+)([\\/](?.+?))?[\\/](?[^\\/]+)\.json$"); + private static readonly Regex NamespacePathRegex = new Regex(@"[\\/]tags[\\/](?[^\\/]+)([\\/](?.+?))?[\\/](?[^\\/]+)\.json$"); static public Tag TryParse(string absPath, string nsPath) { - var match = NAMESPACE_PATH_REGEX.Match(absPath, nsPath.Length); + var match = NamespacePathRegex.Match(absPath, nsPath.Length); if (!match.Success) return null; var type = Tag.TryGetType(match.Groups["type"].Value); if (type == null) return null; diff --git a/DataPackChecker/Parsers/WorldGen/BiomeParser.cs b/DataPackChecker/Parsers/WorldGen/BiomeParser.cs index 5da5dcd..7120a0f 100644 --- a/DataPackChecker/Parsers/WorldGen/BiomeParser.cs +++ b/DataPackChecker/Parsers/WorldGen/BiomeParser.cs @@ -8,9 +8,9 @@ namespace DataPackChecker.Parsers.WorldGen { static class BiomeParser { - private static readonly Regex NAMESPACE_PATH_REGEX = new Regex(@"[\\/]worldgen[\\/]biome([\\/](?.+?))?[\\/](?[^\\/]+)\.json$"); + private static readonly Regex NamespacePathRegex = new Regex(@"[\\/]worldgen[\\/]biome([\\/](?.+?))?[\\/](?[^\\/]+)\.json$"); static public Biome TryParse(string absPath, string nsPath) { - var match = NAMESPACE_PATH_REGEX.Match(absPath, nsPath.Length); + var match = NamespacePathRegex.Match(absPath, nsPath.Length); if (!match.Success) return null; var biome = new Biome(match.Groups["path"].Value.Replace('\\', '/'), match.Groups["name"].Value); using FileStream fs = new FileStream(absPath, FileMode.Open); diff --git a/DataPackChecker/Parsers/WorldGen/ConfiguredCarverParser.cs b/DataPackChecker/Parsers/WorldGen/ConfiguredCarverParser.cs index 9b04521..ae9d64d 100644 --- a/DataPackChecker/Parsers/WorldGen/ConfiguredCarverParser.cs +++ b/DataPackChecker/Parsers/WorldGen/ConfiguredCarverParser.cs @@ -8,9 +8,9 @@ namespace DataPackChecker.Parsers.WorldGen { static class ConfiguredCarverParser { - private static readonly Regex NAMESPACE_PATH_REGEX = new Regex(@"[\\/]worldgen[\\/]configured_carver([\\/](?.+?))?[\\/](?[^\\/]+)\.json$"); + private static readonly Regex NamespacePathRegex = new Regex(@"[\\/]worldgen[\\/]configured_carver([\\/](?.+?))?[\\/](?[^\\/]+)\.json$"); static public ConfiguredCarver TryParse(string absPath, string nsPath) { - var match = NAMESPACE_PATH_REGEX.Match(absPath, nsPath.Length); + var match = NamespacePathRegex.Match(absPath, nsPath.Length); if (!match.Success) return null; var configuredCarver = new ConfiguredCarver(match.Groups["path"].Value.Replace('\\', '/'), match.Groups["name"].Value); using FileStream fs = new FileStream(absPath, FileMode.Open); diff --git a/DataPackChecker/Parsers/WorldGen/ConfiguredFeatureParser.cs b/DataPackChecker/Parsers/WorldGen/ConfiguredFeatureParser.cs index d4cc3ef..3a744b6 100644 --- a/DataPackChecker/Parsers/WorldGen/ConfiguredFeatureParser.cs +++ b/DataPackChecker/Parsers/WorldGen/ConfiguredFeatureParser.cs @@ -8,9 +8,9 @@ namespace DataPackChecker.Parsers.WorldGen { static class ConfiguredFeatureParser { - private static readonly Regex NAMESPACE_PATH_REGEX = new Regex(@"[\\/]worldgen[\\/]configured_feature([\\/](?.+?))?[\\/](?[^\\/]+)\.json$"); + private static readonly Regex NamespacePathRegex = new Regex(@"[\\/]worldgen[\\/]configured_feature([\\/](?.+?))?[\\/](?[^\\/]+)\.json$"); static public ConfiguredFeature TryParse(string absPath, string nsPath) { - var match = NAMESPACE_PATH_REGEX.Match(absPath, nsPath.Length); + var match = NamespacePathRegex.Match(absPath, nsPath.Length); if (!match.Success) return null; var configuredFeature = new ConfiguredFeature(match.Groups["path"].Value.Replace('\\', '/'), match.Groups["name"].Value); using FileStream fs = new FileStream(absPath, FileMode.Open); diff --git a/DataPackChecker/Parsers/WorldGen/ConfiguredStructureFeatureParser.cs b/DataPackChecker/Parsers/WorldGen/ConfiguredStructureFeatureParser.cs index d347187..35f4889 100644 --- a/DataPackChecker/Parsers/WorldGen/ConfiguredStructureFeatureParser.cs +++ b/DataPackChecker/Parsers/WorldGen/ConfiguredStructureFeatureParser.cs @@ -8,9 +8,9 @@ namespace DataPackChecker.Parsers.WorldGen { static class ConfiguredStructureFeatureParser { - private static readonly Regex NAMESPACE_PATH_REGEX = new Regex(@"[\\/]worldgen[\\/]configured_structure_feature([\\/](?.+?))?[\\/](?[^\\/]+)\.json$"); + private static readonly Regex NamespacePathRegex = new Regex(@"[\\/]worldgen[\\/]configured_structure_feature([\\/](?.+?))?[\\/](?[^\\/]+)\.json$"); static public ConfiguredStructureFeature TryParse(string absPath, string nsPath) { - var match = NAMESPACE_PATH_REGEX.Match(absPath, nsPath.Length); + var match = NamespacePathRegex.Match(absPath, nsPath.Length); if (!match.Success) return null; var configuredStructureFeature = new ConfiguredStructureFeature(match.Groups["path"].Value.Replace('\\', '/'), match.Groups["name"].Value); using FileStream fs = new FileStream(absPath, FileMode.Open); diff --git a/DataPackChecker/Parsers/WorldGen/ConfiguredSurfaceBuilderParser.cs b/DataPackChecker/Parsers/WorldGen/ConfiguredSurfaceBuilderParser.cs index 2f06019..55718eb 100644 --- a/DataPackChecker/Parsers/WorldGen/ConfiguredSurfaceBuilderParser.cs +++ b/DataPackChecker/Parsers/WorldGen/ConfiguredSurfaceBuilderParser.cs @@ -8,9 +8,9 @@ namespace DataPackChecker.Parsers.WorldGen { static class ConfiguredSurfaceBuilderParser { - private static readonly Regex NAMESPACE_PATH_REGEX = new Regex(@"[\\/]worldgen[\\/]configured_surface_builder([\\/](?.+?))?[\\/](?[^\\/]+)\.json$"); + private static readonly Regex NamespacePathRegex = new Regex(@"[\\/]worldgen[\\/]configured_surface_builder([\\/](?.+?))?[\\/](?[^\\/]+)\.json$"); static public ConfiguredSurfaceBuilder TryParse(string absPath, string nsPath) { - var match = NAMESPACE_PATH_REGEX.Match(absPath, nsPath.Length); + var match = NamespacePathRegex.Match(absPath, nsPath.Length); if (!match.Success) return null; var configuredSurfaceBuilder = new ConfiguredSurfaceBuilder(match.Groups["path"].Value.Replace('\\', '/'), match.Groups["name"].Value); using FileStream fs = new FileStream(absPath, FileMode.Open); diff --git a/DataPackChecker/Parsers/WorldGen/NoiseSettingsParser.cs b/DataPackChecker/Parsers/WorldGen/NoiseSettingsParser.cs index 5cd0103..1254f6c 100644 --- a/DataPackChecker/Parsers/WorldGen/NoiseSettingsParser.cs +++ b/DataPackChecker/Parsers/WorldGen/NoiseSettingsParser.cs @@ -8,9 +8,9 @@ namespace DataPackChecker.Parsers.WorldGen { static class NoiseSettingsParser { - private static readonly Regex NAMESPACE_PATH_REGEX = new Regex(@"[\\/]worldgen[\\/]noise_settings([\\/](?.+?))?[\\/](?[^\\/]+)\.json$"); + private static readonly Regex NamespacePathRegex = new Regex(@"[\\/]worldgen[\\/]noise_settings([\\/](?.+?))?[\\/](?[^\\/]+)\.json$"); static public NoiseSettings TryParse(string absPath, string nsPath) { - var match = NAMESPACE_PATH_REGEX.Match(absPath, nsPath.Length); + var match = NamespacePathRegex.Match(absPath, nsPath.Length); if (!match.Success) return null; var noiseSettings = new NoiseSettings(match.Groups["path"].Value.Replace('\\', '/'), match.Groups["name"].Value); using FileStream fs = new FileStream(absPath, FileMode.Open); diff --git a/DataPackChecker/Parsers/WorldGen/ProcessorListParser.cs b/DataPackChecker/Parsers/WorldGen/ProcessorListParser.cs index 6b189a4..7b62750 100644 --- a/DataPackChecker/Parsers/WorldGen/ProcessorListParser.cs +++ b/DataPackChecker/Parsers/WorldGen/ProcessorListParser.cs @@ -8,9 +8,9 @@ namespace DataPackChecker.Parsers.WorldGen { static class ProcessorListParser { - private static readonly Regex NAMESPACE_PATH_REGEX = new Regex(@"[\\/]worldgen[\\/]processor_list([\\/](?.+?))?[\\/](?[^\\/]+)\.json$"); + private static readonly Regex NamespacePathRegex = new Regex(@"[\\/]worldgen[\\/]processor_list([\\/](?.+?))?[\\/](?[^\\/]+)\.json$"); static public ProcessorList TryParse(string absPath, string nsPath) { - var match = NAMESPACE_PATH_REGEX.Match(absPath, nsPath.Length); + var match = NamespacePathRegex.Match(absPath, nsPath.Length); if (!match.Success) return null; var processorList = new ProcessorList(match.Groups["path"].Value.Replace('\\', '/'), match.Groups["name"].Value); using FileStream fs = new FileStream(absPath, FileMode.Open); diff --git a/DataPackChecker/Parsers/WorldGen/TemplatePoolParser.cs b/DataPackChecker/Parsers/WorldGen/TemplatePoolParser.cs index 6c82e16..f3accca 100644 --- a/DataPackChecker/Parsers/WorldGen/TemplatePoolParser.cs +++ b/DataPackChecker/Parsers/WorldGen/TemplatePoolParser.cs @@ -8,9 +8,9 @@ namespace DataPackChecker.Parsers.WorldGen { static class TemplatePoolParser { - private static readonly Regex NAMESPACE_PATH_REGEX = new Regex(@"[\\/]worldgen[\\/]template_pool([\\/](?.+?))?[\\/](?[^\\/]+)\.json$"); + private static readonly Regex NamespacePathRegex = new Regex(@"[\\/]worldgen[\\/]template_pool([\\/](?.+?))?[\\/](?[^\\/]+)\.json$"); static public TemplatePool TryParse(string absPath, string nsPath) { - var match = NAMESPACE_PATH_REGEX.Match(absPath, nsPath.Length); + var match = NamespacePathRegex.Match(absPath, nsPath.Length); if (!match.Success) return null; var templatePool = new TemplatePool(match.Groups["path"].Value.Replace('\\', '/'), match.Groups["name"].Value); using FileStream fs = new FileStream(absPath, FileMode.Open); diff --git a/DataPackChecker/Program.cs b/DataPackChecker/Program.cs index 58c80dc..4ac1017 100644 --- a/DataPackChecker/Program.cs +++ b/DataPackChecker/Program.cs @@ -8,22 +8,24 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Reflection; namespace DataPackChecker { class Program { - const string VERSION = "Data Pack Checker 3.0.0"; + const string Version = "Data Pack Checker 3.0.0"; static void Main(string[] args) { var parser = new Parser(with => { with.EnableDashDash = true; }); + var parserResult = parser.ParseArguments(args); - parserResult.WithParsed(options => Run(parserResult, options)) + parserResult.WithParsed(options => Run(parserResult, options)) .WithNotParsed(errs => DisplayErrors(parserResult, errs)); } - static void DisplayErrors(ParserResult result, IEnumerable errs) { + private static void DisplayErrors(ParserResult result, IEnumerable errs) { if (errs.IsVersion()) { DisplayVersion(); } else { @@ -31,20 +33,33 @@ static void DisplayErrors(ParserResult result, IEnumerable errs) { } } - static void DisplayHelp(ParserResult result) { + private static void DisplayHelp(ParserResult result) { var helpText = HelpText.AutoBuild(result, h => { - h.Heading = VERSION; + h.Heading = Version; h.Copyright = "Made by Bertie2011 / ThrownException / Bertiecrafter"; return HelpText.DefaultParsingErrorsHandler(result, h); }, e => e); Console.WriteLine(helpText); } - static void DisplayVersion() { - Console.WriteLine(VERSION); + private static void DisplayVersion() { + Console.WriteLine(Version); + } + + private static void FromFile(string path) { + try { + Main(ConsoleHelper.CreateArgs(File.ReadAllLines(path)[0])); + } catch (Exception e) { + ConsoleHelper.WriteError(e); + } } private static void Run(ParserResult result, Options options) { + if (!string.IsNullOrWhiteSpace(options.ArgsPath)) { + FromFile(options.ArgsPath); + return; + } + var (rules, errors) = RuleRegistry.FromDirectory(Path.Join(".", "Rules")); var ruleInfo = new RuleInfoPrinter(rules); var checker = new Checker(rules); diff --git a/DataPackChecker/Properties/launchSettings.json b/DataPackChecker/Properties/launchSettings.json index d0f41e3..0489227 100644 --- a/DataPackChecker/Properties/launchSettings.json +++ b/DataPackChecker/Properties/launchSettings.json @@ -1,7 +1,8 @@ { "profiles": { "DataPackChecker": { - "commandName": "Project" + "commandName": "Project", + "commandLineArgs": "-f \"args.txt\"" } } } \ No newline at end of file diff --git a/Shared/Data/Resources/Command.cs b/Shared/Data/Resources/Command.cs index 9903b7e..58cce78 100644 --- a/Shared/Data/Resources/Command.cs +++ b/Shared/Data/Resources/Command.cs @@ -5,11 +5,11 @@ namespace DataPackChecker.Shared.Data.Resources { public class Command { - private static readonly char[] COMMAND_BRACKET_OPEN = new char[] { '[', '{' }; - private static readonly Dictionary COMMAND_BRACKET_CLOSE = new Dictionary { + private static readonly char[] CommandBracketOpen = new char[] { '[', '{' }; + private static readonly Dictionary CommandBracketClose = new Dictionary { { '[', ']' }, { '{', '}' } }; - private static readonly char[] COMMAND_QUOTES = new char[] { '"', '\'' }; + private static readonly char[] CommandQuotes = new char[] { '"', '\'' }; public enum Type { Command, Comment, Whitespace @@ -108,11 +108,11 @@ private void ParseCommand(string data, int startIndex) { escape = false; } else if (c == '\\') { escape = true; - } else if (quote == null && COMMAND_BRACKET_OPEN.Any(b => b == c)) { + } else if (quote == null && CommandBracketOpen.Any(b => b == c)) { brackets.Push(c); - } else if (quote == null && brackets.Count != 0 && c == COMMAND_BRACKET_CLOSE[brackets.Peek()]) { + } else if (quote == null && brackets.Count != 0 && c == CommandBracketClose[brackets.Peek()]) { brackets.Pop(); - } else if (COMMAND_QUOTES.Any(q => q == c)) { + } else if (CommandQuotes.Any(q => q == c)) { quote = quote == null ? c : (char?)null; } }