Skip to content

Commit

Permalink
Add progress listener to mapping-io conversion; deduplicate lang files
Browse files Browse the repository at this point in the history
  • Loading branch information
NebelNidas committed Oct 10, 2022
1 parent d9521bc commit 95bb87f
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 51 deletions.
22 changes: 22 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"[java]": {
"editor.suggest.showClasses": true,
"editor.suggest.showMethods": true,
"editor.suggest.showConstructors": true,
"editor.suggest.showConstants": true,
"editor.suggest.showEnumMembers": true,
"editor.suggest.showEnums": true,
"editor.suggest.showEvents": true,
"editor.suggest.showFields": true,
"editor.suggest.showInterfaces": true,
"editor.suggest.showKeywords": true,
"editor.suggest.showVariables": true,
"editor.suggest.showSnippets": true,
"editor.suggest.showWords": true,
"editor.lightbulb.enabled": true,
"editor.quickSuggestions": {
"other": "on"
}
},
"java.inlayHints.parameterNames.exclusions": []
}
15 changes: 13 additions & 2 deletions enigma-swing/src/main/java/cuchaz/enigma/gui/GuiController.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,17 @@ public CompletableFuture<Void> openMappings(MappingFormat format, Path path) {
EntryTree<EntryMapping> mappings;

if (useMappingIo) {
String loadingMessage;
if (format.getMappingIoCounterpart().hasSingleFile()) {
loadingMessage = I18n.translate("progress.mappings.loading_file");
} else {
loadingMessage = I18n.translate("progress.mappings.loading_directory");
}

progress.init(1, loadingMessage);
MemoryMappingTree mappingTree = new MemoryMappingTree();
MappingReader.read(path, format.getMappingIoCounterpart(), mappingTree);
mappings = MappingIoConverter.fromMappingIo(mappingTree);
mappings = MappingIoConverter.fromMappingIo(mappingTree, progress);
} else {
mappings = format.read(path, progress, saveParameters);
}
Expand Down Expand Up @@ -218,10 +226,13 @@ public CompletableFuture<Void> saveMappings(Path path, MappingFormat format) {
loadedMappingPath = path;

if (useMappingIo) {
MemoryMappingTree mappingTree = MappingIoConverter.toMappingIo(mapper.getObfToDeobf());
MemoryMappingTree mappingTree = MappingIoConverter.toMappingIo(mapper.getObfToDeobf(), progress);

progress.init(1, I18n.translate("progress.mappings.writing"));
MappingWriter writer = MappingWriter.create(path, format.getMappingIoCounterpart());
mappingTree.accept(writer);
writer.close();
progress.step(1, I18n.translate("progress.done"));
} else if (saveAll) {
format.write(mapper.getObfToDeobf(), path, progress, saveParameters);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import net.fabricmc.mappingio.tree.MappingTree.FieldMapping;
import net.fabricmc.mappingio.tree.MappingTree.MethodArgMapping;
import net.fabricmc.mappingio.tree.MappingTree.MethodMapping;

import cuchaz.enigma.ProgressListener;
import cuchaz.enigma.translation.mapping.EntryMap;
import cuchaz.enigma.translation.mapping.EntryMapping;
import cuchaz.enigma.translation.mapping.tree.EntryTree;
Expand All @@ -25,16 +25,22 @@
import cuchaz.enigma.translation.representation.entry.FieldEntry;
import cuchaz.enigma.translation.representation.entry.LocalVariableEntry;
import cuchaz.enigma.translation.representation.entry.MethodEntry;
import cuchaz.enigma.utils.I18n;

public class MappingIoConverter {
public static MemoryMappingTree toMappingIo(EntryTree<EntryMapping> mappings) {
public static MemoryMappingTree toMappingIo(EntryTree<EntryMapping> mappings, ProgressListener progress) {
List<EntryTreeNode<EntryMapping>> classes = StreamSupport.stream(mappings.spliterator(), false)
.filter(node -> node.getEntry() instanceof ClassEntry)
.toList();

progress.init(classes.size(), I18n.translate("progress.mappings.converting.to_mappingio"));
int steps = 0;

MemoryMappingTree mappingTree = new MemoryMappingTree();
mappingTree.visitNamespaces("intermediary", Arrays.asList("named"));

for (EntryTreeNode<EntryMapping> classNode : classes) {
progress.step(steps++, classNode.getEntry().getFullName());
writeClass(classNode, mappings, mappingTree);
}

Expand Down Expand Up @@ -134,10 +140,13 @@ private static void writeMethodArg(EntryTreeNode<EntryMapping> methodArgNode, Me
mappingTree.visitComment(MappedElementKind.METHOD_ARG, methodArgMapping.javadoc());
}

public static EntryTree<EntryMapping> fromMappingIo(MemoryMappingTree mappingTree) {
public static EntryTree<EntryMapping> fromMappingIo(MemoryMappingTree mappingTree, ProgressListener progress) {
EntryTree<EntryMapping> dstMappingTree = new HashEntryTree<>();
progress.init(mappingTree.getClasses().size(), I18n.translate("progress.mappings.converting.from_mappingio"));
int steps = 0;

for (ClassMapping classMapping : mappingTree.getClasses()) {
progress.step(steps++, classMapping.getDstName(0) != null ? classMapping.getDstName(0) : classMapping.getSrcName());
readClass(classMapping, dstMappingTree);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ public enum EnigmaMappingsReader implements MappingsReader {
FILE {
@Override
public EntryTree<EntryMapping> read(Path path, ProgressListener progress, MappingSaveParameters saveParameters) throws IOException, MappingParseException {
progress.init(1, I18n.translate("progress.mappings.enigma_file.loading"));
progress.init(1, I18n.translate("progress.mappings.loading_file"));

EntryTree<EntryMapping> mappings = new HashEntryTree<>();
readFile(path, mappings);

progress.step(1, I18n.translate("progress.mappings.enigma_file.done"));
progress.step(1, I18n.translate("progress.done"));

return mappings;
}
Expand All @@ -56,7 +56,7 @@ public EntryTree<EntryMapping> read(Path root, ProgressListener progress, Mappin

List<Path> files = Files.walk(root).filter(f -> !Files.isDirectory(f)).filter(f -> f.toString().endsWith(".mapping")).toList();

progress.init(files.size(), I18n.translate("progress.mappings.enigma_directory.loading"));
progress.init(files.size(), I18n.translate("progress.mappings.loading_directory"));
int step = 0;

for (Path file : files) {
Expand Down Expand Up @@ -98,7 +98,7 @@ public static EntryTree<EntryMapping> readFiles(ProgressListener progress, Path.
throw new IllegalArgumentException("No paths to read mappings from");
}

progress.init(paths.length, I18n.translate("progress.mappings.enigma_directory.loading"));
progress.init(paths.length, I18n.translate("progress.mappings.loading_directory"));
int step = 0;

for (Path file : paths) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public enum EnigmaMappingsWriter implements MappingsWriter {
public void write(EntryTree<EntryMapping> mappings, MappingDelta<EntryMapping> delta, Path path, ProgressListener progress, MappingSaveParameters saveParameters) {
Collection<ClassEntry> classes = mappings.getRootNodes().filter(entry -> entry.getEntry() instanceof ClassEntry).map(entry -> (ClassEntry) entry.getEntry()).toList();

progress.init(classes.size(), I18n.translate("progress.mappings.enigma_file.writing"));
progress.init(classes.size(), I18n.translate("progress.mappings.writing"));

int steps = 0;

Expand All @@ -78,7 +78,7 @@ public void write(EntryTree<EntryMapping> mappings, MappingDelta<EntryMapping> d

applyDeletions(path, changedClasses, mappings, delta.getBaseMappings(), saveParameters.getFileNameFormat());

progress.init(changedClasses.size(), I18n.translate("progress.mappings.enigma_directory.writing"));
progress.init(changedClasses.size(), I18n.translate("progress.mappings.writing"));

AtomicInteger steps = new AtomicInteger();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void write(EntryTree<EntryMapping> mappings, MappingDelta<EntryMapping> d
List<String> methodLines = new ArrayList<>();

List<? extends Entry<?>> rootEntries = Lists.newArrayList(mappings).stream().map(EntryTreeNode::getEntry).toList();
progress.init(rootEntries.size(), I18n.translate("progress.mappings.srg_file.generating"));
progress.init(rootEntries.size(), I18n.translate("progress.mappings.converting"));

int steps = 0;

Expand All @@ -54,7 +54,7 @@ public void write(EntryTree<EntryMapping> mappings, MappingDelta<EntryMapping> d
writeEntry(classLines, fieldLines, methodLines, mappings, entry);
}

progress.init(3, I18n.translate("progress.mappings.srg_file.writing"));
progress.init(3, I18n.translate("progress.mappings.writing"));

try (PrintWriter writer = new LfPrintWriter(Files.newBufferedWriter(path))) {
progress.step(0, I18n.translate("type.classes"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private EntryTree<EntryMapping> read(Path path, List<String> lines, ProgressList
EntryTree<EntryMapping> mappings = new HashEntryTree<>();
lines.remove(0);

progress.init(lines.size(), I18n.translate("progress.mappings.tiny_file.loading"));
progress.init(lines.size(), I18n.translate("progress.mappings.loading_file"));

for (int lineNumber = 0; lineNumber < lines.size(); lineNumber++) {
progress.step(lineNumber, "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public EntryTree<EntryMapping> read(Path path, ProgressListener progress, Mappin
private EntryTree<EntryMapping> read(Path path, List<String> lines, ProgressListener progress) throws MappingParseException {
EntryTree<EntryMapping> mappings = new HashEntryTree<>();

progress.init(lines.size(), "progress.mappings.tiny_v2.loading");
progress.init(lines.size(), "progress.mappings.loading_file");

BitSet state = new BitSet(STATE_SIZE);
@SuppressWarnings({"unchecked", "rawtypes"}) MappingPair<? extends Entry<?>, RawEntryMapping>[] holds = new MappingPair[STATE_SIZE];
Expand Down
16 changes: 7 additions & 9 deletions enigma/src/main/resources/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
"log_panel.messages": "Messages",
"log_panel.users": "Users",

"progress.done": "Done!",
"progress.operation": "%s - Operation in progress",
"progress.jar.indexing": "Indexing jar",
"progress.jar.indexing.entries": "Entries...",
Expand All @@ -142,15 +143,12 @@
"progress.sources.writing": "Writing sources...",
"progress.classes.deobfuscating": "Deobfuscating classes...",
"progress.classes.decompiling": "Decompiling classes...",
"progress.mappings.enigma_file.loading": "Loading mapping file",
"progress.mappings.enigma_file.done": "Done!",
"progress.mappings.enigma_file.writing": "Writing classes",
"progress.mappings.enigma_directory.loading": "Loading mapping files",
"progress.mappings.enigma_directory.writing": "Writing classes",
"progress.mappings.tiny_file.loading": "Loading mapping file",
"progress.mappings.tiny_v2.loading": "Loading mapping file",
"progress.mappings.srg_file.generating": "Generating mappings",
"progress.mappings.srg_file.writing": "Writing mappings",
"progress.mappings.loading_file": "Loading mapping file",
"progress.mappings.loading_directory": "Loading mapping files",
"progress.mappings.writing": "Writing classes",
"progress.mappings.converting": "Converting mappings",
"progress.mappings.converting.to_mappingio": "Converting to mapping-io",
"progress.mappings.converting.from_mappingio": "Converting from mapping-io",
"progress.stats": "Generating stats",
"progress.stats.data": "Generating data",

Expand Down
14 changes: 5 additions & 9 deletions enigma/src/main/resources/lang/fr_fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
"log_panel.messages": "Messages",
"log_panel.users": "Utilisateurs",

"progress.done": "Terminé !",
"progress.operation": "%s - Opération en cours",
"progress.jar.indexing": "Indexation du jar",
"progress.jar.indexing.entries": "Entrées...",
Expand All @@ -141,15 +142,10 @@
"progress.sources.writing": "Écriture des sources...",
"progress.classes.deobfuscating": "Déobfuscation des classes...",
"progress.classes.decompiling": "Décompilation des classes...",
"progress.mappings.enigma_file.loading": "Chargement du fichier de mappings",
"progress.mappings.enigma_file.done": "Terminé !",
"progress.mappings.enigma_file.writing": "Écriture des classes",
"progress.mappings.enigma_directory.loading": "Chargement des fichiers de mappings",
"progress.mappings.enigma_directory.writing": "Écriture des classes",
"progress.mappings.tiny_file.loading": "Chargement du fichier de mappings",
"progress.mappings.tiny_v2.loading": "Chargement du fichier de mappings",
"progress.mappings.srg_file.generating": "Génération des mappings",
"progress.mappings.srg_file.writing": "Écriture des mappings",
"progress.mappings.loading_file": "Chargement du fichier de mappings",
"progress.mappings.loading_directory": "Chargement des fichiers de mappings",
"progress.mappings.writing": "Écriture des mappings",
"progress.mappings.converting": "Conversion des mappings",
"progress.stats": "Génération des statistiques",
"progress.stats.data": "Génération des données",

Expand Down
13 changes: 4 additions & 9 deletions enigma/src/main/resources/lang/ja_jp.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
"log_panel.messages": "メッセージ",
"log_panel.users": "ユーザー",

"progress.done": "完了しました!",
"progress.operation": "%s - 処理中",
"progress.jar.indexing": "jarのインデックス中",
"progress.jar.indexing.entries": "エントリー...",
Expand All @@ -142,15 +143,9 @@
"progress.sources.writing": "ソースコードを書き出し中...",
"progress.classes.deobfuscating": "クラスを難読化解除中...",
"progress.classes.decompiling": "クラスのデコンパイル中...",
"progress.mappings.enigma_file.loading": "マッピングファイルをロード",
"progress.mappings.enigma_file.done": "完了しました!",
"progress.mappings.enigma_file.writing": "クラスの書き出し中",
"progress.mappings.enigma_directory.loading": "マッピングファイルの読込中",
"progress.mappings.enigma_directory.writing": "クラスの書き出し中",
"progress.mappings.tiny_file.loading": "マッピングファイルの読込中",
"progress.mappings.tiny_v2.loading": "マッピングファイルの読込中",
"progress.mappings.srg_file.generating": "マッピングの作成中",
"progress.mappings.srg_file.writing": "マッピングの書き出し中",
"progress.mappings.loading_file": "マッピングファイルをロード",
"progress.mappings.loading_directory": "マッピングファイルの読込中",
"progress.mappings.writing": "マッピングの書き出し中",
"progress.stats": "統計情報を作成中",
"progress.stats.data": "データの作成中",

Expand Down
13 changes: 4 additions & 9 deletions enigma/src/main/resources/lang/zh_cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
"info_panel.tree.implementations": "实现",
"info_panel.tree.calls": "调用图",

"progress.done": "完成!",
"progress.operation": "%s - 进行中",
"progress.jar.indexing": "索引 Jar",
"progress.jar.indexing.entries": "条目...",
Expand All @@ -85,15 +86,9 @@
"progress.sources.writing": "写出源码中...",
"progress.classes.deobfuscating": "反混淆类中...",
"progress.classes.decompiling": "反编译类中...",
"progress.mappings.enigma_file.loading": "加载映射文件",
"progress.mappings.enigma_file.done": "完成!",
"progress.mappings.enigma_file.writing": "写入类",
"progress.mappings.enigma_directory.loading": "加载映射文件",
"progress.mappings.enigma_directory.writing": "写入类",
"progress.mappings.tiny_file.loading": "加载映射文件",
"progress.mappings.tiny_v2.loading": "加载映射文件",
"progress.mappings.srg_file.generating": "生成映射",
"progress.mappings.srg_file.writing": "写出映射",
"progress.mappings.loading_file": "加载映射文件",
"progress.mappings.loading_directory": "加载映射文件",
"progress.mappings.writing": "写出映射",
"progress.stats": "生成统计范围",
"progress.stats.data": "生成数据",

Expand Down

0 comments on commit 95bb87f

Please sign in to comment.