├── .classpath ├── .gitignore ├── .project ├── README.md ├── Releases └── ReplaceModsWithForgeCSVMappingsGUI v1.2.jar ├── lib ├── Fernflower.jar └── opencsv-3.9.jar └── src └── org └── golde └── java └── rmwfcsvmg ├── EnumForgeVersion.java ├── Main.java ├── Mapping.java ├── ThreadReplaceCSV.java ├── utils ├── FernFlowerUtils.java ├── FileUtils.java └── JavaUtils.java └── windows ├── PanelConsole.java └── PanelMain.java /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .metadata 2 | bin/ 3 | tmp/ 4 | *.tmp 5 | *.bak 6 | *.swp 7 | *~.nib 8 | local.properties 9 | .settings/ 10 | .loadpath 11 | .recommenders 12 | 13 | # External tool builders 14 | .externalToolBuilders/ 15 | 16 | # Locally stored "Eclipse launch configurations" 17 | *.launch 18 | 19 | # PyDev specific (Python IDE for Eclipse) 20 | *.pydevproject 21 | 22 | # CDT-specific (C/C++ Development Tooling) 23 | .cproject 24 | 25 | # Java annotation processor (APT) 26 | .factorypath 27 | 28 | # PDT-specific (PHP Development Tools) 29 | .buildpath 30 | 31 | # sbteclipse plugin 32 | .target 33 | 34 | # Tern plugin 35 | .tern-project 36 | 37 | # TeXlipse plugin 38 | .texlipse 39 | 40 | # STS (Spring Tool Suite) 41 | .springBeans 42 | 43 | # Code Recommenders 44 | .recommenders/ 45 | 46 | # Scala IDE specific (Scala & Java development for Eclipse) 47 | .cache-main 48 | .scala_dependencies 49 | .worksheet 50 | data/ 51 | code/ 52 | test/ 53 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | ReplaceModsWithForgeCSVMappingsGUI 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ReplaceModsWithForgeCSVMappingsGUI 2 | A GUI program to decompile forge mods and reformat all the obfuscated code so forge can recompile the mod. 3 | 4 | This is pretty much abandonware at this point. I may make this a console app, or something that comes with all the versions in a zip or some jazz. Not sure. 5 | 6 | If the program doesn't work make a PR or an issue, and I may get around to updating the program. Its really not high on my prioroity sorry. 7 | -------------------------------------------------------------------------------- /Releases/ReplaceModsWithForgeCSVMappingsGUI v1.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/egold555/ReplaceModsWithForgeCSVMappingsGUI/2caf32e3a81957b576c77acd20cdc6268a9608ac/Releases/ReplaceModsWithForgeCSVMappingsGUI v1.2.jar -------------------------------------------------------------------------------- /lib/Fernflower.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/egold555/ReplaceModsWithForgeCSVMappingsGUI/2caf32e3a81957b576c77acd20cdc6268a9608ac/lib/Fernflower.jar -------------------------------------------------------------------------------- /lib/opencsv-3.9.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/egold555/ReplaceModsWithForgeCSVMappingsGUI/2caf32e3a81957b576c77acd20cdc6268a9608ac/lib/opencsv-3.9.jar -------------------------------------------------------------------------------- /src/org/golde/java/rmwfcsvmg/EnumForgeVersion.java: -------------------------------------------------------------------------------- 1 | package org.golde.java.rmwfcsvmg; 2 | 3 | import java.io.File; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | import org.golde.java.rmwfcsvmg.utils.JavaUtils; 8 | 9 | public enum EnumForgeVersion { 10 | 11 | v1_7_10("http://export.mcpbot.golde.org/mcp_stable/12-1.7.10/mcp_stable-12-1.7.10.zip", "1.7.10"), 12 | v1_8("http://export.mcpbot.golde.org/mcp_stable/18-1.8/mcp_stable-18-1.8.zip", "1.8"), 13 | v1_8_8("http://export.mcpbot.golde.org/mcp_stable/20-1.8.8/mcp_stable-20-1.8.8.zip", "1.8.8"), 14 | v1_8_9("http://export.mcpbot.golde.org/mcp_stable/22-1.8.9/mcp_stable-22-1.8.9.zip", "1.8.9"), 15 | v1_9("http://export.mcpbot.golde.org/mcp_stable/24-1.9/mcp_stable-24-1.9.zip", "1.9"), 16 | v1_9_4("http://export.mcpbot.golde.org/mcp_stable/26-1.9.4/mcp_stable-26-1.9.4.zip", "1.9.4"), 17 | v1_10_2("http://export.mcpbot.golde.org/mcp_stable/29-1.10.2/mcp_stable-29-1.10.2.zip", "1.10.2"), 18 | v1_11("http://export.mcpbot.golde.org/mcp_stable/32-1.11/mcp_stable-32-1.11.zip", "1.11"), 19 | v1_12("http://export.mcpbot.golde.org/mcp_stable/39-1.12/mcp_stable-39-1.12.zip", "1.12"), 20 | v1_13_2("http://export.mcpbot.golde.org/mcp_stable/47-1.13.2/mcp_stable-47-1.13.2.zip", "1.13.2"), 21 | v1_14_2("http://export.mcpbot.golde.org/mcp_stable/53-1.14.2/mcp_stable-53-1.14.2.zip", "1.14.4"), 22 | v1_15("http://export.mcpbot.golde.org/mcp_stable/60-1.15/mcp_stable-60-1.15.zip", "1.15"), 23 | Snapshot("", "Snapshot"), 24 | ; 25 | 26 | private String zipLink; 27 | private File extractionDirectory; 28 | private String goodName; 29 | EnumForgeVersion(String zipLink, String goodName) { 30 | this.zipLink = zipLink; 31 | this.goodName = goodName; 32 | if(!JavaUtils.isStringEmpty(goodName)) { 33 | extractionDirectory = new File(Main.FILE_DATA_MAPPINGS_STABLE, goodName); 34 | } 35 | } 36 | 37 | public String getZipLink() { 38 | return zipLink; 39 | } 40 | 41 | public Mapping getMappings() { 42 | return new Mapping(extractionDirectory); 43 | } 44 | 45 | public void setCustom(String snapshotNum, String versionNum) { 46 | snapshotNum = snapshotNum.toLowerCase(); 47 | if(snapshotNum.startsWith("snapshot_")) { 48 | snapshotNum = snapshotNum.replace("snapshot_", ""); 49 | } 50 | extractionDirectory = new File(Main.FILE_DATA_MAPPINGS_SNAPSHOT, snapshotNum); 51 | zipLink = "http://export.mcpbot.golde.org/mcp_snapshot/" + snapshotNum + "-" + versionNum + "/mcp_snapshot-" + snapshotNum + "-" + versionNum + ".zip"; 52 | } 53 | 54 | public static String[] valuesNice() { 55 | List toReturn = new ArrayList(); 56 | for(EnumForgeVersion value:values()) { 57 | toReturn.add(value.goodName); 58 | } 59 | return toReturn.toArray(new String[0]); 60 | } 61 | 62 | public static EnumForgeVersion get(String variable) { 63 | for(EnumForgeVersion value:values()) { 64 | if(variable.equalsIgnoreCase(value.goodName)) { 65 | return value; 66 | } 67 | } 68 | System.out.println("This wasnt suppost to happen!"); 69 | return null; 70 | } 71 | 72 | public File getExtractionDirectory() { 73 | return extractionDirectory; 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /src/org/golde/java/rmwfcsvmg/Main.java: -------------------------------------------------------------------------------- 1 | package org.golde.java.rmwfcsvmg; 2 | 3 | import java.awt.event.ActionEvent; 4 | import java.awt.event.ActionListener; 5 | import java.io.File; 6 | import java.nio.file.Paths; 7 | 8 | import javax.swing.JFrame; 9 | import javax.swing.JMenu; 10 | import javax.swing.JMenuBar; 11 | import javax.swing.JMenuItem; 12 | 13 | import org.golde.java.rmwfcsvmg.utils.JavaUtils; 14 | import org.golde.java.rmwfcsvmg.windows.PanelConsole; 15 | import org.golde.java.rmwfcsvmg.windows.PanelMain; 16 | 17 | public class Main { 18 | 19 | public static File FILE_MAIN = new File(Paths.get(".").toAbsolutePath().normalize().toString()); 20 | public static File FILE_CODE = new File(FILE_MAIN, "code"); 21 | public static File FILE_DATA = new File(FILE_MAIN, "data"); 22 | public static File FILE_DATA_TEMP = new File(FILE_DATA, "temp"); 23 | public static File FILE_DATA_MAPPINGS = new File(FILE_DATA, "mappings"); 24 | public static File FILE_DATA_MAPPINGS_STABLE = new File(FILE_DATA_MAPPINGS, "stable"); 25 | public static File FILE_DATA_MAPPINGS_SNAPSHOT = new File(FILE_DATA_MAPPINGS, "snapshot"); 26 | 27 | public static final String PROGRAM_NAME = "Mod CSV Replacer"; 28 | public static final String PROGRAM_VERSION = "v1.2 Beta"; 29 | 30 | public static PanelConsole console = new PanelConsole(); 31 | 32 | public static void main(String[] args) { 33 | 34 | //Folder stuff 35 | FILE_CODE.mkdir(); 36 | 37 | FILE_DATA.mkdir(); 38 | FILE_DATA_TEMP.mkdir(); 39 | FILE_DATA_MAPPINGS.mkdir(); 40 | FILE_DATA_MAPPINGS_STABLE.mkdir(); 41 | FILE_DATA_MAPPINGS_SNAPSHOT.mkdir(); 42 | 43 | //JFrame GUI Stuff 44 | JFrame frame = new JFrame(PROGRAM_NAME + " " + PROGRAM_VERSION); 45 | JMenuBar menubar = new JMenuBar(); 46 | 47 | frame.add(new PanelMain()); 48 | frame.setJMenuBar(menubar); 49 | frame.setSize(400, 300); 50 | frame.setResizable(false); 51 | frame.setLocationRelativeTo(null); 52 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 53 | 54 | 55 | JMenu menu1 = new JMenu("Program"); 56 | 57 | 58 | JMenuItem menuItemAbout = new JMenuItem("About"); 59 | menuItemAbout.setToolTipText("About application"); 60 | menuItemAbout.addActionListener(new ActionListener() { 61 | 62 | @Override 63 | public void actionPerformed(ActionEvent arg0) { 64 | JavaUtils.dialog( 65 | PROGRAM_NAME + " " + PROGRAM_VERSION + "\n" + 66 | "By Eric Golde", 67 | frame, "About", JavaUtils.MessageLogo.NONE); 68 | } 69 | 70 | }); 71 | menu1.add(menuItemAbout); 72 | 73 | JMenuItem menuItemOptions = new JMenuItem("Toggle Console"); 74 | menuItemOptions.setToolTipText("Show/Hide output console"); 75 | menuItemOptions.addActionListener(new ActionListener() { 76 | 77 | @Override 78 | public void actionPerformed(ActionEvent arg0) { 79 | console.toggle(); 80 | } 81 | 82 | }); 83 | menu1.add(menuItemOptions); 84 | 85 | JMenuItem menuItemExit = new JMenuItem("Exit"); 86 | menuItemExit.setToolTipText("Exit application"); 87 | menuItemExit.addActionListener(new ActionListener() { 88 | 89 | @Override 90 | public void actionPerformed(ActionEvent arg0) { 91 | quit(); 92 | } 93 | 94 | }); 95 | menu1.add(menuItemExit); 96 | 97 | menubar.add(menu1); 98 | 99 | frame.addWindowListener(new java.awt.event.WindowAdapter() { 100 | @Override 101 | public void windowClosing(java.awt.event.WindowEvent windowEvent) { 102 | quit(); 103 | } 104 | }); 105 | 106 | frame.setVisible(true); 107 | } 108 | 109 | static void quit() { 110 | //console.quit(); 111 | System.exit(0); 112 | } 113 | 114 | 115 | 116 | } 117 | -------------------------------------------------------------------------------- /src/org/golde/java/rmwfcsvmg/Mapping.java: -------------------------------------------------------------------------------- 1 | package org.golde.java.rmwfcsvmg; 2 | 3 | import java.io.File; 4 | 5 | public class Mapping { 6 | 7 | private final boolean hasAlreadyDownloaded; 8 | private final File CSV_FIELDS; 9 | private final File CSV_METHODS; 10 | private final File CSV_PARAMS; 11 | 12 | public Mapping(File extractionDirecxtory) { 13 | hasAlreadyDownloaded = extractionDirecxtory.exists(); 14 | CSV_FIELDS = new File(extractionDirecxtory, "fields.csv"); 15 | CSV_METHODS = new File(extractionDirecxtory, "methods.csv"); 16 | CSV_PARAMS = new File(extractionDirecxtory, "params.csv"); 17 | } 18 | 19 | public boolean hasAlreadyDownloaded() { 20 | return hasAlreadyDownloaded; 21 | } 22 | 23 | public File getCSV_FIELDS() { 24 | return CSV_FIELDS; 25 | } 26 | 27 | public File getCSV_METHODS() { 28 | return CSV_METHODS; 29 | } 30 | 31 | public File getCSV_PARAMS() { 32 | return CSV_PARAMS; 33 | } 34 | 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/org/golde/java/rmwfcsvmg/ThreadReplaceCSV.java: -------------------------------------------------------------------------------- 1 | package org.golde.java.rmwfcsvmg; 2 | 3 | import java.io.File; 4 | import java.util.ArrayList; 5 | 6 | import org.golde.java.rmwfcsvmg.utils.FernFlowerUtils; 7 | import org.golde.java.rmwfcsvmg.utils.FileUtils; 8 | import org.golde.java.rmwfcsvmg.utils.JavaUtils; 9 | import org.golde.java.rmwfcsvmg.windows.PanelMain; 10 | 11 | public class ThreadReplaceCSV extends Thread{ 12 | 13 | private EnumForgeVersion selectedForgeVersion; 14 | private File selectedFile; 15 | private PanelMain panelMain; 16 | private long startTime; 17 | 18 | public ThreadReplaceCSV(EnumForgeVersion selectedForgeVersion, File selectedFile, PanelMain panelMain) { 19 | 20 | this.selectedForgeVersion = selectedForgeVersion; 21 | this.selectedFile = selectedFile; 22 | this.panelMain = panelMain; 23 | startTime = System.nanoTime(); 24 | this.start(); 25 | } 26 | 27 | void log(String msg) { 28 | System.out.println(msg); 29 | } 30 | 31 | @Override 32 | public void run() { 33 | panelMain.btnGo.setEnabled(false); 34 | panelMain.btnSelectMod.setEnabled(false); 35 | panelMain.comboBoxForgeVersion.setEnabled(false); 36 | 37 | 38 | Mapping mappings = selectedForgeVersion.getMappings(); 39 | log("Downloading CSV mappings..."); 40 | if(!selectedForgeVersion.getMappings().hasAlreadyDownloaded()) { 41 | String zipFile = FileUtils.downloadFile(selectedForgeVersion.getZipLink(), "zip"); 42 | if(zipFile == null) { 43 | JavaUtils.simpleError("Could not find ZIP @: " + selectedForgeVersion.getZipLink() + ".zip", panelMain); 44 | reset(); 45 | return; 46 | } 47 | log("Unzipping CSV Mappings...."); 48 | FileUtils.unZipIt(zipFile, selectedForgeVersion.getExtractionDirectory()); 49 | } 50 | updateProgress(0.1); 51 | 52 | try { 53 | //Delete existing code directory files 54 | log("Deleting code directory..."); 55 | FileUtils.deleteDirectory(Main.FILE_CODE); 56 | 57 | log("====FernFlower Decomile Start===="); 58 | FernFlowerUtils.decompile(selectedFile, Main.FILE_DATA_TEMP, false); 59 | log("====FernFlower Decomile End===="); 60 | updateProgress(0.5); 61 | log("unziping FernFlower output to code folder..."); 62 | FileUtils.unZipIt(new File(Main.FILE_DATA_TEMP, selectedFile.getName()), Main.FILE_CODE); 63 | updateProgress(0.6); 64 | 65 | ArrayList filesToReplace = new ArrayList(); 66 | FileUtils.listFilesIncludingSub(Main.FILE_CODE, filesToReplace); 67 | log("====Replace CSV Start===="); 68 | for(File file:filesToReplace) { 69 | if(!FileUtils.getFileExtension(file).equals("java")) {continue;} 70 | log("Replacing " + file.getName()); 71 | FileUtils.replaceSelected(file, FileUtils.gatherReplacementsFromFile(mappings.getCSV_FIELDS())); 72 | FileUtils.replaceSelected(file, FileUtils.gatherReplacementsFromFile(mappings.getCSV_METHODS())); 73 | FileUtils.replaceSelected(file, FileUtils.gatherReplacementsFromFile(mappings.getCSV_PARAMS())); 74 | } 75 | log("====Replace CSV End===="); 76 | }catch(Exception e) { 77 | JavaUtils.simpleError(e, panelMain); 78 | reset(); 79 | return; 80 | } 81 | updateProgress(1.0); 82 | //End 83 | JavaUtils.successMessage("Successfully decompiled mod in " + elapsedTime(startTime) + " seconds!", panelMain); 84 | reset(); 85 | } 86 | 87 | private void reset() { 88 | FileUtils.deleteDirectory(Main.FILE_DATA_TEMP); 89 | panelMain.btnGo.setEnabled(true); 90 | panelMain.btnSelectMod.setEnabled(true); 91 | panelMain.comboBoxForgeVersion.setEnabled(true); 92 | } 93 | 94 | private void updateProgress(double percentFinished) { 95 | int percent = (int)Math.round(percentFinished * 100); 96 | panelMain.progressBar.setString("Processing " + percent + "%"); 97 | panelMain.progressBar.setValue(percent); 98 | } 99 | 100 | private double elapsedTime(long startTime) { 101 | return (double)(System.nanoTime() - startTime) / 1000000000.0; 102 | } 103 | 104 | } 105 | -------------------------------------------------------------------------------- /src/org/golde/java/rmwfcsvmg/utils/FernFlowerUtils.java: -------------------------------------------------------------------------------- 1 | package org.golde.java.rmwfcsvmg.utils; 2 | 3 | import java.io.File; 4 | 5 | import org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler; 6 | 7 | public class FernFlowerUtils { 8 | 9 | public static void decompile(File file, File to) { 10 | decompile(file, to, false); 11 | } 12 | 13 | public static void decompile(File file, File to, boolean renameAll) { 14 | String[] args = null; 15 | 16 | if(renameAll) { 17 | args = new String[] {"-ren=1", file.getAbsolutePath(), to.getAbsolutePath() }; 18 | }else { 19 | args = new String[] {file.getAbsolutePath(), to.getAbsolutePath() }; 20 | } 21 | 22 | ConsoleDecompiler.main(args); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/org/golde/java/rmwfcsvmg/utils/FileUtils.java: -------------------------------------------------------------------------------- 1 | package org.golde.java.rmwfcsvmg.utils; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.File; 5 | import java.io.FileInputStream; 6 | import java.io.FileOutputStream; 7 | import java.io.FileReader; 8 | import java.io.IOException; 9 | import java.net.URL; 10 | import java.nio.channels.Channels; 11 | import java.nio.channels.ReadableByteChannel; 12 | import java.util.ArrayList; 13 | import java.util.zip.ZipEntry; 14 | import java.util.zip.ZipInputStream; 15 | 16 | import com.opencsv.CSVReader; 17 | 18 | public class FileUtils { 19 | 20 | public static String downloadFile(String url, String extention) { 21 | try { 22 | String fName = "data/temp/tempFile." + extention; 23 | URL website = new URL(url); 24 | ReadableByteChannel rbc = Channels.newChannel(website.openStream()); 25 | FileOutputStream fos = new FileOutputStream(fName); 26 | fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); 27 | fos.close(); 28 | return fName; 29 | }catch(Exception e) { 30 | System.err.println("Could not find ZIP @: " + url + extention); 31 | return null; 32 | } 33 | } 34 | 35 | public static void unZipIt(File zipFile, File outputFolder) { 36 | unZipIt(zipFile.getAbsolutePath(), outputFolder.getAbsolutePath()); 37 | } 38 | public static void unZipIt(String zipFile, File outputFolder) { 39 | unZipIt(zipFile, outputFolder.getAbsolutePath()); 40 | } 41 | public static void unZipIt(String zipFile, String outputFolder){ 42 | 43 | byte[] buffer = new byte[1024]; 44 | 45 | try{ 46 | 47 | //create output directory is not exists 48 | File folder = new File(outputFolder); 49 | if(!folder.exists()){ 50 | folder.mkdir(); 51 | } 52 | 53 | //get the zip file content 54 | ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFile)); 55 | //get the zipped file list entry 56 | ZipEntry ze = zis.getNextEntry(); 57 | 58 | while(ze!=null){ 59 | String fileName = ze.getName(); 60 | if (! fileName.endsWith("/")) { 61 | File newFile = new File(outputFolder + File.separator + fileName); 62 | 63 | //create all non exists folders 64 | //else you will hit FileNotFoundException for compressed folder 65 | new File(newFile.getParent()).mkdirs(); 66 | 67 | FileOutputStream fos = new FileOutputStream(newFile); 68 | 69 | int len; 70 | while ((len = zis.read(buffer)) > 0) { 71 | fos.write(buffer, 0, len); 72 | } 73 | 74 | fos.close(); 75 | } 76 | ze = zis.getNextEntry(); 77 | } 78 | 79 | zis.closeEntry(); 80 | zis.close(); 81 | 82 | 83 | }catch(IOException ex){ 84 | ex.printStackTrace(); 85 | } 86 | } 87 | 88 | public static void listFilesIncludingSub(File directory, ArrayList files) { 89 | File[] fList = directory.listFiles(); 90 | for (File file : fList) { 91 | if (file.isFile()) { 92 | files.add(file); 93 | } else if (file.isDirectory()) { 94 | listFilesIncludingSub(file, files); 95 | } 96 | } 97 | } 98 | public static void deleteDirectory(File dir) { 99 | deleteDirectoryNon(dir); 100 | dir.mkdirs(); 101 | } 102 | 103 | private static boolean deleteDirectoryNon(File dir) { 104 | if (dir.isDirectory()) { 105 | File[] children = dir.listFiles(); 106 | for (int i = 0; i < children.length; i++) { 107 | boolean success = deleteDirectoryNon(children[i]); 108 | if (!success) { 109 | return false; 110 | } 111 | } 112 | } 113 | return dir.delete(); 114 | } 115 | 116 | public static void replaceSelected(File file, ArrayList replacements) { 117 | replaceSelected(file, file, replacements); 118 | } 119 | 120 | public static void replaceSelected(File oFile, File nFile, ArrayList replacements) { 121 | try { 122 | BufferedReader file = new BufferedReader(new FileReader(oFile)); 123 | String line;String input = ""; 124 | while ((line = file.readLine()) != null) input += line + "\r\n"; 125 | file.close(); 126 | 127 | for (Replacement repl: replacements) { 128 | input = input.replace(repl.replaceWhat, repl.replaceWith); 129 | } 130 | 131 | FileOutputStream fileOut = new FileOutputStream(nFile); 132 | fileOut.write(input.getBytes()); 133 | fileOut.close(); 134 | } catch (Exception e) { 135 | e.printStackTrace(); 136 | } 137 | } 138 | 139 | public static ArrayList gatherReplacementsFromFile(File csv) { 140 | ArrayList replacements = new ArrayList(); 141 | 142 | CSVReader reader = null; 143 | try { 144 | reader = new CSVReader(new FileReader(csv)); 145 | String[] line; 146 | while ((line = reader.readNext()) != null) { 147 | String obf = line[0]; 148 | String forge = line[1]; 149 | replacements.add(new Replacement(obf, forge)); 150 | } 151 | } catch (IOException e) { 152 | e.printStackTrace(); 153 | } 154 | 155 | return replacements; 156 | } 157 | 158 | private static class Replacement { 159 | public String replaceWhat; 160 | public String replaceWith; 161 | public Replacement(String what, String with) { 162 | this.replaceWhat = what; 163 | this.replaceWith = with; 164 | } 165 | } 166 | 167 | public static String getFileExtension(File file) { 168 | String name = file.getName(); 169 | try { 170 | return name.substring(name.lastIndexOf(".") + 1); 171 | } catch (Exception e) { 172 | return ""; 173 | } 174 | } 175 | 176 | } 177 | -------------------------------------------------------------------------------- /src/org/golde/java/rmwfcsvmg/utils/JavaUtils.java: -------------------------------------------------------------------------------- 1 | package org.golde.java.rmwfcsvmg.utils; 2 | 3 | import java.awt.Component; 4 | import java.io.PrintWriter; 5 | import java.io.StringWriter; 6 | 7 | import javax.swing.JOptionPane; 8 | 9 | public class JavaUtils { 10 | 11 | public enum MessageLogo{ 12 | ERROR(0), 13 | INFORMATION(1), 14 | WARNING(2), 15 | QUESTION(3), 16 | NONE(-1); 17 | 18 | public final int INT_VALUE; 19 | MessageLogo(int value){ 20 | INT_VALUE = value; 21 | } 22 | } 23 | 24 | public static boolean isStringEmpty(String s) { 25 | 26 | if(s == null) {return true;} 27 | if(s.equalsIgnoreCase("")) {return true;} 28 | if(s.equalsIgnoreCase(" ")) {return true;} 29 | 30 | return false; 31 | } 32 | 33 | public static void simpleError(Exception e, Component parent) { 34 | StringWriter writer = new StringWriter(); 35 | e.printStackTrace(new PrintWriter(writer)); 36 | String message = writer.toString(); 37 | dialog(message, parent, "Error", MessageLogo.ERROR); 38 | } 39 | 40 | public static void simpleError(String e, Component parent) { 41 | dialog(e, parent, "Error", MessageLogo.ERROR); 42 | } 43 | 44 | public static void successMessage(String message, Component parent) { 45 | dialog(message, parent, "Success", MessageLogo.INFORMATION); 46 | } 47 | 48 | public static void dialog(String message, Component parent, String title, MessageLogo logo) 49 | { 50 | JOptionPane.showMessageDialog(parent, message, title, logo.INT_VALUE); 51 | System.out.println("Dialog: " + title); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/org/golde/java/rmwfcsvmg/windows/PanelConsole.java: -------------------------------------------------------------------------------- 1 | package org.golde.java.rmwfcsvmg.windows; 2 | 3 | import java.io.*; 4 | import java.awt.*; 5 | import java.awt.event.*; 6 | import javax.swing.*; 7 | import javax.swing.text.DefaultCaret; 8 | 9 | public class PanelConsole extends WindowAdapter implements WindowListener, ActionListener, Runnable 10 | { 11 | private JFrame frame; 12 | private JTextArea textArea; 13 | private Thread reader; 14 | private Thread reader2; 15 | private boolean quit; 16 | 17 | private final PipedInputStream pin=new PipedInputStream(); 18 | private final PipedInputStream pin2=new PipedInputStream(); 19 | 20 | private boolean showing = false; 21 | 22 | public PanelConsole() 23 | { 24 | // create all components and add them 25 | frame=new JFrame("Console"); 26 | Dimension frameSize=new Dimension(400, 300); 27 | int x=(int)(frameSize.width/2); 28 | int y=(int)(frameSize.height/2); 29 | frame.setBounds(x,y,frameSize.width,frameSize.height); 30 | 31 | textArea=new JTextArea(); 32 | textArea.setEditable(false); 33 | 34 | //auto scrolling 35 | DefaultCaret caret = (DefaultCaret)textArea.getCaret(); 36 | caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE); 37 | 38 | JButton button=new JButton("clear"); 39 | 40 | frame.getContentPane().setLayout(new BorderLayout()); 41 | frame.getContentPane().add(new JScrollPane(textArea),BorderLayout.CENTER); 42 | frame.getContentPane().add(button,BorderLayout.SOUTH); 43 | frame.setVisible(showing); 44 | 45 | frame.addWindowListener(this); 46 | button.addActionListener(this); 47 | 48 | try 49 | { 50 | PipedOutputStream pout=new PipedOutputStream(this.pin); 51 | System.setOut(new PrintStream(pout,true)); 52 | } 53 | catch (java.io.IOException io) 54 | { 55 | textArea.append("Couldn't redirect STDOUT to this console\n"+io.getMessage()); 56 | } 57 | catch (SecurityException se) 58 | { 59 | textArea.append("Couldn't redirect STDOUT to this console\n"+se.getMessage()); 60 | } 61 | 62 | try 63 | { 64 | PipedOutputStream pout2=new PipedOutputStream(this.pin2); 65 | System.setErr(new PrintStream(pout2,true)); 66 | } 67 | catch (java.io.IOException io) 68 | { 69 | textArea.append("Couldn't redirect STDERR to this console\n"+io.getMessage()); 70 | } 71 | catch (SecurityException se) 72 | { 73 | textArea.append("Couldn't redirect STDERR to this console\n"+se.getMessage()); 74 | } 75 | 76 | quit=false; // signals the Threads that they should exit 77 | 78 | // Starting two separate threads to read from the PipedInputStreams 79 | // 80 | reader=new Thread(this); 81 | reader.setDaemon(true); 82 | reader.start(); 83 | // 84 | reader2=new Thread(this); 85 | reader2.setDaemon(true); 86 | reader2.start(); 87 | 88 | 89 | } 90 | 91 | public void quit() { 92 | this.notifyAll(); // stop all threads 93 | try { reader.join(1000);pin.close(); } catch (Exception e){} 94 | try { reader2.join(1000);pin2.close(); } catch (Exception e){} 95 | frame.dispose(); 96 | } 97 | 98 | public synchronized void actionPerformed(ActionEvent evt) 99 | { 100 | textArea.setText(""); 101 | } 102 | 103 | public synchronized void run() 104 | { 105 | try 106 | { 107 | while (Thread.currentThread()==reader) 108 | { 109 | try { this.wait(100);}catch(InterruptedException ie) {} 110 | if (pin.available()!=0) 111 | { 112 | String input=this.readLine(pin); 113 | textArea.append(input); 114 | } 115 | if (quit) return; 116 | } 117 | 118 | while (Thread.currentThread()==reader2) 119 | { 120 | try { this.wait(100);}catch(InterruptedException ie) {} 121 | if (pin2.available()!=0) 122 | { 123 | String input=this.readLine(pin2); 124 | textArea.append(input); 125 | } 126 | if (quit) return; 127 | } 128 | } catch (Exception e) 129 | { 130 | textArea.append("\nConsole reports an Internal error."); 131 | textArea.append("The error is: "+e); 132 | } 133 | 134 | 135 | } 136 | 137 | public synchronized String readLine(PipedInputStream in) throws IOException 138 | { 139 | String input=""; 140 | do 141 | { 142 | int available=in.available(); 143 | if (available==0) break; 144 | byte b[]=new byte[available]; 145 | in.read(b); 146 | input=input+new String(b,0,b.length); 147 | }while( !input.endsWith("\n") && !input.endsWith("\r\n") && !quit); 148 | return input; 149 | } 150 | 151 | public void toggle() { 152 | showing = !showing; 153 | frame.setVisible(showing); 154 | } 155 | 156 | } 157 | -------------------------------------------------------------------------------- /src/org/golde/java/rmwfcsvmg/windows/PanelMain.java: -------------------------------------------------------------------------------- 1 | package org.golde.java.rmwfcsvmg.windows; 2 | 3 | import java.awt.event.ActionEvent; 4 | import java.awt.event.ActionListener; 5 | import java.awt.event.KeyAdapter; 6 | import java.awt.event.KeyEvent; 7 | import java.io.File; 8 | 9 | import javax.swing.DefaultComboBoxModel; 10 | import javax.swing.JButton; 11 | import javax.swing.JComboBox; 12 | import javax.swing.JFileChooser; 13 | import javax.swing.JLabel; 14 | import javax.swing.JPanel; 15 | import javax.swing.JProgressBar; 16 | import javax.swing.JTextField; 17 | import javax.swing.filechooser.FileNameExtensionFilter; 18 | 19 | import org.golde.java.rmwfcsvmg.EnumForgeVersion; 20 | import org.golde.java.rmwfcsvmg.Main; 21 | import org.golde.java.rmwfcsvmg.ThreadReplaceCSV; 22 | import org.golde.java.rmwfcsvmg.utils.JavaUtils; 23 | 24 | @SuppressWarnings({"serial", "rawtypes", "unchecked"}) //Ugg java D: 25 | public class PanelMain extends JPanel{ 26 | 27 | private EnumForgeVersion selectedForgeVersion = EnumForgeVersion.v1_7_10; 28 | public JButton btnGo; 29 | public JComboBox comboBoxForgeVersion; 30 | private JTextField textFieldCustomMCPSnapshotVersion; 31 | private JTextField textFieldCustomMCPMinecraftVersion; 32 | private JLabel lblMCPVersion; 33 | private JLabel lblMinecraftVersion; 34 | private JLabel lblModToApply; 35 | public JButton btnSelectMod; 36 | private File selectedFile = null; 37 | public JProgressBar progressBar; 38 | 39 | public PanelMain() { 40 | 41 | textFieldCustomMCPSnapshotVersion = new JTextField(); 42 | textFieldCustomMCPSnapshotVersion.addKeyListener(new KeyAdapter() { 43 | @Override 44 | public void keyTyped(KeyEvent arg0) { 45 | updateGoButton(); 46 | } 47 | }); 48 | 49 | textFieldCustomMCPSnapshotVersion.setBounds(196, 113, 96, 22); 50 | textFieldCustomMCPSnapshotVersion.setVisible(false); 51 | add(textFieldCustomMCPSnapshotVersion); 52 | textFieldCustomMCPSnapshotVersion.setColumns(10); 53 | 54 | textFieldCustomMCPMinecraftVersion = new JTextField(); 55 | textFieldCustomMCPMinecraftVersion.addKeyListener(new KeyAdapter() { 56 | @Override 57 | public void keyTyped(KeyEvent arg0) { 58 | updateGoButton(); 59 | } 60 | }); 61 | 62 | textFieldCustomMCPMinecraftVersion.setBounds(196, 81, 96, 22); 63 | textFieldCustomMCPMinecraftVersion.setVisible(false); 64 | add(textFieldCustomMCPMinecraftVersion); 65 | textFieldCustomMCPMinecraftVersion.setColumns(10); 66 | 67 | lblMCPVersion = new JLabel("MCP Version"); 68 | lblMCPVersion.setBounds(80, 84, 77, 16); 69 | lblMCPVersion.setVisible(false); 70 | add(lblMCPVersion); 71 | 72 | lblMinecraftVersion = new JLabel("Minecraft Version"); 73 | lblMinecraftVersion.setBounds(80, 116, 104, 16); 74 | lblMinecraftVersion.setVisible(false); 75 | add(lblMinecraftVersion); 76 | 77 | btnGo = new JButton("GO!"); 78 | btnGo.addActionListener(new ActionListener() { 79 | public void actionPerformed(ActionEvent action) { 80 | 81 | pressedGoButton(); 82 | 83 | } 84 | 85 | }); 86 | btnGo.setEnabled(false); 87 | btnGo.setBounds(149, 178, 97, 25); 88 | add(btnGo); 89 | 90 | 91 | comboBoxForgeVersion = new JComboBox(); 92 | comboBoxForgeVersion.setBounds(196, 13, 96, 22); 93 | comboBoxForgeVersion.addActionListener(new ActionListener() { 94 | public void actionPerformed(ActionEvent action) { 95 | 96 | if(action.getID() == ActionEvent.ACTION_PERFORMED) { 97 | selectedForgeVersion = EnumForgeVersion.get((String)comboBoxForgeVersion.getSelectedItem()); 98 | 99 | updateGoButton(); 100 | } 101 | 102 | } 103 | }); 104 | setLayout(null); 105 | 106 | comboBoxForgeVersion.setModel(new DefaultComboBoxModel(EnumForgeVersion.valuesNice())); 107 | add(comboBoxForgeVersion); 108 | 109 | JLabel lblForgeVersion = new JLabel("Forge Version"); 110 | lblForgeVersion.setBounds(80, 16, 96, 16); 111 | add(lblForgeVersion); 112 | 113 | lblModToApply = new JLabel("Mod to apply to"); 114 | lblModToApply.setBounds(79, 52, 104, 16); 115 | add(lblModToApply); 116 | 117 | btnSelectMod = new JButton("Select Mod"); 118 | final PanelMain stupidWorkaroundCauseJava = this; 119 | btnSelectMod.addActionListener(new ActionListener() { 120 | public void actionPerformed(ActionEvent arg0) { 121 | JFileChooser fileChooser = new JFileChooser(Main.FILE_MAIN); 122 | fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("*.jar", "jar")); 123 | fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("*.zip", "zip")); 124 | fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("*.class", "class")); 125 | fileChooser.setAcceptAllFileFilterUsed(false); 126 | fileChooser.setMultiSelectionEnabled(false); 127 | 128 | // 129 | fileChooser.showOpenDialog(stupidWorkaroundCauseJava); 130 | selectedFile = fileChooser.getSelectedFile(); 131 | updateGoButton(); 132 | } 133 | 134 | 135 | }); 136 | btnSelectMod.setBounds(195, 48, 97, 25); 137 | add(btnSelectMod); 138 | 139 | progressBar = new JProgressBar(); 140 | progressBar.setBounds(12, 216, 376, 14); 141 | add(progressBar); 142 | 143 | } 144 | 145 | private void updateGoButton() { 146 | boolean shouldGoButtonBeEnabled = true; 147 | if(selectedForgeVersion == EnumForgeVersion.Snapshot) { 148 | if(!JavaUtils.isStringEmpty(textFieldCustomMCPSnapshotVersion.getText()) && !JavaUtils.isStringEmpty(textFieldCustomMCPMinecraftVersion.getText())) { 149 | EnumForgeVersion.Snapshot.setCustom(textFieldCustomMCPSnapshotVersion.getText(), textFieldCustomMCPMinecraftVersion.getText()); 150 | }else { 151 | shouldGoButtonBeEnabled = false; 152 | } 153 | lblMCPVersion.setVisible(true); 154 | lblMinecraftVersion.setVisible(true); 155 | textFieldCustomMCPSnapshotVersion.setVisible(true); 156 | textFieldCustomMCPMinecraftVersion.setVisible(true); 157 | }else { 158 | lblMCPVersion.setVisible(false); 159 | lblMinecraftVersion.setVisible(false); 160 | textFieldCustomMCPSnapshotVersion.setVisible(false); 161 | textFieldCustomMCPMinecraftVersion.setVisible(false); 162 | } 163 | 164 | if(selectedFile == null || !selectedFile.exists() || selectedFile.isDirectory()) { 165 | shouldGoButtonBeEnabled = false; 166 | } 167 | 168 | btnGo.setEnabled(shouldGoButtonBeEnabled); 169 | } 170 | 171 | private void pressedGoButton() { 172 | new ThreadReplaceCSV(selectedForgeVersion, selectedFile, this); 173 | } 174 | } 175 | --------------------------------------------------------------------------------