use of net.heartsome.license.generator.LicenseIdGenerator in project translationstudio8 by heartsome.
the class LicenseManageDialog method okPressed.
@Override
protected void okPressed() {
LicenseIdValidator va = new LicenseIdValidator(getLicenseId());
if (va.checkLicense()) {
if (va.checkEdition()) {
setVisible(true);
try {
int r = ServiceUtil.active(getLicenseId(), bar);
if (r == Constants.ACTIVE_OK_INT) {
setVisible(false);
super.okPressed();
MessageDialog.openInformation(getShell(), Messages.getString("license.LicenseManageDialog.notice"), Messages.getString("license.LicenseManageDialog.activeSuccess"));
} else if (r == Constants.RETURN_MUTILTEMPBUNDLE_INT) {
setVisible(false);
MessageDialog.openInformation(getShell(), Messages.getString("license.LicenseManageDialog.notice"), Messages.getString("license.LicenseManageDialog.tempMutilActive"));
} else if (r == Constants.RETURN_INVALIDBUNDLE_INT) {
setVisible(false);
MessageDialog.openInformation(getShell(), Messages.getString("license.LicenseManageDialog.notice"), Messages.getString("license.LicenseManageDialog.activedLicense"));
} else if (r == Constants.RETURN_INVALIDLICENSE_INT) {
setVisible(false);
MessageDialog.openInformation(getShell(), Messages.getString("license.LicenseManageDialog.notice"), Messages.getString("license.LicenseManageDialog.infoInvalid"));
} else if (r == Constants.RETURN_EXPIREDLICENSE_INT) {
setVisible(false);
MessageDialog.openInformation(getShell(), Messages.getString("license.LicenseManageDialog.notice"), Messages.getString("license.LicenseManageDialog.expired"));
} else if (r == Constants.RETURN_STOPLICENSE_INT) {
setVisible(false);
MessageDialog.openInformation(getShell(), Messages.getString("license.LicenseManageDialog.notice"), Messages.getString("license.LicenseManageDialog.stopLicense"));
} else if (r == Constants.EXCEPTION_INT8) {
setVisible(false);
MessageDialog.openInformation(getShell(), Messages.getString("license.LicenseManageDialog.notice"), Messages.getString("license.LicenseManageDialog.activeByAdmin"));
System.exit(0);
} else {
setVisible(false);
MessageDialog.openInformation(getShell(), Messages.getString("license.LicenseManageDialog.notice"), MessageFormat.format(Messages.getString("license.LicenseManageDialog.activeFail"), StringUtils.getErrorCode(r)));
}
} catch (Exception e) {
setVisible(false);
e.printStackTrace();
Throwable t = e;
while (t.getCause() != null) {
t = t.getCause();
}
if (t instanceof java.security.cert.CertificateException) {
MessageDialog.openInformation(getShell(), Messages.getString("license.LicenseManageDialog.titleNet"), MessageFormat.format(Messages.getString("license.LicenseManageDialog.infoNet"), Constants.EXCEPTION_STRING16));
} else {
MessageDialog.openInformation(getShell(), Messages.getString("license.LicenseManageDialog.titleNet"), MessageFormat.format(Messages.getString("license.LicenseManageDialog.infoNet"), Constants.EXCEPTION_STRING17));
}
}
} else {
// MessageDialog.openInformation(getShell(), Messages.getString("license.LicenseManageDialog.titleInvalid"),
// MessageFormat.format(Messages.getString("license.LicenseManageDialog.infoInvalid1"),
// getVersionContent(System.getProperty("TSEdition")), getVersionContent(new LicenseIdGenerator(getLicenseId()).getVersion())));
String edition1 = getVersionContent(System.getProperty("TSEdition"));
String editionInput = new LicenseIdGenerator(getLicenseId()).getVersion();
String edition2 = getVersionContent(editionInput);
String message = MessageFormat.format(Messages.getString("license.LicenseManageDialog.infoInvalid1"), edition1, edition2);
ArrayList<HashMap<String, Integer>> list = new ArrayList<HashMap<String, Integer>>();
HashMap<String, Integer> map1 = new HashMap<String, Integer>();
map1.put("start", message.indexOf(edition1));
map1.put("length", edition1.length());
list.add(map1);
HashMap<String, Integer> map2 = new HashMap<String, Integer>();
map2.put("start", message.indexOf(edition2));
map2.put("length", edition2.length());
list.add(map2);
HashMap<String, Integer> map3 = new HashMap<String, Integer>();
map3.put("start", message.lastIndexOf(edition1));
map3.put("length", edition1.length());
list.add(map3);
HashMap<String, Integer> map4 = new HashMap<String, Integer>();
map4.put("start", message.lastIndexOf(edition2));
map4.put("length", edition2.length());
list.add(map4);
new CustomMessageDialog(getShell(), Messages.getString("license.LicenseManageDialog.titleInvalid"), message, list, editionInput).open();
}
} else {
MessageDialog.openInformation(getShell(), Messages.getString("license.LicenseManageDialog.titleInvalid"), Messages.getString("license.LicenseManageDialog.infoInvalid"));
}
}
use of net.heartsome.license.generator.LicenseIdGenerator in project translationstudio8 by heartsome.
the class LicenseManageDialog method createStatusComp.
private void createStatusComp(Composite parent) {
Group statusGroup = new Group(parent, SWT.NONE);
statusGroup.setText(Messages.getString("license.LicenseManageDialog.statusGroup"));
GridData dataStatusGroup = new GridData(GridData.GRAB_HORIZONTAL | GridData.FILL_HORIZONTAL);
dataStatusGroup.heightHint = 150;
statusGroup.setLayoutData(dataStatusGroup);
statusGroup.setLayout(new GridLayout());
GridData data = new GridData(GridData.GRAB_HORIZONTAL | GridData.FILL_HORIZONTAL);
RowLayout layout = new RowLayout();
layout.center = true;
Composite comp0 = new Composite(statusGroup, SWT.NONE);
comp0.setLayoutData(data);
comp0.setLayout(layout);
Label statusLbl = new Label(comp0, SWT.NONE);
statusLbl.setText(Messages.getString("license.LicenseManageDialog.statusLabel"));
if (type == Constants.STATE_NOT_ACTIVATED) {
Label statusLbl1 = new Label(comp0, SWT.NONE);
statusLbl1.setText(Messages.getString("license.LicenseManageDialog.notActiveLabel"));
} else if (type == Constants.STATE_VALID) {
Label statusLbl1 = new Label(comp0, SWT.NONE);
statusLbl1.setText(Messages.getString("license.LicenseManageDialog.activeLabel"));
new Label(comp0, SWT.NONE).setLayoutData(new RowData(30, SWT.DEFAULT));
Button btnCancelActive = new Button(comp0, SWT.NONE);
btnCancelActive.setText(Messages.getString("license.LicenseManageDialog.cancelActiveButton"));
btnCancelActive.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
boolean result = MessageDialog.openConfirm(getShell(), Messages.getString("license.LicenseManageDialog.confirm"), Messages.getString("license.LicenseManageDialog.confirmMessage"));
if (result) {
try {
int re = ServiceUtil.cancel();
if (re == Constants.LOGOUT_SUCCESS) {
MessageDialog.openInformation(getShell(), Messages.getString("license.LicenseManageDialog.notice"), Messages.getString("license.LicenseManageDialog.unactiveSuccess"));
LicenseManageDialog.this.close();
PlatformUI.getWorkbench().restart();
} else {
MessageDialog.openInformation(getShell(), Messages.getString("license.LicenseManageDialog.notice"), Messages.getString("license.LicenseManageDialog.unactiveFail"));
}
} catch (Exception e1) {
e1.printStackTrace();
Throwable t = e1;
while (t.getCause() != null) {
t = t.getCause();
}
if (t instanceof java.security.cert.CertificateException) {
MessageDialog.openInformation(getShell(), Messages.getString("license.LicenseManageDialog.titleNet"), MessageFormat.format(Messages.getString("license.LicenseManageDialog.infoNet"), Constants.EXCEPTION_STRING16));
} else {
MessageDialog.openInformation(getShell(), Messages.getString("license.LicenseManageDialog.titleNet"), MessageFormat.format(Messages.getString("license.LicenseManageDialog.infoNet"), Constants.EXCEPTION_STRING17));
}
}
}
}
});
Composite comp1 = new Composite(statusGroup, SWT.NONE);
comp1.setLayoutData(data);
comp1.setLayout(layout);
Label typeLbl = new Label(comp1, SWT.NONE);
typeLbl.setText(Messages.getString("license.LicenseManageDialog.typeLabel"));
Label typeLbl1 = new Label(comp1, SWT.NONE);
typeLbl1.setText(Messages.getString(utilDate == null ? "license.LicenseManageDialog.typeBusiness" : "license.LicenseManageDialog.typeTemp"));
if (utilDate != null) {
Composite comp2 = new Composite(statusGroup, SWT.NONE);
comp2.setLayoutData(data);
comp2.setLayout(layout);
Label typeLbl2 = new Label(comp2, SWT.NONE);
typeLbl2.setText(Messages.getString("license.LicenseManageDialog.utilDate"));
Label dateLbl = new Label(comp2, SWT.NONE);
dateLbl.setText(utilDate);
}
} else if (type == Constants.STATE_INVALID) {
Label statusLbl1 = new Label(comp0, SWT.NONE);
statusLbl1.setText(Messages.getString("license.LicenseManageDialog.invalidLicense"));
} else if (type == Constants.STATE_EXPIRED) {
Label statusLbl1 = new Label(comp0, SWT.NONE);
statusLbl1.setText(Messages.getString("license.LicenseManageDialog.expired"));
Composite comp1 = new Composite(statusGroup, SWT.NONE);
comp1.setLayoutData(data);
comp1.setLayout(layout);
Label typeLbl = new Label(comp1, SWT.NONE);
typeLbl.setText(Messages.getString("license.LicenseManageDialog.typeLabel"));
Label typeLbl1 = new Label(comp1, SWT.NONE);
typeLbl1.setText(Messages.getString(utilDate == null ? "license.LicenseManageDialog.typeBusiness" : "license.LicenseManageDialog.typeTemp"));
if (utilDate != null) {
Composite comp2 = new Composite(statusGroup, SWT.NONE);
comp2.setLayoutData(data);
comp2.setLayout(layout);
Label typeLbl2 = new Label(comp2, SWT.NONE);
typeLbl2.setText(Messages.getString("license.LicenseManageDialog.utilDate"));
Label dateLbl = new Label(comp2, SWT.NONE);
dateLbl.setText(utilDate);
}
} else if (type == Constants.EXCEPTION_INT16 || type == Constants.EXCEPTION_INT17) {
Label statusLbl1 = new Label(comp0, SWT.NONE);
statusLbl1.setText(Messages.getString("license.LicenseManageDialog.unvalidate"));
Composite comp1 = new Composite(statusGroup, SWT.NONE);
GridData data1 = new GridData(GridData.GRAB_HORIZONTAL | GridData.FILL_BOTH);
comp1.setLayoutData(data1);
GridLayout layout1 = new GridLayout();
comp1.setLayout(layout1);
Label noticeLbl = new Label(comp1, SWT.WRAP);
GridData dataLabel = new GridData(GridData.FILL_HORIZONTAL);
noticeLbl.setLayoutData(dataLabel);
noticeLbl.setText(MessageFormat.format(Messages.getString("license.LicenseManageDialog.noticeLbl"), StringUtils.getErrorCode(type)));
} else if (type == Constants.EXCEPTION_INT14) {
Label statusLbl1 = new Label(comp0, SWT.NONE);
statusLbl1.setText(Messages.getString("license.LicenseManageDialog.licenseException"));
Composite comp1 = new Composite(statusGroup, SWT.NONE);
GridData data1 = new GridData(GridData.GRAB_HORIZONTAL | GridData.FILL_BOTH);
comp1.setLayoutData(data1);
GridLayout layout1 = new GridLayout();
comp1.setLayout(layout1);
Label noticeLbl = new Label(comp1, SWT.WRAP);
GridData dataLabel = new GridData(GridData.FILL_HORIZONTAL);
noticeLbl.setLayoutData(dataLabel);
noticeLbl.setText(MessageFormat.format(Messages.getString("license.LicenseManageDialog.noSameVersion"), getVersionContent(System.getProperty("TSEdition")), getVersionContent(new LicenseIdGenerator(licenseId).getVersion())));
} else if (type == Constants.EXCEPTION_INT15) {
Label statusLbl1 = new Label(comp0, SWT.NONE);
statusLbl1.setText(Messages.getString("license.LicenseManageDialog.licenseException"));
Composite comp1 = new Composite(statusGroup, SWT.NONE);
GridData data1 = new GridData(GridData.GRAB_HORIZONTAL | GridData.FILL_BOTH);
comp1.setLayoutData(data1);
GridLayout layout1 = new GridLayout();
comp1.setLayout(layout1);
Label noticeLbl = new Label(comp1, SWT.WRAP);
GridData dataLabel = new GridData(GridData.FILL_HORIZONTAL);
noticeLbl.setLayoutData(dataLabel);
noticeLbl.setText(Messages.getString("license.LicenseManageDialog.maccodeError"));
} else if (type == Constants.EXCEPTION_INT1 || type == Constants.EXCEPTION_INT2 || type == Constants.EXCEPTION_INT3 || type == Constants.EXCEPTION_INT4) {
Label statusLbl1 = new Label(comp0, SWT.NONE);
statusLbl1.setText(Messages.getString("license.LicenseManageDialog.licenseException"));
Composite comp1 = new Composite(statusGroup, SWT.NONE);
GridData data1 = new GridData(GridData.GRAB_HORIZONTAL | GridData.FILL_BOTH);
comp1.setLayoutData(data1);
GridLayout layout1 = new GridLayout();
comp1.setLayout(layout1);
Label noticeLbl = new Label(comp1, SWT.WRAP);
GridData dataLabel = new GridData(GridData.FILL_HORIZONTAL);
noticeLbl.setLayoutData(dataLabel);
noticeLbl.setText(MessageFormat.format(Messages.getString("license.LicenseManageDialog.licenseExceptionInfo1"), StringUtils.getErrorCode(type)));
} else {
Label statusLbl1 = new Label(comp0, SWT.NONE);
statusLbl1.setText(Messages.getString("license.LicenseManageDialog.licenseException"));
Composite comp1 = new Composite(statusGroup, SWT.NONE);
GridData data1 = new GridData(GridData.GRAB_HORIZONTAL | GridData.FILL_BOTH);
comp1.setLayoutData(data1);
GridLayout layout1 = new GridLayout();
comp1.setLayout(layout1);
Label noticeLbl = new Label(comp1, SWT.WRAP);
GridData dataLabel = new GridData(GridData.FILL_HORIZONTAL);
noticeLbl.setLayoutData(dataLabel);
noticeLbl.setText(MessageFormat.format(Messages.getString("license.LicenseManageDialog.licenseExceptionInfo"), StringUtils.getErrorCode(type)));
}
}
use of net.heartsome.license.generator.LicenseIdGenerator in project translationstudio8 by heartsome.
the class OfflineActiveDialog method okPressed.
@Override
protected void okPressed() {
LicenseIdValidator va = new LicenseIdValidator(getLicenseId());
if (va.checkLicense()) {
if (va.getType()) {
MessageDialog.openInformation(getShell(), Messages.getString("license.LicenseManageDialog.notice"), Messages.getString("license.OfflineActiveDialog.onlyCommercial"));
} else {
if (va.checkEdition()) {
String series = ProtectionFactory.getSeries();
if (series == null || "".equals(series)) {
MessageDialog.openInformation(getShell(), Messages.getString("license.LicenseManageDialog.notice"), MessageFormat.format(Messages.getString("license.OfflineActiveDialog.getActiveKeyFail"), StringUtils.getErrorCode(Constants.EXCEPTION_INT5)));
return;
}
String installKey = null;
OffLineActiveService v = new OffLineActiveService();
if (FileUtils.isExsitInstall()) {
int r = v.readInstallFile();
if (r == Constants.EXCEPTION_INT3 || r == Constants.EXCEPTION_INT4) {
MessageDialog.openInformation(getShell(), Messages.getString("license.LicenseManageDialog.notice"), MessageFormat.format(Messages.getString("license.OfflineActiveDialog.getActiveKeyFail"), StringUtils.getErrorCode(r)));
return;
} else {
installKey = v.getInstallKey();
}
} else {
int r = v.generateInstallFile();
if (r == Constants.EXCEPTION_INT8) {
MessageDialog.openInformation(getShell(), Messages.getString("license.LicenseManageDialog.notice"), Messages.getString("license.OfflineActiveDialog.getActiveKeyByAdmin"));
System.exit(0);
} else if (r == Constants.EXCEPTION_INT10 || r == Constants.EXCEPTION_INT11) {
MessageDialog.openInformation(getShell(), Messages.getString("license.LicenseManageDialog.notice"), MessageFormat.format(Messages.getString("license.OfflineActiveDialog.getActiveKeyFail"), StringUtils.getErrorCode(r)));
return;
} else {
installKey = v.getInstallKey();
}
}
IKeyGenerator gen = new KeyGeneratorImpl();
byte[] k = gen.generateKey(getLicenseId(), series, installKey, OffLineEncrypt.publicKey);
Point p = getShell().getLocation();
super.okPressed();
GetActiveKeyDialog dialog = new GetActiveKeyDialog(getShell(), StringUtils.toHexString(k), p);
int result = dialog.open();
if (result != IDialogConstants.OK_ID) {
System.exit(0);
}
} else {
String edition1 = getVersionContent(System.getProperty("TSEdition"));
String editionInput = new LicenseIdGenerator(getLicenseId()).getVersion();
String edition2 = getVersionContent(editionInput);
String message = MessageFormat.format(Messages.getString("license.LicenseManageDialog.infoInvalid1"), edition1, edition2);
ArrayList<HashMap<String, Integer>> list = new ArrayList<HashMap<String, Integer>>();
HashMap<String, Integer> map1 = new HashMap<String, Integer>();
map1.put("start", message.indexOf(edition1));
map1.put("length", edition1.length());
list.add(map1);
HashMap<String, Integer> map2 = new HashMap<String, Integer>();
map2.put("start", message.indexOf(edition2));
map2.put("length", edition2.length());
list.add(map2);
HashMap<String, Integer> map3 = new HashMap<String, Integer>();
map3.put("start", message.lastIndexOf(edition1));
map3.put("length", edition1.length());
list.add(map3);
HashMap<String, Integer> map4 = new HashMap<String, Integer>();
map4.put("start", message.lastIndexOf(edition2));
map4.put("length", edition2.length());
list.add(map4);
new CustomMessageDialog(getShell(), Messages.getString("license.LicenseManageDialog.titleInvalid"), message, list, editionInput).open();
}
}
} else {
MessageDialog.openInformation(getShell(), Messages.getString("license.LicenseManageDialog.titleInvalid"), Messages.getString("license.LicenseManageDialog.infoInvalid"));
}
}
use of net.heartsome.license.generator.LicenseIdGenerator in project translationstudio8 by heartsome.
the class LicenseIdValidator method checkLicense.
public boolean checkLicense(String licenseId) {
if (licenseId.length() != 24) {
return false;
}
LicenseIdGenerator gen = new LicenseIdGenerator(licenseId);
String temp = gen.getIsTrial();
if (!Constants.TYPE_TMEP.equals(temp) && !Constants.TYPE_BUSINESS.equals(temp)) {
return false;
}
isTrial = Constants.TYPE_TMEP.equals(temp);
if (!System.getProperty("TSVersion").equals(gen.getProductId())) {
return false;
}
if (!System.getProperty("TSEdition").equals(gen.getVersion())) {
return false;
}
return true;
}
Aggregations