8000 Change Config Folder by odnar-dev · Pull Request #457 · tonikelope/megabasterd · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Change Config Folder #457

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions src/main/java/com/tonikelope/megabasterd/MainPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ public final class MainPanel {
public static final String DEFAULT_USER_AGENT = "Mozilla/5.0 (X11; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0";
public static final String ICON_FILE = "/images/pica_roja_big.png";
public static final ExecutorService THREAD_POOL = newCachedThreadPool();
public static volatile String MEGABASTERD_HOME_DIR = System.getProperty("user.home");
public static volatile String MEGABASTERD_HOME_DIR = System.getProperty("user.home") + "/.megabasterd";
public static volatile String MEGABASTERD_DOWNLOAD_DIR = System.getProperty("user.home") + "/Downloads";
private static String _proxy_host;
private static int _proxy_port;
private static boolean _use_proxy;
Expand Down Expand Up @@ -112,6 +113,16 @@ public static void main(String args[]) {

}

if (System.getProperty("os.name").startsWith("Linux")) {
String xdgDataHome = System.getenv("XDG_DATA_HOME");
if (xdgDataHome == null) {
xdgDataHome = System.getProperty("user.home") + "/.local/share";
}
MEGABASTERD_HOME_DIR = xdgDataHome + "/MegaBasterd";
File tmp_dir = new File(MainPanel.MEGABASTERD_HOME_DIR);
tmp_dir.mkdir();
}

File f = new File(getCurrentJarParentPath() + "/.megabasterd_portable");

if (f.exists()) {
Expand Down Expand Up @@ -253,7 +264,7 @@ public MainPanel() {
PrintStream fileOut;

try {
fileOut = new PrintStream(new FileOutputStream(MainPanel.MEGABASTERD_HOME_DIR + "/.MEGABASTERD_DEBUG.log"));
fileOut = new PrintStream(new FileOutputStream(MainPanel.MEGABASTERD_HOME_DIR + "/DEBUG.log"));

System.setOut(fileOut);
System.setErr(fileOut);
Expand Down Expand Up @@ -929,7 +940,7 @@ public void byebyenow(boolean restart, boolean delete_db) {

if (delete_db) {

File db_file = new File(MainPanel.MEGABASTERD_HOME_DIR + "/.megabasterd" + MainPanel.VERSION + "/" + SqliteSingleton.SQLITE_FILE);
File db_file = new File(MainPanel.MEGABASTERD_HOME_DIR + "/" + MainPanel.VERSION + "/" + SqliteSingleton.SQLITE_FILE);

db_file.delete();

Expand All @@ -954,9 +965,9 @@ private void _check_old_version() {

try {

if (!new File(MainPanel.MEGABASTERD_HOME_DIR + "/.megabasterd" + MainPanel.VERSION + "/.old_version_check").exists()) {
if (!new File(MainPanel.MEGABASTERD_HOME_DIR + "/" + MainPanel.VERSION + "/old_version_check").exists()) {

new File(MainPanel.MEGABASTERD_HOME_DIR + "/.megabasterd" + MainPanel.VERSION + "/.old_version_check").createNewFile();
new File(MainPanel.MEGABASTERD_HOME_DIR + "/" + MainPanel.VERSION + "/old_version_check").createNewFile();

File directory = new File(MainPanel.MEGABASTERD_HOME_DIR);

Expand All @@ -970,7 +981,7 @@ private void _check_old_version() {

String old_version = "0.0";

File old_backups_dir = new File(MainPanel.MEGABASTERD_HOME_DIR + "/.megabasterd_old_backups");
File old_backups_dir = new File(MainPanel.MEGABASTERD_HOME_DIR + "/old_backups");

if (!old_backups_dir.exists()) {
old_backups_dir.mkdir();
Expand All @@ -979,7 +990,7 @@ private void _check_old_version() {
for (File file : directory.listFiles()) {

try {
if (file.isDirectory() && file.canRead() && file.getName().startsWith(".megabasterd") && !file.getName().endsWith("backups")) {
if (file.isDirectory() && file.canRead() && !file.getName().endsWith("backups")) {

String current_dir_version = MiscTools.findFirstRegex("[0-9.]+$", file.getName(), 0);

Expand Down Expand Up @@ -1018,7 +1029,7 @@ private void _check_old_version() {
options[0]);

if (n == 1) {
Files.copy(Paths.get(MainPanel.MEGABASTERD_HOME_DIR + "/.megabasterd_old_backups/.megabasterd" + old_version + "/" + SqliteSingleton.SQLITE_FILE), Paths.get(MainPanel.MEGABASTERD_HOME_DIR + "/.megabasterd" + MainPanel.VERSION + "/" + SqliteSingleton.SQLITE_FILE), StandardCopyOption.REPLACE_EXISTING);
Files.copy(Paths.get(MainPanel.MEGABASTERD_HOME_DIR + "/old_backups/" + old_version + "/" + SqliteSingleton.SQLITE_FILE), Paths.get(MainPanel.MEGABASTERD_HOME_DIR + "/" + MainPanel.VERSION + "/" + SqliteSingleton.SQLITE_FILE), StandardCopyOption.REPLACE_EXISTING);

JOptionPane.showMessageDialog(getView(), LabelTranslatorSingleton.getInstance().translate("MegaBasterd will restart"), LabelTranslatorSingleton.getInstance().translate("Restart required"), JOptionPane.WARNING_MESSAGE);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public SettingsDialog(MainPanelView parent, boolean modal) {

String default_download_dir = DBTools.selectSettingValue("default_down_dir");

default_download_dir = Paths.get(default_download_dir == null ? MainPanel.MEGABASTERD_HOME_DIR : default_download_dir).toAbsolutePath().normalize().toString();
default_download_dir = Paths.get(default_download_dir == null ? MainPanel.MEGABASTERD_DOWNLOAD_DIR : default_download_dir).toAbsolutePath().normalize().toString();

_download_path = default_download_dir;

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/tonikelope/megabasterd/SqliteSingleton.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private SqliteSingleton() {

_connections_map = new ConcurrentHashMap();

File database_path = new File(MainPanel.MEGABASTERD_HOME_DIR + "/.megabasterd" + MainPanel.VERSION);
File database_path = new File(MainPanel.MEGABASTERD_HOME_DIR + "/" + MainPanel.VERSION);

database_path.mkdirs();
}
Expand All @@ -44,7 +44,7 @@ public Connection getConn() {

Class.forName("org.sqlite.JDBC");

conn = DriverManager.getConnection("jdbc:sqlite:" + MainPanel.MEGABASTERD_HOME_DIR + "/.megabasterd" + MainPanel.VERSION + "/" + SQLITE_FILE + "?journal_mode=WAL&synchronous=OFF&journal_size_limit=500");
conn = DriverManager.getConnection("jdbc:sqlite:" + MainPanel.MEGABASTERD_HOME_DIR + "/" + MainPanel.VERSION + "/" + SQLITE_FILE + "?journal_mode=WAL&synchronous=OFF&journal_size_limit=500");

_connections_map.put(Thread.currentThread(), conn);
}
Expand Down
0