Browse Source

REPORT-2354 设计器插件操作部分

master
kerry 8 years ago
parent
commit
7f9abdb735
  1. 78
      designer_base/src/com/fr/design/extra/PluginWebBridge.java
  2. 4
      designer_base/src/com/fr/design/extra/WebViewDlgHelper.java
  3. 4
      designer_base/src/com/fr/design/extra/exe/GetLoginInfoExecutor.java
  4. 5
      designer_base/src/com/fr/design/extra/exe/GetPluginCategoriesExecutor.java
  5. 4
      designer_base/src/com/fr/design/extra/exe/GetPluginFromStoreExecutor.java
  6. 60
      designer_base/src/com/fr/design/extra/exe/InstallFromDiskExecutor.java
  7. 110
      designer_base/src/com/fr/design/extra/exe/InstallOnlineExecutor.java
  8. 51
      designer_base/src/com/fr/design/extra/exe/ModifyStatusExecutor.java
  9. 12
      designer_base/src/com/fr/design/extra/exe/ReadUpdateOnlineExecutor.java
  10. 58
      designer_base/src/com/fr/design/extra/exe/UninstallExecutor.java
  11. 46
      designer_base/src/com/fr/design/extra/exe/UpdateFromDiskExecutor.java
  12. 125
      designer_base/src/com/fr/design/extra/exe/UpdateOnlineExecutor.java

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

@ -9,10 +9,10 @@ import com.fr.design.gui.ilable.UILabel;
import com.fr.general.FRLogger; import com.fr.general.FRLogger;
import com.fr.general.Inter; import com.fr.general.Inter;
import com.fr.general.SiteCenter; import com.fr.general.SiteCenter;
import com.fr.plugin.Plugin;
import com.fr.plugin.PluginLicense; import com.fr.plugin.PluginLicense;
import com.fr.plugin.PluginLicenseManager; 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.ArrayUtils;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import javafx.concurrent.Task; import javafx.concurrent.Task;
@ -143,14 +143,16 @@ public class PluginWebBridge {
/** /**
* 从插件服务器上安装插件 * 从插件服务器上安装插件
* *
* @param pluginID 插件的ID * @param pluginInfo 插件的ID
* @param callback 回调函数 * @param callback 回调函数
*/ */
public void installPluginOnline(final String pluginID, final JSObject callback) { public void installPluginOnline(final String pluginInfo, final JSObject callback) {
Task<Void> task = new PluginTask<>(webEngine, callback, new InstallOnlineExecutor(pluginID)); Task<Void> task = new PluginTask<>(webEngine, callback, new InstallOnlineExecutor(pluginInfo));
new Thread(task).start(); new Thread(task).start();
} }
/** /**
* 从磁盘上选择插件安装包进行安装 * 从磁盘上选择插件安装包进行安装
* *
@ -164,13 +166,14 @@ public class PluginWebBridge {
/** /**
* 卸载当前选中的插件 * 卸载当前选中的插件
* *
* @param pluginIDs 插件集合 * @param pluginInfo 插件信息
*/ */
public void uninstallPlugin(JSObject pluginIDs, final JSObject callback) { public void uninstallPlugin(final String pluginInfo, final boolean isForce, final JSObject callback) {
Task<Void> task = new PluginTask<>(webEngine, callback, new UninstallExecutor(jsObjectToStringArray(pluginIDs))); Task<Void> task = new PluginTask<>(webEngine, callback, new UninstallExecutor(pluginInfo, isForce));
new Thread(task).start(); new Thread(task).start();
} }
/** /**
* 从插件服务器上更新选中的插件 * 从插件服务器上更新选中的插件
* *
@ -266,8 +269,9 @@ public class PluginWebBridge {
* *
* @return 已安装的插件组成的数组 * @return 已安装的插件组成的数组
*/ */
public Plugin[] getInstalledPlugins() { public PluginContext[] getInstalledPlugins() {
return PluginLoader.getLoader().getInstalled(); List<PluginContext> plugins = PluginManager.getContexts();
return plugins.toArray(new PluginContext[plugins.size()]);
} }
@ -439,60 +443,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 username = DesignerEnvManager.getEnvManager().getBBSName();
String password = DesignerEnvManager.getEnvManager().getBBSPassword(); String password = DesignerEnvManager.getEnvManager().getBBSPassword();
try { try {
PluginHelper.downloadPluginFile(scriptsId, username, password, new Process<Double>() { PluginUtils.downloadShopScripts(scriptsId, username, password, new Process<Double>() {
@Override @Override
public void process(Double integer) { public void process(Double integer) {
} }
@ -153,7 +153,7 @@ public class WebViewDlgHelper {
try { try {
if (get()) { 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( int rv = JOptionPane.showOptionDialog(
null, null,
Inter.getLocText("FR-Designer-Plugin_Shop_Installed"), 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.DesignerEnvManager;
import com.fr.design.extra.Process; import com.fr.design.extra.Process;
import com.fr.plugin.manage.bbs.BBSPluginLogin;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
/** /**
@ -26,9 +27,10 @@ public class GetLoginInfoExecutor implements Executor {
@Override @Override
public void run(Process<String> process) { public void run(Process<String> process) {
String username = DesignerEnvManager.getEnvManager().getBBSName(); String username = BBSPluginLogin.getInstance().getUserInfo().getUserName();
String inShowUsername = DesignerEnvManager.getEnvManager().getInShowBBsName(); String inShowUsername = DesignerEnvManager.getEnvManager().getInShowBBsName();
if (StringUtils.isEmpty(username) && StringUtils.isEmpty(inShowUsername)) { if (StringUtils.isEmpty(username) && StringUtils.isEmpty(inShowUsername)) {
return;
}else { }else {
result = StringUtils.isEmpty(inShowUsername) ? username : inShowUsername; 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; 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.design.extra.Process;
import com.fr.general.SiteCenter; import com.fr.general.SiteCenter;
import com.fr.general.http.HttpClient; import com.fr.general.http.HttpClient;
@ -32,9 +32,8 @@ public class GetPluginCategoriesExecutor implements Executor {
HttpClient httpClient = new HttpClient(url); HttpClient httpClient = new HttpClient(url);
result = httpClient.getResponseText(); result = httpClient.getResponseText();
} else { } 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; 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.design.extra.Process;
import com.fr.general.FRLogger; import com.fr.general.FRLogger;
import com.fr.general.SiteCenter; import com.fr.general.SiteCenter;
@ -59,7 +59,7 @@ public class GetPluginFromStoreExecutor implements Executor {
FRLogger.getLogger().error(e.getMessage()); FRLogger.getLogger().error(e.getMessage());
} }
} else { } else {
result = PluginHelper.CONNECTION_404; result = PluginConstants.CONNECTION_404;
} }
} }
} }

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

@ -1,12 +1,12 @@
package com.fr.design.extra.exe; 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.design.extra.Process;
import com.fr.general.FRLogger; import com.fr.general.FRLogger;
import com.fr.general.Inter; 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 javax.swing.*;
import java.io.File; import java.io.File;
@ -49,21 +49,55 @@ public class InstallFromDiskExecutor implements Executor {
@Override @Override
public void run(Process<String> process) { public void run(Process<String> process) {
try { PluginManager.getController().install(new File(filePath), new ProgressCallback() {
PluginHelper.installPluginFromDisk(new File(filePath), new After() {
@Override @Override
public void done() { public void updateProgress(String description, double progress) {
}
@Override
public void done(PluginTaskResult result) {
if (result.isSuccess()) {
FRLogger.getLogger().info("插件安装成功"); FRLogger.getLogger().info("插件安装成功");
PluginWebBridge.getHelper().showRestartMessage(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_Warning"),
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.INFORMATION_MESSAGE,
null,
null,
null
);
if (rv == JOptionPane.CANCEL_OPTION || rv == JOptionPane.CLOSED_OPTION) {
return;
} }
}); installWithDepenndence();
} catch (PluginVerifyException e) { }else{
JOptionPane.showMessageDialog(null, e.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); FRLogger.getLogger().info("插件安装失败");
} catch (Exception e) { JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
FRLogger.getLogger().error(e.getMessage());
} }
} }
});
}
} }
}; };
} }
public void installWithDepenndence(){
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("插件安装成功");
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Install_Successful"));
} else{
FRLogger.getLogger().info("插件安装失败");
JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
}
}
});
}
} }

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

@ -1,16 +1,16 @@
package com.fr.design.extra.exe; 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.LoginCheckContext;
import com.fr.design.extra.PluginHelper; import com.fr.design.extra.PluginUtils;
import com.fr.design.extra.Process; import com.fr.design.extra.Process;
import com.fr.general.FRLogger;
import com.fr.general.Inter; import com.fr.general.Inter;
import com.fr.plugin.PluginVerifyException; import com.fr.plugin.context.PluginMarker;
import com.fr.plugin.dependence.PluginDependenceException; import com.fr.plugin.error.PluginErrorCode;
import com.fr.stable.StringUtils; 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.*; import javax.swing.*;
@ -19,10 +19,10 @@ import javax.swing.*;
*/ */
public class InstallOnlineExecutor implements Executor { public class InstallOnlineExecutor implements Executor {
private String pluginID; private String pluginInfo;
public InstallOnlineExecutor(String pluginID) { public InstallOnlineExecutor(String pluginInfo) {
this.pluginID = pluginID; this.pluginInfo = pluginInfo;
} }
@Override @Override
@ -36,69 +36,89 @@ public class InstallOnlineExecutor implements Executor {
new Command() { new Command() {
@Override @Override
public String getExecuteMessage() { public String getExecuteMessage() {
return "正在下载插件:" + pluginID; return "正在下载插件:" + pluginInfo.split("_")[0];
} }
@Override @Override
public void run(final Process<String> process) { public void run(final Process<String> process) {
//下载插件 //下载插件
if(StringUtils.isBlank(DesignerEnvManager.getEnvManager().getBBSName())){ if (!BBSPluginLogin.getInstance().hasLogin()) {
LoginCheckContext.fireLoginCheckListener(); LoginCheckContext.fireLoginCheckListener();
} }
if(StringUtils.isNotBlank(DesignerEnvManager.getEnvManager().getBBSName())) { PluginMarker pluginMarker = PluginUtils.createPluginMarker(pluginInfo);
String username = DesignerEnvManager.getEnvManager().getBBSName(); if (BBSPluginLogin.getInstance().hasLogin()) {
String password = DesignerEnvManager.getEnvManager().getBBSPassword(); PluginManager.getController().download(pluginMarker, new ProgressCallback() {
try {
PluginHelper.downloadPluginFile(pluginID, username, password, new Process<Double>() {
@Override @Override
public void process(Double integer) { public void updateProgress(String description, double aProgress) {
process.process(Math.round(integer * 100) + "%"); process.process(Math.round(aProgress * 100) + "%");
}
@Override
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 (Exception e) {
FRContext.getLogger().error(e.getMessage(), e);
} }
} }
} }
}, };
new Command() {
@Override
public String getExecuteMessage() {
return "正在安装插件:" + pluginID;
} }
public void installPlugin(PluginMarker pluginMarker) {
PluginManager.getController().install(pluginMarker, new ProgressCallback() {
@Override @Override
public void run(Process<String> process) { public void updateProgress(String description, double progress) {
try {
PluginHelper.installPluginFromDisk(PluginHelper.getDownloadTempFile(), new After() { }
@Override @Override
public void done() { public void done(PluginTaskResult result) {
if (result.isSuccess()) {
FRLogger.getLogger().info("插件安装成功");
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Install_Successful"));
} else if (result.errorCode() == PluginErrorCode.OperationNotSupport.getCode()) {
int rv = JOptionPane.showOptionDialog( int rv = JOptionPane.showOptionDialog(
null, null,
Inter.getLocText("FR-Designer-Plugin_Install_Successful"), Inter.getLocText("安装依赖"),
Inter.getLocText("FR-Designer-Plugin_Warning"), Inter.getLocText("FR-Designer-Plugin_Warning"),
JOptionPane.YES_NO_OPTION, JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.INFORMATION_MESSAGE, JOptionPane.INFORMATION_MESSAGE,
null, null,
new String[]{Inter.getLocText("FR-Designer-Basic_Restart_Designer"), Inter.getLocText("FR-Designer-Basic_Restart_Designer_Later")}, null,
null null
); );
if (rv == JOptionPane.OK_OPTION) { if (rv == JOptionPane.CANCEL_OPTION || rv == JOptionPane.CLOSED_OPTION) {
RestartHelper.restart(); return;
}
installPluginWithDependence(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 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("插件安装成功");
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Install_Successful"));
} else {
FRLogger.getLogger().info("插件安装失败");
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; package com.fr.design.extra.exe;
import com.fr.base.FRContext; import com.fr.design.extra.PluginUtils;
import com.fr.design.extra.PluginWebBridge;
import com.fr.design.extra.Process; import com.fr.design.extra.Process;
import com.fr.general.Inter; import com.fr.general.Inter;
import com.fr.plugin.Plugin; import com.fr.plugin.context.PluginContext;
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 com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import javax.swing.*;
/** /**
* Created by richie on 16/3/19. * Created by richie on 16/3/19.
*/ */
public class ModifyStatusExecutor implements Executor { public class ModifyStatusExecutor implements Executor {
private String pluginID; private String pluginInfo;
private boolean active; private boolean active;
private Plugin plugin; private PluginContext plugin;
public ModifyStatusExecutor(String pluginID) { public ModifyStatusExecutor(String pluginInfo) {
this.pluginID = pluginID; this.pluginInfo = pluginInfo;
} }
@Override @Override
@ -37,14 +41,31 @@ public class ModifyStatusExecutor implements Executor {
@Override @Override
public void run(Process<String> process) { public void run(Process<String> process) {
plugin = PluginLoader.getLoader().getPluginById(pluginID); PluginMarker pluginMarker = PluginUtils.createPluginMarker(pluginInfo);
plugin = PluginManager.getContext(pluginMarker);
active = !plugin.isActive(); active = !plugin.isActive();
plugin.setActive(active); if (active) {
try { PluginManager.getController().forbid(pluginMarker, new PluginTaskCallback() {
FRContext.getCurrentEnv().writePlugin(plugin); @Override
PluginWebBridge.getHelper().showRestartMessage(plugin.isActive() ? Inter.getLocText("FR-Designer-Plugin_Has_Been_Actived") : Inter.getLocText("FR-Designer-Plugin_Has_Been_Disabled")); public void done(PluginTaskResult result) {
} catch (Exception e) { if (result.isSuccess()) {
FRContext.getLogger().error(e.getMessage()); 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; 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.design.extra.Process;
import com.fr.general.FRLogger; import com.fr.general.FRLogger;
import com.fr.plugin.Plugin;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
@ -13,7 +11,7 @@ import org.json.JSONObject;
* Created by vito on 16/4/19. * Created by vito on 16/4/19.
*/ */
public class ReadUpdateOnlineExecutor implements Executor { public class ReadUpdateOnlineExecutor implements Executor {
private Plugin[] plugins; private String[] plugins;
private String result; private String result;
@Override @Override
@ -33,11 +31,11 @@ public class ReadUpdateOnlineExecutor implements Executor {
@Override @Override
public void run(Process<String> process) { public void run(Process<String> process) {
try { try {
plugins = PluginsReaderFromStore.readPluginsForUpdate(); plugins = PluginReaderForDesigner.readPluginsForUpdate();
JSONArray jsonArray = new JSONArray(); JSONArray jsonArray = new JSONArray();
for (Plugin plugin : plugins) { for (String plugin : plugins) {
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
jsonObject.put("pluginid", plugin.getId()); jsonObject.put("pluginid", plugin);
jsonArray.put(jsonObject); jsonArray.put(jsonObject);
} }
result = jsonArray.toString(); result = jsonArray.toString();

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

@ -1,12 +1,13 @@
package com.fr.design.extra.exe; package com.fr.design.extra.exe;
import com.fr.base.FRContext; import com.fr.design.extra.PluginUtils;
import com.fr.design.RestartHelper;
import com.fr.design.extra.PluginHelper;
import com.fr.design.extra.Process; import com.fr.design.extra.Process;
import com.fr.general.FRLogger;
import com.fr.general.Inter; import com.fr.general.Inter;
import com.fr.plugin.Plugin; import com.fr.plugin.context.PluginMarker;
import com.fr.plugin.PluginLoader; import com.fr.plugin.manage.PluginManager;
import com.fr.plugin.manage.control.PluginTaskCallback;
import com.fr.plugin.manage.control.PluginTaskResult;
import javax.swing.*; import javax.swing.*;
@ -15,11 +16,13 @@ import javax.swing.*;
*/ */
public class UninstallExecutor implements Executor { public class UninstallExecutor implements Executor {
private String[] pluginIDs; private String pluginInfo;
private boolean isForce;
private String result = "undo"; private String result = "undo";
public UninstallExecutor(String[] pluginIDs) { public UninstallExecutor(String pluginInfo, boolean isForce) {
this.pluginIDs = pluginIDs; this.pluginInfo = pluginInfo;
this.isForce = isForce;
} }
@Override @Override
@ -38,35 +41,20 @@ public class UninstallExecutor implements Executor {
@Override @Override
public void run(Process<String> process) { public void run(Process<String> process) {
int rv = JOptionPane.showOptionDialog( PluginMarker pluginMarker = PluginUtils.createPluginMarker(pluginInfo);
null, PluginManager.getController().uninstall(pluginMarker, isForce, new PluginTaskCallback() {
Inter.getLocText("FR-Designer-Plugin_Will_Be_Delete"), @Override
Inter.getLocText("FR-Designer-Plugin_Warning"), public void done(PluginTaskResult pluginTaskResult) {
JOptionPane.YES_NO_CANCEL_OPTION, if (pluginTaskResult.isSuccess()) {
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"; result = "done";
if (rv == JOptionPane.OK_OPTION) { FRLogger.getLogger().info("删除成功");
RestartHelper.restart(); JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Install_Successful"));
} else {
FRLogger.getLogger().info("删除失败");
JOptionPane.showMessageDialog(null, pluginTaskResult.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
}
} }
});
} }
} }
}; };

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

@ -1,8 +1,14 @@
package com.fr.design.extra.exe; package com.fr.design.extra.exe;
import com.fr.design.extra.PluginWebBridge;
import com.fr.design.extra.Process; 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; import java.io.File;
/** /**
@ -32,9 +38,45 @@ public class UpdateFromDiskExecutor implements Executor {
@Override @Override
public void run(Process<String> process) { 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("更新成功");
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()) {
FRLogger.getLogger().info("更新成功");
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);
}
}
});
}
} }

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

@ -2,30 +2,32 @@ package com.fr.design.extra.exe;
import com.fr.base.FRContext; import com.fr.base.FRContext;
import com.fr.design.DesignerEnvManager; import com.fr.design.DesignerEnvManager;
import com.fr.design.RestartHelper; import com.fr.design.extra.*;
import com.fr.design.extra.After;
import com.fr.design.extra.LoginCheckContext;
import com.fr.design.extra.PluginHelper;
import com.fr.design.extra.Process; import com.fr.design.extra.Process;
import com.fr.general.FRLogger;
import com.fr.general.Inter; import com.fr.general.Inter;
import com.fr.plugin.Plugin; import com.fr.json.JSONObject;
import com.fr.plugin.PluginLoader; import com.fr.plugin.context.PluginMarker;
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 com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import javax.swing.*; import javax.swing.*;
import java.io.File; import java.util.ArrayList;
import java.util.List;
/** /**
* Created by richie on 16/3/19. * Created by richie on 16/3/19.
*/ */
public class UpdateOnlineExecutor implements Executor { public class UpdateOnlineExecutor implements Executor {
private String[] pluginIDs; private String[] pluginInfos;
private static final int PERCENT_100 = 100; private static final int PERCENT_100 = 100;
public UpdateOnlineExecutor(String[] pluginIDs) { public UpdateOnlineExecutor(String[] pluginInfos) {
this.pluginIDs = pluginIDs; this.pluginInfos = pluginInfos;
} }
@Override @Override
@ -48,69 +50,72 @@ public class UpdateOnlineExecutor implements Executor {
LoginCheckContext.fireLoginCheckListener(); LoginCheckContext.fireLoginCheckListener();
} }
if (StringUtils.isNotBlank(DesignerEnvManager.getEnvManager().getBBSName())) { if (StringUtils.isNotBlank(DesignerEnvManager.getEnvManager().getBBSName())) {
try { List<PluginMarker> pluginMarkerList = new ArrayList<PluginMarker>();
for (int i = 0; i < pluginIDs.length; i++) { for (int i = 0; i < pluginInfos.length; i++) {
try { pluginMarkerList.add(PluginUtils.createPluginMarker(pluginInfos[i]));
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);
} }
updatePlugins(pluginMarkerList, process); }
} }
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);
} }
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()) {
FRLogger.getLogger().info("更新成功");
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Install_Successful"));
} else {
FRLogger.getLogger().info("更新失败");
JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
} }
} }
}; });
} }
private void updateFileFromDisk(File fileOnDisk) throws Exception { public void updatePlugins(List<PluginMarker> pluginMarkerList, Process<String> process) {
Plugin plugin = PluginHelper.readPlugin(fileOnDisk); for (int i = 0; i < pluginMarkerList.size(); i++) {
if (plugin == null) { try {
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Illegal_Plugin_Zip"), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); 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_Warning"), JOptionPane.ERROR_MESSAGE);
return; return;
} }
Plugin oldPlugin = PluginLoader.getLoader().getPluginById(plugin.getId()); JSONObject resultArr = new JSONObject(latestPluginInfo);
if (oldPlugin != null) { String latestPluginVersion = (String) resultArr.get("version");
String[] files = PluginHelper.uninstallPlugin(FRContext.getCurrentEnv(), oldPlugin); PluginManager.getController().update(pluginMarkerList.get(i), PluginMarker.create(pluginMarkerList.get(i).getPluginID(), latestPluginVersion), new ProgressCallback() {
PluginHelper.installPluginFromUnzippedTempDir(FRContext.getCurrentEnv(), plugin, new After() {
@Override @Override
public void done() { public void updateProgress(String description, double progress) {
process.process(PERCENT_100 / pluginMarkerList.size() * (a + 1) + "%");
} }
});
@Override
public void done(PluginTaskResult result) {
if (result.isSuccess()) {
FRLogger.getLogger().info("更新成功");
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 { } else {
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Cannot_Update_Not_Install"), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); FRLogger.getLogger().info("更新失败");
JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
} }
} }
});
} catch (Exception e) {
FRContext.getLogger().error(e.getMessage(), e);
}
}
}
} }

Loading…
Cancel
Save