Beispiel #1
0
  public boolean writeInfoToResourceFile(String resourceFileName) {
    ObjectMapper objMapper = new ObjectMapper();
    ObjectNode infoObj = objMapper.createObjectNode();
    infoObj.put("loginId", loginId);
    infoObj.put("mainSummoner", mainSummoner);
    infoObj.put("client version", clientVersion);
    infoObj.put("mainServer", mainServer.getServerCode());

    int i = 0;
    for (String summonerName : summonerList) {
      infoObj.put("summoner" + i, summonerName);
      i++;
    }

    try {
      objMapper.writeValue(new File(resourceFileName), infoObj);
    } catch (IOException e) {

      e.printStackTrace();
    }
    return true;
  }
Beispiel #2
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;
  }