180 lines
5.5 KiB
Java
180 lines
5.5 KiB
Java
package mod_quicklaunch;
|
|
|
|
import java.io.BufferedReader;
|
|
import java.io.BufferedWriter;
|
|
import java.io.File;
|
|
import java.io.FileReader;
|
|
import java.io.FileWriter;
|
|
import java.io.IOException;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
|
|
import basics.BasicGuiApp;
|
|
import basics.BasicMod;
|
|
import guis.MainGui;
|
|
import javafx.scene.Scene;
|
|
import javafx.stage.Stage;
|
|
import javafx.stage.StageStyle;
|
|
import main.Start;
|
|
import manager.SettingManager;
|
|
import scenes.SettingScene;
|
|
import update.Updater;
|
|
|
|
public class QuickLaunch extends BasicMod {
|
|
|
|
private File textfile;
|
|
private BufferedReader br;
|
|
private BufferedWriter bw;
|
|
private Map<String, String> shortcuts;
|
|
|
|
public int init() {
|
|
try {
|
|
modName = "QL";
|
|
|
|
System.out.println("QL: Starting QuickLaunch");
|
|
this.textfile = new File(SettingManager.getJarDirectory()+File.separator+"File.txt");
|
|
System.out.println("QL: File name: File.txt");
|
|
if (!this.textfile.exists()) {
|
|
System.out.println("QL: There ist no File");
|
|
this.textfile.createNewFile();
|
|
System.out.println("QL: File.txt created");
|
|
}
|
|
shortcuts = new HashMap<String, String>();
|
|
|
|
System.out.println("QL: Finished Initialisation");
|
|
if(SettingManager.isLoadFileOnBoot()){
|
|
loadFile();
|
|
}
|
|
}
|
|
catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
public void checkInput(String input){
|
|
if (input.equalsIgnoreCase("/cos")){
|
|
this.centerOnScreen();
|
|
} else if (input.equalsIgnoreCase("/cu")) {
|
|
this.checkForUpdates();
|
|
} else if (input.equalsIgnoreCase("exit") || input.equalsIgnoreCase("/x")) {
|
|
System.exit(-1);
|
|
} else if (input.equalsIgnoreCase("help") || input.equalsIgnoreCase("/?")) {
|
|
this.writeHelp();
|
|
} else if (input.equalsIgnoreCase("loadFile") || input.equalsIgnoreCase("/lf")) {
|
|
this.loadFile();
|
|
} else if (input.equalsIgnoreCase("saveFile") || input.equalsIgnoreCase("/sf")) {
|
|
this.saveFile(false);
|
|
}else if (input.equalsIgnoreCase("/s")) {
|
|
this.showShortcuts();
|
|
} else if (input.equalsIgnoreCase("getPath")|| input.equalsIgnoreCase("/gp")) {
|
|
this.getFilePath();
|
|
} else if (input.equalsIgnoreCase("/v")) {
|
|
this.QLversion();
|
|
} else if (input.equalsIgnoreCase("/c")) {
|
|
this.showSettings();
|
|
} else {
|
|
if(shortcuts.containsKey(input)) {
|
|
try {
|
|
|
|
|
|
ProcessBuilder pb = new ProcessBuilder(shortcuts.get(input).split(";"));
|
|
pb.start();
|
|
}catch (IOException io){
|
|
//TODO
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void centerOnScreen() {
|
|
BasicGuiApp.mainStage.centerOnScreen();
|
|
}
|
|
|
|
private void checkForUpdates() {
|
|
new Thread(new Runnable() {
|
|
|
|
public void run() {
|
|
Updater up = new Updater();
|
|
up.checkForUpdate();
|
|
}
|
|
}).start();
|
|
}
|
|
|
|
private void loadFile() {
|
|
try (BufferedReader br = new BufferedReader(new FileReader(this.textfile))){
|
|
System.out.println("loading shortcuts");
|
|
shortcuts.clear();
|
|
String tmpSh = ".";
|
|
String tmpPa = ".";
|
|
while (tmpSh != null) {
|
|
tmpSh = br.readLine();
|
|
if (tmpSh == null) break;
|
|
System.out.println(tmpSh);
|
|
tmpPa = br.readLine();
|
|
System.out.println(tmpPa);
|
|
shortcuts.put(tmpSh, tmpPa);
|
|
System.out.println("shortcut added");
|
|
}}catch (IOException io){
|
|
//TODO
|
|
}
|
|
|
|
try{
|
|
MainGui.addNotification("All shortcuts loaded", 2);
|
|
}catch(NullPointerException npe){
|
|
//will always fail when file gets read on boot
|
|
}
|
|
|
|
|
|
}
|
|
|
|
private void saveFile(boolean silent) {
|
|
try (BufferedWriter bw = new BufferedWriter(new FileWriter(this.textfile))) {
|
|
for (String key : shortcuts.keySet()) {
|
|
bw.write(key);
|
|
bw.newLine();
|
|
bw.write(shortcuts.get(key));
|
|
bw.newLine();
|
|
}
|
|
}catch (IOException io){
|
|
//TODO
|
|
}
|
|
if(!silent) {
|
|
MainGui.addNotification("Data has been written", 2);
|
|
}
|
|
}
|
|
|
|
private void showShortcuts() {
|
|
Stage stage = new Stage();
|
|
ShortcutWindow sw = new ShortcutWindow(shortcuts);
|
|
Scene s = new Scene(sw);
|
|
stage.setScene(s);
|
|
stage.setResizable(false);
|
|
stage.initStyle(StageStyle.UNDECORATED);
|
|
stage.showAndWait();
|
|
saveFile(true);
|
|
}
|
|
|
|
private void getFilePath(){
|
|
MainGui.addNotification("Path: " + textfile.getAbsolutePath(), 6);
|
|
}
|
|
|
|
private void QLversion() {
|
|
MainGui.addNotification("QuickLaunch version: " + Start.VERSION , 5);
|
|
}
|
|
|
|
private void writeHelp() {
|
|
Stage stage = new Stage();
|
|
HelpWindow hw = new HelpWindow();
|
|
Scene s = new Scene(hw);
|
|
stage.setTitle("Help dialog");
|
|
stage.setResizable(false);
|
|
stage.setScene(s);
|
|
stage.showAndWait();
|
|
}
|
|
|
|
private void showSettings() {
|
|
SettingScene sc = new SettingScene();
|
|
BasicGuiApp.mainStage.setScene(sc);
|
|
}
|
|
} |