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) {
|
||||
OptionsProfilesMod.LOGGER.error("An error occurred when listing profiles", e);
|
||||
}
|
||||
|
||||
checkEntriesLoaded();
|
||||
}
|
||||
|
||||
public void checkEntriesLoaded() {
|
||||
this.children().forEach(ProfileEntry::checkLoaded);
|
||||
}
|
||||
|
||||
protected int getScrollbarPosition() {
|
||||
|
|
@ -98,6 +104,7 @@ public class ProfilesList extends ContainerObjectSelectionList<ProfilesList.Prof
|
|||
|
||||
minecraft.options.save();
|
||||
|
||||
ProfilesList.this.checkEntriesLoaded();
|
||||
button.active = false;
|
||||
}
|
||||
);
|
||||
|
|
@ -131,6 +138,10 @@ public class ProfilesList extends ContainerObjectSelectionList<ProfilesList.Prof
|
|||
public List<? extends NarratableEntry> narratables() {
|
||||
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.SodiumExtraLoader;
|
||||
import com.axolotlmaid.optionsprofiles.profiles.loaders.SodiumLoader;
|
||||
import com.seibel.distanthorizons.core.config.ConfigBase;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
|
|
@ -94,6 +93,7 @@ public class Profiles {
|
|||
|
||||
try {
|
||||
Files.copy(options, profileOptions);
|
||||
OptionsProfilesMod.LOGGER.info("[Profile '{}']: Copied file '{}'", profile.getFileName().toString(), options.getFileName().toString());
|
||||
} catch (IOException 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 profileOptions = profile.resolve("options.txt");
|
||||
|
||||
ProfileConfiguration profileConfiguration = ProfileConfiguration.get(profileName);
|
||||
|
||||
if (overwriting) {
|
||||
try (Stream<Path> files = Files.list(profile)) {
|
||||
files.filter(file -> !file.getFileName().toString().equals("configuration.json"))
|
||||
.forEach(file -> {
|
||||
try {
|
||||
// Removes old option files
|
||||
FileUtils.cleanDirectory(profile.toFile());
|
||||
Files.delete(file);
|
||||
OptionsProfilesMod.LOGGER.info("[Profile '{}']: Deleted file '{}'", profileName, file.getFileName().toString());
|
||||
} 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 trying to delete the file '{}'", profileName, file.getFileName().toString(), e);
|
||||
}
|
||||
});
|
||||
} catch (IOException e) {
|
||||
OptionsProfilesMod.LOGGER.error("[Profile '{}']: An error occurred when deleting old options files.", profileName, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -122,6 +127,9 @@ public class Profiles {
|
|||
copyOptionFile(profile, EMBEDDIUM_OPTIONS_FILE);
|
||||
copyOptionFile(profile, DISTANT_HORIZONS_OPTIONS_FILE);
|
||||
|
||||
if (!overwriting) {
|
||||
ProfileConfiguration profileConfiguration = ProfileConfiguration.get(profileName);
|
||||
|
||||
// Add every option value to configuration
|
||||
try (Stream<String> lines = Files.lines(profileOptions)) {
|
||||
List<String> optionsToLoad = profileConfiguration.getOptionsToLoad();
|
||||
|
|
@ -136,6 +144,7 @@ public class Profiles {
|
|||
OptionsProfilesMod.LOGGER.error("[Profile '{}']: An error occurred when adding options to the configuration file", profileName, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isProfileLoaded(String profileName) {
|
||||
Path profile = PROFILES_DIRECTORY.resolve(profileName);
|
||||
|
|
|
|||
Loading…
Reference in a new issue