Skip to content

Commit

Permalink
Lorenz 0.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jamierocks committed Dec 8, 2018
1 parent 9feb85d commit 8b0d9f5
Show file tree
Hide file tree
Showing 43 changed files with 279 additions and 3,746 deletions.
12 changes: 11 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,21 @@ project('FernFlower') {
// Project repositories
repositories {
mavenCentral()
maven {
url 'https://oss.sonatype.org/content/groups/public/'
}
}

// Project dependencies
dependencies {
compile 'com.google.guava:guava:19.0'
compile 'me.jamiemansfield:bombe-core:0.2.0'

// Mapping IO (Lorenz)
compile 'org.cadixdev:lorenz:0.5.0-SNAPSHOT'
compile 'org.cadixdev:lorenz-io-enigma:0.5.0-SNAPSHOT'
compile 'org.cadixdev:lorenz-io-jam:0.5.0-SNAPSHOT'
compile 'org.cadixdev:lorenz-io-kin:0.5.0-SNAPSHOT'

compile project('FernFlower')

testCompile 'junit:junit:4.12'
Expand Down Expand Up @@ -89,6 +98,7 @@ shadowJar {

// License header formatting
license {
exclude '**/blue/lapis/nocturne/gui/io/mappings/MappingsHelper.java'
include '**/*.java'
include '**/*.css'
include '**/*.fxml'
Expand Down
30 changes: 10 additions & 20 deletions src/main/java/blue/lapis/nocturne/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,11 @@

package blue.lapis.nocturne;

import blue.lapis.nocturne.gui.io.mappings.MappingsSaveDialogHelper;
import blue.lapis.nocturne.gui.scene.control.WebLink;
import blue.lapis.nocturne.jar.model.ClassSet;
import blue.lapis.nocturne.mapping.MappingContext;
import blue.lapis.nocturne.mapping.MappingFormat;
import blue.lapis.nocturne.util.helper.PropertiesHelper;
import blue.lapis.nocturne.util.helper.SceneHelper;
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
Expand All @@ -45,7 +41,8 @@
import javafx.scene.text.Text;
import javafx.scene.text.TextFlow;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;
import org.cadixdev.lorenz.MappingSet;
import org.cadixdev.lorenz.io.MappingFormat;

import java.io.IOException;
import java.io.OutputStream;
Expand All @@ -63,16 +60,6 @@ public class Main extends Application {

private static Main instance;

private static final EventHandler<WindowEvent> CLOSE_HANDLER = event -> {
try {
if (MappingsSaveDialogHelper.doDirtyConfirmation()) {
event.consume();
}
} catch (IOException ex) {
throw new RuntimeException(ex);
}
};

private static final Logger LOGGER = Logger.getLogger("Nocturne");
private static final Logger FERNFLOWER_LOGGER = Logger.getLogger("FernFlower");

Expand All @@ -84,7 +71,7 @@ public class Main extends Application {
private Stage mainStage;
private Scene scene;

private final MappingContext mappingContext = new MappingContext();
private MappingSet mappings = MappingSet.create();
private Path currentMappingsPath;
private MappingFormat currentMappingFormat;
private ClassSet loadedJar;
Expand Down Expand Up @@ -214,7 +201,6 @@ public void loadView(String lang) throws IOException {
SceneHelper.addStdStylesheet(scene);
mainStage.setTitle("Nocturne");
mainStage.setScene(scene);
mainStage.setOnCloseRequest(CLOSE_HANDLER);
mainStage.show();
} else {
scene.setRoot(root);
Expand All @@ -237,8 +223,12 @@ public static Stage getMainStage() {
return getInstance().mainStage;
}

public static MappingContext getMappingContext() {
return getInstance().mappingContext;
public static MappingSet getMappings() {
return getInstance().mappings;
}

public static void clearMappings() {
getInstance().mappings = MappingSet.create();
}

public static Path getCurrentMappingsPath() {
Expand Down Expand Up @@ -275,7 +265,7 @@ public static void updateTitle() {
if (getLoadedJar() == null) {
title = "Nocturne";
} else {
title = "Nocturne - " + (getMappingContext().isDirty() ? "*" : "") + getLoadedJar().getName();
title = "Nocturne - " + getLoadedJar().getName();
}

if (!getMainStage().getTitle().equals(title)) {
Expand Down
50 changes: 15 additions & 35 deletions src/main/java/blue/lapis/nocturne/gui/MainController.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@

import blue.lapis.nocturne.Main;
import blue.lapis.nocturne.gui.io.jar.JarDialogHelper;
import blue.lapis.nocturne.gui.io.mappings.MappingsOpenDialogHelper;
import blue.lapis.nocturne.gui.io.mappings.MappingsSaveDialogHelper;
import blue.lapis.nocturne.gui.io.mappings.MappingsHelper;
import blue.lapis.nocturne.gui.scene.control.CodeTab;
import blue.lapis.nocturne.gui.scene.control.IdentifiableTreeItem;
import blue.lapis.nocturne.gui.scene.text.SelectableMember;
import blue.lapis.nocturne.jar.model.JarClassEntry;
import blue.lapis.nocturne.jar.model.hierarchy.Hierarchy;
import blue.lapis.nocturne.jar.model.hierarchy.HierarchyElement;
Expand Down Expand Up @@ -196,37 +194,25 @@ public void closeJar(ActionEvent actionEvent) throws IOException {
saveMappingsAsButton.setDisable(true);
resetMappingsButton.setDisable(true);

Main.getMappingContext().clear();
Main.getMappingContext().setDirty(false);
Main.clearMappings();

updateClassViews();
}

public void loadMappings(ActionEvent actionEvent) throws IOException {
try {
if (MappingsSaveDialogHelper.doDirtyConfirmation()) {
return;
}
} catch (IOException ex) {
throw new RuntimeException(ex);
}
MappingsOpenDialogHelper.openMappings(false);
// TODO: save mappings if needed
MappingsHelper.loadMappings(Main.getMainStage().getOwner(), Main.getMappings());
updateClassViews();
}

public void mergeMappings(ActionEvent actionEvent) throws IOException {
MappingsOpenDialogHelper.openMappings(true);
MappingsHelper.loadMappings(Main.getMainStage().getOwner(), Main.getMappings());
updateClassViews();
}

public void resetMappings(ActionEvent actionEvent) {
try {
if (MappingsSaveDialogHelper.doDirtyConfirmation()) {
return;
}
} catch (IOException ex) {
throw new RuntimeException(ex);
}
// TODO: save mappings if needed
/*
Main.getMappingContext().getMappings().values().forEach(cm -> {
Main.getLoadedJar().getCurrentNames().put(cm.getObfuscatedName(), cm.getObfuscatedName());
JarClassEntry jce = Main.getLoadedJar().getClass(cm.getObfuscatedName()).orElse(null);
Expand All @@ -249,24 +235,20 @@ public void resetMappings(ActionEvent actionEvent) {
member.setDeobfuscated(false);
}));
updateClassViews();
*/
}

public void saveMappings(ActionEvent actionEvent) throws IOException {
MappingsSaveDialogHelper.saveMappings();
// TODO: reimplement old mappings save stuff
MappingsHelper.saveMappingsAs(Main.getMainStage().getOwner(), Main.getMappings());
}

public void saveMappingsAs(ActionEvent actionEvent) throws IOException {
MappingsSaveDialogHelper.saveMappingsAs();
MappingsHelper.saveMappingsAs(Main.getMainStage().getOwner(), Main.getMappings());
}

public void onClose(ActionEvent actionEvent) {
try {
if (MappingsSaveDialogHelper.doDirtyConfirmation()) {
return;
}
} catch (IOException ex) {
throw new RuntimeException(ex);
}
// TODO: save mappings if needed
System.exit(0);
}

Expand Down Expand Up @@ -363,11 +345,9 @@ public void updateClassViews() {
}

private boolean deinitializeCurrentJar() throws IOException {
if (MappingsSaveDialogHelper.doDirtyConfirmation()) {
return false;
}
Main.getMappingContext().clear();
closeAllTabs();
// TODO: save mappings if needed
Main.clearMappings();
this.closeAllTabs();
Main.setLoadedJar(null);
return true;
}
Expand Down
154 changes: 154 additions & 0 deletions src/main/java/blue/lapis/nocturne/gui/io/mappings/MappingsHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
//******************************************************************************
// Copyright (c) Jamie Mansfield <https://jamiemansfield.me/>
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
//******************************************************************************

package blue.lapis.nocturne.gui.io.mappings;

import javafx.stage.FileChooser;
import javafx.stage.Window;
import org.cadixdev.lorenz.MappingSet;
import org.cadixdev.lorenz.io.MappingFormat;
import org.cadixdev.lorenz.io.MappingFormats;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
* A helper class for reading and writing mappings to
* file, graphically.
*
* @author Jamie Mansfield
* @since 0.1.0
*/
public final class MappingsHelper {

private static final Map<FileChooser.ExtensionFilter, MappingFormat> FORMATS = new HashMap<>();
private static final FileChooser FILE_CHOOSER = new FileChooser();

private static void register(final FileChooser.ExtensionFilter filter,
final MappingFormat format,
final boolean isDefault) {
FORMATS.put(filter, format);
FILE_CHOOSER.getExtensionFilters().add(filter);
if (isDefault) FILE_CHOOSER.setSelectedExtensionFilter(filter);
}

private static void register(final FileChooser.ExtensionFilter filter,
final MappingFormat format) {
register(filter, format, false);
}

static {
register(Formats.SRG, MappingFormats.SRG, true);
register(Formats.CSRG, MappingFormats.CSRG);
register(Formats.TSRG, MappingFormats.TSRG);
register(Formats.ENIGMA, MappingFormats.byId("enigma"));
register(Formats.JAM, MappingFormats.byId("jam"));
register(Formats.KIN, MappingFormats.byId("kin"));
}

/**
* Loads mappings to the given {@link MappingSet}, in the {@link Window}.
*
* @param window The parent window
* @param mappings The mappings
* @return {@code true} if the mappings were read successfully;
* {@code false} otherwise
*/
public static boolean loadMappings(final Window window, final MappingSet mappings) {
// Setup the file chooser appropriately for the operation being done
FILE_CHOOSER.setTitle("Load Mappings");

// Gets the mappings
final File mappingsPath = FILE_CHOOSER.showOpenDialog(window);
if (mappingsPath == null) return false;

// Reads from file
try {
FORMATS.get(FILE_CHOOSER.getSelectedExtensionFilter()).read(mappings, mappingsPath.toPath());
}
catch (final IOException ex) {
ex.printStackTrace();
return false;
}

return true;
}

/**
* Saves mappings from the given {@link MappingSet}, in the {@link Window}.
*
* @param window The parent window
* @param mappings The mappings
* @return {@code true} if the mappings were written successfully;
* {@code false} otherwise
*/
public static boolean saveMappingsAs(final Window window, final MappingSet mappings) {
// Setup the file chooser appropriately for the operation being done
FILE_CHOOSER.setTitle("Save Mappings");

// Gets the mappings
final File mappingsPath = FILE_CHOOSER.showSaveDialog(window);
if (mappingsPath == null) return false;

// Reads from file
try {
FORMATS.get(FILE_CHOOSER.getSelectedExtensionFilter()).write(mappings, mappingsPath.toPath());
}
catch (final IOException ex) {
ex.printStackTrace();
return false;
}

return true;
}

private MappingsHelper() {
}

/**
* A pseudo-enumeration of {@link FileChooser.ExtensionFilter}s.
*/
public static final class Formats {

public static final FileChooser.ExtensionFilter SRG = new FileChooser.ExtensionFilter(
"SRG Files",
"*.srg"
);

public static final FileChooser.ExtensionFilter CSRG = new FileChooser.ExtensionFilter(
"CSRG Files",
"*.csrg"
);

public static final FileChooser.ExtensionFilter TSRG = new FileChooser.ExtensionFilter(
"TSRG Files",
"*.tsrg"
);

public static final FileChooser.ExtensionFilter ENIGMA = new FileChooser.ExtensionFilter(
"Enigma Files",
"*.enigma", "*.mappings"
);

public static final FileChooser.ExtensionFilter JAM = new FileChooser.ExtensionFilter(
"JAM Files",
"*.jam"
);

public static final FileChooser.ExtensionFilter KIN = new FileChooser.ExtensionFilter(
"Kin Files",
"*.kin"
);

private Formats() {
}

}

}
Loading

0 comments on commit 8b0d9f5

Please sign in to comment.