Skip to content
This repository has been archived by the owner on Jun 26, 2022. It is now read-only.

Commit

Permalink
config file to save and load exe path
Browse files Browse the repository at this point in the history
  • Loading branch information
requinDr committed Feb 4, 2022
1 parent 71404d4 commit c90389d
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions src/main/java/fr/fatestaynight/packager/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@
import java.awt.event.ActionEvent;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;

import javax.swing.JFileChooser;

Expand Down Expand Up @@ -175,6 +178,7 @@ public class Main extends JFrame {
private static final String WINDOW_TITLE = "Fate/stay night [Translation helper] - 0.6";
private static final int DEFAULT_WIDTH = 820;
private static final int DEFAULT_HEIGHT = 480;
private static final String CONFIG_FILE = "config_fsn-helper.txt";

// Composants graphiques
private JButton start_btn;
Expand All @@ -187,7 +191,7 @@ public class Main extends JFrame {

private PageFetcher pageFetch;
private Language[] languages;
private String path;
private String path = "";

public Main() {

Expand Down Expand Up @@ -233,7 +237,17 @@ private void setupTopMenu() {
this.exe_location.addActionListener(e -> this.findExe());

this.game_launch = new JButton("Lancer le jeu");
game_launch.setEnabled(false);
// cherche dans la config s'il y a un chemin enregistré
try {
BufferedReader brFile = new BufferedReader(new FileReader(CONFIG_FILE));
path = brFile.readLine();
brFile.close();
} catch (IOException e1) {
e1.printStackTrace();
}
if (path.equals("")){
game_launch.setEnabled(false);
}
this.game_launch.addActionListener(e -> this.gameLauncher());

fileSelectPane.add(fileNamePane);
Expand Down Expand Up @@ -384,6 +398,9 @@ private void updateTexts() {
*/
private void findExe() {
String currentDir = System.getProperty("user.dir");
if (!path.equals("")) {
currentDir = path;
}
JFileChooser choix = new JFileChooser(currentDir);
FileFilter filter = new FileNameExtensionFilter("EXE File","exe");

Expand All @@ -396,6 +413,15 @@ private void findExe() {
// chemin absolu du fichier choisi
path = choix.getSelectedFile().getAbsolutePath();
game_launch.setEnabled(true);

// écrit le chemin dans un fichier de config
try {
PrintWriter writer = new PrintWriter(CONFIG_FILE, "UTF-8");
writer.println(path);
writer.close();
} catch (FileNotFoundException | UnsupportedEncodingException e) {
e.printStackTrace();
}
}
}

Expand Down

0 comments on commit c90389d

Please sign in to comment.