16
16
import com .krazzzzymonkey .catalyst .value .types .ModeValue ;
17
17
import com .krazzzzymonkey .catalyst .value .types .SubMenu ;
18
18
import com .krazzzzymonkey .catalyst .xray .XRayData ;
19
- import net .minecraft .client .Minecraft ;
20
19
import net .minecraft .item .Item ;
21
20
import org .apache .commons .io .FileUtils ;
22
21
23
22
import javax .annotation .Nonnull ;
24
23
import javax .annotation .Nullable ;
25
24
import java .io .*;
25
+ import java .nio .file .Path ;
26
26
import java .util .ArrayList ;
27
27
import java .util .List ;
28
28
import java .util .Map ;
29
29
import java .util .Objects ;
30
30
31
31
public class FileManager {
32
32
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 ();
45
39
private static final Gson gsonPretty = new GsonBuilder ().setPrettyPrinting ().create ();
46
40
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 ( );
56
50
57
51
public static @ Nullable File getAssetFile (@ Nonnull String path ) {
52
+ Main .logger .info ("Requesting asset: " + path );
58
53
File file = new File (ASSET_DIR + File .separator + path );
54
+ Main .logger .info ("Loading asset file: " + file .getPath ());
59
55
if (file .exists ()) return file ;
60
56
try {
61
- Main .logger .info ("Creating asset from default resource: " + path );
57
+ Main .logger .info ("Asset not found locally, creating from default resource: " + path );
62
58
file .getParentFile ().mkdirs ();
63
59
FileUtils .copyInputStreamToFile (resourceAsStream (path ), file );
64
60
} catch (IOException | SecurityException e ) {
@@ -78,9 +74,8 @@ private static void loadInventoryCleaner() {
78
74
loadJson = new BufferedReader (new FileReader (INVENTORY_CLEANER ));
79
75
JsonObject jsonObject = (JsonObject ) jsonParser .parse (loadJson );
80
76
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 ())));
84
79
} catch (Exception e ) {
85
80
e .printStackTrace ();
86
81
}
@@ -167,7 +162,7 @@ public static void saveFont() {
167
162
}
168
163
169
164
public static void loadPrefix () {
170
- BufferedReader loadJson = null ;
165
+ BufferedReader loadJson ;
171
166
try {
172
167
loadJson = new BufferedReader (new FileReader (PREFIX ));
173
168
JsonObject moduleJason = (JsonObject ) jsonParser .parse (loadJson );
@@ -200,8 +195,8 @@ public static void loadModules(String profile) {
200
195
try {
201
196
BufferedReader loadJson = new BufferedReader (new FileReader (HACKS ));
202
197
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 ( )));
205
200
}
206
201
}
207
202
@@ -366,7 +361,7 @@ public static void loadModules(String profile) {
366
361
367
362
} catch (NullPointerException e ) {
368
363
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 ()) {
370
365
saveModules (profile );
371
366
} else saveModules ("default" );
372
367
@@ -375,7 +370,7 @@ public static void loadModules(String profile) {
375
370
}
376
371
mods .setKey (jsonMod .get ("bind" ).getAsJsonObject ().get ("key" ).getAsInt ());
377
372
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 ()) {
379
374
ProfileManager .currentProfile = profile ;
380
375
} else ProfileManager .currentProfile = "default" ;
381
376
}
@@ -618,7 +613,7 @@ public static void saveModules(String profile) {
618
613
}
619
614
json .add (module .getModuleName (), jsonHack );
620
615
}
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 ( )));
622
617
623
618
saveJson .println (gsonPretty .toJson (json ));
624
619
saveJson .close ();
@@ -643,13 +638,14 @@ public static void write(File outputFile, List<String> writeContent, boolean new
643
638
if (writer != null ) {
644
639
writer .close ();
645
640
}
646
- } catch (Exception ex2 ) {
641
+ } catch (Exception e ) {
642
+ e .printStackTrace ();
647
643
}
648
644
}
649
645
}
650
646
651
647
public static List <String > read (File inputFile ) {
652
- ArrayList <String > readContent = new ArrayList <String >();
648
+ ArrayList <String > readContent = new ArrayList <>();
653
649
BufferedReader reader = null ;
654
650
try {
655
651
reader = new BufferedReader (new FileReader (inputFile ));
@@ -662,7 +658,8 @@ public static List<String> read(File inputFile) {
662
658
if (reader != null ) {
663
659
reader .close ();
664
660
}
665
- } catch (Exception ex2 ) {
661
+ } catch (Exception e ) {
662
+ e .printStackTrace ();
666
663
}
667
664
}
668
665
return readContent ;
@@ -673,21 +670,21 @@ public static void init() {
673
670
}
674
671
675
672
public static void reload () {
676
- if (!CATALYST_DIR .exists ()) {
677
- CATALYST_DIR .mkdir ();
673
+ if (!CATALYST_DIR .toFile (). exists ()) {
674
+ CATALYST_DIR .toFile (). mkdir ();
678
675
}
679
- if (!ALT_DIR .exists ()) {
680
- ALT_DIR .mkdir ();
676
+ if (!ALT_DIR .toFile (). exists ()) {
677
+ ALT_DIR .toFile (). mkdir ();
681
678
}
682
- if (!PROFILES_DIR .exists ()) {
683
- PROFILES_DIR .mkdir ();
679
+ if (!PROFILES_DIR .toFile (). exists ()) {
680
+ PROFILES_DIR .toFile (). mkdir ();
684
681
}
685
682
if (!CURRENTPROFILE .exists ()) {
686
683
saveCurrentProfile ();
687
684
} else {
688
685
loadCurrentProfile ();
689
686
}
690
- if (!(new File ( PROFILES_DIR , ProfileManager .currentProfile + ".json" ).exists ())) {
687
+ if (!(PROFILES_DIR . resolve ( ProfileManager .currentProfile + ".json" ). toFile ( ).exists ())) {
691
688
Main .logger .warn ("Profile: " + ProfileManager .currentProfile + " does not exist! Setting default Profile" );
692
689
ProfileManager .currentProfile = "default" ;
693
690
saveModules (ProfileManager .currentProfile );
0 commit comments