Browse Source

Merge pull request #19 in PF/design from ~KERRY/design-pf:9.0 to 9.0

* commit '68c33117566ef88ba9ff9c8f1d308c838cb57c1a':
  修改PMD
  修改PMD
  避免魔术数
  REPORT-235
  report-2354 整合后台插件操作代码
  REPORT-2354 设计器插件操作部分
  REPORT-2354 设计器插件操作部分
master
kerry 8 years ago
parent
commit
872d3677bb
  1. 15
      designer_base/src/com/fr/design/extra/PluginConstants.java
  2. 192
      designer_base/src/com/fr/design/extra/PluginOperateUtils.java
  3. 60
      designer_base/src/com/fr/design/extra/PluginReaderForDesigner.java
  4. 107
      designer_base/src/com/fr/design/extra/PluginUtils.java
  5. 119
      designer_base/src/com/fr/design/extra/PluginWebBridge.java
  6. 4
      designer_base/src/com/fr/design/extra/WebViewDlgHelper.java
  7. 4
      designer_base/src/com/fr/design/extra/exe/GetLoginInfoExecutor.java
  8. 5
      designer_base/src/com/fr/design/extra/exe/GetPluginCategoriesExecutor.java
  9. 4
      designer_base/src/com/fr/design/extra/exe/GetPluginFromStoreExecutor.java
  10. 72
      designer_base/src/com/fr/design/extra/exe/InstallFromDiskExecutor.java
  11. 138
      designer_base/src/com/fr/design/extra/exe/InstallOnlineExecutor.java
  12. 51
      designer_base/src/com/fr/design/extra/exe/ModifyStatusExecutor.java
  13. 12
      designer_base/src/com/fr/design/extra/exe/ReadUpdateOnlineExecutor.java
  14. 62
      designer_base/src/com/fr/design/extra/exe/UninstallExecutor.java
  15. 47
      designer_base/src/com/fr/design/extra/exe/UpdateFromDiskExecutor.java
  16. 140
      designer_base/src/com/fr/design/extra/exe/UpdateOnlineExecutor.java
  17. 20
      designer_base/src/com/fr/design/extra/exe/callback/AbstractPluginTaskCallback.java
  18. 33
      designer_base/src/com/fr/design/extra/exe/callback/DownloadCallback.java
  19. 53
      designer_base/src/com/fr/design/extra/exe/callback/InstallFromDiskCallback.java
  20. 53
      designer_base/src/com/fr/design/extra/exe/callback/InstallOnlineCallback.java
  21. 29
      designer_base/src/com/fr/design/extra/exe/callback/JSCallback.java
  22. 28
      designer_base/src/com/fr/design/extra/exe/callback/ModifyStatusCallback.java
  23. 26
      designer_base/src/com/fr/design/extra/exe/callback/UnistallPluginCallback.java
  24. 54
      designer_base/src/com/fr/design/extra/exe/callback/UpdateFromDiskCallback.java
  25. 55
      designer_base/src/com/fr/design/extra/exe/callback/UpdateOnlineCallback.java
  26. 10
      designer_base/src/com/fr/design/extra/exe/extratask/ExtraPluginTask.java
  27. 25
      designer_base/src/com/fr/design/extra/exe/extratask/InstallPluginTask.java
  28. 28
      designer_base/src/com/fr/design/extra/exe/extratask/UpdatePluginTask.java

15
designer_base/src/com/fr/design/extra/PluginConstants.java

@ -0,0 +1,15 @@
package com.fr.design.extra;
/**
* Created by ibm on 2017/5/25.
*/
public class PluginConstants {
public static final int BYTES_NUM = 1024;
private static final String TEMP_PATH = System.getProperty("user.dir") + "/tmp";
public static final String DOWNLOAD_PATH = System.getProperty("user.dir") + "/download";
//插件依赖的下载位置
public static final String DEPENDENCE_DOWNLOAD_PATH = System.getProperty("user.dir") + "/download/dependence";
public static final String TEMP_FILE = "temp.zip";
public static final String CONNECTION_404 = "404";
}

192
designer_base/src/com/fr/design/extra/PluginOperateUtils.java

@ -0,0 +1,192 @@
package com.fr.design.extra;
import com.fr.base.FRContext;
import com.fr.design.DesignerEnvManager;
import com.fr.design.extra.exe.callback.*;
import com.fr.design.extra.exe.extratask.InstallPluginTask;
import com.fr.design.extra.exe.extratask.UpdatePluginTask;
import com.fr.general.FRLogger;
import com.fr.general.Inter;
import com.fr.general.SiteCenter;
import com.fr.general.http.HttpClient;
import com.fr.json.JSONObject;
import com.fr.plugin.context.PluginContext;
import com.fr.plugin.context.PluginMarker;
import com.fr.plugin.manage.PluginManager;
import com.fr.plugin.manage.bbs.BBSPluginLogin;
import com.fr.plugin.manage.control.PluginTaskCallback;
import com.fr.plugin.manage.control.PluginTaskResult;
import com.fr.stable.ArrayUtils;
import com.fr.stable.StringUtils;
import javafx.scene.web.WebEngine;
import netscape.javascript.JSObject;
import org.json.JSONArray;
import sun.plugin2.main.server.Plugin;
import javax.swing.*;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
/**
* Created by ibm on 2017/5/26.
*/
public class PluginOperateUtils {
public static void installPluginOnline(final String pluginInfo, JSCallback jsCallback) {
//下载插件
if (!BBSPluginLogin.getInstance().hasLogin()) {
LoginCheckContext.fireLoginCheckListener();
}
PluginMarker pluginMarker = PluginUtils.createPluginMarker(pluginInfo);
if (BBSPluginLogin.getInstance().hasLogin()) {
PluginManager.getController().download(pluginMarker, new DownloadCallback(new InstallPluginTask(pluginMarker, jsCallback), jsCallback));
}
}
public static void installPluginFromDisk(final String filePath, JSCallback jsCallback) {
PluginManager.getController().install(new File(filePath), new InstallFromDiskCallback(new File(filePath), jsCallback));
}
public static void updatePluginOnline(JSObject pluginIDs, JSCallback jsCallback) {
String[] pluginInfos = jsObjectToStringArray(pluginIDs);
if (!(BBSPluginLogin.getInstance().hasLogin())) {
LoginCheckContext.fireLoginCheckListener();
}
if (BBSPluginLogin.getInstance().hasLogin()) {
List<PluginMarker> pluginMarkerList = new ArrayList<PluginMarker>();
for (int i = 0; i < pluginInfos.length; i++) {
pluginMarkerList.add(PluginUtils.createPluginMarker(pluginInfos[i]));
}
for (int i = 0; i < pluginMarkerList.size(); i++) {
try {
//todo check下此插件的最新版本
String latestPluginInfo = PluginUtils.getLatestPluginInfo(pluginMarkerList.get(i).getPluginID());
if (StringUtils.isEmpty(latestPluginInfo) || PluginConstants.CONNECTION_404.equals(latestPluginInfo)) {
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Connect_Failed"), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
return;
}
JSONObject resultArr = new JSONObject(latestPluginInfo);
String latestPluginVersion = (String) resultArr.get("version");
PluginMarker pluginMarker = pluginMarkerList.get(i);
PluginMarker toPluginMarker = PluginMarker.create(pluginMarkerList.get(i).getPluginID(), latestPluginVersion);
PluginManager.getController().download(pluginMarkerList.get(i), new DownloadCallback(new UpdatePluginTask(pluginMarker, toPluginMarker, jsCallback), jsCallback));
} catch (Exception e) {
FRContext.getLogger().error(e.getMessage(), e);
}
}
}
}
public static void updatePluginFromDisk(final String filePath, JSCallback jsCallback) {
PluginManager.getController().update(new File(filePath), new UpdateFromDiskCallback(new File(filePath), jsCallback));
}
public static void setPluginActive(String pluginInfo, JSCallback jsCallback) {
PluginMarker pluginMarker = PluginUtils.createPluginMarker(pluginInfo);
PluginContext plugin = PluginManager.getContext(pluginMarker);
boolean active = !plugin.isActive();
PluginTaskCallback modifyStatusCallback = new ModifyStatusCallback(active);
if (active) {
PluginManager.getController().forbid(pluginMarker, modifyStatusCallback);
} else {
PluginManager.getController().enable(pluginMarker, modifyStatusCallback);
}
}
public static void uninstallPlugin(final String pluginInfo, final boolean isForce, JSCallback jsCallback) {
PluginMarker pluginMarker = PluginUtils.createPluginMarker(pluginInfo);
PluginManager.getController().uninstall(pluginMarker, isForce, new UnistallPluginCallback());
}
public static void readUpdateOnline(JSCallback jsCallback){
try {
String [] plugins = PluginReaderForDesigner.readPluginsForUpdate();
JSONArray jsonArray = new JSONArray();
for (String plugin : plugins) {
org.json.JSONObject jsonObject = new org.json.JSONObject();
jsonObject.put("pluginid", plugin);
jsonArray.put(jsonObject);
}
String result = jsonArray.toString();
jsCallback.execute(result);
} catch (Exception e) {
FRLogger.getLogger().error(e.getMessage());
}
}
public static void searchPlugin(String keyword, JSCallback jsCallback) {
try {
HttpClient httpClient = new HttpClient(SiteCenter.getInstance().acquireUrlByKind("plugin.plist") + "&keyword=" + keyword);
String result = httpClient.getResponseText();
jsCallback.execute(result);
} catch (Exception e) {
FRLogger.getLogger().error(e.getMessage());
}
}
public static void getPluginFromStore(String category, String seller, String fee, JSCallback jsCallback){
String plistUrl = SiteCenter.getInstance().acquireUrlByKind("plugin.plist");
if (StringUtils.isNotBlank(plistUrl)) {
StringBuilder url = new StringBuilder();
url.append(plistUrl);
if (StringUtils.isNotBlank(category)) {
url.append("&cid=").append(category.split("-")[1]);
}
if (StringUtils.isNotBlank(seller)) {
url.append("&seller=").append(seller.split("-")[1]);
}
if (StringUtils.isNotBlank(fee)) {
url.append("&fee=").append(fee.split("-")[1]);
}
try {
HttpClient httpClient = new HttpClient(url.toString());
String result = httpClient.getResponseText();
jsCallback.execute(result);
} catch (Exception e) {
FRLogger.getLogger().error(e.getMessage());
}
} else {
String result = PluginConstants.CONNECTION_404;
jsCallback.execute(result);
}
}
public static void getPluginCategories(JSCallback jsCallback){
String result;
String url = SiteCenter.getInstance().acquireUrlByKind("plugin.category");
if (url != null) {
HttpClient httpClient = new HttpClient(url);
result = httpClient.getResponseText();
} else {
result = PluginConstants.CONNECTION_404;
}
jsCallback.execute(result);
}
public static void getLoginInfo(JSCallback jsCallback){
String username = BBSPluginLogin.getInstance().getUserInfo().getUserName();
String inShowUsername = DesignerEnvManager.getEnvManager().getInShowBBsName();
if (StringUtils.isEmpty(username) && StringUtils.isEmpty(inShowUsername)) {
return;
}else {
String result = StringUtils.isEmpty(inShowUsername) ? username : inShowUsername;
jsCallback.execute(result);
}
}
private static String[] jsObjectToStringArray(JSObject obj) {
if (obj == null) {
return ArrayUtils.EMPTY_STRING_ARRAY;
}
int len = (int) obj.getMember("length");
List<String> list = new ArrayList<>();
for (int i = 0; i < len; i++) {
list.add(obj.getSlot(i).toString());
}
return list.toArray(new String[len]);
}
}

60
designer_base/src/com/fr/design/extra/PluginReaderForDesigner.java

@ -0,0 +1,60 @@
package com.fr.design.extra;
import com.fr.general.GeneralUtils;
import com.fr.general.Inter;
import com.fr.general.SiteCenter;
import com.fr.general.http.HttpClient;
import com.fr.json.JSONArray;
import com.fr.json.JSONException;
import com.fr.json.JSONObject;
import com.fr.plugin.manage.PluginManager;
import com.fr.stable.EncodeConstants;
import com.fr.stable.StringUtils;
import java.net.URLDecoder;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
/**
* Created by ibm on 2017/5/25.
*/
public class PluginReaderForDesigner {
private static Set<String> pluginsToUpdate = new HashSet<String>();
/**
* 从插件商店服务器读取插件信息以JSON形式返回
*
* @return 插件信息
*/
public static String[] readPluginsForUpdate() throws Exception {
String resText = null;
String url = SiteCenter.getInstance().acquireUrlByKind("plugin.update");
if (StringUtils.isNotEmpty(url)) {
HashMap<String, String> para = new HashMap<String, String>();
para.put("plugins", PluginUtils.transPluginsToString(PluginManager.getContexts()));
//只有当前设计器的jar高于插件新版本需要的jarTime时, 才提示更新该插件.
para.put("jarTime", GeneralUtils.readBuildNO());
HttpClient httpClient = new HttpClient(url, para);
resText = httpClient.getResponseText();
String charSet = EncodeConstants.ENCODING_UTF_8;
resText = URLDecoder.decode(URLDecoder.decode(resText, charSet), charSet);
}
if (StringUtils.isNotEmpty(resText)) {
try {
pluginsToUpdate.clear();
JSONArray jsonArray = new JSONArray(resText);
for (int i = 0, size = jsonArray.length(); i < size; i++) {
JSONObject jo = jsonArray.optJSONObject(i);
String id = jo.optString("id");
if(StringUtils.isNotEmpty(id)){
pluginsToUpdate.add(jo.optString("id", ""));
}
}
} catch (JSONException e) {
throw new Exception(Inter.getLocText("FS-Web-Plugin_Read_Plugin_List_Error"));
}
}
return pluginsToUpdate.toArray(new String[pluginsToUpdate.size()]);
}
}

107
designer_base/src/com/fr/design/extra/PluginUtils.java

@ -0,0 +1,107 @@
package com.fr.design.extra;
import com.fr.general.FRLogger;
import com.fr.general.Inter;
import com.fr.general.SiteCenter;
import com.fr.general.http.HttpClient;
import com.fr.json.JSONArray;
import com.fr.json.JSONObject;
import com.fr.plugin.context.PluginContext;
import com.fr.plugin.context.PluginMarker;
import com.fr.stable.EncodeConstants;
import com.fr.stable.StableUtils;
import com.fr.stable.StringUtils;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URLDecoder;
import java.util.HashMap;
import java.util.List;
/**
* Created by ibm on 2017/5/25.
*/
public class PluginUtils {
public static PluginMarker createPluginMarker(String pluginInfo) {
//todo 判空
String[] plugin = pluginInfo.split("_");
PluginMarker pluginMarker = PluginMarker.create(plugin[0], plugin[1]);
return pluginMarker;
}
public static String getLatestPluginInfo(String pluginID){
String result = "";
String plistUrl = SiteCenter.getInstance().acquireUrlByKind("plugin.searchAPI");
if (StringUtils.isNotEmpty(plistUrl)) {
StringBuilder url = new StringBuilder(plistUrl);
if (StringUtils.isNotBlank(pluginID)) {
url.append("?keyword=").append(pluginID);
}
try {
HttpClient httpClient = new HttpClient(url.toString());
result = httpClient.getResponseText();
} catch (Exception e) {
FRLogger.getLogger().error(e.getMessage());
}
} else {
result = PluginConstants.CONNECTION_404;
}
return result;
}
public static String transPluginsToString(List<PluginContext> plugins) throws Exception {
JSONArray jsonArray = new JSONArray();
for (PluginContext plugin : plugins) {
JSONObject jo = new JSONObject();
jo.put("id", plugin.getID());
jo.put("version", plugin.getVersion());
jsonArray.put(jo);
}
return jsonArray.toString();
}
public static void downloadShopScripts(String id, String username, String password, Process<Double> p) throws Exception{
HttpClient httpClient = new HttpClient(getDownloadPath(id, username, password));
if (httpClient.getResponseCode() == HttpURLConnection.HTTP_OK) {
int totalSize = httpClient.getContentLength();
InputStream reader = httpClient.getResponseStream();
String temp = StableUtils.pathJoin(PluginConstants.DOWNLOAD_PATH, PluginConstants.TEMP_FILE);
StableUtils.makesureFileExist(new File(temp));
FileOutputStream writer = new FileOutputStream(temp);
byte[] buffer = new byte[PluginConstants.BYTES_NUM];
int bytesRead = 0;
int totalBytesRead = 0;
while ((bytesRead = reader.read(buffer)) > 0) {
writer.write(buffer, 0, bytesRead);
buffer = new byte[PluginConstants.BYTES_NUM];
totalBytesRead += bytesRead;
p.process(totalBytesRead / (double) totalSize);
}
reader.close();
writer.flush();
writer.close();
} else {
throw new com.fr.plugin.PluginVerifyException(Inter.getLocText("FR-Designer-Plugin_Connect_Server_Error"));
}
}
private static String getDownloadPath(String id, String username, String password) throws Exception {
HashMap<String, String> map = new HashMap<String, String>();
map.put("id", id);
map.put("username", username);
map.put("password", password);
HttpClient httpClient = new HttpClient(SiteCenter.getInstance().acquireUrlByKind("plugin.download"), map);
String resText = httpClient.getResponseText();
String charSet = EncodeConstants.ENCODING_UTF_8;
resText = URLDecoder.decode(URLDecoder.decode(resText, charSet), charSet);
return resText;
}
}

119
designer_base/src/com/fr/design/extra/PluginWebBridge.java

@ -5,14 +5,15 @@ import com.fr.design.DesignerEnvManager;
import com.fr.design.RestartHelper;
import com.fr.design.dialog.UIDialog;
import com.fr.design.extra.exe.*;
import com.fr.design.extra.exe.callback.JSCallback;
import com.fr.design.gui.ilable.UILabel;
import com.fr.general.FRLogger;
import com.fr.general.Inter;
import com.fr.general.SiteCenter;
import com.fr.plugin.Plugin;
import com.fr.plugin.PluginLicense;
import com.fr.plugin.PluginLicenseManager;
import com.fr.plugin.PluginLoader;
import com.fr.plugin.context.PluginContext;
import com.fr.plugin.manage.PluginManager;
import com.fr.stable.ArrayUtils;
import com.fr.stable.StringUtils;
import javafx.concurrent.Task;
@ -143,42 +144,45 @@ public class PluginWebBridge {
/**
* 从插件服务器上安装插件
*
* @param pluginID 插件的ID
* @param pluginInfo 插件的ID
* @param callback 回调函数
*/
public void installPluginOnline(final String pluginID, final JSObject callback) {
Task<Void> task = new PluginTask<>(webEngine, callback, new InstallOnlineExecutor(pluginID));
new Thread(task).start();
public void installPluginOnline(final String pluginInfo, final JSObject callback) {
JSCallback jsCallback = new JSCallback(webEngine, callback);
PluginOperateUtils.installPluginOnline(pluginInfo,jsCallback);
}
/**
* 从磁盘上选择插件安装包进行安装
*
* @param filePath 插件包的路径
*/
public void installPluginFromDisk(final String filePath, final JSObject callback) {
Task<Void> task = new PluginTask<>(webEngine, callback, new InstallFromDiskExecutor(filePath));
new Thread(task).start();
JSCallback jsCallback = new JSCallback(webEngine, callback);
PluginOperateUtils.installPluginFromDisk(filePath,jsCallback);
}
/**
* 卸载当前选中的插件
*
* @param pluginIDs 插件集合
* @param pluginInfo 插件信息
*/
public void uninstallPlugin(JSObject pluginIDs, final JSObject callback) {
Task<Void> task = new PluginTask<>(webEngine, callback, new UninstallExecutor(jsObjectToStringArray(pluginIDs)));
new Thread(task).start();
public void uninstallPlugin(final String pluginInfo, final boolean isForce, final JSObject callback) {
JSCallback jsCallback = new JSCallback(webEngine, callback);
PluginOperateUtils.uninstallPlugin(pluginInfo, isForce, jsCallback);
}
/**
* 从插件服务器上更新选中的插件
*
* @param pluginIDs 插件集合
*/
public void updatePluginOnline(JSObject pluginIDs, final JSObject callback) {
Task<Void> task = new PluginTask<>(webEngine, callback, new UpdateOnlineExecutor(jsObjectToStringArray(pluginIDs)));
new Thread(task).start();
JSCallback jsCallback = new JSCallback(webEngine, callback);
PluginOperateUtils.updatePluginOnline(pluginIDs, jsCallback);
}
/**
@ -187,8 +191,8 @@ public class PluginWebBridge {
* @param filePath 插件包的路径
*/
public void updatePluginFromDisk(String filePath, final JSObject callback) {
Task<Void> task = new PluginTask<>(webEngine, callback, new UpdateFromDiskExecutor(filePath));
new Thread(task).start();
JSCallback jsCallback = new JSCallback(webEngine, callback);
PluginOperateUtils.updatePluginFromDisk(filePath, jsCallback);
}
/**
@ -197,16 +201,16 @@ public class PluginWebBridge {
* @param pluginID 插件ID
*/
public void setPluginActive(String pluginID, final JSObject callback) {
Task<Void> task = new PluginTask<>(webEngine, callback, new ModifyStatusExecutor(pluginID));
new Thread(task).start();
JSCallback jsCallback = new JSCallback(webEngine, callback);
PluginOperateUtils.setPluginActive(pluginID, jsCallback);
}
/**
* 已安装插件检查更新
*/
public void readUpdateOnline(final JSObject callback) {
Task<Void> task = new PluginTask<>(webEngine, callback, new ReadUpdateOnlineExecutor());
new Thread(task).start();
JSCallback jsCallback = new JSCallback(webEngine, callback);
PluginOperateUtils.readUpdateOnline(jsCallback);
}
/**
@ -266,8 +270,9 @@ public class PluginWebBridge {
*
* @return 已安装的插件组成的数组
*/
public Plugin[] getInstalledPlugins() {
return PluginLoader.getLoader().getInstalled();
public PluginContext[] getInstalledPlugins() {
List<PluginContext> plugins = PluginManager.getContexts();
return plugins.toArray(new PluginContext[plugins.size()]);
}
@ -298,8 +303,8 @@ public class PluginWebBridge {
* @param keyword 关键字
*/
public void searchPlugin(String keyword, final JSObject callback) {
Task<Void> task = new PluginTask<>(webEngine, callback, new SearchOnlineExecutor(keyword));
new Thread(task).start();
JSCallback jsCallback = new JSCallback(webEngine, callback);
PluginOperateUtils.searchPlugin(keyword, jsCallback);
}
/**
@ -311,8 +316,8 @@ public class PluginWebBridge {
* @param callback 回调函数
*/
public void getPluginFromStore(String category, String seller, String fee, final JSObject callback) {
Task<Void> task = new PluginTask<>(webEngine, callback, new GetPluginFromStoreExecutor(category, seller, fee));
new Thread(task).start();
JSCallback jsCallback = new JSCallback(webEngine, callback);
PluginOperateUtils.getPluginFromStore(category, seller, fee, jsCallback);
}
/**
@ -321,8 +326,8 @@ public class PluginWebBridge {
* @param callback 回调函数
*/
public void getPluginCategories(final JSObject callback) {
Task<Void> task = new PluginTask<>(webEngine, callback, new GetPluginCategoriesExecutor());
new Thread(task).start();
JSCallback jsCallback = new JSCallback(webEngine, callback);
PluginOperateUtils.getPluginCategories(jsCallback);
}
/**
@ -372,8 +377,8 @@ public class PluginWebBridge {
* @param callback
*/
public void getLoginInfo(final JSObject callback) {
Task<Void> task = new PluginTask<>(webEngine, callback, new GetLoginInfoExecutor());
new Thread(task).start();
JSCallback jsCallback = new JSCallback(webEngine, callback);
PluginOperateUtils.getLoginInfo(jsCallback);
}
/**
@ -439,60 +444,6 @@ public class PluginWebBridge {
}
}
/**
* 从硬盘升级
*
* @param fileOnDisk 硬盘上的文件
*/
public void updateFileFromDisk(File fileOnDisk) {
try {
Plugin plugin = PluginHelper.readPlugin(fileOnDisk);
if (plugin == null) {
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Illegal_Plugin_Zip"), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
return;
}
Plugin oldPlugin = PluginLoader.getLoader().getPluginById(plugin.getId());
if (oldPlugin != null) {
// 说明安装了同ID的插件,再比较两个插件的版本
if (PluginHelper.isNewThan(plugin, oldPlugin)) {
// 说明是新的插件,删除老的然后安装新的
final String[] files = PluginHelper.uninstallPlugin(FRContext.getCurrentEnv(), oldPlugin);
PluginHelper.installPluginFromUnzippedTempDir(FRContext.getCurrentEnv(), plugin, new After() {
@Override
public void done() {
int rv = JOptionPane.showOptionDialog(
null,
Inter.getLocText("FR-Designer-Plugin_Update_Successful"),
Inter.getLocText("FR-Designer-Plugin_Warning"),
JOptionPane.YES_NO_OPTION,
JOptionPane.INFORMATION_MESSAGE,
null,
new String[]{Inter.getLocText("FR-Designer-Basic_Restart_Designer"),
Inter.getLocText("FR-Designer-Basic_Restart_Designer_Later")
},
null
);
if (rv == JOptionPane.OK_OPTION) {
RestartHelper.restart();
}
// 如果不是立即重启,就把要删除的文件存放起来
if (rv == JOptionPane.CANCEL_OPTION || rv == JOptionPane.CLOSED_OPTION) {
RestartHelper.saveFilesWhichToDelete(files);
}
}
});
} else {
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Version_Is_Lower_Than_Current"), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
}
} else {
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Cannot_Update_Not_Install"), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
}
} catch (Exception e1) {
JOptionPane.showMessageDialog(null, e1.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
}
}
/*-------------------------------登录部分的处理----------------------------------*/

4
designer_base/src/com/fr/design/extra/WebViewDlgHelper.java

@ -133,7 +133,7 @@ public class WebViewDlgHelper {
String username = DesignerEnvManager.getEnvManager().getBBSName();
String password = DesignerEnvManager.getEnvManager().getBBSPassword();
try {
PluginHelper.downloadPluginFile(scriptsId, username, password, new Process<Double>() {
PluginUtils.downloadShopScripts(scriptsId, username, password, new Process<Double>() {
@Override
public void process(Double integer) {
}
@ -153,7 +153,7 @@ public class WebViewDlgHelper {
try {
if (get()) {
IOUtils.unzip(new File(StableUtils.pathJoin(PluginHelper.DOWNLOAD_PATH, PluginHelper.TEMP_FILE)), StableUtils.getInstallHome());
IOUtils.unzip(new File(StableUtils.pathJoin(PluginConstants.DOWNLOAD_PATH, PluginConstants.TEMP_FILE)), StableUtils.getInstallHome());
int rv = JOptionPane.showOptionDialog(
null,
Inter.getLocText("FR-Designer-Plugin_Shop_Installed"),

4
designer_base/src/com/fr/design/extra/exe/GetLoginInfoExecutor.java

@ -2,6 +2,7 @@ package com.fr.design.extra.exe;
import com.fr.design.DesignerEnvManager;
import com.fr.design.extra.Process;
import com.fr.plugin.manage.bbs.BBSPluginLogin;
import com.fr.stable.StringUtils;
/**
@ -26,9 +27,10 @@ public class GetLoginInfoExecutor implements Executor {
@Override
public void run(Process<String> process) {
String username = DesignerEnvManager.getEnvManager().getBBSName();
String username = BBSPluginLogin.getInstance().getUserInfo().getUserName();
String inShowUsername = DesignerEnvManager.getEnvManager().getInShowBBsName();
if (StringUtils.isEmpty(username) && StringUtils.isEmpty(inShowUsername)) {
return;
}else {
result = StringUtils.isEmpty(inShowUsername) ? username : inShowUsername;
}

5
designer_base/src/com/fr/design/extra/exe/GetPluginCategoriesExecutor.java

@ -1,6 +1,6 @@
package com.fr.design.extra.exe;
import com.fr.design.extra.PluginHelper;
import com.fr.design.extra.PluginConstants;
import com.fr.design.extra.Process;
import com.fr.general.SiteCenter;
import com.fr.general.http.HttpClient;
@ -32,9 +32,8 @@ public class GetPluginCategoriesExecutor implements Executor {
HttpClient httpClient = new HttpClient(url);
result = httpClient.getResponseText();
} else {
result = PluginHelper.CONNECTION_404;
result = PluginConstants.CONNECTION_404;
}
}
}
};

4
designer_base/src/com/fr/design/extra/exe/GetPluginFromStoreExecutor.java

@ -1,6 +1,6 @@
package com.fr.design.extra.exe;
import com.fr.design.extra.PluginHelper;
import com.fr.design.extra.PluginConstants;
import com.fr.design.extra.Process;
import com.fr.general.FRLogger;
import com.fr.general.SiteCenter;
@ -59,7 +59,7 @@ public class GetPluginFromStoreExecutor implements Executor {
FRLogger.getLogger().error(e.getMessage());
}
} else {
result = PluginHelper.CONNECTION_404;
result = PluginConstants.CONNECTION_404;
}
}
}

72
designer_base/src/com/fr/design/extra/exe/InstallFromDiskExecutor.java

@ -1,12 +1,12 @@
package com.fr.design.extra.exe;
import com.fr.design.extra.After;
import com.fr.design.extra.PluginHelper;
import com.fr.design.extra.PluginWebBridge;
import com.fr.design.extra.Process;
import com.fr.general.FRLogger;
import com.fr.general.Inter;
import com.fr.plugin.PluginVerifyException;
import com.fr.plugin.error.PluginErrorCode;
import com.fr.plugin.manage.PluginManager;
import com.fr.plugin.manage.control.PluginTaskResult;
import com.fr.plugin.manage.control.ProgressCallback;
import javax.swing.*;
import java.io.File;
@ -24,7 +24,7 @@ public class InstallFromDiskExecutor implements Executor {
@Override
public String getTaskFinishMessage() {
return "已成功安装";
return Inter.getLocText("FR-Designer-Plugin_Success_Install");
}
@Override
@ -33,7 +33,7 @@ public class InstallFromDiskExecutor implements Executor {
new Command() {
@Override
public String getExecuteMessage() {
return "正在解压文件" + filePath;
return Inter.getLocText("FR-Designer-Plugin_Unzipping") + filePath;
}
@Override
@ -44,26 +44,60 @@ public class InstallFromDiskExecutor implements Executor {
new Command() {
@Override
public String getExecuteMessage() {
return "正在安装";
return Inter.getLocText("FR-Designer-Plugin_Installing");
}
@Override
public void run(Process<String> process) {
try {
PluginHelper.installPluginFromDisk(new File(filePath), new After() {
@Override
public void done() {
FRLogger.getLogger().info("插件安装成功");
PluginWebBridge.getHelper().showRestartMessage(Inter.getLocText("FR-Designer-Plugin_Install_Successful"));
PluginManager.getController().install(new File(filePath), new ProgressCallback() {
@Override
public void updateProgress(String description, double progress) {
}
@Override
public void done(PluginTaskResult result) {
if (result.isSuccess()) {
FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Install_Success"));
} else if(result.errorCode() == PluginErrorCode.OperationNotSupport.getCode()){
int rv = JOptionPane.showOptionDialog(
null,
Inter.getLocText(Inter.getLocText("FR-Designer-Plugin_Install_Dependence")),
Inter.getLocText("FR-Designer-Plugin_Warning"),
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.INFORMATION_MESSAGE,
null,
null,
null
);
if (rv == JOptionPane.CANCEL_OPTION || rv == JOptionPane.CLOSED_OPTION) {
return;
}
installWithDependence();
}else{
FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Install_Failed"));
JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
}
});
} catch (PluginVerifyException e) {
JOptionPane.showMessageDialog(null, e.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
} catch (Exception e) {
FRLogger.getLogger().error(e.getMessage());
}
}
});
}
}
};
}
public void installWithDependence(){
PluginManager.getController().install(new File(filePath), new ProgressCallback() {
@Override
public void updateProgress(String description, double progress) {
}
@Override
public void done(PluginTaskResult result) {
if (result.isSuccess()) {
FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Install_Success"));
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Install_Successful"));
} else{
FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Install_Failed"));
JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
}
}
});
}
}

138
designer_base/src/com/fr/design/extra/exe/InstallOnlineExecutor.java

@ -1,16 +1,16 @@
package com.fr.design.extra.exe;
import com.fr.base.FRContext;
import com.fr.design.DesignerEnvManager;
import com.fr.design.RestartHelper;
import com.fr.design.extra.After;
import com.fr.design.extra.LoginCheckContext;
import com.fr.design.extra.PluginHelper;
import com.fr.design.extra.PluginUtils;
import com.fr.design.extra.Process;
import com.fr.general.FRLogger;
import com.fr.general.Inter;
import com.fr.plugin.PluginVerifyException;
import com.fr.plugin.dependence.PluginDependenceException;
import com.fr.stable.StringUtils;
import com.fr.plugin.context.PluginMarker;
import com.fr.plugin.error.PluginErrorCode;
import com.fr.plugin.manage.PluginManager;
import com.fr.plugin.manage.bbs.BBSPluginLogin;
import com.fr.plugin.manage.control.PluginTaskResult;
import com.fr.plugin.manage.control.ProgressCallback;
import javax.swing.*;
@ -19,10 +19,10 @@ import javax.swing.*;
*/
public class InstallOnlineExecutor implements Executor {
private String pluginID;
private String pluginInfo;
public InstallOnlineExecutor(String pluginID) {
this.pluginID = pluginID;
public InstallOnlineExecutor(String pluginInfo) {
this.pluginInfo = pluginInfo;
}
@Override
@ -36,69 +36,89 @@ public class InstallOnlineExecutor implements Executor {
new Command() {
@Override
public String getExecuteMessage() {
return "正在下载插件:" + pluginID;
return Inter.getLocText("FR-Designer-Plugin_Downloading") + ":" + pluginInfo.split("_")[0];
}
@Override
public void run(final Process<String> process) {
//下载插件
if(StringUtils.isBlank(DesignerEnvManager.getEnvManager().getBBSName())){
if (!BBSPluginLogin.getInstance().hasLogin()) {
LoginCheckContext.fireLoginCheckListener();
}
if(StringUtils.isNotBlank(DesignerEnvManager.getEnvManager().getBBSName())) {
String username = DesignerEnvManager.getEnvManager().getBBSName();
String password = DesignerEnvManager.getEnvManager().getBBSPassword();
try {
PluginHelper.downloadPluginFile(pluginID, username, password, new Process<Double>() {
@Override
public void process(Double integer) {
process.process(Math.round(integer * 100) + "%");
}
});
} catch (Exception e) {
FRContext.getLogger().error(e.getMessage(), e);
}
}
}
},
new Command() {
@Override
public String getExecuteMessage() {
return "正在安装插件:" + pluginID;
}
PluginMarker pluginMarker = PluginUtils.createPluginMarker(pluginInfo);
if (BBSPluginLogin.getInstance().hasLogin()) {
PluginManager.getController().download(pluginMarker, new ProgressCallback() {
@Override
public void updateProgress(String description, double aProgress) {
// process.process(Math.round(aProgress * 100) + "%");
}
@Override
public void run(Process<String> process) {
try {
PluginHelper.installPluginFromDisk(PluginHelper.getDownloadTempFile(), new After() {
@Override
public void done() {
int rv = JOptionPane.showOptionDialog(
null,
Inter.getLocText("FR-Designer-Plugin_Install_Successful"),
Inter.getLocText("FR-Designer-Plugin_Warning"),
JOptionPane.YES_NO_OPTION,
JOptionPane.INFORMATION_MESSAGE,
null,
new String[]{Inter.getLocText("FR-Designer-Basic_Restart_Designer"), Inter.getLocText("FR-Designer-Basic_Restart_Designer_Later")},
null
);
if (rv == JOptionPane.OK_OPTION) {
RestartHelper.restart();
public void done(PluginTaskResult result) {
if (result.isSuccess()) {
installPlugin(pluginMarker);
} else {
JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
}
}
});
} catch (PluginVerifyException e) {
JOptionPane.showMessageDialog(null, e.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
} catch (PluginDependenceException e){
JOptionPane.showMessageDialog(null, e.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
} catch (InterruptedException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
}
};
}
public void installPlugin(PluginMarker pluginMarker) {
PluginManager.getController().install(pluginMarker, new ProgressCallback() {
@Override
public void updateProgress(String description, double progress) {
}
@Override
public void done(PluginTaskResult result) {
if (result.isSuccess()) {
FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Install_Success"));
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Install_Successful"));
} else if (result.errorCode() == PluginErrorCode.OperationNotSupport.getCode()) {
int rv = JOptionPane.showOptionDialog(
null,
Inter.getLocText(Inter.getLocText("FR-Designer-Plugin_Install_Success")),
Inter.getLocText("FR-Designer-Plugin_Install_Dependence"),
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.INFORMATION_MESSAGE,
null,
null,
null
);
if (rv == JOptionPane.CANCEL_OPTION || rv == JOptionPane.CLOSED_OPTION) {
return;
}
installPluginWithDependence(pluginMarker);
} else {
JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
}
}
});
}
public void installPluginWithDependence(PluginMarker pluginMarker) {
PluginManager.getController().install(pluginMarker, new ProgressCallback() {
@Override
public void updateProgress(String description, double progress) {
}
@Override
public void done(PluginTaskResult result) {
if (result.isSuccess()) {
FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Install_Success"));
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Install_Successful"));
} else {
FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Install_Failed"));
JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
}
}
});
}
}

51
designer_base/src/com/fr/design/extra/exe/ModifyStatusExecutor.java

@ -1,24 +1,28 @@
package com.fr.design.extra.exe;
import com.fr.base.FRContext;
import com.fr.design.extra.PluginWebBridge;
import com.fr.design.extra.PluginUtils;
import com.fr.design.extra.Process;
import com.fr.general.Inter;
import com.fr.plugin.Plugin;
import com.fr.plugin.PluginLoader;
import com.fr.plugin.context.PluginContext;
import com.fr.plugin.context.PluginMarker;
import com.fr.plugin.manage.PluginManager;
import com.fr.plugin.manage.control.PluginTaskCallback;
import com.fr.plugin.manage.control.PluginTaskResult;
import com.fr.stable.StringUtils;
import javax.swing.*;
/**
* Created by richie on 16/3/19.
*/
public class ModifyStatusExecutor implements Executor {
private String pluginID;
private String pluginInfo;
private boolean active;
private Plugin plugin;
private PluginContext plugin;
public ModifyStatusExecutor(String pluginID) {
this.pluginID = pluginID;
public ModifyStatusExecutor(String pluginInfo) {
this.pluginInfo = pluginInfo;
}
@Override
@ -37,14 +41,31 @@ public class ModifyStatusExecutor implements Executor {
@Override
public void run(Process<String> process) {
plugin = PluginLoader.getLoader().getPluginById(pluginID);
PluginMarker pluginMarker = PluginUtils.createPluginMarker(pluginInfo);
plugin = PluginManager.getContext(pluginMarker);
active = !plugin.isActive();
plugin.setActive(active);
try {
FRContext.getCurrentEnv().writePlugin(plugin);
PluginWebBridge.getHelper().showRestartMessage(plugin.isActive() ? Inter.getLocText("FR-Designer-Plugin_Has_Been_Actived") : Inter.getLocText("FR-Designer-Plugin_Has_Been_Disabled"));
} catch (Exception e) {
FRContext.getLogger().error(e.getMessage());
if (active) {
PluginManager.getController().forbid(pluginMarker, new PluginTaskCallback() {
@Override
public void done(PluginTaskResult result) {
if (result.isSuccess()) {
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Has_Been_Disabled"));
} else {
JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
}
}
});
} else {
PluginManager.getController().enable(pluginMarker, new PluginTaskCallback() {
@Override
public void done(PluginTaskResult result) {
if (result.isSuccess()) {
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Has_Been_Actived"));
} else {
JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
}
}
});
}
}
}

12
designer_base/src/com/fr/design/extra/exe/ReadUpdateOnlineExecutor.java

@ -1,10 +1,8 @@
package com.fr.design.extra.exe;
import com.fr.design.extra.PluginsReaderFromStore;
import com.fr.design.extra.PluginReaderForDesigner;
import com.fr.design.extra.Process;
import com.fr.general.FRLogger;
import com.fr.plugin.Plugin;
import com.fr.stable.StringUtils;
import org.json.JSONArray;
import org.json.JSONObject;
@ -13,7 +11,7 @@ import org.json.JSONObject;
* Created by vito on 16/4/19.
*/
public class ReadUpdateOnlineExecutor implements Executor {
private Plugin[] plugins;
private String[] plugins;
private String result;
@Override
@ -33,11 +31,11 @@ public class ReadUpdateOnlineExecutor implements Executor {
@Override
public void run(Process<String> process) {
try {
plugins = PluginsReaderFromStore.readPluginsForUpdate();
plugins = PluginReaderForDesigner.readPluginsForUpdate();
JSONArray jsonArray = new JSONArray();
for (Plugin plugin : plugins) {
for (String plugin : plugins) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("pluginid", plugin.getId());
jsonObject.put("pluginid", plugin);
jsonArray.put(jsonObject);
}
result = jsonArray.toString();

62
designer_base/src/com/fr/design/extra/exe/UninstallExecutor.java

@ -1,12 +1,13 @@
package com.fr.design.extra.exe;
import com.fr.base.FRContext;
import com.fr.design.RestartHelper;
import com.fr.design.extra.PluginHelper;
import com.fr.design.extra.PluginUtils;
import com.fr.design.extra.Process;
import com.fr.general.FRLogger;
import com.fr.general.Inter;
import com.fr.plugin.Plugin;
import com.fr.plugin.PluginLoader;
import com.fr.plugin.context.PluginMarker;
import com.fr.plugin.manage.PluginManager;
import com.fr.plugin.manage.control.PluginTaskCallback;
import com.fr.plugin.manage.control.PluginTaskResult;
import javax.swing.*;
@ -15,11 +16,13 @@ import javax.swing.*;
*/
public class UninstallExecutor implements Executor {
private String[] pluginIDs;
private String pluginInfo;
private boolean isForce;
private String result = "undo";
public UninstallExecutor(String[] pluginIDs) {
this.pluginIDs = pluginIDs;
public UninstallExecutor(String pluginInfo, boolean isForce) {
this.pluginInfo = pluginInfo;
this.isForce = isForce;
}
@Override
@ -38,35 +41,20 @@ public class UninstallExecutor implements Executor {
@Override
public void run(Process<String> process) {
int rv = JOptionPane.showOptionDialog(
null,
Inter.getLocText("FR-Designer-Plugin_Will_Be_Delete"),
Inter.getLocText("FR-Designer-Plugin_Warning"),
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.INFORMATION_MESSAGE,
null,
new String[]{Inter.getLocText("FR-Designer-Basic_Restart_Designer"),
Inter.getLocText("FR-Designer-Basic_Restart_Designer_Later"),
Inter.getLocText("FR-Designer-Basic_Cancel")
},
null
);
if (rv == JOptionPane.CANCEL_OPTION || rv == JOptionPane.CLOSED_OPTION) {
return;
}
for (String pluginID : pluginIDs) {
try {
Plugin plugin = PluginLoader.getLoader().getPluginById(pluginID);
String[] filesToBeDelete = PluginHelper.uninstallPlugin(FRContext.getCurrentEnv(), plugin);
RestartHelper.saveFilesWhichToDelete(filesToBeDelete);
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
}
}
result = "done";
if (rv == JOptionPane.OK_OPTION) {
RestartHelper.restart();
}
PluginMarker pluginMarker = PluginUtils.createPluginMarker(pluginInfo);
PluginManager.getController().uninstall(pluginMarker, isForce, new PluginTaskCallback() {
@Override
public void done(PluginTaskResult pluginTaskResult) {
if (pluginTaskResult.isSuccess()) {
result = "done";
FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Delete_Success"));
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Install_Successful"));
} else {
FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Delete_Failed"));
JOptionPane.showMessageDialog(null, pluginTaskResult.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
}
}
});
}
}
};

47
designer_base/src/com/fr/design/extra/exe/UpdateFromDiskExecutor.java

@ -1,8 +1,14 @@
package com.fr.design.extra.exe;
import com.fr.design.extra.PluginWebBridge;
import com.fr.design.extra.Process;
import com.fr.general.FRLogger;
import com.fr.general.Inter;
import com.fr.plugin.error.PluginErrorCode;
import com.fr.plugin.manage.PluginManager;
import com.fr.plugin.manage.control.PluginTaskResult;
import com.fr.plugin.manage.control.ProgressCallback;
import javax.swing.*;
import java.io.File;
/**
@ -18,7 +24,7 @@ public class UpdateFromDiskExecutor implements Executor {
@Override
public String getTaskFinishMessage() {
return "插件更新操作结束";
return Inter.getLocText("FR-Designer-Plugin_Update_End");
}
@Override
@ -32,9 +38,44 @@ public class UpdateFromDiskExecutor implements Executor {
@Override
public void run(Process<String> process) {
PluginWebBridge.getHelper().updateFileFromDisk(new File(filePath));
PluginManager.getController().update(new File(filePath), new ProgressCallback() {
@Override
public void updateProgress(String description, double progress) {
}
@Override
public void done(PluginTaskResult result) {
if (result.isSuccess()) {
FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Update_Success"));
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Install_Successful"));
} else if (result.errorCode() == PluginErrorCode.OperationNotSupport.getCode()) {
updatePluginWithDependence();
} else {
JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
}
}
});
}
}
};
}
public void updatePluginWithDependence() {
PluginManager.getController().update(new File(filePath), new ProgressCallback() {
@Override
public void updateProgress(String description, double progress) {
}
@Override
public void done(PluginTaskResult result) {
if (result.isSuccess()) {
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Install_Successful"));
} else {
JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
}
}
});
}
}

140
designer_base/src/com/fr/design/extra/exe/UpdateOnlineExecutor.java

@ -2,30 +2,33 @@ package com.fr.design.extra.exe;
import com.fr.base.FRContext;
import com.fr.design.DesignerEnvManager;
import com.fr.design.RestartHelper;
import com.fr.design.extra.After;
import com.fr.design.extra.LoginCheckContext;
import com.fr.design.extra.PluginHelper;
import com.fr.design.extra.*;
import com.fr.design.extra.Process;
import com.fr.general.FRLogger;
import com.fr.general.Inter;
import com.fr.plugin.Plugin;
import com.fr.plugin.PluginLoader;
import com.fr.plugin.PluginVerifyException;
import com.fr.json.JSONObject;
import com.fr.plugin.context.PluginMarker;
import com.fr.plugin.error.PluginErrorCode;
import com.fr.plugin.manage.PluginManager;
import com.fr.plugin.manage.bbs.BBSPluginLogin;
import com.fr.plugin.manage.control.PluginTaskResult;
import com.fr.plugin.manage.control.ProgressCallback;
import com.fr.stable.StringUtils;
import javax.swing.*;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
/**
* Created by richie on 16/3/19.
*/
public class UpdateOnlineExecutor implements Executor {
private String[] pluginIDs;
private String[] pluginInfos;
private static final int PERCENT_100 = 100;
public UpdateOnlineExecutor(String[] pluginIDs) {
this.pluginIDs = pluginIDs;
public UpdateOnlineExecutor(String[] pluginInfos) {
this.pluginInfos = pluginInfos;
}
@Override
@ -44,73 +47,72 @@ public class UpdateOnlineExecutor implements Executor {
@Override
public void run(Process<String> process) {
if (StringUtils.isBlank(DesignerEnvManager.getEnvManager().getBBSName())) {
if (!(BBSPluginLogin.getInstance().hasLogin())){
LoginCheckContext.fireLoginCheckListener();
}
if (StringUtils.isNotBlank(DesignerEnvManager.getEnvManager().getBBSName())) {
try {
for (int i = 0; i < pluginIDs.length; i++) {
try {
Plugin plugin = PluginLoader.getLoader().getPluginById(pluginIDs[i]);
String id = null;
if (plugin != null) {
id = plugin.getId();
}
String username = DesignerEnvManager.getEnvManager().getBBSName();
String password = DesignerEnvManager.getEnvManager().getBBSPassword();
PluginHelper.downloadPluginFile(id, username, password, new Process<Double>() {
@Override
public void process(Double integer) {
}
});
updateFileFromDisk(PluginHelper.getDownloadTempFile());
process.process(PERCENT_100 / pluginIDs.length * (i + 1) + "%");
} catch (PluginVerifyException e) {
throw e;
} catch (Exception e) {
FRContext.getLogger().error(e.getMessage(), e);
}
}
int rv = JOptionPane.showOptionDialog(
null,
Inter.getLocText("FR-Designer-Plugin_Update_Successful"),
Inter.getLocText("FR-Designer-Plugin_Warning"),
JOptionPane.YES_NO_OPTION,
JOptionPane.INFORMATION_MESSAGE,
null,
new String[]{Inter.getLocText("FR-Designer-Basic_Restart_Designer"),
Inter.getLocText("FR-Designer-Basic_Restart_Designer_Later")
},
null
);
if (rv == JOptionPane.OK_OPTION) {
RestartHelper.restart();
}
} catch (PluginVerifyException e) {
JOptionPane.showMessageDialog(null, e.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
if (BBSPluginLogin.getInstance().hasLogin()) {
List<PluginMarker> pluginMarkerList = new ArrayList<PluginMarker>();
for (int i = 0; i < pluginInfos.length; i++) {
pluginMarkerList.add(PluginUtils.createPluginMarker(pluginInfos[i]));
}
}
updatePlugins(pluginMarkerList, process); }
}
}
};
}
private void updateFileFromDisk(File fileOnDisk) throws Exception {
Plugin plugin = PluginHelper.readPlugin(fileOnDisk);
if (plugin == null) {
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Illegal_Plugin_Zip"), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
return;
}
Plugin oldPlugin = PluginLoader.getLoader().getPluginById(plugin.getId());
if (oldPlugin != null) {
String[] files = PluginHelper.uninstallPlugin(FRContext.getCurrentEnv(), oldPlugin);
PluginHelper.installPluginFromUnzippedTempDir(FRContext.getCurrentEnv(), plugin, new After() {
@Override
public void done() {
public void updatePluginWithDependence(PluginMarker pluginMarker, PluginMarker toMarker) {
PluginManager.getController().update(pluginMarker, toMarker, new ProgressCallback() {
@Override
public void updateProgress(String description, double progress) {
}
@Override
public void done(PluginTaskResult result) {
if (result.isSuccess()) {
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Install_Successful"));
} else {
JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
}
});
} else {
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Cannot_Update_Not_Install"), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
}
});
}
public void updatePlugins(List<PluginMarker> pluginMarkerList, Process<String> process) {
for (int i = 0; i < pluginMarkerList.size(); i++) {
try {
int a = i;
//todo check下此插件的最新版本
String latestPluginInfo = PluginUtils.getLatestPluginInfo(pluginMarkerList.get(i).getPluginID());
if (StringUtils.isEmpty(latestPluginInfo) || PluginConstants.CONNECTION_404.equals(latestPluginInfo)) {
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Connect_Failed"), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
return;
}
JSONObject resultArr = new JSONObject(latestPluginInfo);
String latestPluginVersion = (String) resultArr.get("version");
PluginManager.getController().update(pluginMarkerList.get(i), PluginMarker.create(pluginMarkerList.get(i).getPluginID(), latestPluginVersion), new ProgressCallback() {
@Override
public void updateProgress(String description, double progress) {
process.process(PERCENT_100 / pluginMarkerList.size() * (a + 1) + "%");
}
@Override
public void done(PluginTaskResult result) {
if (result.isSuccess()) {
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Install_Successful"));
} else if (result.errorCode() == PluginErrorCode.OperationNotSupport.getCode()) {
updatePluginWithDependence(pluginMarkerList.get(a), PluginMarker.create(pluginMarkerList.get(a).getPluginID(), latestPluginVersion));
} else {
JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
}
}
});
} catch (Exception e) {
FRContext.getLogger().error(e.getMessage(), e);
}
}
}
}

20
designer_base/src/com/fr/design/extra/exe/callback/AbstractPluginTaskCallback.java

@ -0,0 +1,20 @@
package com.fr.design.extra.exe.callback;
import com.fr.plugin.context.PluginMarker;
import com.fr.plugin.manage.control.ProgressCallback;
/**
* Created by ibm on 2017/5/26.
*/
public abstract class AbstractPluginTaskCallback implements ProgressCallback{
protected PluginMarker pluginMarker;
protected JSCallback jsCallback;
@Override
public void updateProgress(String description, double aProgress) {
}
}

33
designer_base/src/com/fr/design/extra/exe/callback/DownloadCallback.java

@ -0,0 +1,33 @@
package com.fr.design.extra.exe.callback;
import com.fr.design.extra.exe.extratask.ExtraPluginTask;
import com.fr.general.Inter;
import com.fr.plugin.manage.control.PluginTaskResult;
import javax.swing.*;
/**
* Created by ibm on 2017/5/26.
*/
public class DownloadCallback extends AbstractPluginTaskCallback {
private ExtraPluginTask extraPluginTask;
public DownloadCallback(ExtraPluginTask extraPluginTask, JSCallback jsCallback) {
this.extraPluginTask = extraPluginTask;
this.jsCallback = jsCallback;
}
@Override
public void updateProgress(String description, double aProgress) {
jsCallback.execute(String.valueOf(aProgress));
}
@Override
public void done(PluginTaskResult result) {
if (result.isSuccess()) {
extraPluginTask.doExtraPluginTask();
} else {
JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
}
}
}

53
designer_base/src/com/fr/design/extra/exe/callback/InstallFromDiskCallback.java

@ -0,0 +1,53 @@
package com.fr.design.extra.exe.callback;
import com.fr.general.FRLogger;
import com.fr.general.Inter;
import com.fr.plugin.error.PluginErrorCode;
import com.fr.plugin.manage.PluginManager;
import com.fr.plugin.manage.control.PluginTaskResult;
import javax.swing.*;
import java.io.File;
/**
* Created by ibm on 2017/5/26.
*/
public class InstallFromDiskCallback extends AbstractPluginTaskCallback {
private File zipFile;
public InstallFromDiskCallback(File zipFile, JSCallback jsCallback) {
this.zipFile = zipFile;
this.jsCallback = jsCallback;
}
@Override
public void updateProgress(String description, double aProgress) {
jsCallback.execute(String.valueOf(aProgress));
}
@Override
public void done(PluginTaskResult result) {
if (result.isSuccess()) {
FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Install_Success"));
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Install_Successful"));
} else if (result.errorCode() == PluginErrorCode.OperationNotSupport.getCode()) {
int rv = JOptionPane.showOptionDialog(
null,
Inter.getLocText(Inter.getLocText("FR-Designer-Plugin_Install_Success")),
Inter.getLocText("FR-Designer-Plugin_Install_Dependence"),
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.INFORMATION_MESSAGE,
null,
null,
null
);
if (rv == JOptionPane.CANCEL_OPTION || rv == JOptionPane.CLOSED_OPTION) {
return;
}
PluginManager.getController().install(zipFile, new InstallFromDiskCallback(zipFile, jsCallback));
} else {
JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
}
}
}

53
designer_base/src/com/fr/design/extra/exe/callback/InstallOnlineCallback.java

@ -0,0 +1,53 @@
package com.fr.design.extra.exe.callback;
import com.fr.general.FRLogger;
import com.fr.general.Inter;
import com.fr.plugin.context.PluginMarker;
import com.fr.plugin.error.PluginErrorCode;
import com.fr.plugin.manage.PluginManager;
import com.fr.plugin.manage.control.PluginTaskResult;
import javax.swing.*;
/**
* Created by ibm on 2017/5/26.
*/
public class InstallOnlineCallback extends AbstractPluginTaskCallback {
public InstallOnlineCallback(PluginMarker pluginMarker, JSCallback jsCallback){
this.pluginMarker = pluginMarker;
this.jsCallback = jsCallback;
}
@Override
public void updateProgress(String description, double aProgress) {
jsCallback.execute(String.valueOf(aProgress));
}
@Override
public void done(PluginTaskResult result) {
if (result.isSuccess()) {
FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Install_Success"));
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Install_Successful"));
} else if (result.errorCode() == PluginErrorCode.OperationNotSupport.getCode()) {
int rv = JOptionPane.showOptionDialog(
null,
Inter.getLocText(Inter.getLocText("FR-Designer-Plugin_Install_Success")),
Inter.getLocText("FR-Designer-Plugin_Install_Dependence"),
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.INFORMATION_MESSAGE,
null,
null,
null
);
if (rv == JOptionPane.CANCEL_OPTION || rv == JOptionPane.CLOSED_OPTION) {
return;
}
//执行JS回调
PluginManager.getController().install(pluginMarker, new InstallOnlineCallback(pluginMarker, jsCallback));
} else {
JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
}
}
}

29
designer_base/src/com/fr/design/extra/exe/callback/JSCallback.java

@ -0,0 +1,29 @@
package com.fr.design.extra.exe.callback;
import javafx.scene.web.WebEngine;
import netscape.javascript.JSObject;
/**
* Created by ibm on 2017/5/27.
*/
public class JSCallback {
private WebEngine webEngine;
private JSObject callback;
public JSCallback(final WebEngine webEngine, final JSObject callback) {
this.webEngine = webEngine;
this.callback = callback;
}
public void execute(String newValue) {
String fun = "(" + callback + ")(\"" + newValue + "\")";
try {
webEngine.executeScript(fun);
} catch (Exception e) {
webEngine.executeScript("alert(\"" + e.getMessage() + "\")");
}
}
}

28
designer_base/src/com/fr/design/extra/exe/callback/ModifyStatusCallback.java

@ -0,0 +1,28 @@
package com.fr.design.extra.exe.callback;
import com.fr.general.Inter;
import com.fr.plugin.manage.control.PluginTaskCallback;
import com.fr.plugin.manage.control.PluginTaskResult;
import javax.swing.*;
/**
* Created by ibm on 2017/5/27.
*/
public class ModifyStatusCallback implements PluginTaskCallback{
private boolean isActive;
public ModifyStatusCallback (boolean isActive){
this.isActive = isActive;
}
@Override
public void done(PluginTaskResult result) {
if (result.isSuccess()) {
String modifyMessage = isActive ? Inter.getLocText("FR-Designer-Plugin_Has_Been_Actived") : Inter.getLocText("FR-Designer-Plugin_Has_Been_Disabled");
JOptionPane.showMessageDialog(null, modifyMessage);
} else {
JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
}
}
}

26
designer_base/src/com/fr/design/extra/exe/callback/UnistallPluginCallback.java

@ -0,0 +1,26 @@
package com.fr.design.extra.exe.callback;
import com.fr.general.FRLogger;
import com.fr.general.Inter;
import com.fr.plugin.manage.control.PluginTaskCallback;
import com.fr.plugin.manage.control.PluginTaskResult;
import sun.plugin2.main.server.Plugin;
import javax.swing.*;
/**
* Created by ibm on 2017/5/27.
*/
public class UnistallPluginCallback implements PluginTaskCallback {
@Override
public void done(PluginTaskResult result) {
if (result.isSuccess()) {
FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Delete_Success"));
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Install_Successful"));
} else {
FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Delete_Failed"));
JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
}
}
}

54
designer_base/src/com/fr/design/extra/exe/callback/UpdateFromDiskCallback.java

@ -0,0 +1,54 @@
package com.fr.design.extra.exe.callback;
import com.fr.general.FRLogger;
import com.fr.general.Inter;
import com.fr.general.jsqlparser.expression.StringValue;
import com.fr.plugin.error.PluginErrorCode;
import com.fr.plugin.manage.PluginManager;
import com.fr.plugin.manage.control.PluginTaskResult;
import javax.swing.*;
import java.io.File;
/**
* Created by ibm on 2017/5/27.
*/
public class UpdateFromDiskCallback extends AbstractPluginTaskCallback {
private File zipFile;
public UpdateFromDiskCallback(File zipFile,JSCallback jsCallback) {
this.zipFile = zipFile;
this.jsCallback = jsCallback;
}
@Override
public void updateProgress(String description, double aProgress) {
jsCallback.execute(String.valueOf(aProgress));
}
@Override
public void done(PluginTaskResult result) {
if (result.isSuccess()) {
FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Install_Success"));
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Install_Successful"));
} else if (result.errorCode() == PluginErrorCode.OperationNotSupport.getCode()) {
int rv = JOptionPane.showOptionDialog(
null,
Inter.getLocText(Inter.getLocText("FR-Designer-Plugin_Install_Success")),
Inter.getLocText("FR-Designer-Plugin_Install_Dependence"),
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.INFORMATION_MESSAGE,
null,
null,
null
);
if (rv == JOptionPane.CANCEL_OPTION || rv == JOptionPane.CLOSED_OPTION) {
return;
}
PluginManager.getController().update(zipFile, new UpdateFromDiskCallback(zipFile, jsCallback));
} else {
JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
}
}
}

55
designer_base/src/com/fr/design/extra/exe/callback/UpdateOnlineCallback.java

@ -0,0 +1,55 @@
package com.fr.design.extra.exe.callback;
import com.fr.general.FRLogger;
import com.fr.general.Inter;
import com.fr.plugin.context.PluginMarker;
import com.fr.plugin.error.PluginErrorCode;
import com.fr.plugin.manage.PluginManager;
import com.fr.plugin.manage.control.PluginTaskResult;
import javax.swing.*;
/**
* Created by ibm on 2017/5/26.
*/
public class UpdateOnlineCallback extends AbstractPluginTaskCallback {
public PluginMarker toPluginMarker;
public UpdateOnlineCallback(PluginMarker pluginMarker , PluginMarker toPluginMarker, JSCallback jsCallback) {
this.pluginMarker = pluginMarker;
this.toPluginMarker = toPluginMarker;
this.jsCallback = jsCallback;
}
@Override
public void updateProgress(String description, double aProgress) {
jsCallback.execute(String.valueOf(aProgress));
}
@Override
public void done(PluginTaskResult result) {
if (result.isSuccess()) {
FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Update_Success"));
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Install_Successful"));
} else if (result.errorCode() == PluginErrorCode.OperationNotSupport.getCode()) {
int rv = JOptionPane.showOptionDialog(
null,
Inter.getLocText(Inter.getLocText("FR-Designer-Plugin_Install_Success")),
Inter.getLocText("FR-Designer-Plugin_Install_Dependence"),
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.INFORMATION_MESSAGE,
null,
null,
null
);
if (rv == JOptionPane.CANCEL_OPTION || rv == JOptionPane.CLOSED_OPTION) {
return;
}
PluginManager.getController().update(pluginMarker, toPluginMarker, new UpdateOnlineCallback(pluginMarker, toPluginMarker, jsCallback));
} else {
FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Delete_Failed"));
JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
}
}
}

10
designer_base/src/com/fr/design/extra/exe/extratask/ExtraPluginTask.java

@ -0,0 +1,10 @@
package com.fr.design.extra.exe.extratask;
/**
* Created by ibm on 2017/5/27.
*/
public interface ExtraPluginTask {
void doExtraPluginTask();
}

25
designer_base/src/com/fr/design/extra/exe/extratask/InstallPluginTask.java

@ -0,0 +1,25 @@
package com.fr.design.extra.exe.extratask;
import com.fr.design.extra.exe.callback.InstallOnlineCallback;
import com.fr.design.extra.exe.callback.JSCallback;
import com.fr.plugin.context.PluginMarker;
import com.fr.plugin.manage.PluginManager;
import javax.swing.*;
/**
* Created by ibm on 2017/5/27.
*/
public class InstallPluginTask implements ExtraPluginTask{
public PluginMarker pluginMarker;
public JSCallback jsCallback;
public InstallPluginTask(PluginMarker pluginMarker, JSCallback jsCallback){
this.pluginMarker = pluginMarker;
this.jsCallback = jsCallback;
}
@Override
public void doExtraPluginTask() {
PluginManager.getController().install(pluginMarker, new InstallOnlineCallback(pluginMarker, jsCallback));
}
}

28
designer_base/src/com/fr/design/extra/exe/extratask/UpdatePluginTask.java

@ -0,0 +1,28 @@
package com.fr.design.extra.exe.extratask;
import com.fr.design.extra.exe.callback.JSCallback;
import com.fr.design.extra.exe.callback.UpdateOnlineCallback;
import com.fr.form.ui.WaterMark;
import com.fr.plugin.context.PluginMarker;
import com.fr.plugin.manage.PluginManager;
/**
* Created by ibm on 2017/5/27.
*/
public class UpdatePluginTask implements ExtraPluginTask {
public PluginMarker pluginMarker;
public PluginMarker toPluginMarker;
public JSCallback jsCallback;
public UpdatePluginTask(PluginMarker pluginMarker, PluginMarker toPluginMarker, JSCallback jsCallback){
this.pluginMarker = pluginMarker;
this.toPluginMarker = toPluginMarker;
this.jsCallback = jsCallback;
}
@Override
public void doExtraPluginTask() {
PluginManager.getController().update(pluginMarker, toPluginMarker, new UpdateOnlineCallback(pluginMarker, toPluginMarker, jsCallback));
}
}
Loading…
Cancel
Save