Update Profiles.java
This commit is contained in:
parent
ae35603bf7
commit
2ba38a6a5b
1 changed files with 74 additions and 67 deletions
|
|
@ -24,24 +24,29 @@ public class Profiles {
|
|||
Files.createDirectory(profile);
|
||||
|
||||
if (Files.exists(profile)) {
|
||||
System.out.println("Profile created.");
|
||||
System.out.println("[Options Profiles] Profile created.");
|
||||
|
||||
writeOptionsFilesIntoProfile(profileName);
|
||||
} else {
|
||||
System.out.println("Profile was not created successfully.");
|
||||
System.out.println("[Options Profiles] Profile was not created successfully.");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.out.println("An error occurred when creating a profile.");
|
||||
System.out.println("[Options Profiles] An error occurred when creating a profile.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeOptionsFilesIntoProfile(String profileName) {
|
||||
private static void writeOptionFile(String profileName, String optionsFile, boolean isSodium) {
|
||||
Path profile = Paths.get("options-profiles/" + profileName);
|
||||
|
||||
// options.txt
|
||||
Path options = Paths.get("options.txt");
|
||||
Path profileOptions = Paths.get(profile.toAbsolutePath() + "/options.txt");
|
||||
Path options;
|
||||
Path profileOptions = Paths.get(profile.toAbsolutePath() + "/" + optionsFile);
|
||||
|
||||
if (isSodium) {
|
||||
options = Paths.get("config/" + optionsFile);
|
||||
} else {
|
||||
options = Paths.get(optionsFile);
|
||||
}
|
||||
|
||||
try (Stream<String> paths = Files.lines(options)) {
|
||||
if (Files.exists(profileOptions))
|
||||
|
|
@ -52,40 +57,29 @@ public class Profiles {
|
|||
Files.write(profileOptions, line.getBytes(), StandardOpenOption.CREATE, StandardOpenOption.APPEND);
|
||||
Files.write(profileOptions, "\n".getBytes(), StandardOpenOption.APPEND);
|
||||
} catch (IOException e) {
|
||||
System.out.println("An error occurred when writing a profile.");
|
||||
System.out.println("[Options Profiles] An error occurred when writing a profile.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
} catch (IOException e) {
|
||||
System.out.println("An error occurred when reading options.txt.");
|
||||
System.out.println("[Options Profiles] An error occurred when reading an options file.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeOptionsFilesIntoProfile(String profileName) {
|
||||
// options.txt
|
||||
writeOptionFile(profileName, "options.txt", false);
|
||||
|
||||
// sodium-options.json
|
||||
// if (Platform.isFabric()) {
|
||||
// if (Platform.isModLoaded("sodium")) {
|
||||
// Path sodiumConfiguration = Paths.get("config/sodium-options.json");
|
||||
// Path sodiumConfigurationProfile = Paths.get(profile.toAbsolutePath() + "/sodium-options.json");
|
||||
//
|
||||
// try (Stream<String> paths = Files.lines(sodiumConfiguration)) {
|
||||
// if (Files.exists(sodiumConfigurationProfile))
|
||||
// Files.newBufferedWriter(sodiumConfigurationProfile, StandardOpenOption.TRUNCATE_EXISTING);
|
||||
//
|
||||
// paths.forEach(line -> {
|
||||
// try {
|
||||
// Files.write(sodiumConfigurationProfile, line.getBytes(), StandardOpenOption.CREATE, StandardOpenOption.APPEND);
|
||||
// Files.write(sodiumConfigurationProfile, "\n".getBytes(), StandardOpenOption.APPEND);
|
||||
// } catch (IOException e) {
|
||||
// System.out.println("An error occurred when writing a profile.");
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// });
|
||||
// } catch (IOException e) {
|
||||
// System.out.println("An error occurred when reading options.txt.");
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
if (Files.exists(Paths.get("config/sodium-options.json"))) {
|
||||
writeOptionFile(profileName, "sodium-options.json", true);
|
||||
}
|
||||
|
||||
// optionsof.txt
|
||||
if (Files.exists(Paths.get("optionsof.txt"))) {
|
||||
writeOptionFile(profileName, "optionsof.txt", false);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isProfileLoaded(String profileName) {
|
||||
|
|
@ -98,19 +92,27 @@ public class Profiles {
|
|||
List<String> linesOptions = Files.readAllLines(options);
|
||||
List<String> linesProfileOptions = Files.readAllLines(profileOptions);
|
||||
|
||||
// if (Platform.isFabric()) {
|
||||
// if (Platform.isModLoaded("sodium")) {
|
||||
// Path sodiumConfiguration = Paths.get("config/sodium-options.json");
|
||||
// Path sodiumConfigurationProfile = Paths.get(profile.toAbsolutePath() + "/sodium-options.json");
|
||||
//
|
||||
// if (Files.exists(sodiumConfigurationProfile)) {
|
||||
// List<String> linesSodiumConfig = Files.readAllLines(sodiumConfiguration);
|
||||
// List<String> linesSodiumConfigProfile = Files.readAllLines(sodiumConfigurationProfile);
|
||||
//
|
||||
// return linesOptions.equals(linesProfileOptions) && linesSodiumConfig.equals(linesSodiumConfigProfile);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// sodium-options.json
|
||||
Path sodiumConfiguration = Paths.get("config/sodium-options.json");
|
||||
Path sodiumConfigurationProfile = Paths.get(profile.toAbsolutePath() + "/sodium-options.json");
|
||||
|
||||
if (Files.exists(sodiumConfigurationProfile)) {
|
||||
List<String> linesSodiumConfig = Files.readAllLines(sodiumConfiguration);
|
||||
List<String> linesSodiumConfigProfile = Files.readAllLines(sodiumConfigurationProfile);
|
||||
|
||||
return linesOptions.equals(linesProfileOptions) && linesSodiumConfig.equals(linesSodiumConfigProfile);
|
||||
}
|
||||
|
||||
// optionsof.txt
|
||||
Path optifineConfiguration = Paths.get("optionsof.txt");
|
||||
Path optifineConfigurationProfile = Paths.get(profile.toAbsolutePath() + "/optionsof.txt");
|
||||
|
||||
if (Files.exists(optifineConfigurationProfile)) {
|
||||
List<String> linesOptifineConfig = Files.readAllLines(optifineConfiguration);
|
||||
List<String> linesOptifineConfigProfile = Files.readAllLines(optifineConfigurationProfile);
|
||||
|
||||
return linesOptions.equals(linesProfileOptions) && linesOptifineConfig.equals(linesOptifineConfigProfile);
|
||||
}
|
||||
|
||||
return linesOptions.equals(linesProfileOptions);
|
||||
} catch (IOException e) {
|
||||
|
|
@ -120,12 +122,11 @@ public class Profiles {
|
|||
return false;
|
||||
}
|
||||
|
||||
public static void loadProfile(String profileName) {
|
||||
private static void loadOptionFile(String profileName, String optionsFile) {
|
||||
Path profile = Paths.get("options-profiles/" + profileName);
|
||||
|
||||
// options.txt
|
||||
Path options = Paths.get("options.txt");
|
||||
Path profileOptions = Paths.get(profile.toAbsolutePath() + "/options.txt");
|
||||
Path options = Paths.get(optionsFile);
|
||||
Path profileOptions = Paths.get(profile.toAbsolutePath() + "/" + optionsFile);
|
||||
|
||||
try (Stream<String> paths = Files.lines(profileOptions)) {
|
||||
Files.newBufferedWriter(options, StandardOpenOption.TRUNCATE_EXISTING);
|
||||
|
|
@ -135,25 +136,31 @@ public class Profiles {
|
|||
Files.write(options, line.getBytes(), StandardOpenOption.APPEND);
|
||||
Files.write(options, "\n".getBytes(), StandardOpenOption.APPEND);
|
||||
} catch (IOException e) {
|
||||
System.out.println("An error occurred when loading a profile.");
|
||||
System.out.println("[Options Profiles] An error occurred when loading a profile.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
} catch (IOException e) {
|
||||
System.out.println("An error occurred when loading a profile.");
|
||||
System.out.println("[Options Profiles] An error occurred when loading a profile.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void loadProfile(String profileName) {
|
||||
Path profile = Paths.get("options-profiles/" + profileName);
|
||||
|
||||
// options.txt
|
||||
loadOptionFile(profileName, "options.txt");
|
||||
|
||||
// sodium-options.json
|
||||
// if (Platform.isFabric()) {
|
||||
// if (Platform.isModLoaded("sodium")) {
|
||||
// Path sodiumConfigurationProfile = Paths.get(profile.toAbsolutePath() + "/sodium-options.json");
|
||||
//
|
||||
// if (Files.exists(sodiumConfigurationProfile)) {
|
||||
// SodiumConfigLoader.load(sodiumConfigurationProfile);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
Path sodiumConfigurationProfile = Paths.get(profile.toAbsolutePath() + "/sodium-options.json");
|
||||
|
||||
if (Files.exists(Paths.get(profile.toAbsolutePath() + "/sodium-options.json")))
|
||||
SodiumConfigLoader.load(sodiumConfigurationProfile);
|
||||
|
||||
// optifineof.txt
|
||||
if (Files.exists(Paths.get(profile.toAbsolutePath() + "/optionsof.txt")))
|
||||
loadOptionFile(profileName, "optifineof.txt");
|
||||
}
|
||||
|
||||
public static void renameProfile(String profileName, String newProfileName) {
|
||||
|
|
@ -161,18 +168,18 @@ public class Profiles {
|
|||
Path newProfile = Paths.get("options-profiles/" + newProfileName);
|
||||
|
||||
if (Files.exists(newProfile))
|
||||
System.out.println("New profile already exists!");
|
||||
System.out.println("[Options Profiles] New profile already exists!");
|
||||
|
||||
try {
|
||||
Files.move(profile, newProfile);
|
||||
|
||||
if (Files.exists(newProfile)) {
|
||||
System.out.println("Profile renamed.");
|
||||
System.out.println("[Options Profiles] Profile renamed.");
|
||||
} else {
|
||||
System.out.println("Profile was not renamed successfully.");
|
||||
System.out.println("[Options Profiles] Profile was not renamed successfully.");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.out.println("Profile was not renamed successfully.");
|
||||
System.out.println("[Options Profiles] Profile was not renamed successfully.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
|
@ -186,10 +193,10 @@ public class Profiles {
|
|||
.map(Path::toFile)
|
||||
.forEach(File::delete);
|
||||
} catch (IOException e) {
|
||||
System.out.println("Profile was not deleted.");
|
||||
System.out.println("[Options Profiles] Profile was not deleted.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
System.out.println("Profile deleted.");
|
||||
System.out.println("[Options Profiles] Profile deleted.");
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue