Fix profiles not being checked if they are loaded every time
This commit is contained in:
parent
746ef7ad3c
commit
a8fa28e834
2 changed files with 37 additions and 17 deletions
|
|
@ -51,6 +51,12 @@ public class ProfilesList extends ContainerObjectSelectionList<ProfilesList.Prof
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
OptionsProfilesMod.LOGGER.error("An error occurred when listing profiles", e);
|
OptionsProfilesMod.LOGGER.error("An error occurred when listing profiles", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkEntriesLoaded();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void checkEntriesLoaded() {
|
||||||
|
this.children().forEach(ProfileEntry::checkLoaded);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int getScrollbarPosition() {
|
protected int getScrollbarPosition() {
|
||||||
|
|
@ -98,6 +104,7 @@ public class ProfilesList extends ContainerObjectSelectionList<ProfilesList.Prof
|
||||||
|
|
||||||
minecraft.options.save();
|
minecraft.options.save();
|
||||||
|
|
||||||
|
ProfilesList.this.checkEntriesLoaded();
|
||||||
button.active = false;
|
button.active = false;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
@ -131,6 +138,10 @@ public class ProfilesList extends ContainerObjectSelectionList<ProfilesList.Prof
|
||||||
public List<? extends NarratableEntry> narratables() {
|
public List<? extends NarratableEntry> narratables() {
|
||||||
return ImmutableList.of(this.editButton, this.loadButton);
|
return ImmutableList.of(this.editButton, this.loadButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void checkLoaded() {
|
||||||
|
this.loadButton.active = !Profiles.isProfileLoaded(profileName.getString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -5,7 +5,6 @@ import com.axolotlmaid.optionsprofiles.profiles.loaders.DistantHorizonsLoader;
|
||||||
import com.axolotlmaid.optionsprofiles.profiles.loaders.EmbeddiumLoader;
|
import com.axolotlmaid.optionsprofiles.profiles.loaders.EmbeddiumLoader;
|
||||||
import com.axolotlmaid.optionsprofiles.profiles.loaders.SodiumExtraLoader;
|
import com.axolotlmaid.optionsprofiles.profiles.loaders.SodiumExtraLoader;
|
||||||
import com.axolotlmaid.optionsprofiles.profiles.loaders.SodiumLoader;
|
import com.axolotlmaid.optionsprofiles.profiles.loaders.SodiumLoader;
|
||||||
import com.seibel.distanthorizons.core.config.ConfigBase;
|
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
@ -94,6 +93,7 @@ public class Profiles {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Files.copy(options, profileOptions);
|
Files.copy(options, profileOptions);
|
||||||
|
OptionsProfilesMod.LOGGER.info("[Profile '{}']: Copied file '{}'", profile.getFileName().toString(), options.getFileName().toString());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
OptionsProfilesMod.LOGGER.error("[Profile '{}']: Unable to copy '{}'", profile.getFileName().toString(), options.getFileName().toString(), e);
|
OptionsProfilesMod.LOGGER.error("[Profile '{}']: Unable to copy '{}'", profile.getFileName().toString(), options.getFileName().toString(), e);
|
||||||
}
|
}
|
||||||
|
|
@ -104,14 +104,19 @@ public class Profiles {
|
||||||
Path profile = PROFILES_DIRECTORY.resolve(profileName);
|
Path profile = PROFILES_DIRECTORY.resolve(profileName);
|
||||||
Path profileOptions = profile.resolve("options.txt");
|
Path profileOptions = profile.resolve("options.txt");
|
||||||
|
|
||||||
ProfileConfiguration profileConfiguration = ProfileConfiguration.get(profileName);
|
|
||||||
|
|
||||||
if (overwriting) {
|
if (overwriting) {
|
||||||
try {
|
try (Stream<Path> files = Files.list(profile)) {
|
||||||
// Removes old option files
|
files.filter(file -> !file.getFileName().toString().equals("configuration.json"))
|
||||||
FileUtils.cleanDirectory(profile.toFile());
|
.forEach(file -> {
|
||||||
|
try {
|
||||||
|
Files.delete(file);
|
||||||
|
OptionsProfilesMod.LOGGER.info("[Profile '{}']: Deleted file '{}'", profileName, file.getFileName().toString());
|
||||||
|
} catch (IOException e) {
|
||||||
|
OptionsProfilesMod.LOGGER.error("[Profile '{}']: An error occurred when trying to delete the file '{}'", profileName, file.getFileName().toString(), e);
|
||||||
|
}
|
||||||
|
});
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
OptionsProfilesMod.LOGGER.error("[Profile '{}']: An error occurred when clearing old options files", profileName, e);
|
OptionsProfilesMod.LOGGER.error("[Profile '{}']: An error occurred when deleting old options files.", profileName, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -122,18 +127,22 @@ public class Profiles {
|
||||||
copyOptionFile(profile, EMBEDDIUM_OPTIONS_FILE);
|
copyOptionFile(profile, EMBEDDIUM_OPTIONS_FILE);
|
||||||
copyOptionFile(profile, DISTANT_HORIZONS_OPTIONS_FILE);
|
copyOptionFile(profile, DISTANT_HORIZONS_OPTIONS_FILE);
|
||||||
|
|
||||||
// Add every option value to configuration
|
if (!overwriting) {
|
||||||
try (Stream<String> lines = Files.lines(profileOptions)) {
|
ProfileConfiguration profileConfiguration = ProfileConfiguration.get(profileName);
|
||||||
List<String> optionsToLoad = profileConfiguration.getOptionsToLoad();
|
|
||||||
|
|
||||||
lines.forEach((line) -> {
|
// Add every option value to configuration
|
||||||
String[] option = line.split(":");
|
try (Stream<String> lines = Files.lines(profileOptions)) {
|
||||||
optionsToLoad.add(option[0]);
|
List<String> optionsToLoad = profileConfiguration.getOptionsToLoad();
|
||||||
});
|
|
||||||
|
|
||||||
profileConfiguration.save();
|
lines.forEach((line) -> {
|
||||||
} catch (IOException e) {
|
String[] option = line.split(":");
|
||||||
OptionsProfilesMod.LOGGER.error("[Profile '{}']: An error occurred when adding options to the configuration file", profileName, e);
|
optionsToLoad.add(option[0]);
|
||||||
|
});
|
||||||
|
|
||||||
|
profileConfiguration.save();
|
||||||
|
} catch (IOException e) {
|
||||||
|
OptionsProfilesMod.LOGGER.error("[Profile '{}']: An error occurred when adding options to the configuration file", profileName, e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue