blob: 18fc305dc1ce323977835fbcecbf9896c3715465 (
plain) (
tree)
|
|
package org.openslx.dozmod.gui.window;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import org.apache.commons.io.IOUtils;
import org.apache.hc.client5.http.utils.Hex;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.openslx.dozmod.Config;
import org.openslx.dozmod.gui.helper.UiFeedback;
import org.openslx.dozmod.util.ResourceLoader;
/**
* Window for showing the disclaimer.
*/
public class DisclaimerWindow extends GenericNoticeWindow implements UiFeedback {
/**
* Version for serialization.
*/
private static final long serialVersionUID = 8479978304760663L;
private final static Logger LOGGER = LogManager.getLogger(PrivacyNoticeWindow.class);
final DisclaimerWindow me = this;
protected String DISCLAIMER_NOTICE;
private static String DISCLAIMER_NOTICE_MD5 = null;
private static String DISCLAIMER_NOTICE_CONTENT = null;
static {
try (InputStream noticeStream = ResourceLoader.getStream("/txt/disclaimer_notice")) {
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] content = IOUtils.toByteArray(noticeStream);
md.update(content);
byte[] md5 = md.digest();
DISCLAIMER_NOTICE_CONTENT = new String(content, StandardCharsets.UTF_8);
DISCLAIMER_NOTICE_MD5 = Hex.encodeHexString(md5).toUpperCase();
} catch (IOException | NoSuchAlgorithmException e) {
LOGGER.error("Failed to get hash of disclaimer notice: ", e);
}
}
public DisclaimerWindow(Frame modalParent) {
super(modalParent, shouldBeShown());
// Set the actual text
setNoticeText(DISCLAIMER_NOTICE_CONTENT);
// function for continue button
btnContinue.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// save the agreement to config
Config.setDisclaimerAgreement(Config.getDisclaimerAgreement()
.replace(DISCLAIMER_NOTICE_MD5, "")
.concat(DISCLAIMER_NOTICE_MD5));
me.dispose();
}
});
}
public static boolean shouldBeShown() {
return !Config.getDisclaimerAgreement().contains(DISCLAIMER_NOTICE_MD5);
}
public static void open(Frame modalParent) {
new DisclaimerWindow(modalParent).setVisible(true);
}
}
|