Skip to content
This repository has been archived by the owner on Feb 26, 2023. It is now read-only.

Commit

Permalink
asset path fixes
Browse files Browse the repository at this point in the history
and some other minor crap
  • Loading branch information
hub committed Oct 1, 2022
1 parent 75e81ec commit c421e4a
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 115 deletions.
21 changes: 0 additions & 21 deletions .github/workflows/workflow.yaml

This file was deleted.

12 changes: 2 additions & 10 deletions src/main/java/com/krazzzzymonkey/catalyst/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,8 @@
import org.lwjgl.opengl.Display;

import java.awt.*;
import java.io.File;
import java.io.IOException;

import static com.krazzzzymonkey.catalyst.managers.FileManager.CATALYST_DIR;


@Mod(modid = Main.MODID, name = Main.NAME, version = Main.VERSION, clientSideOnly = true, guiFactory = "com.krazzzzymonkey.catalyst.managers.accountManager.config.GuiFactory", acceptableRemoteVersions = "*")
public class Main {
Expand All @@ -50,7 +47,6 @@ public static void syncConfig() {
public static final String VERSION = "@version@";
public static int initCount = 0;
public static ModuleManager moduleManager;
public static FontManager fontManager;

public static CFontRenderer fontRenderer;
public static CFontRenderer smallFontRenderer;
Expand All @@ -66,11 +62,8 @@ public static void syncConfig() {
private ConfigurationLoader configLoader;
public static Config config;


public File configFolder;

@EventHandler
public void preInit(FMLPreInitializationEvent E) throws IOException {
public void preInit(FMLPreInitializationEvent E) {


logger.info(" ____ _ _ _ ____ _ _ _ ");
Expand All @@ -80,7 +73,6 @@ public void preInit(FMLPreInitializationEvent E) throws IOException {
logger.info(" \\____\\__,_|\\__\\__,_|_|\\__, |___/\\__| \\____|_|_|\\___|_| |_|\\__|");
logger.info(" |___/ ");
Display.setTitle("Initializing " + NAME + " " + VERSION);
configFolder = CATALYST_DIR;
config = new Config();
// Load Transparent

Expand Down Expand Up @@ -135,7 +127,7 @@ public void init(FMLInitializationEvent E) throws IOException {

@EventHandler
public void postInit(FMLPostInitializationEvent E){
File file = FileManager.getAssetFile("gui" + File.separator + "watermark.png");
// File file = FileManager.getAssetFile("gui" + File.separator + "watermark.png");

Display.setTitle(NAME + " " + VERSION);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void runCommand(String s, String[] args) {
paste.addContent("options.txt", "options.txt not a file or not readable");
}

File hacksConfig = new File(FileManager.CATALYST_DIR, "hacks.json");
File hacksConfig = FileManager.CATALYST_DIR.resolve("hacks.json").toFile();
if (hacksConfig.isFile() && hacksConfig.canRead()) {
try {
paste.addContent("hacks.json", Files
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.krazzzzymonkey.catalyst.utils.ChatColor;
import com.krazzzzymonkey.catalyst.utils.visual.ChatUtils;

import java.io.File;
import java.util.Objects;

public class Profile extends Command {
Expand Down Expand Up @@ -37,9 +38,11 @@ public void runCommand(String s, String[] args) {
}
} else if (args[0].equalsIgnoreCase("list")) {
ChatUtils.normalMessage("Profile List:");
for (int i = 0; i < Objects.requireNonNull(FileManager.PROFILES_DIR.listFiles()).length; i++) {
if (Objects.requireNonNull(FileManager.PROFILES_DIR.listFiles())[i].isFile()) {
ChatUtils.normalMessage(Objects.requireNonNull(FileManager.PROFILES_DIR.listFiles())[i].getName().replace(".json", ""));
File[] files = FileManager.PROFILES_DIR.toFile().listFiles();
Objects.requireNonNull(files);
for (File file : files) {
if (file.isFile()) {
ChatUtils.normalMessage(file.getName().replace(".json", ""));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package com.krazzzzymonkey.catalyst.configuration;

import com.google.common.io.ByteStreams;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.stream.JsonReader;
import com.krazzzzymonkey.catalyst.gui.GuiCustom;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;

import java.io.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

import static com.krazzzzymonkey.catalyst.managers.FileManager.CATALYST_DIR;
import static com.krazzzzymonkey.catalyst.managers.FileManager.getAssetFile;
Expand All @@ -24,7 +25,7 @@ public ConfigurationLoader(Config config) {
public void load() throws Exception {
JsonParser jsonParser = new JsonParser();

File configFolder = new File(CATALYST_DIR, "CatalystMainMenu");
File configFolder = CATALYST_DIR.resolve("CatalystMainMenu").toFile();
if (!configFolder.exists()) {
configFolder.mkdir();
}
Expand Down
81 changes: 39 additions & 42 deletions src/main/java/com/krazzzzymonkey/catalyst/managers/FileManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,49 +16,45 @@
import com.krazzzzymonkey.catalyst.value.types.ModeValue;
import com.krazzzzymonkey.catalyst.value.types.SubMenu;
import com.krazzzzymonkey.catalyst.xray.XRayData;
import net.minecraft.client.Minecraft;
import net.minecraft.item.Item;
import org.apache.commons.io.FileUtils;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.*;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;

public class FileManager {

public static final File CATALYST_DIR = new File(String.format("%s%s%s%s",
Wrapper.INSTANCE.mc().gameDir,
File.separator,
Main.NAME,
File.separator));
public static final File ASSET_DIR = new File(CATALYST_DIR + "/Assets/");
private static final Minecraft mc = Minecraft.getMinecraft();

public static final File ALT_DIR = new File(CATALYST_DIR + "/Catalyst Account Manager/");
public static final File PROFILES_DIR = new File(CATALYST_DIR + "/Profiles/");
private static final File HACKS = new File(PROFILES_DIR, "default.json");
public static final File CLICKGUI = new File(CATALYST_DIR, "clickgui.json");
public static final Path CATALYST_DIR = Wrapper.INSTANCE.mc().gameDir.toPath().resolve(Main.NAME);
public static final Path ASSET_DIR = CATALYST_DIR.resolve("Assets");
public static final Path ALT_DIR = CATALYST_DIR.resolve("Catalyst Account Manager");
public static final Path PROFILES_DIR = CATALYST_DIR.resolve("Profiles");
private static final File HACKS = PROFILES_DIR.resolve("default.json").toFile();
public static final File CLICKGUI = CATALYST_DIR.resolve("clickgui.json").toFile();
private static final Gson gsonPretty = new GsonBuilder().setPrettyPrinting().create();
private static final JsonParser jsonParser = new JsonParser();
private static final File CHATMENTION = new File(CATALYST_DIR, "chatmention.json");
private static final File AUTOGGMESSAGES = new File(CATALYST_DIR, "ggmessages.txt");
private static final File XRAYDATA = new File(CATALYST_DIR, "xraydata.json");
private static final File FRIENDS = new File(CATALYST_DIR, "friends.json");
private static final File ENEMYS = new File(CATALYST_DIR, "enemys.json");
private static final File PREFIX = new File(CATALYST_DIR, "prefix.json");
private static final File CURRENTPROFILE = new File(CATALYST_DIR, "currentprofile.json");
private static final File FONT = new File(CATALYST_DIR, "font.json");
private static final File INVENTORY_CLEANER = new File(CATALYST_DIR, "inventorycleaner.json");
private static final File CHATMENTION = CATALYST_DIR.resolve("chatmention.json").toFile();
private static final File AUTOGGMESSAGES = CATALYST_DIR.resolve("ggmessages.txt").toFile();
private static final File XRAYDATA = CATALYST_DIR.resolve("xraydata.json").toFile();
private static final File FRIENDS = CATALYST_DIR.resolve("friends.json").toFile();
private static final File ENEMYS = CATALYST_DIR.resolve("enemys.json").toFile();
private static final File PREFIX = CATALYST_DIR.resolve("prefix.json").toFile();
private static final File CURRENTPROFILE = CATALYST_DIR.resolve("currentprofile.json").toFile();
private static final File FONT = CATALYST_DIR.resolve("font.json").toFile();
private static final File INVENTORY_CLEANER = CATALYST_DIR.resolve("inventorycleaner.json").toFile();

public static @Nullable File getAssetFile(@Nonnull String path) {
Main.logger.info("Requesting asset: " + path);
File file = new File(ASSET_DIR + File.separator + path);
Main.logger.info("Loading asset file: " + file.getPath());
if (file.exists()) return file;
try {
Main.logger.info("Creating asset from default resource: " + path);
Main.logger.info("Asset not found locally, creating from default resource: " + path);
file.getParentFile().mkdirs();
FileUtils.copyInputStreamToFile(resourceAsStream(path), file);
} catch (IOException | SecurityException e) {
Expand All @@ -78,9 +74,8 @@ private static void loadInventoryCleaner() {
loadJson = new BufferedReader(new FileReader(INVENTORY_CLEANER));
JsonObject jsonObject = (JsonObject) jsonParser.parse(loadJson);
loadJson.close();
jsonObject.get("items").getAsJsonArray().iterator().forEachRemaining(n -> {
InventoryCleaner.listItems.add(Item.getByNameOrId(n.getAsString()));
});
jsonObject.get("items").getAsJsonArray().iterator().forEachRemaining(n -> InventoryCleaner.listItems.add(
Item.getByNameOrId(n.getAsString())));
} catch (Exception e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -167,7 +162,7 @@ public static void saveFont() {
}

public static void loadPrefix() {
BufferedReader loadJson = null;
BufferedReader loadJson;
try {
loadJson = new BufferedReader(new FileReader(PREFIX));
JsonObject moduleJason = (JsonObject) jsonParser.parse(loadJson);
Expand Down Expand Up @@ -200,8 +195,8 @@ public static void loadModules(String profile) {
try {
BufferedReader loadJson = new BufferedReader(new FileReader(HACKS));
if (!profile.equals("")) {
if (new File(PROFILES_DIR, profile + ".json").exists()) {
loadJson = new BufferedReader(new FileReader(new File(PROFILES_DIR, profile + ".json")));
if (PROFILES_DIR.resolve(profile + ".json").toFile().exists()) {
loadJson = new BufferedReader(new FileReader(PROFILES_DIR.resolve(profile + ".json").toFile()));
}
}

Expand Down Expand Up @@ -366,7 +361,7 @@ public static void loadModules(String profile) {

} catch (NullPointerException e) {
Main.logger.warn("Unknown Config for: " + mods.getModuleName() + ". Setting Default config!");
if (new File(PROFILES_DIR, profile + ".json").exists()) {
if (PROFILES_DIR.resolve(profile + ".json").toFile().exists()) {
saveModules(profile);
} else saveModules("default");

Expand All @@ -375,7 +370,7 @@ public static void loadModules(String profile) {
}
mods.setKey(jsonMod.get("bind").getAsJsonObject().get("key").getAsInt());
mods.setBindHold(jsonMod.get("bind").getAsJsonObject().get("held").getAsBoolean());
if (new File(PROFILES_DIR, profile + ".json").exists()) {
if (PROFILES_DIR.resolve(profile + ".json").toFile().exists()) {
ProfileManager.currentProfile = profile;
} else ProfileManager.currentProfile = "default";
}
Expand Down Expand Up @@ -618,7 +613,7 @@ public static void saveModules(String profile) {
}
json.add(module.getModuleName(), jsonHack);
}
PrintWriter saveJson = new PrintWriter(new FileWriter(new File(PROFILES_DIR, profile + ".json")));
PrintWriter saveJson = new PrintWriter(new FileWriter(PROFILES_DIR.resolve(profile + ".json").toFile()));

saveJson.println(gsonPretty.toJson(json));
saveJson.close();
Expand All @@ -643,13 +638,14 @@ public static void write(File outputFile, List<String> writeContent, boolean new
if (writer != null) {
writer.close();
}
} catch (Exception ex2) {
} catch (Exception e) {
e.printStackTrace();
}
}
}

public static List<String> read(File inputFile) {
ArrayList<String> readContent = new ArrayList<String>();
ArrayList<String> readContent = new ArrayList<>();
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(inputFile));
Expand All @@ -662,7 +658,8 @@ public static List<String> read(File inputFile) {
if (reader != null) {
reader.close();
}
} catch (Exception ex2) {
} catch (Exception e) {
e.printStackTrace();
}
}
return readContent;
Expand All @@ -673,21 +670,21 @@ public static void init() {
}

public static void reload() {
if (!CATALYST_DIR.exists()) {
CATALYST_DIR.mkdir();
if (!CATALYST_DIR.toFile().exists()) {
CATALYST_DIR.toFile().mkdir();
}
if (!ALT_DIR.exists()) {
ALT_DIR.mkdir();
if (!ALT_DIR.toFile().exists()) {
ALT_DIR.toFile().mkdir();
}
if (!PROFILES_DIR.exists()) {
PROFILES_DIR.mkdir();
if (!PROFILES_DIR.toFile().exists()) {
PROFILES_DIR.toFile().mkdir();
}
if (!CURRENTPROFILE.exists()) {
saveCurrentProfile();
} else {
loadCurrentProfile();
}
if (!(new File(PROFILES_DIR, ProfileManager.currentProfile + ".json").exists())) {
if (!(PROFILES_DIR.resolve(ProfileManager.currentProfile + ".json").toFile().exists())) {
Main.logger.warn("Profile: " + ProfileManager.currentProfile + " does not exist! Setting default Profile");
ProfileManager.currentProfile = "default";
saveModules(ProfileManager.currentProfile);
Expand Down
Loading

0 comments on commit c421e4a

Please sign in to comment.