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
/.idea
/jLSLauncher.iml
/out/artifacts/jLSLauncher_jar/config.dat
/config.dat
/out/artifacts/jLSLauncher_jar/config.json
/config.json
# 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>
<root id="archive" name="jLSLauncher.jar">
<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>
</artifact>
</component>
+1 -1
View File
@@ -1,7 +1,7 @@
<component name="libraryTable">
<library name="json-20140107">
<CLASSES>
<root url="jar://$PROJECT_DIR$/src/lib/JSON/json-20140107.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/json-20140107.jar!/" />
</CLASSES>
<JAVADOC />
<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.
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
+1
View File
@@ -8,5 +8,6 @@
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="json-20140107" level="project" />
<orderEntry type="library" name="com.cedarsoftware:json-io:4.4.0" level="project" />
</component>
</module>
Binary file not shown.
-1
View File
@@ -33,7 +33,6 @@ public class Config implements Serializable {
}
public void setLastSelectedQuality(int lastSelectedQuality) {
this.lastSelectedQuality = lastSelectedQuality;
ConfigFileIOHandler.save();
}
private int lastSelectedQuality;
public Config() {
@@ -1,53 +1,61 @@
package com.ixab.ConfigHandling;
import com.cedarsoftware.util.io.JsonReader;
import com.cedarsoftware.util.io.JsonWriter;
import com.ixab.Logging.Logger;
import java.io.*;
import java.util.Scanner;
public class ConfigFileIOHandler {
public static Config load(String path) {
Config c = null;
try
{
FileInputStream fileIn = new FileInputStream(path);
ObjectInputStream in = new ObjectInputStream(fileIn);
c = (Config) in.readObject();
in.close();
fileIn.close();
}catch(IOException i)
{
i.printStackTrace();
String content;
StringBuilder sb = new StringBuilder();
try {
String line = null;
FileReader fr = new FileReader(path);
BufferedReader br = new BufferedReader(fr);
while ((line = br.readLine()) != null) {
sb.append(line);
}
br.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
return null;
}catch(ClassNotFoundException e)
{
Logger.print("Config class not found");
} catch (IOException e) {
e.printStackTrace();
return null;
}
return c;
content = sb.toString();
Config c = (Config) JsonReader.jsonToJava(content);
if (c instanceof Config) {
Logger.print("Config loaded.");
return c;
} else {
return null;
}
}
public static void save(Config c, String path) {
try
{
FileOutputStream fileOut =
new FileOutputStream("config.dat");
ObjectOutputStream out = new ObjectOutputStream(fileOut);
out.writeObject(c);
out.close();
fileOut.close();
Logger.print("Config data is saved in config.dat");
}catch(IOException i)
{
i.printStackTrace();
try {
FileWriter fw = new FileWriter(path);
BufferedWriter bw = new BufferedWriter(fw);
bw.write(JsonWriter.formatJson(JsonWriter.objectToJson(c)));
bw.close();
Logger.print("Config saved.");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static Config load() {
return load("config.dat");
return load("config.json");
}
public static void save(Config c) {
save(c, "config.dat");
save(c, "config.json");
}
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"/>
</constraints>
<properties>
<minimumSize width="680" height="400"/>
<preferredSize width="680" height="400"/>
<minimumSize width="680" height="440"/>
<preferredSize width="680" height="440"/>
</properties>
<border type="none"/>
<children>
+1 -1
View File
@@ -242,6 +242,6 @@ public class MainWindow {
frame.setLocationByPlatform(true);
frame.setVisible(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.GUI.AlertWindow;
import com.ixab.GUI.MainWindow;
import com.ixab.Logging.Logger;
import javax.swing.*;
public class Main {
private final static String version = "0.52 Alpha";
private final static String version = "0.55 Alpha";
private static Config c = null;
public static void main(String[] args) {
try {