com.alachisoft.ncache.ncactivate.utils.RegUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nc-common Show documentation
Show all versions of nc-common Show documentation
Internal package of Alachisoft.
/*
* RegUtil.java
*
* Created on October 9, 2006, 10:39 AM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package com.alachisoft.ncache.ncactivate.utils;
import com.alachisoft.ncache.licensing.config.ConfigHandler;
import com.alachisoft.ncache.licensing.config.InfoType;
import com.alachisoft.ncache.licensing.config.LicenseInfo;
import com.alachisoft.ncache.licensing.config.NCacheInfo;
import com.alachisoft.ncache.runtime.util.RuntimeUtil;
import java.nio.file.Paths;
/**
* @author Administrator
*/
public class RegUtil {
private static final String NCInfoFileOnLinux = "/usr/lib/ncinfo.xml";
private static final String LicenseInfoFileOnLinux = "/usr/lib/nclicense.xml";
private static final String LicenseInfoFileOnWindows = Paths.get("config", "nclicense.xml").toString();
public static String notFound = "";
public static NCacheInfo nCacheInfo;
public static LicenseInfo licenseInfo;
public static String winStub = "ncstub.bin";//"vcstub.dll";
public static String linuxStub = ".ncstub.so";//".vcstub.so";
private static String _installDir;
private static boolean loaded;
/**
* Creates a new instance of RegUtil
*/
public RegUtil() {
}
public static String getNCHome() {
String ncHome = System.getenv("NCHOME");
if (ncHome == null) {
LoadRegistry();
if (nCacheInfo != null)
ncHome = nCacheInfo.getProduct().getInstallDir();
}
return ncHome;
}
public static void LoadRegistry() /*throws IOException*/ {
if (loaded) {
return;
}
try {
loaded = true;
if (RuntimeUtil.getCurrentOS() == RuntimeUtil.OS.Linux) {
nCacheInfo = ConfigHandler.readNCacheInfo(NCInfoFileOnLinux);
licenseInfo = ConfigHandler.readLicenseInfo(LicenseInfoFileOnLinux);
} else if (RuntimeUtil.getCurrentOS() == RuntimeUtil.OS.Windows) {
nCacheInfo = ConfigHandler.readNCInfoFromRegistry();
licenseInfo = ConfigHandler.readLicenseInfoFromRegistry();
}
} catch (Exception e) {
loaded = false;
}
}
public static void StoreRegistry() {
if (nCacheInfo == null || licenseInfo == null) {
return;
}
ConfigHandler.writeNCacheInfo(NCInfoFileOnLinux, convertNCacheDomToXML());
ConfigHandler.writeNCacheInfo(NCInfoFileOnLinux, convertNCacheDomToXML());
}
public static String getKey(InfoType Type, RegKeys RegKey) {
LoadRegistry();
if (nCacheInfo == null) {
return "";
}
switch (Type) {
case PRODUCT:
return nCacheInfo.getProduct().getValue(RegKey);
case DEPLOYMENT:
return nCacheInfo.getDeploymentInfo().getValue(RegKey);
case USER:
return nCacheInfo.getUserInfo().getValue(RegKey);
case LICENSE:
return licenseInfo.getValue(RegKey);
}
return "";
}
public static void setKey(InfoType type, RegKeys regKey, String value) {
if (nCacheInfo == null) {
return;
}
switch (type) {
case PRODUCT:
nCacheInfo.getProduct().setValue(regKey, value);
case DEPLOYMENT:
nCacheInfo.getDeploymentInfo().setValue(regKey, value);
case USER:
nCacheInfo.getUserInfo().setValue(regKey, value);
}
}
public static String getInstallCode() {
LoadRegistry();
String installCode = null;
if (nCacheInfo != null && nCacheInfo.getProduct() != null) {
installCode = nCacheInfo.getProduct().getInstallCode();
}
if (installCode != null) {
installCode = installCode.trim();
}
return installCode;
}
private static String getInstallDir() {
LoadRegistry();
if (_installDir == null) {
if (nCacheInfo != null) ;
_installDir = nCacheInfo.getProduct().getInstallDir();
}
return _installDir;
}
private static String convertNCacheDomToXML() {
return nCacheInfo.getXmlString();
}
}