Now using JSON config file. Bug fixes and improvements.

This commit is contained in:
da
2016-05-18 20:52:22 +02:00
parent a67d4d70d7
commit f2501ee103
12 changed files with 49 additions and 40 deletions
+2 -2
View File
@@ -1,6 +1,6 @@
/out/production /out/production
/.idea /.idea
/jLSLauncher.iml /jLSLauncher.iml
/out/artifacts/jLSLauncher_jar/config.dat /out/artifacts/jLSLauncher_jar/config.json
/config.dat /config.json
# Created by .ignore support plugin (hsz.mobi) # Created by .ignore support plugin (hsz.mobi)
+1 -1
View File
@@ -3,7 +3,7 @@
<output-path>$PROJECT_DIR$/out/artifacts/jLSLauncher_jar</output-path> <output-path>$PROJECT_DIR$/out/artifacts/jLSLauncher_jar</output-path>
<root id="archive" name="jLSLauncher.jar"> <root id="archive" name="jLSLauncher.jar">
<element id="module-output" name="jLSLauncher" /> <element id="module-output" name="jLSLauncher" />
<element id="extracted-dir" path="$PROJECT_DIR$/src/lib/JSON/json-20140107.jar" path-in-jar="/" /> <element id="extracted-dir" path="$PROJECT_DIR$/lib/json-20140107.jar" path-in-jar="/" />
</root> </root>
</artifact> </artifact>
</component> </component>
+1 -1
View File
@@ -1,7 +1,7 @@
<component name="libraryTable"> <component name="libraryTable">
<library name="json-20140107"> <library name="json-20140107">
<CLASSES> <CLASSES>
<root url="jar://$PROJECT_DIR$/src/lib/JSON/json-20140107.jar!/" /> <root url="jar://$PROJECT_DIR$/lib/json-20140107.jar!/" />
</CLASSES> </CLASSES>
<JAVADOC /> <JAVADOC />
<SOURCES /> <SOURCES />
+1 -1
View File
@@ -22,7 +22,7 @@ Optionally you can download Livestreamer here: http://docs.livestreamer.io/insta
`jLSLauncher.jar` does not need an installation and can be executed as is. `jLSLauncher.jar` does not need an installation and can be executed as is.
You can move or copy this tool to any other location you like. You can move or copy this tool to any other location you like.
The configuration is stored in a file named `config.dat` which, if present, has to be moved to the same location. The configuration is stored in a file named `config.json` which, if present, has to be moved to the same location.
### Usage of jLSLauncher ### Usage of jLSLauncher
+1
View File
@@ -8,5 +8,6 @@
<orderEntry type="inheritedJdk" /> <orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="json-20140107" level="project" /> <orderEntry type="library" name="json-20140107" level="project" />
<orderEntry type="library" name="com.cedarsoftware:json-io:4.4.0" level="project" />
</component> </component>
</module> </module>
Binary file not shown.
-1
View File
@@ -33,7 +33,6 @@ public class Config implements Serializable {
} }
public void setLastSelectedQuality(int lastSelectedQuality) { public void setLastSelectedQuality(int lastSelectedQuality) {
this.lastSelectedQuality = lastSelectedQuality; this.lastSelectedQuality = lastSelectedQuality;
ConfigFileIOHandler.save();
} }
private int lastSelectedQuality; private int lastSelectedQuality;
public Config() { public Config() {
@@ -1,53 +1,61 @@
package com.ixab.ConfigHandling; package com.ixab.ConfigHandling;
import com.cedarsoftware.util.io.JsonReader;
import com.cedarsoftware.util.io.JsonWriter;
import com.ixab.Logging.Logger; import com.ixab.Logging.Logger;
import java.io.*; import java.io.*;
import java.util.Scanner;
public class ConfigFileIOHandler { public class ConfigFileIOHandler {
public static Config load(String path) { public static Config load(String path) {
Config c = null;
try String content;
{ StringBuilder sb = new StringBuilder();
FileInputStream fileIn = new FileInputStream(path); try {
ObjectInputStream in = new ObjectInputStream(fileIn); String line = null;
c = (Config) in.readObject(); FileReader fr = new FileReader(path);
in.close(); BufferedReader br = new BufferedReader(fr);
fileIn.close(); while ((line = br.readLine()) != null) {
}catch(IOException i) sb.append(line);
{ }
i.printStackTrace(); br.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
return null; return null;
}catch(ClassNotFoundException e) } catch (IOException e) {
{
Logger.print("Config class not found");
e.printStackTrace(); e.printStackTrace();
return null; return null;
} }
content = sb.toString();
Config c = (Config) JsonReader.jsonToJava(content);
if (c instanceof Config) {
Logger.print("Config loaded.");
return c; return c;
} else {
return null;
}
} }
public static void save(Config c, String path) { public static void save(Config c, String path) {
try try {
{ FileWriter fw = new FileWriter(path);
FileOutputStream fileOut = BufferedWriter bw = new BufferedWriter(fw);
new FileOutputStream("config.dat"); bw.write(JsonWriter.formatJson(JsonWriter.objectToJson(c)));
ObjectOutputStream out = new ObjectOutputStream(fileOut); bw.close();
out.writeObject(c); Logger.print("Config saved.");
out.close(); } catch (FileNotFoundException e) {
fileOut.close(); e.printStackTrace();
Logger.print("Config data is saved in config.dat"); } catch (IOException e) {
}catch(IOException i) e.printStackTrace();
{
i.printStackTrace();
} }
} }
public static Config load() { public static Config load() {
return load("config.dat"); return load("config.json");
} }
public static void save(Config c) { public static void save(Config c) {
save(c, "config.dat"); save(c, "config.json");
} }
public static void save() { public static void save() {
save(ConfigFileInstanceHandler.getConfig(), "config.dat"); save(ConfigFileInstanceHandler.getConfig(), "config.json");
} }
} }
+2 -2
View File
@@ -6,8 +6,8 @@
<xy x="20" y="20" width="680" height="500"/> <xy x="20" y="20" width="680" height="500"/>
</constraints> </constraints>
<properties> <properties>
<minimumSize width="680" height="400"/> <minimumSize width="680" height="440"/>
<preferredSize width="680" height="400"/> <preferredSize width="680" height="440"/>
</properties> </properties>
<border type="none"/> <border type="none"/>
<children> <children>
+1 -1
View File
@@ -242,6 +242,6 @@ public class MainWindow {
frame.setLocationByPlatform(true); frame.setLocationByPlatform(true);
frame.setVisible(true); frame.setVisible(true);
frame.setResizable(true); frame.setResizable(true);
frame.setMinimumSize(new Dimension(680, 400)); frame.setMinimumSize(new Dimension(680, 440));
} }
} }
+2 -1
View File
@@ -5,11 +5,12 @@ import com.ixab.ConfigHandling.ConfigFileIOHandler;
import com.ixab.ConfigHandling.ConfigFileInstanceHandler; import com.ixab.ConfigHandling.ConfigFileInstanceHandler;
import com.ixab.GUI.AlertWindow; import com.ixab.GUI.AlertWindow;
import com.ixab.GUI.MainWindow; import com.ixab.GUI.MainWindow;
import com.ixab.Logging.Logger;
import javax.swing.*; import javax.swing.*;
public class Main { public class Main {
private final static String version = "0.52 Alpha"; private final static String version = "0.55 Alpha";
private static Config c = null; private static Config c = null;
public static void main(String[] args) { public static void main(String[] args) {
try { try {