use of com.github.jakz.romlib.json.GameListAdapter in project rom-manager by Jakz.
the class GameSetManager method saveSetStatus.
public void saveSetStatus(GameSet set) {
try {
Path basePath = GlobalSettings.DATA_PATH.resolve(set.ident());
Files.createDirectories(basePath);
Path settingsPath = basePath.resolve("settings.json");
try (BufferedWriter wrt = Files.newBufferedWriter(settingsPath)) {
MyGameSetFeatures helper = set.helper();
wrt.write(Json.build().toJson(helper.settings(), Settings.class));
}
Path statusPath = basePath.resolve("status.json");
Gson gson = Json.prebuild().registerTypeAdapter(GameList.class, new GameListAdapter(set.list())).create();
try (BufferedWriter wrt = Files.newBufferedWriter(statusPath)) {
wrt.write(gson.toJson(set.list()));
Log.getLogger(LogSource.STATUS).i(LogTarget.romset(set), "Romset status saved on json");
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.github.jakz.romlib.json.GameListAdapter in project rom-manager by Jakz.
the class GameSetManager method loadSetStatus.
public boolean loadSetStatus(GameSet set) {
try {
Path basePath = Paths.get("data/", set.ident());
Path settingsPath = basePath.resolve("settings.json");
try {
AssetManager assetManager = set.getAssetManager();
for (Asset asset : assetManager.getSupportedAssets()) Files.createDirectories(set.getAssetPath(asset, false));
} catch (IOException e) {
e.printStackTrace();
// TODO: log
}
if (!Files.exists(settingsPath)) {
logger.d("Unable to load game status for %s: no saved status found.", set.toString());
settings.put(set, new Settings(manager, Arrays.asList(set.getSupportedAttributes())));
return false;
} else {
try (BufferedReader rdr = Files.newBufferedReader(settingsPath)) {
Settings settings = Json.build().fromJson(rdr, Settings.class);
if (settings == null)
throw new JsonParseException("Unable to load settings for gameset " + set);
this.settings.put(set, settings);
logger.d("Loaded gameset status for %s", set.toString());
} catch (JsonParseException e) {
if (e.getCause() instanceof ClassNotFoundException)
Log.getLogger(LogSource.STATUS).e("Error while loading plugin state: %s", e.getCause().toString());
e.printStackTrace();
}
Path statusPath = basePath.resolve("status.json");
Gson gson = Json.prebuild().registerTypeAdapter(GameList.class, new GameListAdapter(set.list())).create();
try (BufferedReader rdr = Files.newBufferedReader(statusPath)) {
gson.fromJson(rdr, GameList.class);
set.refreshStatus();
logger.d("Current status: %d/%d roms in %d/%d/%d games", set.status().getFoundRomsCount(), set.info().romCount(), set.status().getCorrectCount(), set.status().getIncompleteCount(), set.info().gameCount());
if (set.hasFeature(Feature.CLONES))
set.clones().updateStatus();
return true;
} catch (NoSuchFileException e) {
return false;
}
}
} catch (FileNotFoundException e) {
return false;
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
Aggregations