Archived
Now using JSON config file. Bug fixes and improvements.
This commit is contained in:
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user