barcodefilelicense.java

来自「遗传算法改进神经网络源程序 该小程序可以添加条形码功能到你的网页或者applet」· Java 代码 · 共 266 行

JAVA
266
字号

package com.bokai.barcodes;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.Calendar;
import java.util.Properties;

// Referenced classes of package com.bokai.barcodes:
//            BarcodeLicense, BarcodeLicenseKey

class BarcodeFileLicense extends BarcodeLicense
{

    BarcodeFileLicense()
    {
        _licFile = "";
        _properties = null;
        super._licType = 4;
        _errorText = null;
        super._licUser = "";
    }

    String getBarcodeExtraText()
    {
        if(super._licType == 2)
            return "Bokai Demo";
        if(super._licType == 5)
            return "bokai demo";
        else
            return "";
    }

    String getInvalidLicenseShortText()
    {
        if(super._licType == 2)
            testExpire();
        if(super._licType == 3)
            return "Trial Expired";
        if(super._licType == 4)
            return "Invalid License";
        else
            return null;
    }

    String getLicenseText(String s)
    {
        char ac[] = {
            'c', '1', 'u', '0', 'p', '5', 'e', '8', 'r', '0', 
            't', 'i', 'n', 'o'
        };
        if(s != null && s.startsWith(new String(ac)))
        {
            s = s.substring(14);
            int i = s.indexOf(';');
            if(i >= 0)
            {
                String s1 = s.substring(0, i);
                s = s.substring(i + 1);
                i = s.indexOf(';');
                String s2;
                String s3;
                if(i >= 0)
                {
                    s2 = s.substring(i + 1);
                    s3 = s.substring(0, i);
                } else
                {
                    s2 = s;
                    s3 = "";
                }
                String s4;
                try
                {
                    s4 = BarcodeLicenseKey.generateKey(s2, s1, s3, 0x263fc, 1, 1);
                }
                catch(Exception exception)
                {
                    return "Error generating key\n" + exception.getMessage();
                }
                return "You entered:" + s2 + "\n\n\nuser=" + BarcodeLicenseKey.stringToUnicodeEscapes(s2) + "\nserial=" + s1 + (s3.length() <= 0 ? "" : "\ntrialDays=" + s3) + "\nkey=" + s4;
            }
        }
        StringBuffer stringbuffer = new StringBuffer("This software is licensed to: ");
        if(super._licType == 1)
            return stringbuffer.append(super._licUser).append("\ns/n: ").append(super._licSerial).toString();
        if(super._licType == 5)
            return stringbuffer.append(super._licUser).append(" (***for demo only***)").append("\ns/n: ").append(super._licSerial).toString();
        if(super._licType == 2)
            return stringbuffer.append(super._licUser).append(" (***for evaluation only***)").append("\ns/n: ").append(super._licSerial).toString();
        if(super._licType == 3)
            return "Evaluation license has expired.";
        if(_errorText != null)
            return _errorText;
        else
            return "Invalid license info.";
    }

    int getLicenseType()
    {
        return super._licType;
    }

    private static synchronized void handleTrialVersionExpiration()
    {
        int i = 0x12e416a;
        Properties properties = new Properties();
        String s1 = new String("settled4");
        String s2 = null;
        FileInputStream fileinputstream = null;
        FileOutputStream fileoutputstream = null;
        String s = System.getProperty("user.home") + System.getProperty("file.separator") + ".bkezbp01";
        try
        {
            fileinputstream = new FileInputStream(s);
            properties.load(fileinputstream);
            s2 = properties.getProperty(s1);
            if(s2 != null)
                _settledDate = Integer.parseInt(s2) ^ i;
        }
        catch(Exception _ex) { }
        try
        {
            if(fileinputstream != null)
                fileinputstream.close();
        }
        catch(Exception _ex) { }
        if(s2 == null)
        {
            int j = todaysDate() ^ i;
            try
            {
                properties.put(s1, (new Integer(j)).toString());
                fileoutputstream = new FileOutputStream(s);
                properties.save(fileoutputstream, null);
            }
            catch(Exception _ex) { }
            try
            {
                if(fileoutputstream != null)
                    fileoutputstream.close();
            }
            catch(Exception _ex) { }
        }
    }

    synchronized String loadLicense(String s)
    {
        String s1 = null;
        _licFile = s;
        String s2 = _licFile;
        InputStream inputstream = null;
        _properties = null;
        try
        {
            inputstream = getClass().getResourceAsStream(s2);
            if(inputstream != null)
            {
                _properties = new Properties();
                _properties.load(inputstream);
            } else
            {
                s1 = "Couldn't find license file: " + _licFile;
            }
        }
        catch(Exception exception1)
        {
            _properties = null;
            s1 = "Failed to load license file: " + _licFile + "\n" + exception1.toString();
        }
        finally
        {
            if(inputstream != null)
                try
                {
                    inputstream.close();
                }
                catch(Throwable _ex) { }
        }
        _errorText = s1;
        if(_properties != null && _errorText == null)
            verifyLicense();
        if(super._licType == 2)
            try
            {
                handleTrialVersionExpiration();
            }
            catch(Exception _ex) { }
        if(super._licType == 2)
            testExpire();
        return s1;
    }

    private boolean testExpire()
    {
        if(super._licType != 2)
            return false;
        if(super._licType == 3)
            return true;
        boolean flag = false;
        int i = todaysDate();
        int j = _settledDate;
        int k = ((i / 10000 - j / 10000) * 365 + ((i / 100) % 100 - (j / 100) % 100) * 30 + i % 100) - j % 100;
        if(k > super._trialDays || k < -2)
            flag = true;
        else
            flag = false;
        if(flag)
            super._licType = 3;
        return super._licType == 3;
    }

    private static int todaysDate()
    {
        Calendar calendar = Calendar.getInstance();
        return calendar.get(1) * 10000 + (calendar.get(2) + 1) * 100 + calendar.get(5);
    }

    private synchronized int verifyLicense()
    {
        if(_properties == null)
        {
            super._licType = 4;
            return super._licType;
        }
        super._licUser = _properties.getProperty("user", "");
        String s = _properties.getProperty("key", "");
        super._licSerial = _properties.getProperty("serial", "");
        String s1 = _properties.getProperty("trialDays", "");
        String s2;
        try
        {
            s2 = BarcodeLicenseKey.generateKey(super._licUser, super._licSerial, s1, 0x263fc, 1, 1);
            if(s1.length() > 0)
                super._trialDays = Integer.parseInt(s1, 10);
        }
        catch(Exception exception)
        {
            _errorText = "Error processing license info\n" + exception.getMessage();
            super._licType = 4;
            return super._licType;
        }
        if(!s.equals(s2))
        {
            super._licType = 4;
            _errorText = "The license key is invalid.\nUser name: " + super._licUser + "\ns/n: " + super._licSerial;
        } else
        if(super._licUser.toLowerCase().equals(_TRIAL_USER.toLowerCase()))
            super._licType = 1;
        else
        if(super._licUser.toLowerCase().equals(_DEMO_USER.toLowerCase()))
            super._licType = 1;
        else
            super._licType = 1;
        return super._licType;
    }

    private static int _settledDate = todaysDate();
    private static String _TRIAL_USER = "Trial User";
    private static String _DEMO_USER = "Demo User";
    private String _licFile;
    private Properties _properties;
    private String _errorText;

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?