-Import/export settings
This commit is contained in:
tonikelope 2017-12-31 18:17:46 +01:00
parent 564021c869
commit 4e3884a367
5 changed files with 336 additions and 455 deletions

View File

@ -7,6 +7,7 @@ import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -162,7 +163,6 @@ public final class DBTools {
ps.setString(1, upload[0]);
ps.setString(2, upload[1]);
ps.addBatch();
}
@ -170,7 +170,7 @@ public final class DBTools {
}
}
public static synchronized String selectSettingValueFromDB(String key) {
public static synchronized String selectSettingValue(String key) {
String value = null;
@ -190,7 +190,7 @@ public final class DBTools {
return value;
}
public static synchronized void insertSettingValueInDB(String key, String value) throws SQLException {
public static synchronized void insertSettingValue(String key, String value) throws SQLException {
try (Connection conn = SqliteSingleton.getInstance().getConn(); PreparedStatement ps = conn.prepareStatement("INSERT OR REPLACE INTO settings (key,value) VALUES (?, ?)")) {
@ -202,6 +202,40 @@ public final class DBTools {
}
}
public static synchronized HashMap<String, Object> selectSettingsValues() throws SQLException {
HashMap<String, Object> settings = new HashMap<>();
ResultSet res;
try (Connection conn = SqliteSingleton.getInstance().getConn(); Statement stat = conn.createStatement()) {
res = stat.executeQuery("SELECT * FROM settings");
while (res.next()) {
settings.put(res.getString("key"), res.getString("value"));
}
}
return settings;
}
public static synchronized void insertSettingsValues(HashMap<String, Object> settings) throws SQLException {
try (Connection conn = SqliteSingleton.getInstance().getConn(); PreparedStatement ps = conn.prepareStatement("INSERT OR REPLACE INTO settings (key,value) VALUES (?, ?)")) {
for (Map.Entry<String, Object> entry : settings.entrySet()) {
ps.setString(1, entry.getKey());
ps.setString(2, (String) entry.getValue());
ps.addBatch();
}
ps.executeBatch();
}
}
public static synchronized ArrayList<HashMap<String, Object>> selectDownloads() throws SQLException {
ArrayList<HashMap<String, Object>> downloads = new ArrayList<>();
@ -286,6 +320,53 @@ public final class DBTools {
return accounts;
}
public static synchronized void insertMegaAccounts(HashMap<String, Object> accounts) throws SQLException {
try (Connection conn = SqliteSingleton.getInstance().getConn(); PreparedStatement ps = conn.prepareStatement("INSERT OR REPLACE INTO mega_accounts (email,password,password_aes,user_hash) VALUES (?, ?, ?, ?)")) {
if (!accounts.isEmpty()) {
for (Map.Entry<String, Object> entry : accounts.entrySet()) {
ps.setString(1, (String) entry.getKey());
ps.setString(2, (String) ((HashMap<String, Object>) entry.getValue()).get("password"));
ps.setString(3, (String) ((HashMap<String, Object>) entry.getValue()).get("password_aes"));
ps.setString(4, (String) ((HashMap<String, Object>) entry.getValue()).get("user_hash"));
ps.addBatch();
}
ps.executeBatch();
}
}
}
public static synchronized void insertELCAccounts(HashMap<String, Object> accounts) throws SQLException {
try (Connection conn = SqliteSingleton.getInstance().getConn(); PreparedStatement ps = conn.prepareStatement("INSERT OR REPLACE INTO elc_accounts (host,user,apikey) VALUES (?, ?, ?)")) {
if (!accounts.isEmpty()) {
for (Map.Entry<String, Object> entry : accounts.entrySet()) {
ps.setString(1, (String) entry.getKey());
ps.setString(2, (String) ((HashMap<String, Object>) entry.getValue()).get("user"));
ps.setString(3, (String) ((HashMap<String, Object>) entry.getValue()).get("apikey"));
ps.addBatch();
}
ps.executeBatch();
}
}
}
public static synchronized HashMap<String, Object> selectELCAccounts() throws SQLException {
HashMap<String, Object> accounts = new HashMap<>();

View File

@ -567,7 +567,7 @@ public final class Download implements Transference, Runnable, SecureSingleThrea
_file.renameTo(new File(filename));
String verify_file = selectSettingValueFromDB("verify_down_file");
String verify_file = selectSettingValue("verify_down_file");
if (verify_file != null && verify_file.equals("yes")) {
_checking_cbc = true;

View File

@ -46,7 +46,7 @@ import org.apache.http.auth.UsernamePasswordCredentials;
*/
public final class MainPanel {
public static final String VERSION = "2.62";
public static final String VERSION = "2.63";
public static final int THROTTLE_SLICE_SIZE = 16 * 1024;
public static final int DEFAULT_BYTE_BUFFER_SIZE = 16 * 1024;
public static final int STREAMER_PORT = 1337;
@ -423,7 +423,7 @@ public final class MainPanel {
}
public void loadUserSettings() {
String def_slots = selectSettingValueFromDB("default_slots_down");
String def_slots = selectSettingValue("default_slots_down");
if (def_slots != null) {
_default_slots_down = parseInt(def_slots);
@ -431,7 +431,7 @@ public final class MainPanel {
_default_slots_down = Download.WORKERS_DEFAULT;
}
def_slots = selectSettingValueFromDB("default_slots_up");
def_slots = selectSettingValue("default_slots_up");
if (def_slots != null) {
_default_slots_up = parseInt(def_slots);
@ -439,7 +439,7 @@ public final class MainPanel {
_default_slots_up = Upload.WORKERS_DEFAULT;
}
String use_slots = selectSettingValueFromDB("use_slots_down");
String use_slots = selectSettingValue("use_slots_down");
if (use_slots != null) {
_use_slots_down = use_slots.equals("yes");
@ -447,7 +447,7 @@ public final class MainPanel {
_use_slots_down = Download.USE_SLOTS_DEFAULT;
}
use_slots = selectSettingValueFromDB("use_slots_up");
use_slots = selectSettingValue("use_slots_up");
if (use_slots != null) {
_use_slots_up = use_slots.equals("yes");
@ -455,7 +455,7 @@ public final class MainPanel {
_use_slots_up = Upload.USE_SLOTS_DEFAULT;
}
String max_downloads = selectSettingValueFromDB("max_downloads");
String max_downloads = selectSettingValue("max_downloads");
if (max_downloads != null) {
_max_dl = parseInt(max_downloads);
@ -463,7 +463,7 @@ public final class MainPanel {
_max_dl = Download.SIM_TRANSFERENCES_DEFAULT;
}
String max_uploads = selectSettingValueFromDB("max_uploads");
String max_uploads = selectSettingValue("max_uploads");
if (max_uploads != null) {
_max_ul = parseInt(max_uploads);
@ -471,13 +471,13 @@ public final class MainPanel {
_max_ul = Upload.SIM_TRANSFERENCES_DEFAULT;
}
_default_download_path = selectSettingValueFromDB("default_down_dir");
_default_download_path = selectSettingValue("default_down_dir");
if (_default_download_path == null) {
_default_download_path = ".";
}
String limit_dl_speed = selectSettingValueFromDB("limit_download_speed");
String limit_dl_speed = selectSettingValue("limit_download_speed");
if (limit_dl_speed != null) {
@ -488,7 +488,7 @@ public final class MainPanel {
_limit_download_speed = LIMIT_TRANSFERENCE_SPEED_DEFAULT;
}
String limit_ul_speed = selectSettingValueFromDB("limit_upload_speed");
String limit_ul_speed = selectSettingValue("limit_upload_speed");
if (limit_ul_speed != null) {
@ -499,7 +499,7 @@ public final class MainPanel {
_limit_upload_speed = LIMIT_TRANSFERENCE_SPEED_DEFAULT;
}
String max_download_speed = selectSettingValueFromDB("max_download_speed");
String max_download_speed = selectSettingValue("max_download_speed");
if (max_download_speed != null) {
_max_dl_speed = parseInt(max_download_speed);
@ -507,7 +507,7 @@ public final class MainPanel {
_max_dl_speed = MAX_TRANSFERENCE_SPEED_DEFAULT;
}
String max_upload_speed = selectSettingValueFromDB("max_upload_speed");
String max_upload_speed = selectSettingValue("max_upload_speed");
if (max_upload_speed != null) {
_max_up_speed = parseInt(max_upload_speed);
@ -522,15 +522,15 @@ public final class MainPanel {
Logger.getLogger(MainPanel.class.getName()).log(SEVERE, null, ex);
}
_mega_account_down = DBTools.selectSettingValueFromDB("mega_account_down");
_mega_account_down = DBTools.selectSettingValue("mega_account_down");
String use_account;
_use_mega_account_down = ((use_account = DBTools.selectSettingValueFromDB("use_mega_account_down")) != null && use_account.equals("yes"));
_use_mega_account_down = ((use_account = DBTools.selectSettingValue("use_mega_account_down")) != null && use_account.equals("yes"));
_master_pass_hash = DBTools.selectSettingValueFromDB("master_pass_hash");
_master_pass_hash = DBTools.selectSettingValue("master_pass_hash");
_master_pass_salt = DBTools.selectSettingValueFromDB("master_pass_salt");
_master_pass_salt = DBTools.selectSettingValue("master_pass_salt");
if (_master_pass_salt == null) {
@ -538,14 +538,14 @@ public final class MainPanel {
_master_pass_salt = Bin2BASE64(genRandomByteArray(CryptTools.PBKDF2_SALT_BYTE_LENGTH));
DBTools.insertSettingValueInDB("master_pass_salt", _master_pass_salt);
DBTools.insertSettingValue("master_pass_salt", _master_pass_salt);
} catch (SQLException ex) {
Logger.getLogger(MainPanel.class.getName()).log(Level.SEVERE, null, ex);
}
}
String use_proxy = selectSettingValueFromDB("use_proxy");
String use_proxy = selectSettingValue("use_proxy");
if (use_proxy != null) {
_use_proxy = use_proxy.equals("yes");
@ -555,15 +555,15 @@ public final class MainPanel {
if (_use_proxy) {
_proxy_host = DBTools.selectSettingValueFromDB("proxy_host");
_proxy_host = DBTools.selectSettingValue("proxy_host");
String proxy_port = DBTools.selectSettingValueFromDB("proxy_port");
String proxy_port = DBTools.selectSettingValue("proxy_port");
_proxy_port = (proxy_port == null || proxy_port.isEmpty()) ? 8080 : Integer.parseInt(proxy_port);
String proxy_user = DBTools.selectSettingValueFromDB("proxy_user");
String proxy_user = DBTools.selectSettingValue("proxy_user");
String proxy_pass = DBTools.selectSettingValueFromDB("proxy_pass");
String proxy_pass = DBTools.selectSettingValue("proxy_pass");
if (proxy_user != null && !proxy_user.isEmpty() && proxy_pass != null) {
@ -576,7 +576,7 @@ public final class MainPanel {
}
}
String use_megacrypter_reverse = selectSettingValueFromDB("megacrypter_reverse");
String use_megacrypter_reverse = selectSettingValue("megacrypter_reverse");
if (use_megacrypter_reverse != null) {
_megacrypter_reverse = use_megacrypter_reverse.equals("yes");
@ -586,12 +586,12 @@ public final class MainPanel {
if (_megacrypter_reverse) {
String reverse_port = DBTools.selectSettingValueFromDB("megacrypter_reverse_port");
String reverse_port = DBTools.selectSettingValue("megacrypter_reverse_port");
_megacrypter_reverse_port = (reverse_port == null || reverse_port.isEmpty()) ? DEFAULT_MEGA_PROXY_PORT : Integer.parseInt(reverse_port);
}
String use_smart_proxy = selectSettingValueFromDB("smart_proxy");
String use_smart_proxy = selectSettingValue("smart_proxy");
if (use_smart_proxy != null) {
_use_smart_proxy = use_smart_proxy.equals("yes");
@ -601,7 +601,7 @@ public final class MainPanel {
if (_use_smart_proxy) {
_use_smart_proxy_url = selectSettingValueFromDB("smart_proxy_url");
_use_smart_proxy_url = selectSettingValue("smart_proxy_url");
}
}

View File

@ -31,7 +31,7 @@
<Group type="102" attributes="0">
<Component id="status" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="ok_button" min="-2" pref="130" max="-2" attributes="0"/>
<Component id="save_button" min="-2" pref="130" max="-2" attributes="0"/>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Component id="cancel_button" min="-2" pref="130" max="-2" attributes="0"/>
</Group>
@ -52,7 +52,7 @@
<Component id="status" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="1" attributes="0">
<Component id="ok_button" min="-2" max="-2" attributes="0"/>
<Component id="save_button" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
@ -61,16 +61,16 @@
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JButton" name="ok_button">
<Component class="javax.swing.JButton" name="save_button">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Dialog" size="18" style="1"/>
</Property>
<Property name="text" type="java.lang.String" value="OK"/>
<Property name="text" type="java.lang.String" value="SAVE"/>
<Property name="doubleBuffered" type="boolean" value="true"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="ok_buttonActionPerformed"/>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="save_buttonActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="cancel_button">
@ -109,7 +109,7 @@
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="downloads_scroll_pane" pref="905" max="32767" attributes="0"/>
<Component id="downloads_scroll_pane" pref="986" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
@ -578,7 +578,7 @@
</Group>
<Component id="limit_upload_speed_checkbox" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace min="0" pref="280" max="32767" attributes="0"/>
<EmptySpace min="0" pref="361" max="32767" attributes="0"/>
</Group>
</Group>
<EmptySpace max="-2" attributes="0"/>
@ -734,11 +734,8 @@
<Component id="encrypt_pass_checkbox" min="-2" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Component id="jLabel1" pref="712" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="mega_account_import_button" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="mega_account_export_button" min="-2" max="-2" attributes="0"/>
<Component id="jLabel1" pref="793" max="32767" attributes="0"/>
<EmptySpace min="-2" pref="193" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Component id="remove_mega_account_button" min="-2" max="-2" attributes="0"/>
@ -752,16 +749,12 @@
<Component id="add_elc_account_button" min="-2" max="-2" attributes="0"/>
</Group>
<Group type="102" attributes="0">
<Component id="mega_accounts_label" min="-2" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="mega_accounts_label" min="-2" max="-2" attributes="0"/>
<Component id="elc_accounts_label" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Component id="elc_accounts_label" min="-2" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
<Component id="elc_account_import_button" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="elc_account_export_button" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
@ -779,26 +772,18 @@
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="mega_accounts_label" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="jLabel1" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="mega_account_export_button" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="mega_account_import_button" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="mega_accounts_scrollpane" pref="127" max="32767" attributes="0"/>
<Component id="mega_accounts_scrollpane" pref="133" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="remove_mega_account_button" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="add_mega_account_button" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="32767" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="elc_accounts_label" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="elc_account_export_button" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="elc_account_import_button" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<Component id="elc_accounts_label" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="elc_accounts_scrollpane" pref="127" max="32767" attributes="0"/>
<Component id="elc_accounts_scrollpane" pref="133" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="remove_elc_account_button" alignment="3" min="-2" max="-2" attributes="0"/>
@ -982,50 +967,6 @@
<Property name="text" type="java.lang.String" value="Note: you can use a (optional) alias for your email addresses -&gt; bob@supermail.com#bob_mail"/>
</Properties>
</Component>
<Component class="javax.swing.JButton" name="mega_account_export_button">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Dialog" size="14" style="1"/>
</Property>
<Property name="text" type="java.lang.String" value="Export"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="mega_account_export_buttonActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="mega_account_import_button">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Dialog" size="14" style="1"/>
</Property>
<Property name="text" type="java.lang.String" value="Import"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="mega_account_import_buttonActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="elc_account_export_button">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Dialog" size="14" style="1"/>
</Property>
<Property name="text" type="java.lang.String" value="Export"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="elc_account_export_buttonActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="elc_account_import_button">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Dialog" size="14" style="1"/>
</Property>
<Property name="text" type="java.lang.String" value="Import"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="elc_account_import_buttonActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Container>
<Container class="javax.swing.JPanel" name="jPanel1">
@ -1040,9 +981,16 @@
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="proxy_panel" max="32767" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="proxy_panel" max="32767" attributes="0"/>
<Group type="102" alignment="1" attributes="0">
<Component id="import_settings_button" min="-2" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
<Component id="export_settings_button" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
@ -1052,7 +1000,12 @@
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="proxy_panel" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="297" max="32767" attributes="0"/>
<EmptySpace pref="248" max="32767" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="export_settings_button" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="import_settings_button" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
@ -1203,11 +1156,11 @@
<EmptySpace max="-2" attributes="0"/>
<Component id="proxy_user_label" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="proxy_user_textfield" pref="294" max="32767" attributes="0"/>
<Component id="proxy_user_textfield" pref="257" max="32767" attributes="0"/>
<EmptySpace min="-2" max="-2" attributes="0"/>
<Component id="proxy_pass_label" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="proxy_pass_textfield" pref="304" max="32767" attributes="0"/>
<Component id="proxy_pass_textfield" pref="422" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
@ -1271,6 +1224,28 @@
</Container>
</SubComponents>
</Container>
<Component class="javax.swing.JButton" name="import_settings_button">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Dialog" size="22" style="1"/>
</Property>
<Property name="text" type="java.lang.String" value="IMPORT SETTINGS"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="import_settings_buttonActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="export_settings_button">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Dialog" size="22" style="1"/>
</Property>
<Property name="text" type="java.lang.String" value="EXPORT SETTINGS"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="export_settings_buttonActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Container>
</SubComponents>

File diff suppressed because it is too large Load Diff