Exemple #1
0
  public boolean loadInfoFromResourceFile() {
    ObjectMapper objMapper = new ObjectMapper();
    // Get the location of the class files at runtime, backtrack a level to the root directory,
    // Then get the path to the resource directory.
    try {
      File inFile = new File(configFileLocation);

      if (!inFile.exists()) {
        // The file doesn't exist. Create it with default empty values.
        writeInfoToResourceFile();
      }

      // JsonNode rootNode = objMapper.readTree(new File("./res/configItems/userConfig.json"));
      // Get the location of the class files at runtime, backtrack a level to the root directory,
      // Then get the path to the resource directory.
      JsonNode rootNode = objMapper.readTree(inFile);
      loginId = rootNode.path("loginId").getTextValue();
      mainSummoner = rootNode.path("mainSummoner").getTextValue();
      mainServer = LeagueServer.findServerByCode(rootNode.path("mainServer").getTextValue());
      clientVersion = rootNode.path("client version").getTextValue();
      Iterator<String> fieldIterator = rootNode.getFieldNames();
      while (fieldIterator.hasNext()) {
        String currentField = fieldIterator.next();
        if (!currentField.startsWith("summoner")) {
          continue;
        }
        summonerList.add(rootNode.path(currentField).getTextValue());
      }

    } catch (JsonProcessingException e) {
      e.printStackTrace();
      return false;
    } catch (IOException e) {
      e.printStackTrace();
      return false;
    }
    return true;
  }