2018-01-31 15:03:53 +00:00
|
|
|
package the.bytecode.club.bytecodeviewer;
|
|
|
|
|
2021-06-29 09:41:29 +00:00
|
|
|
import com.google.gson.reflect.TypeToken;
|
2018-01-31 15:03:53 +00:00
|
|
|
import me.konloch.kontainer.io.DiskReader;
|
|
|
|
import me.konloch.kontainer.io.DiskWriter;
|
2021-06-29 09:41:29 +00:00
|
|
|
import the.bytecode.club.bytecodeviewer.util.MiscUtils;
|
2018-01-31 15:03:53 +00:00
|
|
|
|
2021-06-29 09:41:29 +00:00
|
|
|
import javax.swing.*;
|
|
|
|
import java.io.File;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2021-06-21 09:45:31 +00:00
|
|
|
|
2021-06-29 09:41:29 +00:00
|
|
|
import static the.bytecode.club.bytecodeviewer.BytecodeViewer.gson;
|
2021-07-10 16:05:08 +00:00
|
|
|
import static the.bytecode.club.bytecodeviewer.Configuration.maxRecentFiles;
|
2021-06-29 09:41:29 +00:00
|
|
|
import static the.bytecode.club.bytecodeviewer.Constants.*;
|
2018-01-31 15:03:53 +00:00
|
|
|
|
2021-07-24 02:25:51 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite *
|
|
|
|
* Copyright (C) 2014 Kalen 'Konloch' Kinloch - http://bytecodeviewer.com *
|
|
|
|
* *
|
|
|
|
* This program is free software: you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
|
|
|
***************************************************************************/
|
|
|
|
|
2018-01-31 15:03:53 +00:00
|
|
|
/**
|
2018-01-31 15:41:24 +00:00
|
|
|
* @author Konloch
|
2021-06-29 09:41:29 +00:00
|
|
|
* @since 6/29/2021
|
2018-01-31 15:03:53 +00:00
|
|
|
*/
|
2021-06-29 09:41:29 +00:00
|
|
|
public class Settings
|
|
|
|
{
|
|
|
|
public static boolean firstBoot = true; //stays true after settings load on first boot
|
|
|
|
public static boolean hasSetLanguageAsSystemLanguage = false;
|
|
|
|
private static List<String> recentPlugins;
|
|
|
|
private static List<String> recentFiles;
|
|
|
|
|
|
|
|
static
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if (new File(filesName).exists())
|
|
|
|
recentFiles = gson.fromJson(DiskReader.loadAsString(filesName), new TypeToken<ArrayList<String>>() {}.getType());
|
|
|
|
else
|
|
|
|
recentFiles = DiskReader.loadArrayList(getBCVDirectory() + fs + "recentfiles.bcv", false);
|
|
|
|
|
|
|
|
if (new File(pluginsName).exists())
|
|
|
|
recentPlugins = gson.fromJson(DiskReader.loadAsString(pluginsName), new TypeToken<ArrayList<String>>() {}.getType());
|
|
|
|
else
|
|
|
|
recentPlugins = DiskReader.loadArrayList(getBCVDirectory() + fs + "recentplugins.bcv", false);
|
|
|
|
|
2021-07-10 16:05:08 +00:00
|
|
|
MiscUtils.deduplicateAndTrim(recentFiles, maxRecentFiles);
|
|
|
|
MiscUtils.deduplicateAndTrim(recentPlugins, maxRecentFiles);
|
2021-06-29 09:41:29 +00:00
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add the recent file
|
|
|
|
*
|
|
|
|
* @param f the recent file
|
|
|
|
*/
|
2021-07-05 04:24:19 +00:00
|
|
|
public static synchronized void addRecentFile(File f)
|
2021-06-29 09:41:29 +00:00
|
|
|
{
|
|
|
|
recentFiles.remove(f.getAbsolutePath()); // already added on the list
|
|
|
|
recentFiles.add(0, f.getAbsolutePath());
|
2021-07-10 16:05:08 +00:00
|
|
|
MiscUtils.deduplicateAndTrim(recentFiles, maxRecentFiles);
|
2021-06-29 09:41:29 +00:00
|
|
|
DiskWriter.replaceFile(filesName, MiscUtils.listToString(recentFiles), false);
|
|
|
|
resetRecentFilesMenu();
|
|
|
|
}
|
|
|
|
|
2021-07-05 04:24:19 +00:00
|
|
|
public static synchronized void removeRecentFile(File f)
|
|
|
|
{
|
|
|
|
if(recentFiles.remove(f.getAbsolutePath()))
|
|
|
|
{
|
|
|
|
DiskWriter.replaceFile(filesName, MiscUtils.listToString(recentFiles), false);
|
|
|
|
resetRecentFilesMenu();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-07 05:38:47 +00:00
|
|
|
public static String getRecentFile()
|
|
|
|
{
|
|
|
|
if(recentFiles.isEmpty())
|
|
|
|
return null;
|
|
|
|
|
|
|
|
return recentFiles.get(0);
|
|
|
|
}
|
|
|
|
|
2021-06-29 09:41:29 +00:00
|
|
|
/**
|
|
|
|
* Add to the recent plugin list
|
|
|
|
*
|
|
|
|
* @param f the plugin file
|
|
|
|
*/
|
2021-07-05 04:24:19 +00:00
|
|
|
public static synchronized void addRecentPlugin(File f)
|
2021-06-29 09:41:29 +00:00
|
|
|
{
|
|
|
|
recentPlugins.remove(f.getAbsolutePath()); // already added on the list
|
|
|
|
recentPlugins.add(0, f.getAbsolutePath());
|
2021-07-10 16:05:08 +00:00
|
|
|
MiscUtils.deduplicateAndTrim(recentPlugins, maxRecentFiles);
|
2021-06-29 09:41:29 +00:00
|
|
|
DiskWriter.replaceFile(pluginsName, MiscUtils.listToString(recentPlugins), false);
|
|
|
|
resetRecentFilesMenu();
|
|
|
|
}
|
|
|
|
|
2021-07-05 04:24:19 +00:00
|
|
|
public static synchronized void removeRecentPlugin(File f)
|
|
|
|
{
|
|
|
|
if(recentPlugins.remove(f.getAbsolutePath()))
|
|
|
|
{
|
|
|
|
DiskWriter.replaceFile(pluginsName, MiscUtils.listToString(recentPlugins), false);
|
|
|
|
resetRecentFilesMenu();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-29 09:41:29 +00:00
|
|
|
/**
|
|
|
|
* resets the recent files menu
|
|
|
|
*/
|
|
|
|
protected static void resetRecentFilesMenu()
|
|
|
|
{
|
|
|
|
//build recent files
|
|
|
|
BytecodeViewer.viewer.recentFilesSecondaryMenu.removeAll();
|
|
|
|
for (String s : recentFiles)
|
|
|
|
{
|
|
|
|
if (!s.isEmpty())
|
|
|
|
{
|
|
|
|
JMenuItem m = new JMenuItem(s);
|
|
|
|
m.addActionListener(e ->
|
|
|
|
{
|
|
|
|
JMenuItem m12 = (JMenuItem) e.getSource();
|
|
|
|
BytecodeViewer.openFiles(new File[]{new File(m12.getText())}, true);
|
|
|
|
});
|
|
|
|
BytecodeViewer.viewer.recentFilesSecondaryMenu.add(m);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//build recent plugins
|
|
|
|
BytecodeViewer.viewer.recentPluginsSecondaryMenu.removeAll();
|
|
|
|
for (String s : recentPlugins)
|
|
|
|
{
|
|
|
|
if (!s.isEmpty())
|
|
|
|
{
|
|
|
|
JMenuItem m = new JMenuItem(s);
|
|
|
|
m.addActionListener(e ->
|
|
|
|
{
|
|
|
|
JMenuItem m1 = (JMenuItem) e.getSource();
|
|
|
|
BytecodeViewer.startPlugin(new File(m1.getText()));
|
|
|
|
});
|
|
|
|
BytecodeViewer.viewer.recentPluginsSecondaryMenu.add(m);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|