private void UpdateMeta(MetaWriter.SaveType type, bool onlyUpdateChanged, bool showActionDialog = true) { if (type == MetaWriter.SaveType.File) { if (!ConfirmNewStringIds()) { return; } using (IStream stream = _fileManager.OpenReadWrite()) { #if DEBUG_SAVE_ALL MetaWriter metaUpdate = new MetaWriter(writer, (uint)_tag.RawTag.MetaLocation.AsOffset(), _cache, _buildInfo, type, null, _stringIdTrie); #else var metaUpdate = new MetaWriter(stream, (uint)_tag.RawTag.MetaLocation.AsOffset(), _cache, _buildInfo, type, _fileChanges, _stringIdTrie); #endif metaUpdate.WriteFields(_pluginVisitor.Values); _cache.SaveChanges(stream); _fileChanges.MarkAllUnchanged(); } if (showActionDialog) { MetroMessageBox.Show("Meta Saved", "The metadata has been saved back to the original file."); } } else if (_rteProvider != null) { using (IStream metaStream = _rteProvider.GetMetaStream(_cache)) { if (metaStream != null) { FieldChangeSet changes = onlyUpdateChanged ? _memoryChanges : null; var metaUpdate = new MetaWriter(metaStream, _tag.RawTag.MetaLocation.AsPointer(), _cache, _buildInfo, type, changes, _stringIdTrie); metaUpdate.WriteFields(_pluginVisitor.Values); if (showActionDialog) { if (onlyUpdateChanged) { MetroMessageBox.Show("Meta Poked", "All changed metadata has been poked to the game."); } else { MetroMessageBox.Show("Meta Poked", "The metadata has been poked to the game."); } } } else { ShowConnectionError(); } } } }
private async void CompileClick(object sender, RoutedEventArgs e) { // Logger Setup string folder = "Compiler"; if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } string logPath = Path.Combine(folder, "ScriptCompiler.log"); using (var logStream = File.Create(logPath)) { // Create the logger and the exception collector. They are used for debugging. var traceListener = new TextWriterTraceListener(logStream); var logger = new ScriptCompilerLogger(traceListener); var exceptionCollector = new ParsingExceptionCollector(); logger.Information($"Attempting to compile: {_scriptFile.Name}, Time: {DateTime.Now}"); try { // Get the script file. string hsc = txtScript.Text; // Measure the time it took to compile the scripts. var stopWatch = Stopwatch.StartNew(); // Compile the scripts. ScriptData compileData = await Task.Run(() => CompileScripts(hsc, _progress, logger, exceptionCollector)); stopWatch.Stop(); var timeSpan = stopWatch.Elapsed; string compilationMessage = $"The scripts were successfully compiled in {Math.Round(timeSpan.TotalSeconds, 3)} seconds."; logger.Information(compilationMessage); // Show the message box. var saveResult = MetroMessageBox.Show("Scripts Compiled", compilationMessage + "\nWARNING: This compiler is not 100% accurate and could corrupt the map in rare cases. Making a backup before proceeding is advisable." + "\n\nDo you want to save the changes to the file?", MetroMessageBox.MessageBoxButtons.YesNo); if (saveResult == MetroMessageBox.MessageBoxResult.Yes) { //TODO: Move this to its own function. await Task.Run(() => { using (IStream stream = _streamManager.OpenReadWrite()) { _scriptFile.SaveScripts(compileData, stream, _progress); _cashefile.SaveChanges(stream); } }); RefreshMeta(); StatusUpdater.Update("Scripts saved"); } } // Handle Parsing Errors. catch (OperationCanceledException opEx) { if (exceptionCollector.ContainsExceptions) { HandleParsingErrors(opEx, exceptionCollector, logger); } else { MetroMessageBox.Show("Operation Canceled", opEx.Message); } } // Handle Compiler Errors. catch (CompilerException compEx) { HandleCompilerErrors(compEx, logger); } finally { logger.Flush(); ResetProgressBar(); } } }
private void UpdateMeta(MetaWriter.SaveType type, bool onlyUpdateChanged, bool showActionDialog = true) { if (type == MetaWriter.SaveType.File) { if (!ConfirmNewStringIds()) { return; } using (IStream stream = _fileManager.OpenReadWrite()) { #if DEBUG_SAVE_ALL MetaWriter metaUpdate = new MetaWriter(writer, (uint)_tag.RawTag.MetaLocation.AsOffset(), _cache, _buildInfo, type, null, _stringIdTrie); #else var metaUpdate = new MetaWriter(stream, (uint)_tag.RawTag.MetaLocation.AsOffset(), _cache, _buildInfo, type, _fileChanges, _stringIdTrie); #endif metaUpdate.WriteFields(_pluginVisitor.Values); _cache.SaveChanges(stream); _fileChanges.MarkAllUnchanged(); } if (showActionDialog) { MetroMessageBox.Show("Tag Saved", "The changes have been saved back to the original file." + (_buildInfo.UsesCompression && _cache.Engine == EngineType.SecondGeneration ? "\r\n\r\nNote: This file must be compressed from the Tools menu before attempting to load ingame." : "")); } } else if (_rteProvider != null) { var rteProvider = _rteProvider; if (App.AssemblyStorage.AssemblyNetworkPoke.NetworkRteProvider != null) { rteProvider = App.AssemblyStorage.AssemblyNetworkPoke.NetworkRteProvider; } using (IStream metaStream = rteProvider.GetMetaStream(_cache)) { if (metaStream != null) { FieldChangeSet changes = onlyUpdateChanged ? _memoryChanges : null; var metaUpdate = new MetaWriter(metaStream, _tag.RawTag.MetaLocation.AsPointer(), _cache, _buildInfo, type, changes, _stringIdTrie); metaUpdate.WriteFields(_pluginVisitor.Values); if (showActionDialog) { if (onlyUpdateChanged) { StatusUpdater.Update("All changed fields have been poked to the game."); } else { StatusUpdater.Update("The changes have been poked to the game."); } } } else { ShowConnectionError(); } } } }