/** Attempts to find a config If there is one load it If there is not one create one */ private void loadConfig() { config = new Properties(defaults); try { configPath = Minecraft.getMinecraft().mcDataDir.getCanonicalPath() + File.separatorChar + "config" + File.separatorChar + "ServerListFolder" + File.separatorChar; File cfg = new File(configPath + "ServerListFolder.cfg"); if (cfg.exists()) { ServerListFolder.info("Config file found, loading..."); config.load(new FileInputStream(configPath + "ServerListFolder.cfg")); } else { ServerListFolder.info("No config file found, creating..."); createConfig(cfg); } } catch (Exception e) { ServerListFolder.warn(e.toString()); } }
/** Loads the property data into the local data */ public void loadConfigData() { ServerListFolder.info("Loading Config to Local Data"); configVersion = this.getIntProperty("configVersion"); FolderMotdColor = this.getStringProperty("FolderMotdColor"); parseColor(); FolderMotdText = this.getStringProperty("FolderMotdText"); checkForConfigUpdate(); }
/** Checks if the config version has changed and adds the options which are new. */ private void checkForConfigUpdate() { if (version != configVersion) { ServerListFolder.info("Updating the config..."); switch (configVersion) { case 0: if (FolderMotdColor.equals(defaults.getProperty("FolderMotdColor"))) { config.setProperty("FolderMotdColor", defaults.getProperty("FolderMotdColor")); } if (FolderMotdText.equals(defaults.getProperty("FolderMotdText"))) { config.setProperty("FolderMotdText", defaults.getProperty("FolderMotdText")); } case 1: // for the next version. } config.setProperty("configVersion", "" + version); saveConfig(); } }
/** * Creates a config properties of default values Then saves the config to the config location * * @param cfg config file */ private void createConfig(File cfg) { File folder = new File(configPath); if (!folder.exists()) { ServerListFolder.info("No folder found, creating..."); folder.mkdirs(); } try { cfg.createNewFile(); config.setProperty("configVersion", "" + version); config.setProperty("FolderMotdColor", "purple"); config.setProperty("FolderMotdText", "Folder"); config.store( new FileOutputStream(configPath + "ServerListFolder.cfg"), "Server List Folder Mod Config" + "\nUse the color names(without spaces!) form: http://www.minecraftwiki.net/wiki/Color_Codes"); } catch (Exception e) { ServerListFolder.warn(e.toString()); } }
public ServerListFolderConfig() { ServerListFolder.info("Attempting to load/create the configuration."); loadConfig(); loadConfigData(); }