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);
|
Files.createDirectory(profile);
|
||||||
|
|
||||||
if (Files.exists(profile)) {
|
if (Files.exists(profile)) {
|
||||||
System.out.println("Profile created.");
|
System.out.println("[Options Profiles] Profile created.");
|
||||||
|
|
||||||
writeOptionsFilesIntoProfile(profileName);
|
writeOptionsFilesIntoProfile(profileName);
|
||||||
} else {
|
} else {
|
||||||
System.out.println("Profile was not created successfully.");
|
System.out.println("[Options Profiles] Profile was not created successfully.");
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} 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();
|
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);
|
Path profile = Paths.get("options-profiles/" + profileName);
|
||||||
|
|
||||||
// options.txt
|
Path options;
|
||||||
Path options = Paths.get("options.txt");
|
Path profileOptions = Paths.get(profile.toAbsolutePath() + "/" + optionsFile);
|
||||||
Path profileOptions = Paths.get(profile.toAbsolutePath() + "/options.txt");
|
|
||||||
|
if (isSodium) {
|
||||||
|
options = Paths.get("config/" + optionsFile);
|
||||||
|
} else {
|
||||||
|
options = Paths.get(optionsFile);
|
||||||
|
}
|
||||||
|
|
||||||
try (Stream<String> paths = Files.lines(options)) {
|
try (Stream<String> paths = Files.lines(options)) {
|
||||||
if (Files.exists(profileOptions))
|
if (Files.exists(profileOptions))
|
||||||
|
|
@ -52,40 +57,29 @@ public class Profiles {
|
||||||
Files.write(profileOptions, line.getBytes(), StandardOpenOption.CREATE, StandardOpenOption.APPEND);
|
Files.write(profileOptions, line.getBytes(), StandardOpenOption.CREATE, StandardOpenOption.APPEND);
|
||||||
Files.write(profileOptions, "\n".getBytes(), StandardOpenOption.APPEND);
|
Files.write(profileOptions, "\n".getBytes(), StandardOpenOption.APPEND);
|
||||||
} catch (IOException e) {
|
} 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();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (IOException e) {
|
} 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();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void writeOptionsFilesIntoProfile(String profileName) {
|
||||||
|
// options.txt
|
||||||
|
writeOptionFile(profileName, "options.txt", false);
|
||||||
|
|
||||||
// sodium-options.json
|
// sodium-options.json
|
||||||
// if (Platform.isFabric()) {
|
if (Files.exists(Paths.get("config/sodium-options.json"))) {
|
||||||
// if (Platform.isModLoaded("sodium")) {
|
writeOptionFile(profileName, "sodium-options.json", true);
|
||||||
// Path sodiumConfiguration = Paths.get("config/sodium-options.json");
|
}
|
||||||
// Path sodiumConfigurationProfile = Paths.get(profile.toAbsolutePath() + "/sodium-options.json");
|
|
||||||
//
|
// optionsof.txt
|
||||||
// try (Stream<String> paths = Files.lines(sodiumConfiguration)) {
|
if (Files.exists(Paths.get("optionsof.txt"))) {
|
||||||
// if (Files.exists(sodiumConfigurationProfile))
|
writeOptionFile(profileName, "optionsof.txt", false);
|
||||||
// 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();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isProfileLoaded(String profileName) {
|
public static boolean isProfileLoaded(String profileName) {
|
||||||
|
|
@ -98,19 +92,27 @@ public class Profiles {
|
||||||
List<String> linesOptions = Files.readAllLines(options);
|
List<String> linesOptions = Files.readAllLines(options);
|
||||||
List<String> linesProfileOptions = Files.readAllLines(profileOptions);
|
List<String> linesProfileOptions = Files.readAllLines(profileOptions);
|
||||||
|
|
||||||
// if (Platform.isFabric()) {
|
// sodium-options.json
|
||||||
// if (Platform.isModLoaded("sodium")) {
|
Path sodiumConfiguration = Paths.get("config/sodium-options.json");
|
||||||
// Path sodiumConfiguration = Paths.get("config/sodium-options.json");
|
Path sodiumConfigurationProfile = Paths.get(profile.toAbsolutePath() + "/sodium-options.json");
|
||||||
// Path sodiumConfigurationProfile = Paths.get(profile.toAbsolutePath() + "/sodium-options.json");
|
|
||||||
//
|
if (Files.exists(sodiumConfigurationProfile)) {
|
||||||
// if (Files.exists(sodiumConfigurationProfile)) {
|
List<String> linesSodiumConfig = Files.readAllLines(sodiumConfiguration);
|
||||||
// List<String> linesSodiumConfig = Files.readAllLines(sodiumConfiguration);
|
List<String> linesSodiumConfigProfile = Files.readAllLines(sodiumConfigurationProfile);
|
||||||
// List<String> linesSodiumConfigProfile = Files.readAllLines(sodiumConfigurationProfile);
|
|
||||||
//
|
return linesOptions.equals(linesProfileOptions) && linesSodiumConfig.equals(linesSodiumConfigProfile);
|
||||||
// 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);
|
return linesOptions.equals(linesProfileOptions);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|
@ -120,12 +122,11 @@ public class Profiles {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void loadProfile(String profileName) {
|
private static void loadOptionFile(String profileName, String optionsFile) {
|
||||||
Path profile = Paths.get("options-profiles/" + profileName);
|
Path profile = Paths.get("options-profiles/" + profileName);
|
||||||
|
|
||||||
// options.txt
|
Path options = Paths.get(optionsFile);
|
||||||
Path options = Paths.get("options.txt");
|
Path profileOptions = Paths.get(profile.toAbsolutePath() + "/" + optionsFile);
|
||||||
Path profileOptions = Paths.get(profile.toAbsolutePath() + "/options.txt");
|
|
||||||
|
|
||||||
try (Stream<String> paths = Files.lines(profileOptions)) {
|
try (Stream<String> paths = Files.lines(profileOptions)) {
|
||||||
Files.newBufferedWriter(options, StandardOpenOption.TRUNCATE_EXISTING);
|
Files.newBufferedWriter(options, StandardOpenOption.TRUNCATE_EXISTING);
|
||||||
|
|
@ -135,25 +136,31 @@ public class Profiles {
|
||||||
Files.write(options, line.getBytes(), StandardOpenOption.APPEND);
|
Files.write(options, line.getBytes(), StandardOpenOption.APPEND);
|
||||||
Files.write(options, "\n".getBytes(), StandardOpenOption.APPEND);
|
Files.write(options, "\n".getBytes(), StandardOpenOption.APPEND);
|
||||||
} catch (IOException e) {
|
} 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();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (IOException e) {
|
} 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();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void loadProfile(String profileName) {
|
||||||
|
Path profile = Paths.get("options-profiles/" + profileName);
|
||||||
|
|
||||||
|
// options.txt
|
||||||
|
loadOptionFile(profileName, "options.txt");
|
||||||
|
|
||||||
// sodium-options.json
|
// sodium-options.json
|
||||||
// if (Platform.isFabric()) {
|
Path sodiumConfigurationProfile = Paths.get(profile.toAbsolutePath() + "/sodium-options.json");
|
||||||
// if (Platform.isModLoaded("sodium")) {
|
|
||||||
// Path sodiumConfigurationProfile = Paths.get(profile.toAbsolutePath() + "/sodium-options.json");
|
if (Files.exists(Paths.get(profile.toAbsolutePath() + "/sodium-options.json")))
|
||||||
//
|
SodiumConfigLoader.load(sodiumConfigurationProfile);
|
||||||
// if (Files.exists(sodiumConfigurationProfile)) {
|
|
||||||
// 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) {
|
public static void renameProfile(String profileName, String newProfileName) {
|
||||||
|
|
@ -161,18 +168,18 @@ public class Profiles {
|
||||||
Path newProfile = Paths.get("options-profiles/" + newProfileName);
|
Path newProfile = Paths.get("options-profiles/" + newProfileName);
|
||||||
|
|
||||||
if (Files.exists(newProfile))
|
if (Files.exists(newProfile))
|
||||||
System.out.println("New profile already exists!");
|
System.out.println("[Options Profiles] New profile already exists!");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Files.move(profile, newProfile);
|
Files.move(profile, newProfile);
|
||||||
|
|
||||||
if (Files.exists(newProfile)) {
|
if (Files.exists(newProfile)) {
|
||||||
System.out.println("Profile renamed.");
|
System.out.println("[Options Profiles] Profile renamed.");
|
||||||
} else {
|
} else {
|
||||||
System.out.println("Profile was not renamed successfully.");
|
System.out.println("[Options Profiles] Profile was not renamed successfully.");
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.out.println("Profile was not renamed successfully.");
|
System.out.println("[Options Profiles] Profile was not renamed successfully.");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -186,10 +193,10 @@ public class Profiles {
|
||||||
.map(Path::toFile)
|
.map(Path::toFile)
|
||||||
.forEach(File::delete);
|
.forEach(File::delete);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.out.println("Profile was not deleted.");
|
System.out.println("[Options Profiles] Profile was not deleted.");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("Profile deleted.");
|
System.out.println("[Options Profiles] Profile deleted.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue