use of org.terasology.rendering.nui.layers.mainMenu.FilePickerPopup in project Terasology by MovingBlocks.
the class IdentityIOHelper method importIdentities.
public void importIdentities() {
FilePickerPopup filePicker = nuiManager.pushScreen(FilePickerPopup.ASSET_URI, FilePickerPopup.class);
filePicker.setTitle(importPopupTitle);
filePicker.setOkHandler(path -> {
Map<PublicIdentityCertificate, ClientIdentity> newIdentities;
try (BufferedReader reader = Files.newBufferedReader(path)) {
newIdentities = GSON.fromJson(reader, MAP_TYPE);
} catch (IOException | JsonIOException | JsonSyntaxException ex) {
nuiManager.pushScreen(MessagePopup.ASSET_URI, MessagePopup.class).setMessage(translationSystem.translate("${engine:menu#identity-import-failed}"), ex.toString());
return;
}
checkNextConflict(newIdentities.entrySet().iterator(), () -> {
newIdentities.forEach(securityConfig::addIdentity);
nuiManager.pushScreen(MessagePopup.ASSET_URI, MessagePopup.class).setMessage(importPopupTitle, newIdentities.isEmpty() ? translationSystem.translate("${engine:menu#identity-import-no-new}") : String.format(translationSystem.translate("${engine:menu#identity-import-ok}"), newIdentities.size()));
});
});
}
use of org.terasology.rendering.nui.layers.mainMenu.FilePickerPopup in project Terasology by MovingBlocks.
the class IdentityIOHelper method exportIdentities.
public void exportIdentities() {
FilePickerPopup filePicker = nuiManager.pushScreen(FilePickerPopup.ASSET_URI, FilePickerPopup.class);
filePicker.setTitle(exportPopupTitle);
filePicker.setOkHandler(path -> {
Runnable action = () -> {
Map<PublicIdentityCertificate, ClientIdentity> identities = securityConfig.getAllIdentities();
try (BufferedWriter writer = Files.newBufferedWriter(path, StandardOpenOption.CREATE)) {
GSON.toJson(identities, MAP_TYPE, writer);
nuiManager.pushScreen(MessagePopup.ASSET_URI, MessagePopup.class).setMessage(exportPopupTitle, String.format(translationSystem.translate("${engine:menu#identity-export-ok}"), identities.size(), path.toString()));
} catch (IOException | JsonIOException ex) {
nuiManager.pushScreen(MessagePopup.ASSET_URI, MessagePopup.class).setMessage(translationSystem.translate("${engine:menu#identity-export-fail}"), ex.toString());
}
};
if (Files.exists(path)) {
ConfirmPopup confirm = nuiManager.pushScreen(ConfirmPopup.ASSET_URI, ConfirmPopup.class);
confirm.setMessage(exportPopupTitle, String.format(translationSystem.translate("${engine:menu#existing-file-warning}"), path.toString()));
confirm.setOkHandler(action);
} else {
action.run();
}
});
}
Aggregations