diff --git a/.idea/vcs.xml b/.idea/vcs.xml index def6a6a..94a25f7 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -1,7 +1,6 @@ - + - - + \ No newline at end of file diff --git a/src/core/Controller.java b/src/core/Controller.java index c1e7847..77de477 100644 --- a/src/core/Controller.java +++ b/src/core/Controller.java @@ -7,19 +7,24 @@ import javafx.fxml.FXML; import javafx.scene.control.ChoiceBox; import javafx.scene.control.Label; -import javafx.scene.control.Separator; +import javax.swing.*; import java.io.*; import java.text.SimpleDateFormat; public class Controller { -@FXML + @FXML private ChoiceBox save_select; -@FXML + + @FXML + private ChoiceBox load_select; + + @FXML private Label savelabel; private File save_file; + private File load_file; private File[] sandbox_saves_hinterland; private File[] sandbox_saves_local; @@ -46,14 +51,16 @@ public boolean accept(File dir, String name) { Platform.runLater(new Runnable() { @Override public void run() { - for (File file: sandbox_saves_hinterland) { - save_select.getItems().add(file.getName()+" (game)"); + if (sandbox_saves_hinterland != null) { + for (File file : sandbox_saves_hinterland) { + save_select.getItems().add(file.getName() + " (game)"); + } } - save_select.getItems().add(new Separator()); - + if (sandbox_saves_local != null) { for (File file: sandbox_saves_local) { - save_select.getItems().add(file.getName()+" (backup)"); + load_select.getItems().add(file.getName() + " (backup)"); + } } save_select.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener() { @Override @@ -64,6 +71,15 @@ public void changed(ObservableValue observable, Number oldValu savelabel.setText(simpleDateFormat.format(save_file.lastModified())); } }); + load_select.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener() { + @Override + public void changed(ObservableValue observable, Number oldValue, Number newValue) { + System.out.println(newValue); + load_file = sandbox_saves_local[(int) newValue]; + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); + savelabel.setText(simpleDateFormat.format(load_file.lastModified())); + } + }); } }); @@ -73,6 +89,7 @@ public void changed(ObservableValue observable, Number oldValu private static void copyFileUsingStream(File source, File dest) throws IOException { InputStream is = null; OutputStream os = null; + try { is = new FileInputStream(source); os = new FileOutputStream(dest); @@ -87,4 +104,36 @@ private static void copyFileUsingStream(File source, File dest) throws IOExcepti } } + @FXML + private void load() { + if (load_file != null) { + try { + File dest = new File(System.getProperty("user.home") + "\\AppData\\Local\\Hinterland\\TheLongDark\\" + load_file.getName()); + copyFileUsingStream(load_file, dest); + JOptionPane.showMessageDialog(null, "Save Loaded"); + + } catch (IOException e) { + e.printStackTrace(); + } + + } + + } + + @FXML + private void save() { + if (save_file != null) { + try { + File dest = new File("saves\\" + save_file.getName()); + copyFileUsingStream(save_file, dest); + JOptionPane.showMessageDialog(null, "Games Saved"); + + } catch (IOException e) { + e.printStackTrace(); + } + + } + + } + } diff --git a/src/core/Main.java b/src/core/Main.java index fa1425f..85b05bd 100644 --- a/src/core/Main.java +++ b/src/core/Main.java @@ -11,7 +11,7 @@ public class Main extends Application { @Override public void start(Stage primaryStage) throws Exception{ Parent root = FXMLLoader.load(getClass().getResource("main_screen.fxml")); - primaryStage.setTitle("Hello World"); + primaryStage.setTitle("Saver"); Scene mainscreen=new Scene(root); primaryStage.setScene(mainscreen); primaryStage.show(); diff --git a/src/core/main_screen.fxml b/src/core/main_screen.fxml index 3c6e349..990f729 100644 --- a/src/core/main_screen.fxml +++ b/src/core/main_screen.fxml @@ -1,13 +1,8 @@ - - - - - - - + + @@ -19,12 +14,16 @@ -