From c4970cc4addedd4565cf8c3ed9ea92b6a4487e0c Mon Sep 17 00:00:00 2001 From: Thomas Guillemard Date: Fri, 12 Aug 2016 19:23:54 +0200 Subject: Implement Enigma directory format (#1) Others changes: ~ Rework File menu ~ Force UTF-8 for all I/O operations ~ Enigma now detect the original file format and use the correct one when you save a mapping--- .../java/cuchaz/enigma/mapping/MappingsWriter.java | 102 --------------------- 1 file changed, 102 deletions(-) delete mode 100644 src/main/java/cuchaz/enigma/mapping/MappingsWriter.java (limited to 'src/main/java/cuchaz/enigma/mapping/MappingsWriter.java') diff --git a/src/main/java/cuchaz/enigma/mapping/MappingsWriter.java b/src/main/java/cuchaz/enigma/mapping/MappingsWriter.java deleted file mode 100644 index 4793166..0000000 --- a/src/main/java/cuchaz/enigma/mapping/MappingsWriter.java +++ /dev/null @@ -1,102 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015 Jeff Martin. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser General Public - * License v3.0 which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl.html - *

- * Contributors: - * Jeff Martin - initial API and implementation - ******************************************************************************/ -package cuchaz.enigma.mapping; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; - -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import cuchaz.enigma.json.*; - -public class MappingsWriter { - - public void write(File file, Mappings mappings) throws IOException { - if (!file.isDirectory()) { - return; - } - - String[] entries = file.list(); - for (String s : entries) { - File currentFile = new File(file.getPath(), s); - deleteDirectory(currentFile); - } - - Gson gson = new GsonBuilder().setPrettyPrinting().create(); - for (ClassMapping classMapping : sorted(mappings.classes())) { - if (classMapping.getDeobfName() != null && !classMapping.getDeobfName().equalsIgnoreCase("") && !classMapping.getDeobfName().equalsIgnoreCase("null")) { - JsonClass jsonClass = new JsonClass(classMapping.getObfSimpleName(), classMapping.getDeobfName()); - write(jsonClass, classMapping); - - File f = new File(file, jsonClass.getName() + ".json"); - f.getParentFile().mkdirs(); - f.createNewFile(); - FileWriter writer = new FileWriter(f); - writer.write(gson.toJson(jsonClass)); - writer.close(); - } - } - } - - private void write(JsonClass jsonClass, ClassMapping classMapping) { - for (ClassMapping innerClassMapping : sorted(classMapping.innerClasses())) { - JsonClass innerClass = new JsonClass(classMapping.getObfSimpleName() + "$" + innerClassMapping.getObfSimpleName().replace("nome/", ""), innerClassMapping.getDeobfName()); - write(innerClass, innerClassMapping); - jsonClass.addInnerClass(innerClass); - } - - for (FieldMapping fieldMapping : sorted(classMapping.fields())) { - jsonClass.addField(new JsonField(fieldMapping.getObfName(), fieldMapping.getDeobfName(), fieldMapping.getObfType().toString())); - } - - for (MethodMapping methodMapping : sorted(classMapping.methods())) { - List args = new ArrayList<>(); - for (ArgumentMapping argumentMapping : sorted(methodMapping.arguments())) { - args.add(new JsonArgument(argumentMapping.getIndex(), argumentMapping.getName())); - } - if (methodMapping.getObfName().contains("") || methodMapping.getObfName().contains("")) { - jsonClass.addConstructor(new JsonConstructor(methodMapping.getObfSignature().toString(), args, methodMapping.getObfName().contains(""))); - } else { - jsonClass.addMethod(new JsonMethod(methodMapping.getObfName(), methodMapping.getDeobfName(), methodMapping.getObfSignature().toString(), args)); - } - } - } - - private > List sorted(Iterable classes) { - List out = new ArrayList<>(); - for (T t : classes) { - out.add(t); - } - Collections.sort(out); - return out; - } - - public static boolean deleteDirectory(File directory) { - if (directory.exists()) { - File[] files = directory.listFiles(); - if (null != files) { - for (int i = 0; i < files.length; i++) { - if (files[i].isDirectory()) { - deleteDirectory(files[i]); - } else { - files[i].delete(); - } - } - } - } - return (directory.delete()); - } -} -- cgit v1.2.3