MCPcopy Create free account
hub / github.com/5zig/The-5zig-Mod / run

Method run

The 5zig Mod/src/eu/the5zig/mod/I18n.java:304–358  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

302 private static void checkUpdates() {
303 Executors.newSingleThreadExecutor(new ThreadFactoryBuilder().setNameFormat("Update language thread").build()).execute(new Runnable() {
304 @Override
305 public void run() {
306 String json;
307 try {
308 json = IOUtil.download("http://5zig.net/api/lang?version=" + Version.LANGVERSION, false);
309 } catch (IOException e) {
310 throw new RuntimeException("Could not fetch Language File updates!", e);
311 }
312 Gson gson = new Gson();
313 JsonParser jsonParser = new JsonParser();
314 JsonArray jsonElement = (JsonArray) jsonParser.parse(json);
315 List<LanguageJSON> allLanguages = Lists.newArrayList();
316 for (JsonElement p : jsonElement) {
317 LanguageJSON server = gson.fromJson(p, LanguageJSON.class);
318 allLanguages.add(server);
319 }
320
321 File languageDir = new File(The5zigMod.getModDirectory(), "lang/" + Version.LANGVERSION);
322 File[] languages = languageDir.listFiles();
323 if (languages == null) {
324 The5zigMod.logger.warn("Language Directory is empty! Did something went wrong with extracting all Resource Bundles?");
325 return;
326 }
327
328 boolean updated = false;
329 for (LanguageJSON languageJSON : allLanguages) {
330 File lang = null;
331 for (File language : languages) {
332 if (!language.getName().equals(languageJSON.name))
333 continue;
334 lang = language;
335 break;
336 }
337 if (lang != null) {
338 String md5 = null;
339 try {
340 md5 = FileUtils.md5(lang);
341 } catch (Exception e) {
342 The5zigMod.logger.error("Could not calculate md5 of " + lang, e);
343 }
344 The5zigMod.logger.debug("MD5 of Language File {} is {}", lang, md5);
345 if (!languageJSON.md5.equals(md5)) {
346 downloadUpdate(languageJSON.name);
347 updated = true;
348 }
349 } else {
350 updated = true;
351 downloadUpdate(languageJSON.name);
352 }
353 }
354 if (!updated) {
355 The5zigMod.logger.info("All Language Files are up to date!");
356 }
357 loadLocales();
358 }
359 });
360 }
361

Callers

nothing calls this directly

Calls 10

downloadMethod · 0.95
getModDirectoryMethod · 0.95
md5Method · 0.95
downloadUpdateMethod · 0.95
loadLocalesMethod · 0.95
parseMethod · 0.80
addMethod · 0.45
equalsMethod · 0.45
getNameMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected