Got rid of history file
This commit is contained in:
parent
29e6a99f82
commit
311ccca5ee
@ -288,8 +288,6 @@ public abstract class AbstractRipper
|
|||||||
AbstractRipper ripper = (AbstractRipper) constructor.newInstance(url);
|
AbstractRipper ripper = (AbstractRipper) constructor.newInstance(url);
|
||||||
return ripper;
|
return ripper;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println(constructor.getName());
|
|
||||||
e.printStackTrace();
|
|
||||||
// Incompatible rippers *will* throw exceptions during instantiation.
|
// Incompatible rippers *will* throw exceptions during instantiation.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,14 +8,10 @@ import java.awt.GridBagConstraints;
|
|||||||
import java.awt.GridBagLayout;
|
import java.awt.GridBagLayout;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
import javax.swing.DefaultListModel;
|
import javax.swing.DefaultListModel;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
@ -49,9 +45,6 @@ public class MainWindow implements Runnable, RipStatusHandler {
|
|||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(MainWindow.class);
|
private static final Logger logger = Logger.getLogger(MainWindow.class);
|
||||||
|
|
||||||
private static final String WINDOW_TITLE = "RipMe";
|
|
||||||
private static final String HISTORY_FILE = ".history";
|
|
||||||
|
|
||||||
private static JFrame mainFrame;
|
private static JFrame mainFrame;
|
||||||
private static JTextField ripTextfield;
|
private static JTextField ripTextfield;
|
||||||
private static JButton ripButton;
|
private static JButton ripButton;
|
||||||
@ -92,7 +85,7 @@ public class MainWindow implements Runnable, RipStatusHandler {
|
|||||||
// TODO Configuration components
|
// TODO Configuration components
|
||||||
|
|
||||||
public MainWindow() {
|
public MainWindow() {
|
||||||
mainFrame = new JFrame(WINDOW_TITLE + " v" + UpdateUtils.getThisJarVersion());
|
mainFrame = new JFrame("RipMe v" + UpdateUtils.getThisJarVersion());
|
||||||
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
//mainFrame.setPreferredSize(new Dimension(400, 180));
|
//mainFrame.setPreferredSize(new Dimension(400, 180));
|
||||||
//mainFrame.setResizable(false);
|
//mainFrame.setResizable(false);
|
||||||
@ -386,48 +379,13 @@ public class MainWindow implements Runnable, RipStatusHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void loadHistory() {
|
private void loadHistory() {
|
||||||
File f; FileReader fr = null; BufferedReader br;
|
for (String url : Utils.getConfigList("download.history")) {
|
||||||
try {
|
historyListModel.addElement(url.trim());
|
||||||
f = new File(HISTORY_FILE);
|
|
||||||
fr = new FileReader(f);
|
|
||||||
br = new BufferedReader(fr);
|
|
||||||
String line;
|
|
||||||
while ( (line = br.readLine()) != null ) {
|
|
||||||
if (!line.trim().equals("")) {
|
|
||||||
historyListModel.addElement(line.trim());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
// Do nothing
|
|
||||||
} catch (IOException e) {
|
|
||||||
logger.error("[!] Error while loading history file " + HISTORY_FILE, e);
|
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
if (fr != null) {
|
|
||||||
fr.close();
|
|
||||||
}
|
|
||||||
} catch (IOException e) { }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveHistory() {
|
private void saveHistory() {
|
||||||
FileWriter fw = null;
|
Utils.setConfigList("download.history", Arrays.asList(historyListModel.toArray()));
|
||||||
try {
|
|
||||||
fw = new FileWriter(HISTORY_FILE, false);
|
|
||||||
for (int i = 0; i < historyListModel.size(); i++) {
|
|
||||||
fw.write( (String) historyListModel.get(i) );
|
|
||||||
fw.write("\n");
|
|
||||||
fw.flush();
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
logger.error("[!] Error while saving history file " + HISTORY_FILE, e);
|
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
if (fw != null) {
|
|
||||||
fw.close();
|
|
||||||
}
|
|
||||||
} catch (IOException e) { }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Thread ripAlbum(String urlString) {
|
private Thread ripAlbum(String urlString) {
|
||||||
|
@ -6,11 +6,13 @@ import java.net.URISyntaxException;
|
|||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
|
import java.util.List;
|
||||||
import java.util.jar.JarEntry;
|
import java.util.jar.JarEntry;
|
||||||
import java.util.jar.JarFile;
|
import java.util.jar.JarFile;
|
||||||
|
|
||||||
import org.apache.commons.configuration.ConfigurationException;
|
import org.apache.commons.configuration.ConfigurationException;
|
||||||
import org.apache.commons.configuration.PropertiesConfiguration;
|
import org.apache.commons.configuration.PropertiesConfiguration;
|
||||||
|
import org.apache.commons.configuration.reloading.FileChangedReloadingStrategy;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -32,6 +34,8 @@ public class Utils {
|
|||||||
configPath = configFile;
|
configPath = configFile;
|
||||||
}
|
}
|
||||||
config = new PropertiesConfiguration(configPath);
|
config = new PropertiesConfiguration(configPath);
|
||||||
|
config.setAutoSave(true);
|
||||||
|
config.setReloadingStrategy(new FileChangedReloadingStrategy());
|
||||||
logger.info("Loaded " + config.getPath());
|
logger.info("Loaded " + config.getPath());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("[!] Failed to load properties file from " + configFile, e);
|
logger.error("[!] Failed to load properties file from " + configFile, e);
|
||||||
@ -70,9 +74,23 @@ public class Utils {
|
|||||||
public static boolean getConfigBoolean(String key, boolean defaultValue) {
|
public static boolean getConfigBoolean(String key, boolean defaultValue) {
|
||||||
return config.getBoolean(key, defaultValue);
|
return config.getBoolean(key, defaultValue);
|
||||||
}
|
}
|
||||||
|
public static List<String> getConfigList(String key) {
|
||||||
|
List<String> result = new ArrayList<String>();
|
||||||
|
for (Object obj : config.getList(key, new ArrayList<String>())) {
|
||||||
|
if (obj instanceof String) {
|
||||||
|
result.add( (String) obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
public static void setConfigBoolean(String key, boolean value) { config.setProperty(key, value); }
|
public static void setConfigBoolean(String key, boolean value) { config.setProperty(key, value); }
|
||||||
public static void setConfigString(String key, String value) { config.setProperty(key, value); }
|
public static void setConfigString(String key, String value) { config.setProperty(key, value); }
|
||||||
public static void setConfigInteger(String key, int value) { config.setProperty(key, value); }
|
public static void setConfigInteger(String key, int value) { config.setProperty(key, value); }
|
||||||
|
public static void setConfigList(String key, List<Object> list) {
|
||||||
|
config.clearProperty(key);
|
||||||
|
config.addProperty(key, list);
|
||||||
|
}
|
||||||
|
|
||||||
public static void saveConfig() {
|
public static void saveConfig() {
|
||||||
try {
|
try {
|
||||||
config.save(config.getPath());
|
config.save(config.getPath());
|
||||||
|
@ -14,6 +14,7 @@ download.timeout = 60000
|
|||||||
# Maximum size of downloaded files in bytes (required)
|
# Maximum size of downloaded files in bytes (required)
|
||||||
download.max_size = 104857600
|
download.max_size = 104857600
|
||||||
|
|
||||||
|
download.history =
|
||||||
# API creds
|
# API creds
|
||||||
twitter.auth = VW9Ybjdjb1pkd2J0U3kwTUh2VXVnOm9GTzVQVzNqM29LQU1xVGhnS3pFZzhKbGVqbXU0c2lHQ3JrUFNNZm8=
|
twitter.auth = VW9Ybjdjb1pkd2J0U3kwTUh2VXVnOm9GTzVQVzNqM29LQU1xVGhnS3pFZzhKbGVqbXU0c2lHQ3JrUFNNZm8=
|
||||||
tumblr.auth = v5kUqGQXUtmF7K0itri1DGtgTs0VQpbSEbh1jxYgj9d2Sq18F8
|
tumblr.auth = v5kUqGQXUtmF7K0itri1DGtgTs0VQpbSEbh1jxYgj9d2Sq18F8
|
||||||
|
Loading…
Reference in New Issue
Block a user