private void EditVfslTag(HaloTag tag) { VFilesList vfsl; using (var stream = _fileInfo.OpenRead()) vfsl = TagDeserializer.Deserialize <VFilesList>(new TagSerializationContext(stream, _cache, tag)); var context = VfslContextFactory.Create(_stack.Context, _fileInfo, _cache, tag, vfsl); _stack.Push(context); }
public void PushPush_ThenReturnsLast() { var commandContext1 = CreateContext(); var commandContext2 = CreateContext(); sut.Push(commandContext1); sut.Push(commandContext2); sut.PeekOrDefault.Should().Be(commandContext2); sut.CurrentCommand.Should().Be(commandContext2.CurrentCommand); sut.UnitOfWork.Should().Be(commandContext2.UnitOfWork); }
public override bool Execute(List <string> args) { if (args.Count != 1) { return(false); } var tag = ArgumentParser.ParseTagIndex(_info, args[0]); if (tag == null) { return(false); } var oldContext = _stack.Context; _stack.Push(EditTagContextFactory.Create(_stack, _info, tag)); var groupName = _info.StringIDs.GetString(tag.Group.Name); var tagName = $"0x{tag.Index:X4}"; if (_info.TagNames.ContainsKey(tag.Index)) { tagName = _info.TagNames[tag.Index]; tagName = $"(0x{tag.Index:X4}) {tagName.Substring(tagName.LastIndexOf('\\') + 1)}"; } Console.WriteLine($"Tag {tagName}.{groupName} has been opened for editing."); Console.WriteLine("New commands are now available. Enter \"help\" to view them."); Console.WriteLine("Use \"exit\" to return to {0}.", oldContext.Name); return(true); }
public async Task ExecuteProjectionsAsync() { using (IUnitOfWork uow = unitOfWorkFactory.CreateUnitOfWork()) { commandContextStack.Push(new CommandContext(null, uow)); try { uow.Begin(); await projectionSubSystem.ExecuteProjectionsAsync(events, uow, GetEventProjectionOptions()); events.Clear(); await uow.CommitAsync(); } finally { commandContextStack.Pop(); } } }
public override bool Execute(List <string> args) { if (args.Count != 1) { return(false); } var tag = ArgumentParser.ParseTagIndex(_cache, args[0]); if (tag == null) { return(false); } var oldContext = _stack.Context; _stack.Push(EditTagContextFactory.Create(_stack, _info, tag)); Console.WriteLine("Tag 0x{0:X8}.{1} has been opened for editing.", tag.Index, _info.StringIds.GetString(tag.Group.Name)); Console.WriteLine("New commands are now available. Enter \"help\" to view them."); Console.WriteLine("Use \"exit\" to return to {0}.", oldContext.Name); return(true); }
static void Main(string[] args) { ConsoleHistory.Initialize(); // Get the file path from the first argument // If no argument is given, load tags.dat var filePath = (args.Length > 0) ? args[0] : "tags.dat"; // If there are extra arguments, use them to automatically execute a command List <string> autoexecCommand = null; if (args.Length > 1) { autoexecCommand = args.Skip(1).ToList(); } if (autoexecCommand == null) { Console.WriteLine("Halo Online Tag Tool [{0}]", Assembly.GetExecutingAssembly().GetName().Version); Console.WriteLine(); Console.WriteLine("Please report any bugs and feature requests at"); Console.WriteLine("<https://github.com/ElDewrito/HaloOnlineTagTool/issues>."); Console.WriteLine(); Console.Write("Reading tags..."); } // Load the tag cache FileInfo fileInfo = null; TagCache cache = null; try { fileInfo = new FileInfo(filePath); using (var stream = fileInfo.Open(FileMode.Open, FileAccess.Read)) cache = new TagCache(stream); } catch (Exception e) { Console.WriteLine("ERROR: " + e.Message); ConsoleHistory.Dump("hott_*_tags_init.log"); return; } if (autoexecCommand == null) { Console.WriteLine("{0} tags loaded.", cache.Tags.Count); } // Version detection EngineVersion closestVersion; var version = VersionDetection.DetectVersion(cache, out closestVersion); if (version != EngineVersion.Unknown) { if (autoexecCommand == null) { var buildDate = DateTime.FromFileTime(cache.Timestamp); Console.WriteLine("- Detected target engine version {0}.", VersionDetection.GetVersionString(closestVersion)); Console.WriteLine("- This cache file was built on {0} at {1}.", buildDate.ToShortDateString(), buildDate.ToShortTimeString()); } } else { Console.WriteLine("WARNING: The cache file's version was not recognized!"); Console.WriteLine("Using the closest known version {0}.", VersionDetection.GetVersionString(closestVersion)); version = closestVersion; } // Load stringIDs Console.Write("Reading stringIDs..."); var stringIdPath = Path.Combine(fileInfo.DirectoryName ?? "", "string_ids.dat"); var resolver = StringIdResolverFactory.Create(version); StringIdCache stringIds = null; try { using (var stream = File.OpenRead(stringIdPath)) stringIds = new StringIdCache(stream, resolver); } catch (IOException) { Console.WriteLine("Warning: unable to open string_ids.dat!"); Console.WriteLine("Commands which require stringID values will be unavailable."); } catch (Exception e) { Console.WriteLine("ERROR: " + e.Message); ConsoleHistory.Dump("hott_*_string_ids_init.log"); return; } if (autoexecCommand == null && stringIds != null) { Console.WriteLine("{0} strings loaded.", stringIds.Strings.Count); Console.WriteLine(); } var info = new OpenTagCache { Cache = cache, CacheFile = fileInfo, StringIds = stringIds, StringIdsFile = (stringIds != null) ? new FileInfo(stringIdPath) : null, Version = version, Serializer = new TagSerializer(version), Deserializer = new TagDeserializer(version), }; // Create command context var contextStack = new CommandContextStack(); var tagsContext = TagCacheContextFactory.Create(contextStack, info); contextStack.Push(tagsContext); // If autoexecuting a command, just run it and return if (autoexecCommand != null) { if (!ExecuteCommand(contextStack.Context, autoexecCommand)) { Console.WriteLine("Unrecognized command: {0}", autoexecCommand[0]); } return; } Console.WriteLine("Enter \"help\" to list available commands. Enter \"exit\" to quit."); while (true) { // Read and parse a command Console.WriteLine(); Console.Write("{0}> ", contextStack.GetPath()); var commandLine = Console.ReadLine(); if (commandLine == null) { break; } string redirectFile; var commandArgs = ArgumentParser.ParseCommand(commandLine, out redirectFile); if (commandArgs.Count == 0) { continue; } // If "exit" or "quit" is given, pop the current context if (commandArgs[0] == "exit" || commandArgs[0] == "quit") { if (!contextStack.Pop()) { break; // No more contexts - quit } continue; } // Handle redirection var oldOut = Console.Out; StreamWriter redirectWriter = null; if (redirectFile != null) { redirectWriter = new StreamWriter(File.Open(redirectFile, FileMode.Create, FileAccess.Write)); Console.SetOut(redirectWriter); } // Try to execute it if (!ExecuteCommand(contextStack.Context, commandArgs)) { Console.WriteLine("Unrecognized command: {0}", commandArgs[0]); Console.WriteLine("Use \"help\" to list available commands."); } // Undo redirection if (redirectFile != null) { Console.SetOut(oldOut); redirectWriter.Dispose(); Console.WriteLine("Wrote output to {0}.", redirectFile); } } }
static void Main(string[] args) { // Get the file path from the first argument // If no argument is given, load tags.dat var filePath = (args.Length > 0) ? args[0] : "tags.dat"; // If there are extra arguments, use them to automatically execute a command List <string> autoexecCommand = null; if (args.Length > 1) { autoexecCommand = args.Skip(1).ToList(); } if (autoexecCommand == null) { Console.WriteLine("Halo Online Tag Tool [{0}]", Assembly.GetExecutingAssembly().GetName().Version); Console.WriteLine("Written by Shockfire"); Console.WriteLine(); Console.WriteLine("Please report any bugs and feature requests at"); Console.WriteLine("<https://gitlab.com/ElDewrito/HaloOnlineTagTool/issues>."); Console.WriteLine(); Console.Write("Reading tags..."); } // Load the tag cache var fileInfo = new FileInfo(filePath); TagCache cache; using (var stream = fileInfo.Open(FileMode.Open, FileAccess.Read)) cache = new TagCache(stream); if (autoexecCommand == null) { Console.WriteLine("{0} tags loaded.", cache.Tags.Count); Console.Write("Reading stringIDs..."); } // Load stringIDs var stringIdPath = Path.Combine(fileInfo.DirectoryName ?? "", "string_ids.dat"); StringIdCache stringIds = null; try { using (var stream = File.OpenRead(stringIdPath)) stringIds = new StringIdCache(stream); } catch (IOException) { Console.Error.WriteLine("Warning: unable to open string_ids.dat!"); Console.Error.WriteLine("Commands which require stringID values will be unavailable."); } if (autoexecCommand == null && stringIds != null) { Console.WriteLine("{0} strings loaded.", stringIds.Strings.Count); } // Create command context var contextStack = new CommandContextStack(); var tagsContext = TagCacheContextFactory.Create(contextStack, cache, fileInfo, stringIds); contextStack.Push(tagsContext); // If autoexecuting a command, just run it and return if (autoexecCommand != null) { if (!ExecuteCommand(contextStack.Context, autoexecCommand)) { Console.Error.WriteLine("Unrecognized command: {0}", autoexecCommand[0]); } return; } Console.WriteLine(); Console.WriteLine("Enter \"help\" to list available commands. Enter \"exit\" to quit."); while (true) { // Read and parse a command Console.WriteLine(); Console.Write("{0}> ", contextStack.GetPath()); var commandLine = Console.ReadLine(); string redirectFile; var commandArgs = ArgumentParser.ParseCommand(commandLine, out redirectFile); if (commandArgs.Count == 0) { continue; } // If "exit" or "quit" is given, pop the current context if (commandArgs[0] == "exit" || commandArgs[0] == "quit") { if (!contextStack.Pop()) { break; // No more contexts - quit } continue; } // Handle redirection var oldOut = Console.Out; StreamWriter redirectWriter = null; if (redirectFile != null) { redirectWriter = new StreamWriter(File.Open(redirectFile, FileMode.Create, FileAccess.Write)); Console.SetOut(redirectWriter); } // Try to execute it if (!ExecuteCommand(contextStack.Context, commandArgs)) { Console.Error.WriteLine("Unrecognized command: {0}", commandArgs[0]); Console.Error.WriteLine("Use \"help\" to list available commands."); } // Undo redirection if (redirectFile != null) { Console.SetOut(oldOut); redirectWriter.Dispose(); Console.WriteLine("Wrote output to {0}.", redirectFile); } } }
static void Main(string[] args) { CultureInfo.DefaultThreadCurrentCulture = CultureInfo.GetCultureInfo("en-US"); ConsoleHistory.Initialize(); // Get the file path from the first argument // If no argument is given, load tags.dat var filePath = (args.Length > 0) ? args[0] : "tags.dat"; // If there are extra arguments, use them to automatically execute a command List <string> autoexecCommand = null; if (args.Length > 1) { autoexecCommand = args.Skip(1).ToList(); } if (autoexecCommand == null) { Console.WriteLine("Tag Tool [{0}]", Assembly.GetExecutingAssembly().GetName().Version); Console.WriteLine(); Console.WriteLine("Please report any bugs and feature requests at"); Console.WriteLine("<https://github.com/camden-smallwood/TagTool/issues>."); Console.WriteLine(); Console.Write("Reading tags..."); } // Load the tag cache FileInfo fileInfo = null; TagCache cache = null; try { fileInfo = new FileInfo(filePath); using (var stream = fileInfo.Open(FileMode.Open, FileAccess.Read)) cache = new TagCache(stream); } catch (Exception e) { Console.WriteLine("ERROR: " + e.Message); ConsoleHistory.Dump("hott_*_tags_init.log"); return; } if (autoexecCommand == null) { Console.WriteLine("{0} tags loaded.", cache.Tags.Count); } // Version detection DefinitionSet closestVersion; var version = Definition.Detect(cache, out closestVersion); if (version != DefinitionSet.Unknown) { if (autoexecCommand == null) { var buildDate = DateTime.FromFileTime(cache.Timestamp); Console.WriteLine("- Detected target engine version {0}.", Definition.GetVersionString(closestVersion)); Console.WriteLine("- This cache file was built on {0} at {1}.", buildDate.ToShortDateString(), buildDate.ToShortTimeString()); } } else { Console.WriteLine("WARNING: The cache file's version was not recognized!"); Console.WriteLine("Using the closest known version {0}.", Definition.GetVersionString(closestVersion)); version = closestVersion; } // Load stringIDs Console.Write("Reading stringIDs..."); var stringIdPath = Path.Combine(fileInfo.DirectoryName ?? "", "string_ids.dat"); var resolver = StringIDResolverFactory.Create(version); StringIDCache stringIds = null; try { using (var stream = File.OpenRead(stringIdPath)) stringIds = new StringIDCache(stream, resolver); } catch (IOException) { Console.WriteLine("Warning: unable to open string_ids.dat!"); Console.WriteLine("Commands which require stringID values will be unavailable."); } catch (Exception e) { Console.WriteLine("ERROR: " + e.Message); ConsoleHistory.Dump("hott_*_string_ids_init.log"); return; } if (autoexecCommand == null && stringIds != null) { Console.WriteLine("{0} strings loaded.", stringIds.Strings.Count); Console.WriteLine(); } var info = new OpenTagCache { Cache = cache, CacheFile = fileInfo, StringIDs = stringIds, StringIDsFile = (stringIds != null) ? new FileInfo(stringIdPath) : null, Version = version, Serializer = new TagSerializer(version), Deserializer = new TagDeserializer(version), }; var tagNamesPath = "TagNames\\tagnames_" + Definition.GetVersionString(version) + ".csv"; if (File.Exists(tagNamesPath)) { using (var tagNamesStream = File.Open(tagNamesPath, FileMode.Open, FileAccess.Read)) { var reader = new StreamReader(tagNamesStream); while (!reader.EndOfStream) { var line = reader.ReadLine(); var separatorIndex = line.IndexOf(','); var indexString = line.Substring(2, separatorIndex - 2); int tagIndex; if (!int.TryParse(indexString, NumberStyles.HexNumber, null, out tagIndex)) { tagIndex = -1; } if (tagIndex < 0 || tagIndex >= cache.Tags.Count) { continue; } var nameString = line.Substring(separatorIndex + 1); if (nameString.Contains(" ")) { var lastSpaceIndex = nameString.LastIndexOf(' '); nameString = nameString.Substring(lastSpaceIndex + 1, nameString.Length - lastSpaceIndex - 1); } info.TagNames[tagIndex] = nameString; } reader.Close(); } } foreach (var tag in info.Cache.Tags) { if (tag != null && !info.TagNames.ContainsKey(tag.Index)) { info.TagNames[tag.Index] = $"0x{tag.Index:X4}"; } } // Create command context var contextStack = new CommandContextStack(); var tagsContext = TagCacheContextFactory.Create(contextStack, info); contextStack.Push(tagsContext); // If autoexecuting a command, just run it and return if (autoexecCommand != null) { if (!ExecuteCommand(contextStack.Context, autoexecCommand)) { Console.WriteLine("Unrecognized command: {0}", autoexecCommand[0]); } return; } Console.WriteLine("Enter \"help\" to list available commands. Enter \"exit\" to quit."); while (true) { // Read and parse a command Console.WriteLine(); Console.Write("{0}> ", contextStack.GetPath()); var commandLine = Console.ReadLine(); if (commandLine == null) { break; } string redirectFile; var commandArgs = ArgumentParser.ParseCommand(commandLine, out redirectFile); if (commandArgs.Count == 0) { continue; } // If "exit" or "quit" is given, pop the current context if (commandArgs[0] == "exit" || commandArgs[0] == "quit") { if (!contextStack.Pop()) { break; // No more contexts - quit } continue; } // Handle redirection var oldOut = Console.Out; StreamWriter redirectWriter = null; if (redirectFile != null) { redirectWriter = new StreamWriter(File.Open(redirectFile, FileMode.Create, FileAccess.Write)); Console.SetOut(redirectWriter); } // Try to execute it if (!ExecuteCommand(contextStack.Context, commandArgs)) { Console.WriteLine("Unrecognized command: {0}", commandArgs[0]); Console.WriteLine("Use \"help\" to list available commands."); } // Undo redirection if (redirectFile != null) { Console.SetOut(oldOut); redirectWriter.Dispose(); Console.WriteLine("Wrote output to {0}.", redirectFile); } } }