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. 64
      designer_base/src/com/fr/design/extra/exe/InstallFromDiskExecutor.java
  7. 138
      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. 62
      designer_base/src/com/fr/design/extra/exe/UninstallExecutor.java
  11. 46
      designer_base/src/com/fr/design/extra/exe/UpdateFromDiskExecutor.java
  12. 139
      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.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,14 +143,16 @@ 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));
public void installPluginOnline(final String pluginInfo, final JSObject callback) {
Task<Void> task = new PluginTask<>(webEngine, callback, new InstallOnlineExecutor(pluginInfo));
new Thread(task).start();
}
/**
* 从磁盘上选择插件安装包进行安装
*
@ -164,13 +166,14 @@ public class PluginWebBridge {
/**
* 卸载当前选中的插件
*
* @param pluginIDs 插件集合
* @param pluginInfo 插件信息
*/
public void uninstallPlugin(JSObject pluginIDs, final JSObject callback) {
Task<Void> task = new PluginTask<>(webEngine, callback, new UninstallExecutor(jsObjectToStringArray(pluginIDs)));
public void uninstallPlugin(final String pluginInfo, final boolean isForce, final JSObject callback) {
Task<Void> task = new PluginTask<>(webEngine, callback, new UninstallExecutor(pluginInfo, isForce));
new Thread(task).start();
}
/**
* 从插件服务器上更新选中的插件
*
@ -266,8 +269,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()]);
}
@ -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 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;
}
}
}

64
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;
@ -49,21 +49,55 @@ public class InstallFromDiskExecutor implements Executor {
@Override
public void run(Process<String> process) {
try {
PluginHelper.installPluginFromDisk(new File(filePath), new After() {
@Override
public void done() {
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("插件安装成功");
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();
}else{
FRLogger.getLogger().info("插件安装失败");
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 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);
}
}
});
}
}

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 "正在下载插件:" + 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("插件安装成功");
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_Warning"),
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("插件安装成功");
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;
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("删除成功");
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;
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;
/**
@ -32,9 +38,45 @@ 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("更新成功");
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);
}
}
});
}
}

139
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.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.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
@ -48,69 +50,72 @@ public class UpdateOnlineExecutor implements Executor {
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);
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()) {
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);
}
});
} 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_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()) {
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 {
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