From cc1dd4f76634eef6cf0cceab203d072f977be2a5 Mon Sep 17 00:00:00 2001 From: trafficlunar Date: Thu, 31 Jul 2025 19:59:15 +0100 Subject: [PATCH] fix: temporarily remove checking if profile is loaded returns incorrect results. --- .../optionsprofiles/profiles/Profiles.java | 100 +++++++++--------- 1 file changed, 51 insertions(+), 49 deletions(-) diff --git a/common/src/main/java/net/trafficlunar/optionsprofiles/profiles/Profiles.java b/common/src/main/java/net/trafficlunar/optionsprofiles/profiles/Profiles.java index 4cd9864..dac09d6 100644 --- a/common/src/main/java/net/trafficlunar/optionsprofiles/profiles/Profiles.java +++ b/common/src/main/java/net/trafficlunar/optionsprofiles/profiles/Profiles.java @@ -146,57 +146,59 @@ public class Profiles { } public static boolean isProfileLoaded(String profileName) { - Path profile = PROFILES_DIRECTORY.resolve(profileName); - ProfileConfiguration profileConfiguration = ProfileConfiguration.get(profileName); + // TODO: rewrite/fix; returns incorrect results - List optionFiles = new ArrayList<>(); - optionFiles.add(OPTIONS_FILE); +// Path profile = PROFILES_DIRECTORY.resolve(profileName); +// ProfileConfiguration profileConfiguration = ProfileConfiguration.get(profileName); +// +// List optionFiles = new ArrayList<>(); +// optionFiles.add(OPTIONS_FILE); +// +// // The next few lines check if the specified file exists. If so, it adds it to the optionFiles ArrayList. +// Optional.of(OPTIFINE_OPTIONS_FILE).filter(Files::exists).ifPresent(optionFiles::add); +// Optional.of(SODIUM_OPTIONS_FILE).filter(file -> Platform.isModLoaded("sodium")).ifPresent(optionFiles::add); +// Optional.of(SODIUM_EXTRA_OPTIONS_FILE).filter(file -> Platform.isModLoaded("sodium-extra")).ifPresent(optionFiles::add); +// Optional.of(IRIS_OPTIONS_FILE).filter(file -> Platform.isModLoaded("iris")).ifPresent(optionFiles::add); +// Optional.of(DISTANT_HORIZONS_OPTIONS_FILE).filter(file -> Platform.isModLoaded("distanthorizons")).ifPresent(optionFiles::add); +// +// // Check if the original option file and the profile option file have the same content +// try { +// for (Path optionFile : optionFiles) { +// Path profileOptions = profile.resolve(optionFile.getFileName()); +// +// if (optionFile.getFileName().equals(OPTIONS_FILE)) { +// try (Stream lines = Files.lines(optionFile)) { +// List optionsToLoad = profileConfiguration.getOptionsToLoad(); +// AtomicBoolean loaded = new AtomicBoolean(false); +// +// lines.forEach((line) -> { +// String[] option = line.split(":"); +// +// if (optionsToLoad.contains(option[0])) { +// try (Stream profileLines = Files.lines(profileOptions)) { +// loaded.set(profileLines.anyMatch(profileLine -> profileLine.equals(line))); +// } catch (IOException e) { +// OptionsProfilesMod.LOGGER.error("[Profile '{}']: An error occurred when checking each line in options.txt if the profiles is loaded", profileName, e); +// } +// } +// }); +// +// return loaded.get(); +// } catch (IOException e) { +// OptionsProfilesMod.LOGGER.error("[Profile '{}']: An error occurred when opening options.txt to check if the profile is loaded", profileName, e); +// } +// } else { +// if (!FileUtils.contentEquals(optionFile.toFile(), profileOptions.toFile())) { +// return false; +// } +// } +// } +// } catch (IOException e) { +// OptionsProfilesMod.LOGGER.error("[Profile '{}']: An error occurred when checking if the profile is loaded", profileName, e); +// return false; +// } - // The next few lines check if the specified file exists. If so, it adds it to the optionFiles ArrayList. - Optional.of(OPTIFINE_OPTIONS_FILE).filter(Files::exists).ifPresent(optionFiles::add); - Optional.of(SODIUM_OPTIONS_FILE).filter(file -> Platform.isModLoaded("sodium")).ifPresent(optionFiles::add); - Optional.of(SODIUM_EXTRA_OPTIONS_FILE).filter(file -> Platform.isModLoaded("sodium-extra")).ifPresent(optionFiles::add); - Optional.of(IRIS_OPTIONS_FILE).filter(file -> Platform.isModLoaded("iris")).ifPresent(optionFiles::add); - Optional.of(DISTANT_HORIZONS_OPTIONS_FILE).filter(file -> Platform.isModLoaded("distanthorizons")).ifPresent(optionFiles::add); - - // Check if the original option file and the profile option file have the same content - try { - for (Path optionFile : optionFiles) { - Path profileOptions = profile.resolve(optionFile.getFileName()); - - if (optionFile.getFileName().equals(OPTIONS_FILE)) { - try (Stream lines = Files.lines(optionFile)) { - List optionsToLoad = profileConfiguration.getOptionsToLoad(); - AtomicBoolean loaded = new AtomicBoolean(false); - - lines.forEach((line) -> { - String[] option = line.split(":"); - - if (optionsToLoad.contains(option[0])) { - try (Stream profileLines = Files.lines(profileOptions)) { - loaded.set(profileLines.anyMatch(profileLine -> profileLine.equals(line))); - } catch (IOException e) { - OptionsProfilesMod.LOGGER.error("[Profile '{}']: An error occurred when checking each line in options.txt if the profiles is loaded", profileName, e); - } - } - }); - - return loaded.get(); - } catch (IOException e) { - OptionsProfilesMod.LOGGER.error("[Profile '{}']: An error occurred when opening options.txt to check if the profile is loaded", profileName, e); - } - } else { - if (!FileUtils.contentEquals(optionFile.toFile(), profileOptions.toFile())) { - return false; - } - } - } - } catch (IOException e) { - OptionsProfilesMod.LOGGER.error("[Profile '{}']: An error occurred when checking if the profile is loaded", profileName, e); - return false; - } - - return true; + return false; } private static void loadOptionFile(String profileName, Path options) {