コード例 #1
0
 /**
  * Load the configuration.
  *
  * @throws Exception any error.
  */
 public static void load() throws Exception {
   version = FullVersion.parse(get("version", version.toString()));
   updateXML = get("update", updateXML);
   managerId = get("id", managerId);
   minecraftFolder = get("minecraft", findMinecraftFolder().getAbsolutePath());
   modsFolder = new File(minecraftFolder, get("mods", "mods")).getAbsolutePath();
   configFolder = new File(minecraftFolder, get("config", "config")).getAbsolutePath();
   markdownCSS =
       new File(get("markdown.css", "NaujaModManager_lib/markdown.css")).getAbsolutePath();
 }
コード例 #2
0
 /**
  * Set the version of the mod manager.
  *
  * @param version new value.
  */
 public static void setVersion(final FullVersion version) {
   Config.version = version;
   properties.put("version", version.toString());
 }
コード例 #3
0
/** Configuration. */
public final class Config {

  /** Logger for this class. */
  private static final Logger LOGGER = Logger.getLogger(Config.class.getSimpleName());

  /** Path of the configuration file. */
  private static final String PATH = "NaujaModManager.props";

  /** Properties. */
  private static Properties properties;

  /** Version of the mod manager. */
  private static FullVersion version =
      FullVersion.get(Version.ALL, new Version(1, 0, 0, Modifier.Release));

  /** XML containing updates. */
  private static String updateXML = "https://raw.github.com/Nauja/Minecraft/master/Manager.xml";

  /** Mod manager id. */
  private static String managerId = "NaujaModManager";

  /** Minecraft folder. */
  private static String minecraftFolder;

  /** Mods folder. */
  private static String modsFolder;

  /** Config folder. */
  private static String configFolder;

  /** markdown.css. */
  private static String markdownCSS;

  /**
   * Get the version of the mod manager.
   *
   * @return version of the mod manager.
   */
  public static FullVersion getVersion() {
    return version;
  }

  /**
   * Set the version of the mod manager.
   *
   * @param version new value.
   */
  public static void setVersion(final FullVersion version) {
    Config.version = version;
    properties.put("version", version.toString());
  }

  /**
   * Get the update XML.
   *
   * @return update XML.
   */
  public static String getUpdateXML() {
    return updateXML;
  }

  /**
   * Get the mod manager id.
   *
   * @return mod manager id.
   */
  public static String getManagerId() {
    return managerId;
  }

  /**
   * Get the minecraft folder.
   *
   * @return minecraft folder.
   */
  public static String getMinecraftFolder() {
    return minecraftFolder;
  }

  /**
   * Get the mods folder.
   *
   * @return mods folder.
   */
  public static String getModsFolder() {
    return modsFolder;
  }

  /**
   * Get the config folder.
   *
   * @return config folder.
   */
  public static String getConfigFolder() {
    return configFolder;
  }

  /**
   * Get the markdown.css.
   *
   * @return markdown.css.
   */
  public static String getMarkdownCSS() {
    return markdownCSS;
  }

  /**
   * Initialize the configuration.
   *
   * @throws Exception any error.
   */
  public static void init() throws Exception {
    // Create the folder.
    final File f = new File(PATH);
    if (!f.exists()) {
      final File p = f.getParentFile();
      if (p != null && !p.exists()) {
        p.mkdirs();
      }
      f.createNewFile();
    }
    // Load the configuration.
    final FileInputStream fis = new FileInputStream(f);
    properties = new Properties();
    properties.load(fis);
    fis.close();
    // Load.
    load();
    // Save.
    final FileOutputStream fos = new FileOutputStream(f);
    properties.store(fos, "");
    fos.close();
  }

  /** Save the configuration. */
  public static void save() throws Exception {
    final FileOutputStream fos = new FileOutputStream(new File(PATH));
    properties.store(fos, "");
    fos.close();
  }

  /**
   * Load the configuration.
   *
   * @throws Exception any error.
   */
  public static void load() throws Exception {
    version = FullVersion.parse(get("version", version.toString()));
    updateXML = get("update", updateXML);
    managerId = get("id", managerId);
    minecraftFolder = get("minecraft", findMinecraftFolder().getAbsolutePath());
    modsFolder = new File(minecraftFolder, get("mods", "mods")).getAbsolutePath();
    configFolder = new File(minecraftFolder, get("config", "config")).getAbsolutePath();
    markdownCSS =
        new File(get("markdown.css", "NaujaModManager_lib/markdown.css")).getAbsolutePath();
  }

  private static String get(final String key, final String value) {
    if (!properties.containsKey(key)) {
      properties.put(key, value);
      return value;
    } else {
      return properties.getProperty(key, value);
    }
  }

  /**
   * Find the minecraft folder for current OS.
   *
   * @return minecraft folder.
   */
  public static File findMinecraftFolder() {
    final String os = System.getProperty("os.name").toLowerCase();
    if (os.indexOf("win") >= 0) {
      return new File(System.getenv("APPDATA"), ".minecraft");
    } else if (os.indexOf("mac") >= 0) {
      return new File(System.getProperty("user.home"), "Library/Application Support/.minecraft");
    } else if (os.indexOf("nux") >= 0 || os.indexOf("nix") >= 0 || os.indexOf("aix") >= 0) {
      return new File(System.getProperty("user.home"), ".minecraft");
    } else {
      LOGGER.log(Level.INFO, Localization.translate("Config.findMinecraftFolder.unkownOS", os));
      return new File(".");
    }
  }
}