22
33import org .apache .commons .io .FileUtils ;
44import org .objectweb .asm .tree .ClassNode ;
5- import the .bytecode .club .jda .api .ClassNodeLoader ;
65import the .bytecode .club .jda .api .ExceptionUI ;
76import the .bytecode .club .jda .gui .FileNavigationPane ;
87import the .bytecode .club .jda .gui .MainViewerGUI ;
1413import java .io .File ;
1514import java .io .FileInputStream ;
1615import java .io .IOException ;
16+ import java .net .MalformedURLException ;
17+ import java .net .URL ;
18+ import java .net .URLClassLoader ;
1719import java .nio .file .Files ;
1820import java .nio .file .Paths ;
1921import java .util .ArrayList ;
@@ -29,21 +31,17 @@ public class JDA {
2931 public static final String fs = System .getProperty ("file.separator" );
3032 public static final String nl = System .getProperty ("line.separator" );
3133 public static final File dataDir = new File (System .getProperty ("user.home" ) + fs + ".jda" );
32- public static final File filesFile = new File (dataDir , "recentfiles.jda" );
34+ public static final File pluginsDir = new File (dataDir , "plugins" );
35+ public static final File recentsFile = new File (dataDir , "recentfiles.jda" );
3336 public static final File settingsFile = new File (dataDir , "settings.jda" );
34- @ Deprecated
35- public static final File tempDir = new File (dataDir , "jda_temp" );
3637 private static final long start = System .currentTimeMillis ();
3738 /*the rest*/
3839 public static MainViewerGUI viewer = null ;
39- public static ClassNodeLoader loader = new ClassNodeLoader (); // TODO MAKE SECURE BECAUSE THIS IS INSECURE
40- public static SecurityMan sm = new SecurityMan (); // TODO MAKE SECURE BECAUSE THIS IS INSECURE
4140 public static ArrayList <FileContainer > files = new ArrayList <>(); //all of BCV's loaded files/classes/etc
4241 private static int maxRecentFiles = 25 ;
4342 private static List <String > recentFiles = new ArrayList <>();
4443 public static String lastDirectory = "" ;
4544 public static ArrayList <Process > createdProcesses = new ArrayList <>();
46- public static boolean deleteForiegnLibraries = true ;
4745
4846 /**
4947 * Main startup
@@ -57,17 +55,19 @@ public static void main(String[] args) {
5755 new ExceptionUI (e );
5856 }
5957 try {
60- System .setSecurityManager (sm );
6158 System .out .println ("JDA (BCV Fork) v" + version );
6259 if (previewCopy )
6360 showMessage ("WARNING: This is a preview/dev copy, you WON'T be alerted when " + version + " is actually out if you use this." + nl +
6461 "Make sure to watch the repo: https://github.com/ecx86/jda for " + version + "'s release" );
6562 getJDADirectory ();
66- if (!filesFile .exists () && !filesFile .createNewFile ()) {
67- throw new RuntimeException ("Could not create recent files file" );
68- }
69- recentFiles .addAll (FileUtils .readLines (filesFile , "UTF-8" ));
63+
64+ loadPlugins ();
65+
7066 Settings .loadGUI ();
67+ if (!recentsFile .exists () && !recentsFile .createNewFile ())
68+ throw new RuntimeException ("Could not create recent files file" );
69+ recentFiles .addAll (FileUtils .readLines (recentsFile , "UTF-8" ));
70+
7171 viewer = new MainViewerGUI ();
7272 Boot .boot ();
7373 JDA .boot (args );
@@ -76,6 +76,29 @@ public static void main(String[] args) {
7676 }
7777 }
7878
79+ private static void loadPlugins () throws MalformedURLException {
80+ if (!pluginsDir .exists ())
81+ if (!pluginsDir .mkdirs ())
82+ throw new RuntimeException ("Couldn't create plugins directory" );
83+ else if (!pluginsDir .isDirectory ())
84+ throw new RuntimeException ("Plugins location is not a directory" );
85+
86+ for (File pluginFile : pluginsDir .listFiles ()) {
87+ if (!pluginFile .getName ().endsWith (".jar" )) {
88+ System .out .println ("Skipping non-jar " + pluginFile .getName ());
89+ continue ;
90+ }
91+
92+ try {
93+ ClassLoader loader = URLClassLoader .newInstance (new URL [] {pluginFile .toURL ()}, JDA .class .getClassLoader ());
94+ Class .forName ("Plugin" , true , loader ).getConstructor ().newInstance ();
95+ } catch (ReflectiveOperationException e ) {
96+ System .err .println ("Failed to load plugin " + pluginFile .getName ());
97+ e .printStackTrace ();
98+ }
99+ }
100+ }
101+
79102 /**
80103 * The version checker thread
81104 */
@@ -90,21 +113,19 @@ public void run() {
90113 * Boot after all of the libraries have been loaded
91114 */
92115 public static void boot (String [] args ) {
93- cleanup ();
94116 Runtime .getRuntime ().addShutdownHook (new Thread () {
95117 @ Override
96118 public void run () {
97119 for (Process proc : createdProcesses )
98120 proc .destroy ();
99121 try {
100- FileUtils .writeLines (filesFile , recentFiles );
122+ FileUtils .writeLines (recentsFile , recentFiles );
101123 } catch (IOException e ) {
102124 new ExceptionUI (e );
103125 }
104126 if (!viewer .isMaximized )
105127 viewer .unmaximizedPos = viewer .getLocation ();
106128 Settings .saveGUI ();
107- cleanup ();
108129 }
109130 });
110131
@@ -440,16 +461,6 @@ public static void resetRecentFilesMenu() {
440461 }
441462 }
442463
443- /**
444- * Clears the temp directory
445- */
446- public static void cleanup () {
447- try {
448- FileUtils .cleanDirectory (tempDir );
449- } catch (Exception e ) {
450- }
451- }
452-
453464 public static ArrayList <String > createdRandomizedNames = new ArrayList <>();
454465
455466 /**
@@ -501,14 +512,12 @@ private static boolean isWindows() {
501512 * @param f file you want hidden
502513 */
503514 private static void hideFile (File f ) {
504- sm .stopBlocking ();
505515 try {
506516 // Hide file by running attrib system command (on Windows)
507517 Runtime .getRuntime ().exec ("attrib +H " + f .getAbsolutePath ());
508518 } catch (Exception e ) {
509519 new ExceptionUI (e );
510520 }
511- sm .setBlocking ();
512521 }
513522
514523 private static boolean isCtrlDown (KeyEvent e ) {
0 commit comments