use of org.eclipse.osgi.service.datalocation.Location in project translationstudio8 by heartsome.
the class PreferenceUtil method initProductEdition.
public static void initProductEdition() {
System.getProperties().put("TSVersion", "89");
Location configArea = Platform.getInstallLocation();
if (configArea == null) {
System.getProperties().put("TSEdition", "");
System.getProperties().put("TSVersion", "");
return;
}
URL location = null;
try {
VTDGen vg = new VTDGen();
AutoPilot ap = new AutoPilot();
location = new URL(configArea.getURL().toExternalForm() + "features");
String featureFolderName = location.getFile();
File featureFolder = new File(featureFolderName);
// 遍历 features 目录
if (featureFolder.isDirectory()) {
boolean isU = false;
boolean isF = false;
boolean isP = false;
boolean isL = false;
String strUVersion = null;
String strFVersion = null;
String strPVersion = null;
String strLVersion = null;
for (File f : featureFolder.listFiles()) {
String name = f.getName();
if (name.startsWith("net.heartsome.cat.ts.edition_")) {
if (vg.parseFile(f.getAbsolutePath() + File.separator + "feature.xml", true)) {
VTDNav vn = vg.getNav();
ap.bind(vn);
ap.selectXPath("/feature");
if (ap.evalXPath() != -1) {
int idIndex = vn.getAttrVal("id");
int versionIndex = vn.getAttrVal("version");
if (idIndex == -1 || versionIndex == -1) {
System.getProperties().put("TSEdition", "");
return;
}
String id = vn.toRawString(idIndex);
String version = vn.toRawString(versionIndex);
if (name.equals(id + "_" + version)) {
// 由于 feature 可以包含,因此要遍历所有以 net.heartsome.cat.ts.edition_ 开头的目录,找到版本最高的
if (id.equals("net.heartsome.cat.ts.edition_ultimate.feature")) {
isU = true;
strUVersion = version;
break;
} else if (id.equals("net.heartsome.cat.ts.edition_professional.feature")) {
isF = true;
strFVersion = version;
continue;
} else if (id.equals("net.heartsome.cat.ts.edition_personal.feature")) {
isP = true;
strPVersion = version;
continue;
} else if (id.equals("net.heartsome.cat.ts.edition_lite.feature")) {
isL = true;
strLVersion = version;
continue;
}
} else {
System.getProperties().put("TSEdition", "");
return;
}
} else {
System.getProperties().put("TSEdition", "");
}
} else {
System.getProperties().put("TSEdition", "");
}
}
}
if (isU) {
System.getProperties().put("TSEdition", "U");
System.getProperties().put("TSVersionDate", strUVersion);
} else if (isF) {
System.getProperties().put("TSEdition", "F");
System.getProperties().put("TSVersionDate", strFVersion);
} else if (isP) {
System.getProperties().put("TSEdition", "P");
System.getProperties().put("TSVersionDate", strPVersion);
} else if (isL) {
System.getProperties().put("TSEdition", "L");
System.getProperties().put("TSVersionDate", strLVersion);
} else {
System.getProperties().put("TSEdition", "");
System.getProperties().put("TSVersionDate", "");
}
} else {
System.getProperties().put("TSEdition", "");
}
location = new URL(configArea.getURL().toExternalForm() + "plugins");
String pluginsFolderName = location.getFile();
File pluginsFolder = new File(pluginsFolderName);
// 遍历 plugins 目录
if (pluginsFolder.isDirectory()) {
List<String> lstPluginName = new ArrayList<String>();
for (File f : pluginsFolder.listFiles()) {
String name = f.getName();
if (name.endsWith(".jar") && (name.startsWith("net.heartsome.cat.ts.ui.plugin_") || name.startsWith("net.heartsome.cat.ts.ui.advanced_") || name.startsWith("net.heartsome.cat.ts.fuzzyTranslation_") || name.startsWith("net.heartsome.cat.converter.ui_") || name.startsWith("net.heartsome.cat.ts.ui.docx_") || name.startsWith("net.heartsome.cat.ts.ui.qa_") || name.startsWith("net.heartsome.cat.database.ui_") || name.startsWith("net.heartsome.cat.database.hsql_") || name.startsWith("net.heartsome.cat.database.oracle_") || name.startsWith("net.heartsome.cat.ts.importproject_") || name.startsWith("net.heartsome.cat.ts.exportproject_") || name.startsWith("net.heartsome.cat.ts.handlexlf_") || name.startsWith("net.heartsome.cat.ts.lockrepeat_") || name.startsWith("net.heartsome.cat.ts.jumpsegment_"))) {
String pluginName = name.substring(0, name.indexOf("_"));
// 更新后原来的插件会保留在 plugins 目录下,应此 lstPluginName 会有重复添加 pluginName 的情况,所以在此处添加判断。
if (!lstPluginName.contains(pluginName)) {
lstPluginName.add(pluginName);
}
}
}
String edition = System.getProperty("TSEdition");
if (lstPluginName.size() == 14 && lstPluginName.indexOf("net.heartsome.cat.ts.ui.plugin") != -1 && lstPluginName.indexOf("net.heartsome.cat.ts.ui.advanced") != -1 && lstPluginName.indexOf("net.heartsome.cat.ts.fuzzyTranslation") != -1 && lstPluginName.indexOf("net.heartsome.cat.converter.ui") != -1 && lstPluginName.indexOf("net.heartsome.cat.ts.ui.docx") != -1 && lstPluginName.indexOf("net.heartsome.cat.ts.ui.qa") != -1 && lstPluginName.indexOf("net.heartsome.cat.database.ui") != -1 && lstPluginName.indexOf("net.heartsome.cat.database.hsql") != -1 && lstPluginName.indexOf("net.heartsome.cat.database.oracle") != -1 && lstPluginName.indexOf("net.heartsome.cat.ts.importproject") != -1 && lstPluginName.indexOf("net.heartsome.cat.ts.exportproject") != -1 && lstPluginName.indexOf("net.heartsome.cat.ts.handlexlf") != -1 && lstPluginName.indexOf("net.heartsome.cat.ts.lockrepeat") != -1 && lstPluginName.indexOf("net.heartsome.cat.ts.jumpsegment") != -1) {
if (!(edition != null && (edition.equals("U") || edition.equals("F")))) {
System.getProperties().put("TSEdition", "");
}
} else if (lstPluginName.size() == 6 && lstPluginName.indexOf("net.heartsome.cat.converter.ui") != -1 && lstPluginName.indexOf("net.heartsome.cat.ts.ui.qa") != -1 && lstPluginName.indexOf("net.heartsome.cat.database.ui") != -1 && lstPluginName.indexOf("net.heartsome.cat.database.hsql") != -1 && lstPluginName.indexOf("net.heartsome.cat.ts.importproject") != -1 && lstPluginName.indexOf("net.heartsome.cat.ts.jumpsegment") != -1) {
if (!(edition != null && edition.equals("P"))) {
System.getProperties().put("TSEdition", "");
}
} else if (lstPluginName.size() == 0) {
if (!(edition != null && edition.equals("L"))) {
System.getProperties().put("TSEdition", "");
}
} else {
System.getProperties().put("TSEdition", "");
}
} else {
System.getProperties().put("TSEdition", "");
}
// if (System.getProperty("TSEdition").equals("")) {
// return;
// }
// String product = Platform.getProduct().getName();
// if (Util.isMac()) {
// location = new URL(configArea.getURL().toExternalForm() + product + ".app" + File.separator
// + "Contents" + File.separator + "MacOS" + File.separator + product + ".ini");
// } else {
// location = new URL(configArea.getURL().toExternalForm() + product + ".ini");
// }
// String fileName = location.getFile();
// BufferedReader in = new BufferedReader(new FileReader(fileName));
// String line = null;
// String tsVersion = null;
// String tsSerial = null;
// while ((line = in.readLine()) != null) {
// if (line.startsWith("TSProductVersion")) {
// tsVersion = line.substring(line.indexOf("=") + 1);
// }
// if (line.startsWith("TSProductSerialNumber")) {
// tsSerial = line.substring(line.indexOf("=") + 1);
// }
// }
// if (tsVersion != null && tsSerial != null && tsVersion.length() == 16 && tsSerial.length() == 16) {
// String edition = System.getProperty("TSEdition");
// int[] arrValue = new int[16];
// for (int i = 0; i < tsVersion.length(); i++) {
// arrValue[i] = Integer.parseInt(Character.toString(tsVersion.charAt(i)));
// }
// int[] arrSerialNum = new int[16];
// for (int i = 0; i < tsSerial.length(); i++) {
// arrSerialNum[i] = Integer.parseInt(Character.toString(tsSerial.charAt(i)));
// }
// String strFullChar = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
// boolean isU = ((arrValue[1] + arrValue[8]) * (arrValue[7] - arrValue[14])) == (strFullChar.indexOf("U") +
// 1);// 验证旗舰版的规则
// boolean isF = arrValue[4] != 0
// && (arrValue[2] - arrValue[9] + arrValue[15]) / arrValue[4] == (strFullChar.indexOf("F") + 1);
// boolean isP = arrValue[5] * (arrValue[3] + arrValue[10] + arrValue[12]) == (strFullChar.indexOf("P") +
// 1);
// boolean isL = (arrValue[0] + arrValue[6] + arrValue[11] + arrValue[13]) == (strFullChar.indexOf("L") +
// 1);
//
// boolean isUVersion = arrSerialNum[12] + arrSerialNum[13] == 8 && arrSerialNum[2] + arrSerialNum[3] ==
// 9;// 验证旗舰版是否满足
// boolean isFVersion = arrSerialNum[6] * arrSerialNum[15] == 8 && arrSerialNum[2] * arrSerialNum[5] == 9;//
// 验证专业版是否满足
// boolean isPVersion = arrSerialNum[3] * arrSerialNum[4] == 8 && arrSerialNum[0] * arrSerialNum[13] == 9;//
// 验证个人版是否满足
// boolean isLVersion = arrSerialNum[0] * arrSerialNum[3] == 8 && arrSerialNum[1] == 9;// 验证精简版是否满足
// if (edition.equals("U")) {
// // 验证 TSEdition
// if (!isU) {
// System.getProperties().put("TSEdition", "");
// } else {
// if (isF) {
// System.getProperties().put("TSEdition", "");
// } else if (isP) {
// System.getProperties().put("TSEdition", "");
// } else if (isL) {
// System.getProperties().put("TSEdition", "");
// }
// }
// // 验证序列号
// if (isUVersion) {
// if (!(isFVersion) && !(isPVersion) && !(isLVersion)) {
// System.getProperties().put("TSVersion", "89");
// } else {
// System.getProperties().put("TSVersion", "");
// }
// } else {
// System.getProperties().put("TSVersion", "");
// }
// } else if (edition.equals("F")) {
// if (!isF) {
// System.getProperties().put("TSEdition", "");
// } else {
// if (isU) {
// System.getProperties().put("TSEdition", "");
// } else if (isP) {
// System.getProperties().put("TSEdition", "");
// } else if (isL) {
// System.getProperties().put("TSEdition", "");
// }
// }
// if (isFVersion) {
// if (!(isUVersion) && !(isPVersion) && !(isLVersion)) {
// System.getProperties().put("TSVersion", "89");
// } else {
// System.getProperties().put("TSVersion", "");
// }
// } else {
// System.getProperties().put("TSVersion", "");
// }
// } else if (edition.equals("P")) {
// if (!isP) {
// System.getProperties().put("TSEdition", "");
// } else {
// if (isU) {
// System.getProperties().put("TSEdition", "");
// } else if (isF) {
// System.getProperties().put("TSEdition", "");
// } else if (isL) {
// System.getProperties().put("TSEdition", "");
// }
// }
// if (isPVersion) {
// if (!(isUVersion) && !(isFVersion) && !(isLVersion)) {
// System.getProperties().put("TSVersion", "89");
// } else {
// System.getProperties().put("TSVersion", "");
// }
// } else {
// System.getProperties().put("TSVersion", "");
// }
// } else if (edition.equals("L")) {
// if (!isL) {
// System.getProperties().put("TSEdition", "");
// } else {
// if (isU) {
// System.getProperties().put("TSEdition", "");
// } else if (isF) {
// System.getProperties().put("TSEdition", "");
// } else if (isP) {
// System.getProperties().put("TSEdition", "");
// }
// }
// if (isLVersion) {
// if (!(isUVersion) && !(isFVersion) && !(isPVersion)) {
// System.getProperties().put("TSVersion", "89");
// } else {
// System.getProperties().put("TSVersion", "");
// }
// } else {
// System.getProperties().put("TSVersion", "");
// }
// }
// } else {
// System.getProperties().put("TSEdition", "");
// System.getProperties().put("TSVersion", "");
// }
} catch (MalformedURLException e) {
e.printStackTrace();
LOGGER.error(Messages.getString("preference.PreferenceUtil.logger1"), e);
} catch (XPathEvalException e) {
e.printStackTrace();
LOGGER.error(Messages.getString("preference.PreferenceUtil.logger1"), e);
} catch (NavException e) {
e.printStackTrace();
LOGGER.error(Messages.getString("preference.PreferenceUtil.logger1"), e);
} catch (XPathParseException e) {
e.printStackTrace();
LOGGER.error(Messages.getString("preference.PreferenceUtil.logger1"), e);
}
}
use of org.eclipse.osgi.service.datalocation.Location in project translationstudio8 by heartsome.
the class PreferenceUtil method checkCleanValue.
/**
* 检查 osgi.clean 的值,如果为 true,就改为 false
* @param locale
* ;
*/
public static void checkCleanValue() {
Location configArea = Platform.getInstallLocation();
if (configArea == null) {
return;
}
URL location = null;
try {
location = new URL(configArea.getURL().toExternalForm() + "configuration" + File.separator + "config.ini");
} catch (MalformedURLException e) {
// This should never happen
}
try {
String fileName = location.getFile();
File file = new File(fileName);
fileName += ".bak";
file.renameTo(new File(fileName));
BufferedReader in = new BufferedReader(new FileReader(fileName));
BufferedWriter out = null;
boolean isFind = false;
try {
String line = in.readLine();
StringBuffer sbOut = new StringBuffer();
while (line != null) {
if (line.trim().equals("osgi.clean=true")) {
sbOut.append("osgi.clean=false");
isFind = true;
} else {
sbOut.append(line);
}
sbOut.append("\n");
line = in.readLine();
}
if (isFind) {
out = new BufferedWriter(new FileWriter(location.getFile()));
out.write(sbOut.toString());
out.flush();
}
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (out != null) {
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
File tmpFile = new File(location.getFile() + ".bak");
if (isFind) {
if (tmpFile.exists()) {
tmpFile.delete();
}
} else {
tmpFile.renameTo(new File(location.getFile()));
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
use of org.eclipse.osgi.service.datalocation.Location in project cubrid-manager by CUBRID.
the class SelectWorkspaceDialog method pickWorkspaceDir.
/**
*
* Pick up the workspace directory
*
* @param shell Shell
* @param productName String
* @param productVersion String
* @return boolean
*/
public static boolean pickWorkspaceDir(Shell shell, String productName, String productVersion) {
//check whether switch workspace and do not need to pop up dialog for select workspace
boolean isSwitchWorkspace = "true".equals(PersistUtils.getGlobalPreferenceValue(CommonUIPlugin.PLUGIN_ID, SwitchWorkspaceAction.KEY_IS_SWITCH_WORKSPACE));
Location instanceLoc = Platform.getInstanceLocation();
String lastUsedWs = getLastSetWorkspaceDirectory();
boolean isRemember = isRememberWorkspace();
if (isRemember && (lastUsedWs == null || lastUsedWs.length() == 0)) {
isRemember = false;
isSwitchWorkspace = false;
}
if (isRemember) {
String ret = SelectWorkspaceDialog.checkWorkspaceDirectory(lastUsedWs, false, productName, productVersion);
if (ret != null) {
CommonUITool.openErrorBox(shell, ret);
isRemember = false;
isSwitchWorkspace = false;
}
}
String workspaceLocation = null;
if (isRemember || isSwitchWorkspace) {
boolean isOk = false;
workspaceLocation = lastUsedWs;
try {
isOk = instanceLoc.set(new URL("file", null, workspaceLocation), true);
} catch (IllegalStateException e) {
isOk = false;
} catch (MalformedURLException e) {
isOk = false;
} catch (IOException e) {
isOk = false;
}
PersistUtils.setGlobalPreferenceValue(CommonUIPlugin.PLUGIN_ID, SwitchWorkspaceAction.KEY_IS_SWITCH_WORKSPACE, "false");
if (isOk) {
return true;
} else {
CommonUITool.openErrorBox(shell, Messages.errWorkspaceUsed);
}
}
SelectWorkspaceDialog pwDialog = new SelectWorkspaceDialog(shell, false, productName, productVersion);
int ret = pwDialog.open();
if (ret != IDialogConstants.OK_ID) {
CommonUITool.openErrorBox(shell, Messages.errNoWorkspace);
return false;
}
return true;
}
use of org.eclipse.osgi.service.datalocation.Location in project dbeaver by serge-rider.
the class DBeaverApplication method start.
@Override
public Object start(IApplicationContext context) {
instance = this;
Location instanceLoc = Platform.getInstanceLocation();
if (!instanceLoc.isSet()) {
if (!setDefaultWorkspacePath(instanceLoc)) {
return IApplication.EXIT_OK;
}
}
// Add bundle load logger
Bundle brandingBundle = context.getBrandingBundle();
if (brandingBundle != null) {
BundleContext bundleContext = brandingBundle.getBundleContext();
if (bundleContext != null) {
bundleContext.addBundleListener(new BundleLoadListener());
}
}
Log.addListener(new Log.Listener() {
@Override
public void loggedMessage(Object message, Throwable t) {
DBeaverSplashHandler.showMessage(CommonUtils.toString(message));
}
});
final Runtime runtime = Runtime.getRuntime();
// Init Core plugin and mark it as standalone version
DBeaverCore.setApplication(this);
initDebugWriter();
//$NON-NLS-1$
log.debug(GeneralUtils.getProductTitle() + " is starting");
//$NON-NLS-1$ //$NON-NLS-2$
log.debug("Install path: '" + SystemVariablesResolver.getInstallPath() + "'");
//$NON-NLS-1$ //$NON-NLS-2$
log.debug("Instance path: '" + instanceLoc.getURL() + "'");
log.debug("Memory available " + (runtime.totalMemory() / (1024 * 1024)) + "Mb/" + (runtime.maxMemory() / (1024 * 1024)) + "Mb");
// Write version info
writeWorkspaceInfo();
// Run instance server
instanceServer = DBeaverInstanceServer.startInstanceServer();
// Set default resource encoding to UTF-8
String defEncoding = DBeaverCore.getGlobalPreferenceStore().getString(DBeaverPreferences.DEFAULT_RESOURCE_ENCODING);
if (CommonUtils.isEmpty(defEncoding)) {
defEncoding = GeneralUtils.UTF8_ENCODING;
}
ResourcesPlugin.getPlugin().getPluginPreferences().setValue(ResourcesPlugin.PREF_ENCODING, defEncoding);
// Create display
getDisplay();
// Prefs default
PlatformUI.getPreferenceStore().setDefault(IWorkbenchPreferenceConstants.KEY_CONFIGURATION_ID, ApplicationWorkbenchAdvisor.DBEAVER_SCHEME_NAME);
try {
log.debug("Run workbench");
int returnCode = PlatformUI.createAndRunWorkbench(display, createWorkbenchAdvisor());
if (returnCode == PlatformUI.RETURN_RESTART) {
return IApplication.EXIT_RESTART;
}
return IApplication.EXIT_OK;
} finally {
/*
try {
Job.getJobManager().join(null, new NullProgressMonitor());
}
catch (InterruptedException e) {
e.printStackTrace();
}
*/
display.dispose();
display = null;
}
}
use of org.eclipse.osgi.service.datalocation.Location in project cubrid-manager by CUBRID.
the class Application method start.
public Object start(IApplicationContext context) throws Exception {
ApplicationUtil.setApplicationType(ApplicationType.CUBRID_MANAGER);
String applicationType = ApplicationType.CUBRID_MANAGER.getShortName();
Display display = null;
try {
display = PlatformUI.createDisplay();
Shell shell = CommonUITool.getSplashShell(display);
if (!CommonUITool.jreVersionCheck()) {
CommonUITool.openErrorBox(shell, com.cubrid.common.ui.spi.Messages.unsupportedJRE);
context.applicationRunning();
return IApplication.EXIT_OK;
}
if (!SelectWorkspaceDialog.pickWorkspaceDir(shell, applicationType, Version.buildVersionId)) {
context.applicationRunning();
return IApplication.EXIT_OK;
}
String workspace = SelectWorkspaceDialog.getLastSetWorkspaceDirectory();
LogUtil.configLogger(null, workspace);
int returnCode = PlatformUI.createAndRunWorkbench(display, new ApplicationWorkbenchAdvisor());
if (returnCode == PlatformUI.RETURN_RESTART) {
return IApplication.EXIT_RESTART;
}
return IApplication.EXIT_OK;
} finally {
if (display != null) {
display.dispose();
}
Location instanceLoc = Platform.getInstanceLocation();
if (instanceLoc != null) {
instanceLoc.release();
}
}
}
Aggregations