diff --git a/designer/src/com/fr/design/mainframe/bbs/BBSDialog.java b/designer/src/com/fr/design/mainframe/bbs/BBSDialog.java index 8dbdd0acf2..856e9264a1 100644 --- a/designer/src/com/fr/design/mainframe/bbs/BBSDialog.java +++ b/designer/src/com/fr/design/mainframe/bbs/BBSDialog.java @@ -143,9 +143,8 @@ public class BBSDialog extends UIDialog { * 提供给web页面调用的关闭窗口 */ public void closeWindow() { - this.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); + this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); this.setVisible(false); - this.dispose(); } /** * 略 diff --git a/designer_base/src/com/fr/design/extra/PluginWebBridge.java b/designer_base/src/com/fr/design/extra/PluginWebBridge.java index 0f5122f3e3..ce6dd8fba3 100644 --- a/designer_base/src/com/fr/design/extra/PluginWebBridge.java +++ b/designer_base/src/com/fr/design/extra/PluginWebBridge.java @@ -1,8 +1,11 @@ package com.fr.design.extra; +import com.fr.base.FRContext; +import com.fr.design.RestartHelper; import com.fr.design.dialog.UIDialog; import com.fr.design.extra.exe.*; import com.fr.general.FRLogger; +import com.fr.general.Inter; import com.fr.general.http.HttpClient; import com.fr.plugin.Plugin; import com.fr.plugin.PluginLoader; @@ -92,10 +95,10 @@ public class PluginWebBridge { /** * 从插件服务器上更新选中的插件 * - * @param pluginID 插件的ID + * @param pluginIDs 插件集合 */ - public void updatePluginOnline(String pluginID, final JSObject callback) { - Task task = new PluginTask<>(webEngine, callback, new UpdateOnlineExecutor(pluginID)); + public void updatePluginOnline(JSObject pluginIDs, final JSObject callback) { + Task task = new PluginTask<>(webEngine, callback, new UpdateOnlineExecutor(jsObjectToStringArray(pluginIDs))); new Thread(task).start(); } @@ -193,7 +196,7 @@ public class PluginWebBridge { public String getPluginFromStore(String category, String seller, String fee) { - StringBuilder url = new StringBuilder("http://192.168.101.20/ShopServer?pg=plist"); + StringBuilder url = new StringBuilder("http://127.0.0.1:8080/ShopServer?pg=plist"); if (StringUtils.isNotBlank(category)) { url.append("&cid=").append(category.split("-")[1]); } @@ -206,7 +209,7 @@ public class PluginWebBridge { String resText = null; try { HttpClient httpClient = new HttpClient(url.toString()); - //httpClient.setTimeout(5000); + httpClient.setTimeout(3000); resText = httpClient.getResponseText(); } catch (Exception e) { FRLogger.getLogger().error(e.getMessage()); @@ -214,10 +217,77 @@ public class PluginWebBridge { return resText == null ? StringUtils.EMPTY : resText; } + + public void showRestartMessage(String message){ + int rv = JOptionPane.showOptionDialog( + null, + message, + 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 closeWindow() { if (uiDialog != null) { uiDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); uiDialog.setVisible(false); } } + + 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); + } + } } diff --git a/designer_base/src/com/fr/design/extra/exe/InstallFromDiskExecutor.java b/designer_base/src/com/fr/design/extra/exe/InstallFromDiskExecutor.java index 098a91c029..cb803f3141 100644 --- a/designer_base/src/com/fr/design/extra/exe/InstallFromDiskExecutor.java +++ b/designer_base/src/com/fr/design/extra/exe/InstallFromDiskExecutor.java @@ -1,5 +1,16 @@ package com.fr.design.extra.exe; +import com.fr.design.RestartHelper; +import com.fr.design.extra.After; +import com.fr.design.extra.PluginHelper; +import com.fr.design.extra.PluginWebBridge; +import com.fr.general.FRLogger; +import com.fr.general.Inter; +import org.apache.poi.poifs.crypt.AgileDecryptor; + +import javax.swing.*; +import java.io.File; + /** * Created by richie on 16/3/19. */ @@ -27,11 +38,6 @@ public class InstallFromDiskExecutor implements Executor { @Override public void run() { - try { - Thread.sleep(2000); - } catch (InterruptedException e) { - e.printStackTrace(); - } } }, new Command() { @@ -43,9 +49,15 @@ public class InstallFromDiskExecutor implements Executor { @Override public void run() { try { - Thread.sleep(2000); - } catch (InterruptedException e) { - e.printStackTrace(); + PluginHelper.installPluginFromDisk(new File(filePath), new After() { + @Override + public void done() { + FRLogger.getLogger().info("插件安装成功"); + PluginWebBridge.getHelper().showRestartMessage(Inter.getLocText("FR-Designer-Plugin_Install_Successful")); + } + }); + } catch (Exception e1) { + FRLogger.getLogger().error(e1.getMessage()); } } } diff --git a/designer_base/src/com/fr/design/extra/exe/InstallOnlineExecutor.java b/designer_base/src/com/fr/design/extra/exe/InstallOnlineExecutor.java index 7baf378fd2..348898877f 100644 --- a/designer_base/src/com/fr/design/extra/exe/InstallOnlineExecutor.java +++ b/designer_base/src/com/fr/design/extra/exe/InstallOnlineExecutor.java @@ -1,5 +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.PluginHelper; +import com.fr.design.extra.PluginWebBridge; +import com.fr.design.extra.Process; +import com.fr.general.Inter; + +import javax.swing.*; + /** * Created by richie on 16/3/19. */ @@ -27,10 +38,17 @@ public class InstallOnlineExecutor implements Executor { @Override public void run() { + String username = DesignerEnvManager.getEnvManager().getBBSName(); + String password = DesignerEnvManager.getEnvManager().getBBSPassword(); try { - Thread.sleep(3000); - } catch (InterruptedException e) { - e.printStackTrace(); + PluginHelper.downloadPluginFile(pluginID,username,password, new Process() { + @Override + public void process(Double integer) { + + } + }); + } catch (Exception e) { + FRContext.getLogger().error(e.getMessage(), e); } } }, @@ -43,9 +61,16 @@ public class InstallOnlineExecutor implements Executor { @Override public void run() { try { - Thread.sleep(3000); + PluginHelper.installPluginFromDisk(PluginHelper.getDownloadTempFile(), new After() { + @Override + public void done() { + PluginWebBridge.getHelper().showRestartMessage(Inter.getLocText("FR-Designer-Plugin_Update_Successful")); + } + }); } catch (InterruptedException e) { e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); } } } diff --git a/designer_base/src/com/fr/design/extra/exe/ModifyStatusExecutor.java b/designer_base/src/com/fr/design/extra/exe/ModifyStatusExecutor.java index ff5d82bd5f..2d5b0f8c70 100644 --- a/designer_base/src/com/fr/design/extra/exe/ModifyStatusExecutor.java +++ b/designer_base/src/com/fr/design/extra/exe/ModifyStatusExecutor.java @@ -1,5 +1,12 @@ package com.fr.design.extra.exe; +import com.fr.base.FRContext; +import com.fr.design.extra.PluginWebBridge; +import com.fr.general.Inter; +import com.fr.plugin.Plugin; +import com.fr.plugin.PluginLoader; +import com.fr.stable.StringUtils; + /** * Created by richie on 16/3/19. */ @@ -7,19 +14,38 @@ public class ModifyStatusExecutor implements Executor { private String pluginID; private boolean active; + private Plugin plugin; - public ModifyStatusExecutor(String pluginID, boolean active) { + public ModifyStatusExecutor(String pluginID) { this.pluginID = pluginID; - this.active = active; } @Override public String getTaskFinishMessage() { - return "插件" + pluginID + "已更改为可用状态:" + active; + return plugin.isActive() ? Inter.getLocText("FR-Designer-Plugin_Has_Been_Actived") : Inter.getLocText("FR-Designer-Plugin_Has_Been_Disabled"); } @Override public Command[] getCommands() { - return new Command[0]; + return new Command[]{ + new Command() { + @Override + public String getExecuteMessage() { + return StringUtils.EMPTY; + } + @Override + public void run() { + plugin = PluginLoader.getLoader().getPluginById(pluginID); + 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()); + } + } + } + }; } } diff --git a/designer_base/src/com/fr/design/extra/exe/UninstallExecutor.java b/designer_base/src/com/fr/design/extra/exe/UninstallExecutor.java index 5138c1a58a..56b1c5304c 100644 --- a/designer_base/src/com/fr/design/extra/exe/UninstallExecutor.java +++ b/designer_base/src/com/fr/design/extra/exe/UninstallExecutor.java @@ -1,5 +1,14 @@ 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.general.Inter; +import com.fr.plugin.Plugin; +import com.fr.plugin.PluginLoader; + +import javax.swing.*; + /** * Created by richie on 16/3/19. */ @@ -18,6 +27,45 @@ public class UninstallExecutor implements Executor { @Override public Command[] getCommands() { - return new Command[0]; + return new Command[]{ + new Command() { + @Override + public String getExecuteMessage() { + return "删除成功"; + } + + @Override + public void run() { + 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); + } + } + if (rv == JOptionPane.OK_OPTION) { + RestartHelper.restart(); + } + } + } + }; } } diff --git a/designer_base/src/com/fr/design/extra/exe/UpdateFromDiskExecutor.java b/designer_base/src/com/fr/design/extra/exe/UpdateFromDiskExecutor.java index cfc0ab222a..26615b9b30 100644 --- a/designer_base/src/com/fr/design/extra/exe/UpdateFromDiskExecutor.java +++ b/designer_base/src/com/fr/design/extra/exe/UpdateFromDiskExecutor.java @@ -1,5 +1,9 @@ package com.fr.design.extra.exe; +import com.fr.design.extra.PluginWebBridge; + +import java.io.File; + /** * Created by richie on 16/3/19. */ @@ -13,11 +17,23 @@ public class UpdateFromDiskExecutor implements Executor { @Override public String getTaskFinishMessage() { - return "插件已更新完毕"; + return "插件更新操作结束"; } @Override public Command[] getCommands() { - return new Command[0]; + return new Command[]{ + new Command() { + @Override + public String getExecuteMessage() { + return null; + } + + @Override + public void run() { + PluginWebBridge.getHelper().updateFileFromDisk(new File(filePath)); + } + } + }; } }