/** * called every time a setting is changed saves settings file to * .minecraft/mods/$backendname/guiconfig.properties coming soon: set name of config file * * @param context The context to save. */ @SuppressWarnings("rawtypes") public void save(String context) { if (!settingsLoaded) { return; } try { File path = ModSettings.getAppDir( "/" + ModSettings.contextDatadirs.get(context) + "/" + backendname + "/"); ModSettings.dbgout( "saving context " + context + " (" + path.getAbsolutePath() + " [" + ModSettings.contextDatadirs.get(context) + "])"); if (!path.exists()) { path.mkdirs(); } File file = new File(path, "guiconfig.properties"); Properties p = new Properties(); for (int i = 0; i < Settings.size(); i++) { Setting z = Settings.get(i); p.put(z.backendName, z.toString(context)); } FileOutputStream out = new FileOutputStream(file); p.store(out, ""); } catch (Exception e) { e.printStackTrace(); } }
/** * Prepends the save label to provided {@link Setting} parameter. * * <p>NOTE: This expects you to not create {@link Setting} for saved variants. * * <p>{@link ApplicationSettings} will load saved settings if present in the settings file. Saved * settings share the same name as their default counterpart, but are prefixed with SAVED_. * * <p>e.g EDITOR_FONT vs SAVED_EDITOR_FONT * * @param setting * @return */ public static String prependSaveLabel(Setting setting) { return prependSaveLabel(setting.toString()); }
public int getPropertyAsInt(Setting key) { return Integer.parseInt(props.get().getProperty(key.toString(), key.getDefaultValue())); }