public void Export() { try { String directory = ModTextResources.Export.FieldsDirectory; if (Directory.Exists(directory)) { Log.Warning($"[{nameof(FieldExporter)}] Some fields refer to each other. They should be exported together."); Log.Warning($"[{nameof(FieldExporter)}] Export was skipped bacause the directory already exists: [{directory}]."); return; } Log.Message($"[{nameof(FieldExporter)}] Exporting..."); FieldFormatter formatter = new FieldFormatter(); KeyValuePair <Int32, String> chocoboForest = new KeyValuePair <Int32, String>(945, "MES_CHOCO"); foreach (KeyValuePair <Int32, String> pair in ExtensionMethodsIEnumerable.Append(FF9DBAll.EventDB, chocoboForest)) { Int32 fieldZoneId = pair.Key; String path = EmbadedTextResources.GetCurrentPath("/Field/" + GetFieldTextFileName(fieldZoneId) + ".mes"); String text = EmbadedSentenseLoader.LoadText(path); if (text == null) { continue; } String name = fieldZoneId.ToString("D4", CultureInfo.InvariantCulture) + '_' + pair.Value; text = TextOpCodeModifier.Modify(text); String[] lines = FF9TextTool.ExtractSentense(text); TxtEntry[] commands = formatter.Build(name, lines); Directory.CreateDirectory(directory); String outputPath = Path.Combine(directory, name + ".strings"); TxtWriter.WriteStrings(outputPath, commands); } ExportTags(directory, formatter); Log.Message($"[{nameof(FieldExporter)}] Exporting completed successfully."); } catch (Exception ex) { Log.Error(ex, $"[{nameof(FieldExporter)}] Failed to export resource."); } }
private void Initialize() { String directory = ModTextResources.Import.FieldsDirectory; if (!Directory.Exists(directory)) { Log.Warning($"[{TypeName}] Import was skipped bacause a directory does not exist: [{directory}]."); return; } Log.Message($"[{TypeName}] Initialization..."); try { _dic = new Dictionary <String, LinkedList <UInt64> >(); _customTags = LoadCustomTags(); _fieldTags = LoadFieldTags(); KeyValuePair <Int32, String> chocoboForest = new KeyValuePair <Int32, String>(945, "MES_CHOCO"); foreach (KeyValuePair <Int32, String> pair in ExtensionMethodsIEnumerable.Append(FF9DBAll.EventDB, chocoboForest)) { _fieldZoneId = pair.Key; _fieldFileName = _fieldZoneId.ToString("D4", CultureInfo.InvariantCulture) + '_' + pair.Value; if (!ReadEmbadedText(_fieldZoneId, out _original)) { _cache[_fieldZoneId] = null; continue; } if (!ReadExternalText(out _external)) { Log.Warning($"[{TypeName}] External file not found: [{Path.Combine(ModTextResources.Import.FieldsDirectory, _fieldFileName + ".strings")}]"); _cache[_fieldZoneId] = _original; continue; } if (_original.Length != _external.Length) { Log.Warning($"[{TypeName}] Number of lines in files does not match. [Original: {_original.Length}, External: {_external.Length}]"); _cache[_fieldZoneId] = _original; continue; } _fieldTags.TryGetValue(_fieldFileName, out _fieldReplacements); _cache[_fieldZoneId] = MergeEntries(); } ResolveReferences(); _initialized = true; if (_watcher == null) { _watcherEvent = new AutoResetEvent(false); _watcherTask = Task.Run(DoWatch); _watcher = new FileSystemWatcher(directory, "*.strings"); GameLoopManager.Quit += _watcher.Dispose; _watcher.Changed += OnChangedFileInDirectory; _watcher.Created += OnChangedFileInDirectory; _watcher.Deleted += OnChangedFileInDirectory; _watcher.EnableRaisingEvents = true; } Log.Message($"[{TypeName}] Initialization completed successfully."); } catch (Exception ex) { Log.Error(ex, $"[{TypeName}] Initialization failed."); } finally { _dic = null; _original = null; _external = null; _fieldReplacements = null; } }