From 9ed189e65122c1efad2f441ab4a91e8e7134aeb9 Mon Sep 17 00:00:00 2001 From: "Allan C. M. Lira" Date: Fri, 19 Jun 2020 08:40:20 -0300 Subject: [PATCH] Removes activation key: tc.Deploy no longer require an activation key (#53) * Removes activation key: tc.Deploy no longer require an activation key - tc.Deploy no longer check/use the key but the /r option on deploy command line still can be used without errors; - Removes /r option from the standard help; - DeploySettings.rasKey is no longer filled; - GlobalConstantPool no longer provide a "free sdk limitation" if DeploySettings.rasKey is null because TC is FOSSA * Removes activation key: RegisterSDK class is no longer being used - Removes RegisterSDK because is no longer being used; - tc.Deploy: - Affected by deletion of RegisterSDK - Fix /r case arg skip; - Removes FREE_BLOCKED_PLATFORMS - Removes Convert import (no longer used) - Launcher: - Affected by deletion of RegisterSDK - No longer has the key insertion screen - Remove /r from instructions helper - Remove track of TC usage - Fix some warnings * Removes activation key: DeploySettings.hasKey no longer makes sense - Removes hasKey and isFreeSDK attributes from DeploySettings - the above changes have affected tc.Deploy/J2TC and the errors have been corrected --- TotalCrossSDK/src/main/java/tc/Deploy.java | 39 +-- .../src/main/java/tc/tools/RegisterSDK.java | 314 ------------------ .../java/tc/tools/RegisterSDKException.java | 15 - .../tools/converter/GlobalConstantPool.java | 9 - .../main/java/tc/tools/converter/J2TC.java | 33 +- .../tc/tools/deployer/DeploySettings.java | 3 - .../src/main/java/totalcross/Launcher.java | 132 +------- 7 files changed, 10 insertions(+), 535 deletions(-) delete mode 100644 TotalCrossSDK/src/main/java/tc/tools/RegisterSDK.java delete mode 100644 TotalCrossSDK/src/main/java/tc/tools/RegisterSDKException.java diff --git a/TotalCrossSDK/src/main/java/tc/Deploy.java b/TotalCrossSDK/src/main/java/tc/Deploy.java index ed879f0489..a02a1ab00c 100644 --- a/TotalCrossSDK/src/main/java/tc/Deploy.java +++ b/TotalCrossSDK/src/main/java/tc/Deploy.java @@ -11,7 +11,6 @@ import java.util.Calendar; import tc.tools.JarClassPathLoader; -import tc.tools.RegisterSDK; import tc.tools.converter.J2TC; import tc.tools.deployer.Bitmaps; import tc.tools.deployer.DeploySettings; @@ -24,7 +23,6 @@ import tc.tools.deployer.Deployer4LinuxArm; import tc.tools.deployer.DeployerException; import tc.tools.deployer.Utils; -import totalcross.sys.Convert; import totalcross.util.ElementNotFoundException; import totalcross.util.IntHashtable; @@ -47,14 +45,9 @@ public static void main(String[] args) throws Exception { public static final int BUILD_IPHONE = 128; public static final int BUILD_ANDROID = 256; public static final int BUILD_WINMO = 512; // guich@tc125_17 - private static int FREE_BLOCKED_PLATFORMS = BUILD_WINCE | BUILD_WINMO | BUILD_LINUX; public static final int BUILD_ALL = 0xFFFF; - public static final String FREE_EXCLUDED_CLASSES = "totalcross.io.device.gps,litebase,totalcross.map,"; - public static final int FREE_MAX_SIZE = 150000; - private boolean waitIfError; // guich@tc111_24 - public static String activationKey; public Deploy(String[] args) throws Exception { try { @@ -71,7 +64,6 @@ public Deploy(String[] args) throws Exception { // tc.tools.Deploy palm wince win32 linux bb String fileName = args[0]; int options = parseOptions(args); - new RegisterSDK(activationKey); Deployer4IPhoneIPA.iosKeystoreInit(); @@ -358,15 +350,7 @@ public boolean accept(File dir, String fileName) { DeploySettings.quiet = false; break; case 'r': - String key = args[++i].toUpperCase(); - if (key.startsWith("%")) { - key = System.getenv(key.substring(1, key.length() - 1)); - } - if (key == null || key.length() != 24) { - throw new DeployerException( - "The key must be specified in the following format: XXXXXXXXXXXXXXXXXXXXXXXX; optionally, you can use %key% to refer to an environment variable"); - } - activationKey = key; + i++; // Ignore next argument break; case 't': DeploySettings.testClass = true; @@ -400,26 +384,6 @@ public boolean accept(File dir, String fileName) { } } } - if (activationKey == null) { - activationKey = RegisterSDK.getStoredActivationKey(); - } - if (activationKey == null) { - throw new DeployerException( - "You must provide a registration key! If you're a PROFESSIONAL or ENTERPRISE, go to the TotalCross site and login into your account; the SDK key will be shown. If you're a STARTER, the key was sent to the email that you used to download the SDK."); - } else { - DeploySettings.rasKey = Convert.hexStringToBytes(activationKey, true); - DeploySettings.isFreeSDK = new String(DeploySettings.rasKey, 0, 4).equals("TCST"); - System.out.println("The application was signed with the given registration key."); - - if (DeploySettings.isFreeSDK) { - if (options == BUILD_ALL) { - options &= ~FREE_BLOCKED_PLATFORMS; - } else if ((options & FREE_BLOCKED_PLATFORMS) != 0) { - throw new DeployerException( - "The free SDK does not allow deployments to these platforms: wince, winmo, win32, linux"); - } - } - } return options; } @@ -467,7 +431,6 @@ private void usage() { + " /p : Package the vm and litebase with the application, creating a single installation file. " + "The SDK must be in the path or in the TOTALCROSS3_HOME environment variable. " + "The files are always installed at the same folder of the application, so each application will have its own vm.\n" - + " /r key : Specify a registration key to be used to activate TotalCross when required\n" + " /t : Just test the classes to see if there are any invalid references. Images are not converted, and nothing is written to disk.\n" + " /v : Verbose output for information messages\n" + " /w : Waits for a key press if an error occurs\n" diff --git a/TotalCrossSDK/src/main/java/tc/tools/RegisterSDK.java b/TotalCrossSDK/src/main/java/tc/tools/RegisterSDK.java deleted file mode 100644 index 5ac55bf621..0000000000 --- a/TotalCrossSDK/src/main/java/tc/tools/RegisterSDK.java +++ /dev/null @@ -1,314 +0,0 @@ -// Copyright (C) 2000-2013 SuperWaba Ltda. -// Copyright (C) 2014-2020 TotalCross Global Mobile Platform Ltda. -// -// SPDX-License-Identifier: LGPL-2.1-only - -package tc.tools; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.URL; -import java.net.URLConnection; -import java.net.UnknownHostException; -import java.nio.charset.Charset; -import java.security.InvalidKeyException; -import java.security.Key; -import java.security.NoSuchAlgorithmException; -import java.util.HashMap; -import java.util.zip.Deflater; -import java.util.zip.DeflaterOutputStream; - -import javax.crypto.BadPaddingException; -import javax.crypto.Cipher; -import javax.crypto.IllegalBlockSizeException; -import javax.crypto.NoSuchPaddingException; -import javax.crypto.spec.SecretKeySpec; - -import net.harawata.appdirs.AppDirsFactory; -import tc.tools.deployer.Utils; - -public final class RegisterSDK { - private static final String MAGIC = "T0T@LCR0$$"; - private static final int DATE_MASK = 0xBADCFE; - - private static final int INVALID_DATE = -1000; - private static final int INVALID_REGISTRATION_KEY = -1001; - private static final int EXPIRED_CONTRACT = -1002; - private static final int NO_MORE_DEVELOPERS = -1003; - private static final int CONTRACT_NOT_ACTIVE = -1004; - private static final int INVALID_COMPANY = -1005; - private static final int CONTRACT_DEACTIVATED = -1006; - private static final int DEVICE_DISABLED = -1007; - - private String user, home, key; - private int today; - private File flicense; - - public RegisterSDK(String key, String user) throws Exception { - this(key, false); - storeActivationKey(key); - } - - public RegisterSDK(String newkey) throws Exception { - this(newkey, false); - } - - private RegisterSDK(String key, boolean force) throws Exception { - this.key = key; - if (key.startsWith("54435354")) { - return; - } - if (key.length() != 24) { - throw new RegisterSDKException("The key is incorrect"); - } - today = Utils.getToday(); - user = System.getProperty("user.name"); - home = System.getProperty("user.home"); - flicense = new File(home + "/" + key + ".key"); - if (force || !flicense.exists()) { - updateLicense(); - } - int ret = checkLicense(); - if (ret == EXPIRED || ret == OLD || ret == INVALID) // if expired or last activation occured after 8 hours - { - updateLicense(); - if (checkLicense() == EXPIRED) { - throw new RegisterSDKException("The license is expired"); - } - } - if (giexp != -1) { - System.out.println("Next SDK expiration date: " + showDate(giexp)); - } - } - - public static void main(String[] args) { - if (args.length != 1) { - System.out.println("Format: tc.tools.RegisterSDK "); - } else { - try { - new RegisterSDK(args[0], true); - } catch (Exception e) { - e.printStackTrace(); - } - } - } - - private byte[] doCrypto(boolean encrypt, byte[] in) throws NoSuchAlgorithmException, NoSuchPaddingException, - InvalidKeyException, IllegalBlockSizeException, BadPaddingException { - char[] keystr = (key + "CAFEBABE").toCharArray(); - byte[] keybytes = new byte[16]; - for (int i = 0, n = keystr.length; i < n; i += 2) { - keybytes[i / 2] = (byte) Integer.valueOf("" + keystr[i] + keystr[i + 1], 16).intValue(); - } - - Key secretKey = new SecretKeySpec(keybytes, "AES"); - Cipher cipher = Cipher.getInstance("AES"); - cipher.init(encrypt ? Cipher.ENCRYPT_MODE : Cipher.DECRYPT_MODE, secretKey); - return cipher.doFinal(in); - } - - private static final int EXPIRED = 0; - private static final int OLD = -1; - private static final int VALID = -2; - private static final int INVALID = -3; - - private int giexp = -1; - - private int checkLicense() throws Exception { - try { - // read license file - InputStream in = new FileInputStream(flicense); - byte[] fin = new byte[in.available()]; - in.read(fin); - in.close(); - // use the key passed to launcher - byte[] bin = doCrypto(false, fin); - DataInputStream ds = new DataInputStream(new ByteArrayInputStream(bin)); - // skip trash - int xdataLen = Math.abs(key.hashCode() % 1000); - ds.skip(xdataLen); - // checks if the magic equals - boolean magicEquals = false; - try { - String magic = ds.readUTF(); - magicEquals = magic.equals(MAGIC); - } catch (Exception e) { - } - if (!magicEquals) { - System.out.println( - "This license key does not correspond to the stored key! Requesting new license with current key..."); - return INVALID; - } - // read the rest of stored data and compare with current values - String skv = ds.readUTF(); - HashMap kv = Utils.pipeSplit(skv); - String storedUser = kv.get("user"); - String storedFolder = kv.get("home"); - int iexp = ds.readInt(); - // check if user has changed the time - long storedTimestamp = ds.readLong(); - long currentTimestamp = System.currentTimeMillis(); - long hoursElapsed = (currentTimestamp - storedTimestamp) / (60 * 60 * 1000); - if (hoursElapsed < 0) { - throw new RegisterSDKException("The computer's time is invalid."); - } - boolean expired = today >= iexp; - - int diffU = storedUser.equals(user) ? 0 : 1; - int diffF = storedFolder.equals(home) ? 0 : 2; - int diff = diffU | diffF; - - if (diff != 0) { - System.out.println("The license parameters have changed (#" + diff + "). A new license will be requested"); - } else { - giexp = iexp; - } - return diff != 0 ? INVALID : expired ? EXPIRED : hoursElapsed > 12 ? OLD : VALID; - } catch (FileNotFoundException fnfe) { - throw new RegisterSDKException("License not found! Check if this computer's internet is available."); - } catch (javax.crypto.BadPaddingException bpe) { - System.out.println( - "This license key does not correspond to the stored key! Requesting new license with current key..."); - return INVALID; - } - } - - private void updateLicense() throws Exception { - try { - // connect to the registration service and validate the key and mac. - int expdate = getExpdateFromServer(); - if (expdate <= 0) { - switch (expdate) { - case INVALID_DATE: - throw new RegisterSDKException("Please update your computer's date."); - case INVALID_REGISTRATION_KEY: - throw new RegisterSDKException("The registration key is invalid."); - case EXPIRED_CONTRACT: - throw new RegisterSDKException("The contract is EXPIRED."); - case NO_MORE_DEVELOPERS: - throw new RegisterSDKException("The number of active developers has been reached."); - case CONTRACT_NOT_ACTIVE: - throw new RegisterSDKException( - "This contract is not yet active. Please send email to renato@totalcross.com with your registration key."); - case INVALID_COMPANY: - throw new RegisterSDKException("Invalid company"); - case CONTRACT_DEACTIVATED: - throw new RegisterSDKException( - "The contract is suspended due to payment reasons. Please contact renato@totalcross.com."); - case DEVICE_DISABLED: - throw new RegisterSDKException("This device is disabled."); - } - } else { - ByteArrayOutputStream baos = new ByteArrayOutputStream(128); - DataOutputStream ds = new DataOutputStream(baos); - // generate fake data to put before and at end of important data - java.util.Random r = new java.util.Random(expdate); - int xdataLen = Math.abs(key.hashCode() % 1000); - byte[] xdata = new byte[xdataLen]; - r.nextBytes(xdata); - ds.write(xdata); - // write important data - ds.writeUTF(MAGIC); - ds.writeUTF(Utils.pipeConcat("home", home, "user", user)); // MUST BE ALPHABETHICAL ORDER! - ds.writeInt(expdate); - ds.writeLong(System.currentTimeMillis()); - // write fake data at end - r.nextBytes(xdata); - ds.write(xdata); - ds.close(); - byte[] bytes = baos.toByteArray(); - byte[] cript = doCrypto(true, bytes); - OutputStream out = new FileOutputStream(flicense); - out.write(cript); - out.close(); - } - } catch (RegisterSDKException rse) { - throw rse; - } catch (UnknownHostException uhe) { - System.out.println( - "INTERNET NOT AVAILABLE! TotalCross requires activation of the SDK. Once the date below is reached, the SDK will block."); - } catch (Throwable e) { - System.out.println("Exception during license update: " + e.getClass().getSimpleName() + " - " + e.getMessage()); - } - } - - private int getExpdateFromServer() throws IOException { - // zip data - ByteArrayOutputStream bas = new ByteArrayOutputStream(256); - Deflater dd = new Deflater(9, false); - DeflaterOutputStream def = new DeflaterOutputStream(bas, dd); - DataOutputStream ds = new DataOutputStream(def); - ds.writeUTF(key); - ds.writeUTF(Utils.pipeConcat("home", home, "user", user)); // MUST BE ALPHABETHICAL ORDER! - ds.writeInt(today); - def.finish(); - dd.end(); - byte[] bytes = bas.toByteArray(); - - // prepare connection - URLConnection con = new URL("http://www.superwaba.net/SDKRegistrationService/SDKRegistration").openConnection(); - con.setRequestProperty("Request-Method", "POST"); - con.setConnectTimeout(5000); - con.setUseCaches(false); - con.setDoOutput(true); - con.setDoInput(true); - - // send data - OutputStream os = con.getOutputStream(); - os.write(bytes); - os.close(); - - // get response - the expiration date or a negative value for error codes - InputStream in = con.getInputStream(); - DataInputStream dis = new DataInputStream(in); - int expdate = dis.readInt() ^ DATE_MASK; - int expcontract = dis.readInt() ^ DATE_MASK; - if (expcontract != 0) { - System.out.println("INFO: the contract will expire at " + showDate(expcontract)); - } - dis.close(); - in.close(); - - return expdate; - } - - private String showDate(int d) { - int day = d % 100; - int month = d / 100 % 100; - int year = d / 10000; - return day + " " + totalcross.util.Date.monthNames[month] + ", " + year; - } - - public static String getStoredActivationKey() { - String activationKey = null; - try (FileInputStream fis = new FileInputStream( - new File(AppDirsFactory.getInstance().getUserDataDir(null, null, "TotalCross"), "key.dat"))) { - byte[] b = new byte[24]; - fis.read(b); - activationKey = new String(b, "UTF-8"); - } catch (FileNotFoundException e) { - } catch (java.io.IOException e) { - e.printStackTrace(); - } - return activationKey; - } - - private static void storeActivationKey(String activationKey) throws IOException { - File parent = new File(AppDirsFactory.getInstance().getUserDataDir(null, null, "TotalCross")); - if (!parent.exists()) { - parent.mkdirs(); - } - try (FileOutputStream fos = new FileOutputStream(new File(parent, "key.dat"))) { - fos.write(activationKey.getBytes(Charset.forName("UTF-8"))); - } - } -} diff --git a/TotalCrossSDK/src/main/java/tc/tools/RegisterSDKException.java b/TotalCrossSDK/src/main/java/tc/tools/RegisterSDKException.java deleted file mode 100644 index f129e5483e..0000000000 --- a/TotalCrossSDK/src/main/java/tc/tools/RegisterSDKException.java +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (C) 2000-2013 SuperWaba Ltda. -// Copyright (C) 2014-2020 TotalCross Global Mobile Platform Ltda. -// -// SPDX-License-Identifier: LGPL-2.1-only - -package tc.tools; - -public class RegisterSDKException extends Exception { - public RegisterSDKException(String s) { - super(s); - } - - public RegisterSDKException() { - } -} diff --git a/TotalCrossSDK/src/main/java/tc/tools/converter/GlobalConstantPool.java b/TotalCrossSDK/src/main/java/tc/tools/converter/GlobalConstantPool.java index 770d0e2f32..e629116832 100644 --- a/TotalCrossSDK/src/main/java/tc/tools/converter/GlobalConstantPool.java +++ b/TotalCrossSDK/src/main/java/tc/tools/converter/GlobalConstantPool.java @@ -402,15 +402,6 @@ private static int putField(Hashtable ht, Vector v, int type, String className, value = to; } - // free sdk limitation - if (DeploySettings.rasKey == null && value.indexOf('.') != -1) { - String pkg = value.substring(0, value.lastIndexOf('.')); - if (Deploy.FREE_EXCLUDED_CLASSES.indexOf(pkg + ",") != -1) { - throw new DeployerException("The class " + value + " is not allowed in the FREE SDK. The excluded classes are: " - + Deploy.FREE_EXCLUDED_CLASSES); - } - } - if (htCls.exists(value)) { return ((TCValue) htCls.get(value)).index; } diff --git a/TotalCrossSDK/src/main/java/tc/tools/converter/J2TC.java b/TotalCrossSDK/src/main/java/tc/tools/converter/J2TC.java index af1c98eccd..60e3ed7b2a 100644 --- a/TotalCrossSDK/src/main/java/tc/tools/converter/J2TC.java +++ b/TotalCrossSDK/src/main/java/tc/tools/converter/J2TC.java @@ -90,7 +90,6 @@ public final class J2TC implements JConstants, TCConstants { public TCClass converted; /** The bytes of the stored class */ public byte[] bytes; - public int origSize; public static Vector callForName = new Vector(4); public static boolean notResolvedForNameFound; public static String currentClass, currentMethod; @@ -102,7 +101,6 @@ public final class J2TC implements JConstants, TCConstants { private static int nextRegDStatic = 0; private static int nextRegOStatic = 0; private static boolean syncWarned; - private static int allowedBytes = Deploy.FREE_MAX_SIZE; public J2TC(JavaClass jc) throws IOException, Exception { jc.className = Bytecode2TCCode.replaceTotalCrossLangToJavaLang(jc.className); @@ -117,11 +115,6 @@ public J2TC(JavaClass jc) throws IOException, Exception { tcbas.reset(); tcbasz.reset(); converted.write(new DataStreamLE(tcbas)); - origSize = tcbas.getPos(); - allowedBytes -= origSize; - if (DeploySettings.isFreeSDK && allowedBytes < 0) { - throw new DeployerException("The free SDK allows only 100k of code."); - } //if (dump) {System.out.println(jc.className); byte[] bytes = tcbas.toByteArray(); System.out.println(TCZ.toString(bytes,0,bytes.length));} tc.tools.converter.Storage.compressAndWrite(tcbas, new DataStream(tcbasz)); bytes = tcbasz.toByteArray(); @@ -157,7 +150,6 @@ public J2TC(JavaClass jc, boolean dummy) throws IOException, Exception { tcbas.reset(); tcbasz.reset(); converted.write(new DataStreamLE(tcbas)); - origSize = tcbas.getPos(); if (dump) { System.out.println(jc.className); byte[] bytes = tcbas.toByteArray(); @@ -942,7 +934,7 @@ private static int processFiles(Vector vin, Vector vout) throws Exception { } } else if (!DeploySettings.testClass) { ByteArrayStream basz = new ByteArrayStream(bytes); - print = !name.equals("tckey.bin") && !name.equals("tcparms.bin") && !name.equals(DeploySettings.TCAPP_PROP); + print = !name.equals("tcparms.bin") && !name.equals(DeploySettings.TCAPP_PROP); if (print) { System.out.print("Adding " + name); @@ -1255,29 +1247,6 @@ public static void process(String fName, int options) throws Exception { if (DeploySettings.currentDir == null) { DeploySettings.currentDir = "./"; } - if (DeploySettings.rasKey != null && !DeploySettings.isTotalCrossJarDeploy - && (DeploySettings.isMainWindow || DeploySettings.isService || DeploySettings.isMainClass)) // registration key was specified - guich@tc310: only if not deploying the sdk and if its not a library - { - AESCipher cipher = new AESCipher(); - AESKey key = new AESKey(new byte[] { (byte) 0x06, (byte) 0x05, (byte) 0xF4, (byte) 0xF0, (byte) 0xF4, - (byte) 0x08, (byte) 0x01, (byte) 0x09, (byte) 0xF7, (byte) 0x09, (byte) 0xFE, (byte) 0xFC, (byte) 0xF5, - (byte) 0x04, (byte) 0x00, (byte) 0x0B }); - - cipher.reset(Cipher.OPERATION_ENCRYPT, key, Cipher.CHAINING_CBC, null, Cipher.PADDING_PKCS5); - cipher.update(DeploySettings.rasKey); - byte[] riv = cipher.getIV(); - byte[] out = cipher.getOutput(); - - ByteArrayStream bas = new ByteArrayStream(128); - DataStream ds = new DataStream(bas); - ds.writeInt(riv.length); - ds.writeBytes(riv); - ds.writeInt(out.length); - ds.writeBytes(out); - - byte[] enc = bas.toByteArray(); - vin.addElement(new TCZ.Entry(enc, "tckey.bin", enc.length)); - } if (DeploySettings.mainClassName != null && !DeploySettings.isTotalCrossJarDeploy && DeploySettings.isMainWindow) //flsobral@tc126: test for mainClassName instead of mainClassDir. The later is always null when deploy is used with a zip/jar file. This fixes third-party server activation when the application is deployed from a jar file. - guich@tc310 only if not deploying the sdk and if its not a library { Hashtable htVmParams = new Hashtable(4); diff --git a/TotalCrossSDK/src/main/java/tc/tools/deployer/DeploySettings.java b/TotalCrossSDK/src/main/java/tc/tools/deployer/DeploySettings.java index da4080fa4c..d82c0e5f2a 100644 --- a/TotalCrossSDK/src/main/java/tc/tools/deployer/DeploySettings.java +++ b/TotalCrossSDK/src/main/java/tc/tools/deployer/DeploySettings.java @@ -51,7 +51,6 @@ public class DeploySettings { public static boolean autoStart; - public static byte[] rasKey; public static boolean autoSign; public static String autoSignPassword; public static boolean quiet = true; // to set to false, pass /v(erbose) to tc.Deploy @@ -91,8 +90,6 @@ public class DeploySettings { public static final String TCAPP_PROP = "tcapp.prop"; public static int appBuildNumber = -1; - public static boolean isFreeSDK; - private static List defaultTczs; public static List getDefaultTczs() { diff --git a/TotalCrossSDK/src/main/java/totalcross/Launcher.java b/TotalCrossSDK/src/main/java/totalcross/Launcher.java index 145927f1d6..652ee41ad7 100644 --- a/TotalCrossSDK/src/main/java/totalcross/Launcher.java +++ b/TotalCrossSDK/src/main/java/totalcross/Launcher.java @@ -43,7 +43,6 @@ import net.coobird.thumbnailator.Thumbnails; import sun.awt.image.ToolkitImage; import tc.tools.JarClassPathLoader; -import tc.tools.RegisterSDK; import tc.tools.deployer.DeploySettings; import totalcross.io.IOException; import totalcross.io.Stream; @@ -51,19 +50,13 @@ import totalcross.sys.SpecialKeys; import totalcross.sys.Time; import totalcross.sys.Vm; -import totalcross.ui.Button; import totalcross.ui.Control; -import totalcross.ui.Edit; -import totalcross.ui.Label; import totalcross.ui.MainWindow; import totalcross.ui.UIColors; import totalcross.ui.Window; -import totalcross.ui.dialog.MessageBox; -import totalcross.ui.event.ControlEvent; import totalcross.ui.event.KeyEvent; import totalcross.ui.event.MultiTouchEvent; import totalcross.ui.event.PenEvent; -import totalcross.ui.event.PressListener; import totalcross.util.Hashtable; import totalcross.util.IntHashtable; import totalcross.util.zip.TCZ; @@ -121,7 +114,6 @@ final public class Launcher extends java.applet.Applet implements WindowListener private TCEventThread eventThread; private boolean isMainClass; private boolean isDemo; - private String activationKey; private boolean fastScale; private double toScaleValue = -1; @@ -201,9 +193,6 @@ final public void init() { } fillSettings(); - if (isApplication && !className.equals("tc.Help") && activationKey != null) { - Class.forName("tc.tools.RegisterSDK").getConstructor(String.class).newInstance(activationKey); - } try { _class = getClass(); // guich@500_1: we can use ourselves @@ -233,9 +222,6 @@ final public void init() { // NOTE: java will call a partially constructed object if show() is called before all the objects are constructed if (isApplication) { frame = new LauncherFrame(); - if (activationKey == null) { - new Activate().popup(); - } requestFocus(); } else { setLayout(new java.awt.BorderLayout()); @@ -268,11 +254,6 @@ final public void init() { exit(-1); } } catch (Exception ee) { - String name = ee.getClass().getSimpleName(); - if (name.equals("RegisterSDKException")) { - System.out.println("SDK registration returned: " + ee.getMessage()); - exit(-2); - } if (showInstructionsOnError) { showInstructions(); } @@ -406,18 +387,6 @@ public void run() { Thread.yield(); } mainWindow.appStarting(isDemo ? 80 : -1); - if (isApplication) { - new Thread() { - @Override - public void run() { - try { - new URL("http://www.superwaba.net/SDKRegistrationService/PingService?CHAVE=" + activationKey) - .openConnection().getInputStream().close(); - } catch (Throwable e) { - } - } - }.start(); // keep track of TC usage - } } // guich@200b4_107 - guich@570_3: check if mainWindow is not null to avoid problems when running on Linux. seems that the paint event is being generated before the start one. }); } catch (Throwable e) { @@ -457,8 +426,6 @@ static void showInstructions() { System.out.println(" /dataPath : sets where the PDB and media files are stored"); System.out.println(" /cmdLine <...> : the rest of arguments-1 are passed as the command line"); System.out.println(" /fontSize : set the default font size to the one passed as parameter"); - System.out.println( - " /r : specify a registration key to be used to activate TotalCross when required. You may use %key%, where key is an environment variable"); System.out.println("The class name that extends MainWindow must always be the last argument"); System.out.println("Please notice that the Launcher automatically scales down the resolution to fit in the display, to disable this behavior you may include the argument scale with the value 1"); } @@ -542,14 +509,8 @@ protected void parseArguments(String clazz, String... args) { } } System.out.println("Screen is " + toWidth + "x" + toHeight + "x" + toBpp); - } else if (args[i].equalsIgnoreCase("/r")) { - activationKey = args[++i].toUpperCase(); - if (activationKey.startsWith("%")) { - activationKey = System.getenv(activationKey.substring(1, activationKey.length() - 1)); - } - if (activationKey == null || activationKey.length() != 24) { - throw new RuntimeException("Invalid registration key: " + activationKey); - } + } else if (args[i++].equalsIgnoreCase("/r")) { + // Ignore next argument } else if (args[i].equalsIgnoreCase("/pos")) /* x,y */ { String[] scr = tokenizeString(args[++i].toLowerCase(), ','); @@ -568,15 +529,15 @@ protected void parseArguments(String clazz, String... args) { } else if (args[i].equalsIgnoreCase("/uiStyle")) { String next = args[++i]; if (next.equalsIgnoreCase("Flat")) { - toUI = Settings.Flat; + toUI = Settings.FLAT_UI; } else if (next.equalsIgnoreCase("Vista")) { - toUI = Settings.Vista; + toUI = Settings.VISTA_UI; } else if (next.equalsIgnoreCase("Android")) { - toUI = Settings.Android; + toUI = Settings.ANDROID_UI; } else if (next.equalsIgnoreCase("Holo")) { - toUI = Settings.Holo; + toUI = Settings.HOLO_UI; } else if (next.equalsIgnoreCase("Material")) { - toUI = Settings.Material; + toUI = Settings.MATERIAL_UI; } else { throw new Exception(); } @@ -682,13 +643,6 @@ protected void parseArguments(String clazz, String... args) { toScale = Math.abs(toScaleValue) / toDensityValue; Settings.dataPath = newDataPath; - if (isApplication && activationKey == null) { - activationKey = RegisterSDK.getStoredActivationKey(); - } - if (activationKey != null && activationKey.length() != 24) { - System.err.println("The registration key has incorrect length: " + activationKey.length() + " but must have 24"); - System.exit(0); - } } private String[] tokenizeString(String string, char c) { @@ -1910,7 +1864,7 @@ public void fillSettings() { totalcross.sys.Settings.screenWidthInDPI = 96; } totalcross.sys.Settings.romVersion = 0x02000000; - totalcross.sys.Settings.uiStyle = totalcross.sys.Settings.Vista; + totalcross.sys.Settings.uiStyle = totalcross.sys.Settings.VISTA_UI; totalcross.sys.Settings.screenWidth = toWidth; totalcross.sys.Settings.screenHeight = toHeight; totalcross.sys.Settings.onJavaSE = true; @@ -2348,76 +2302,6 @@ public void setText(String s) { } } - private class Activate extends Window { - - public Activate() { - super("Activation Key required", ROUND_BORDER); - this.fadeOtherWindows = true; - this.canDrag = false; - } - - @Override - public void initUI() { - Label lblKey = new Label("Activation Key"); - final Edit edKey = new Edit(); - edKey.setMaxLength(24); - - add(lblKey, CENTER, CENTER - 50); - add(edKey, LEFT + 20, AFTER, FILL - 20, PREFERRED); - - Button btOk = new Button(" OK "); - add(btOk, CENTER, AFTER + 10); - btOk.addPressListener(new PressListener() { - - @Override - public void controlPressed(ControlEvent e) { - String email = edKey.getText(); - if (email != null && email.length() > 0) { - try { - Class.forName("tc.tools.RegisterSDK").getConstructor(String.class, String.class).newInstance(email, null); - - new Thread() { - @Override - public void run() { - try { - new URL("http://www.superwaba.net/SDKRegistrationService/PingService?CHAVE=" + email) - .openConnection().getInputStream().close(); - } catch (Throwable e) { - } - } - }.start(); // keep track of TC usage - - Activate.this.unpop(); - - } catch (Exception e1) { - - e1.printStackTrace(); - - MessageBox mb = new MessageBox("Error to validate KEY", - "Try again or get a new KEY at www.totalcross.com", new String[] { "Close" }); - mb.setBackColor(totalcross.ui.gfx.Color.getRGB(250, 250, 250)); - mb.setForeColor(0x000000); - mb.popup(); - } - }else { - MessageBox mb = new MessageBox("Error to validate KEY", "Please insert a valid KEY or get a new one at www.totalcross.com", new String[]{"Close"}); - mb.setBackColor(totalcross.ui.gfx.Color.getRGB(250, 250, 250)); - mb.setForeColor(0x000000); - mb.popup(); - } - - } - }); - - add(new Label("Register at totalcross.com"), CENTER, BOTTOM - 20); - } - - @Override - protected void onPopup() { - setRect(CENTER, CENTER, SCREENSIZE + 90, SCREENSIZE + 60); - } - } - public void alert(String msg) { if (!started) { System.out.println("Alert: " + msg);