1616import com .krazzzzymonkey .catalyst .value .types .ModeValue ;
1717import com .krazzzzymonkey .catalyst .value .types .SubMenu ;
1818import com .krazzzzymonkey .catalyst .xray .XRayData ;
19- import net .minecraft .client .Minecraft ;
2019import net .minecraft .item .Item ;
2120import org .apache .commons .io .FileUtils ;
2221
2322import javax .annotation .Nonnull ;
2423import javax .annotation .Nullable ;
2524import java .io .*;
25+ import java .nio .file .Path ;
2626import java .util .ArrayList ;
2727import java .util .List ;
2828import java .util .Map ;
2929import java .util .Objects ;
3030
3131public class FileManager {
3232
33- public static final File CATALYST_DIR = new File (String .format ("%s%s%s%s" ,
34- Wrapper .INSTANCE .mc ().gameDir ,
35- File .separator ,
36- Main .NAME ,
37- File .separator ));
38- public static final File ASSET_DIR = new File (CATALYST_DIR + "/Assets/" );
39- private static final Minecraft mc = Minecraft .getMinecraft ();
40-
41- public static final File ALT_DIR = new File (CATALYST_DIR + "/Catalyst Account Manager/" );
42- public static final File PROFILES_DIR = new File (CATALYST_DIR + "/Profiles/" );
43- private static final File HACKS = new File (PROFILES_DIR , "default.json" );
44- public static final File CLICKGUI = new File (CATALYST_DIR , "clickgui.json" );
33+ public static final Path CATALYST_DIR = Wrapper .INSTANCE .mc ().gameDir .toPath ().resolve (Main .NAME );
34+ public static final Path ASSET_DIR = CATALYST_DIR .resolve ("Assets" );
35+ public static final Path ALT_DIR = CATALYST_DIR .resolve ("Catalyst Account Manager" );
36+ public static final Path PROFILES_DIR = CATALYST_DIR .resolve ("Profiles" );
37+ private static final File HACKS = PROFILES_DIR .resolve ("default.json" ).toFile ();
38+ public static final File CLICKGUI = CATALYST_DIR .resolve ("clickgui.json" ).toFile ();
4539 private static final Gson gsonPretty = new GsonBuilder ().setPrettyPrinting ().create ();
4640 private static final JsonParser jsonParser = new JsonParser ();
47- private static final File CHATMENTION = new File ( CATALYST_DIR , "chatmention.json" );
48- private static final File AUTOGGMESSAGES = new File ( CATALYST_DIR , "ggmessages.txt" );
49- private static final File XRAYDATA = new File ( CATALYST_DIR , "xraydata.json" );
50- private static final File FRIENDS = new File ( CATALYST_DIR , "friends.json" );
51- private static final File ENEMYS = new File ( CATALYST_DIR , "enemys.json" );
52- private static final File PREFIX = new File ( CATALYST_DIR , "prefix.json" );
53- private static final File CURRENTPROFILE = new File ( CATALYST_DIR , "currentprofile.json" );
54- private static final File FONT = new File ( CATALYST_DIR , "font.json" );
55- private static final File INVENTORY_CLEANER = new File ( CATALYST_DIR , "inventorycleaner.json" );
41+ private static final File CHATMENTION = CATALYST_DIR . resolve ( "chatmention.json" ). toFile ( );
42+ private static final File AUTOGGMESSAGES = CATALYST_DIR . resolve ( "ggmessages.txt" ). toFile ( );
43+ private static final File XRAYDATA = CATALYST_DIR . resolve ( "xraydata.json" ). toFile ( );
44+ private static final File FRIENDS = CATALYST_DIR . resolve ( "friends.json" ). toFile ( );
45+ private static final File ENEMYS = CATALYST_DIR . resolve ( "enemys.json" ). toFile ( );
46+ private static final File PREFIX = CATALYST_DIR . resolve ( "prefix.json" ). toFile ( );
47+ private static final File CURRENTPROFILE = CATALYST_DIR . resolve ( "currentprofile.json" ). toFile ( );
48+ private static final File FONT = CATALYST_DIR . resolve ( "font.json" ). toFile ( );
49+ private static final File INVENTORY_CLEANER = CATALYST_DIR . resolve ( "inventorycleaner.json" ). toFile ( );
5650
5751 public static @ Nullable File getAssetFile (@ Nonnull String path ) {
52+ Main .logger .info ("Requesting asset: " + path );
5853 File file = new File (ASSET_DIR + File .separator + path );
54+ Main .logger .info ("Loading asset file: " + file .getPath ());
5955 if (file .exists ()) return file ;
6056 try {
61- Main .logger .info ("Creating asset from default resource: " + path );
57+ Main .logger .info ("Asset not found locally, creating from default resource: " + path );
6258 file .getParentFile ().mkdirs ();
6359 FileUtils .copyInputStreamToFile (resourceAsStream (path ), file );
6460 } catch (IOException | SecurityException e ) {
@@ -78,9 +74,8 @@ private static void loadInventoryCleaner() {
7874 loadJson = new BufferedReader (new FileReader (INVENTORY_CLEANER ));
7975 JsonObject jsonObject = (JsonObject ) jsonParser .parse (loadJson );
8076 loadJson .close ();
81- jsonObject .get ("items" ).getAsJsonArray ().iterator ().forEachRemaining (n -> {
82- InventoryCleaner .listItems .add (Item .getByNameOrId (n .getAsString ()));
83- });
77+ jsonObject .get ("items" ).getAsJsonArray ().iterator ().forEachRemaining (n -> InventoryCleaner .listItems .add (
78+ Item .getByNameOrId (n .getAsString ())));
8479 } catch (Exception e ) {
8580 e .printStackTrace ();
8681 }
@@ -167,7 +162,7 @@ public static void saveFont() {
167162 }
168163
169164 public static void loadPrefix () {
170- BufferedReader loadJson = null ;
165+ BufferedReader loadJson ;
171166 try {
172167 loadJson = new BufferedReader (new FileReader (PREFIX ));
173168 JsonObject moduleJason = (JsonObject ) jsonParser .parse (loadJson );
@@ -200,8 +195,8 @@ public static void loadModules(String profile) {
200195 try {
201196 BufferedReader loadJson = new BufferedReader (new FileReader (HACKS ));
202197 if (!profile .equals ("" )) {
203- if (new File ( PROFILES_DIR , profile + ".json" ).exists ()) {
204- loadJson = new BufferedReader (new FileReader (new File ( PROFILES_DIR , profile + ".json" )));
198+ if (PROFILES_DIR . resolve ( profile + ".json" ). toFile ( ).exists ()) {
199+ loadJson = new BufferedReader (new FileReader (PROFILES_DIR . resolve ( profile + ".json" ). toFile ( )));
205200 }
206201 }
207202
@@ -366,7 +361,7 @@ public static void loadModules(String profile) {
366361
367362 } catch (NullPointerException e ) {
368363 Main .logger .warn ("Unknown Config for: " + mods .getModuleName () + ". Setting Default config!" );
369- if (new File ( PROFILES_DIR , profile + ".json" ).exists ()) {
364+ if (PROFILES_DIR . resolve ( profile + ".json" ). toFile ( ).exists ()) {
370365 saveModules (profile );
371366 } else saveModules ("default" );
372367
@@ -375,7 +370,7 @@ public static void loadModules(String profile) {
375370 }
376371 mods .setKey (jsonMod .get ("bind" ).getAsJsonObject ().get ("key" ).getAsInt ());
377372 mods .setBindHold (jsonMod .get ("bind" ).getAsJsonObject ().get ("held" ).getAsBoolean ());
378- if (new File ( PROFILES_DIR , profile + ".json" ).exists ()) {
373+ if (PROFILES_DIR . resolve ( profile + ".json" ). toFile ( ).exists ()) {
379374 ProfileManager .currentProfile = profile ;
380375 } else ProfileManager .currentProfile = "default" ;
381376 }
@@ -618,7 +613,7 @@ public static void saveModules(String profile) {
618613 }
619614 json .add (module .getModuleName (), jsonHack );
620615 }
621- PrintWriter saveJson = new PrintWriter (new FileWriter (new File ( PROFILES_DIR , profile + ".json" )));
616+ PrintWriter saveJson = new PrintWriter (new FileWriter (PROFILES_DIR . resolve ( profile + ".json" ). toFile ( )));
622617
623618 saveJson .println (gsonPretty .toJson (json ));
624619 saveJson .close ();
@@ -643,13 +638,14 @@ public static void write(File outputFile, List<String> writeContent, boolean new
643638 if (writer != null ) {
644639 writer .close ();
645640 }
646- } catch (Exception ex2 ) {
641+ } catch (Exception e ) {
642+ e .printStackTrace ();
647643 }
648644 }
649645 }
650646
651647 public static List <String > read (File inputFile ) {
652- ArrayList <String > readContent = new ArrayList <String >();
648+ ArrayList <String > readContent = new ArrayList <>();
653649 BufferedReader reader = null ;
654650 try {
655651 reader = new BufferedReader (new FileReader (inputFile ));
@@ -662,7 +658,8 @@ public static List<String> read(File inputFile) {
662658 if (reader != null ) {
663659 reader .close ();
664660 }
665- } catch (Exception ex2 ) {
661+ } catch (Exception e ) {
662+ e .printStackTrace ();
666663 }
667664 }
668665 return readContent ;
@@ -673,21 +670,21 @@ public static void init() {
673670 }
674671
675672 public static void reload () {
676- if (!CATALYST_DIR .exists ()) {
677- CATALYST_DIR .mkdir ();
673+ if (!CATALYST_DIR .toFile (). exists ()) {
674+ CATALYST_DIR .toFile (). mkdir ();
678675 }
679- if (!ALT_DIR .exists ()) {
680- ALT_DIR .mkdir ();
676+ if (!ALT_DIR .toFile (). exists ()) {
677+ ALT_DIR .toFile (). mkdir ();
681678 }
682- if (!PROFILES_DIR .exists ()) {
683- PROFILES_DIR .mkdir ();
679+ if (!PROFILES_DIR .toFile (). exists ()) {
680+ PROFILES_DIR .toFile (). mkdir ();
684681 }
685682 if (!CURRENTPROFILE .exists ()) {
686683 saveCurrentProfile ();
687684 } else {
688685 loadCurrentProfile ();
689686 }
690- if (!(new File ( PROFILES_DIR , ProfileManager .currentProfile + ".json" ).exists ())) {
687+ if (!(PROFILES_DIR . resolve ( ProfileManager .currentProfile + ".json" ). toFile ( ).exists ())) {
691688 Main .logger .warn ("Profile: " + ProfileManager .currentProfile + " does not exist! Setting default Profile" );
692689 ProfileManager .currentProfile = "default" ;
693690 saveModules (ProfileManager .currentProfile );
0 commit comments