Read JSON-formatted history file @param file
(File file)
| 200 | * @param file |
| 201 | */ |
| 202 | private static void readListJSON(File file){ |
| 203 | JSONObject jRoot = null; |
| 204 | try { |
| 205 | byte[] bytes = Files.readAllBytes(Paths.get(file.getAbsolutePath())); |
| 206 | jRoot = new JSONObject(new String(bytes)); |
| 207 | } catch (IOException ex) { |
| 208 | Logger.getLogger(WorldFileList.class.getName()).log(Level.SEVERE, null, ex); |
| 209 | } |
| 210 | |
| 211 | if(jRoot != null){ |
| 212 | jRoot.has("ver"); |
| 213 | String fileVersion = jRoot.getString("ver"); |
| 214 | |
| 215 | Integer verMajor = 0, verMinor = 0; |
| 216 | |
| 217 | String[] split = fileVersion.split("\\."); |
| 218 | if(split.length >= 2){ |
| 219 | verMajor = Integer.decode(split[0]); |
| 220 | verMinor = Integer.decode(split[1]); |
| 221 | } |
| 222 | |
| 223 | if(verMajor == FILE_VER_MAJOR && verMinor >= 0){ |
| 224 | if(jRoot.has("history")){ |
| 225 | JSONArray jHistory = jRoot.getJSONArray("history"); |
| 226 | |
| 227 | for(int i = jHistory.length()-1; i >= 0; --i){ |
| 228 | JSONObject jElement = jHistory.getJSONObject(i); |
| 229 | |
| 230 | if(jElement.has("file") && jElement.has("name")){ |
| 231 | File entryFile = new File(jElement.getString("file")); |
| 232 | String entryName = jElement.getString("name"); |
| 233 | |
| 234 | push(new WorldFileEntry(entryName, entryFile)); |
| 235 | } |
| 236 | } |
| 237 | } |
| 238 | } |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | /** |
| 243 | * Write JSON-formatted history file |