From 4d6a0648647d2f1b455a840d59c6793a2fa3fe8e Mon Sep 17 00:00:00 2001 From: vito Date: Fri, 22 Apr 2016 19:25:08 +0800 Subject: [PATCH 1/2] =?UTF-8?q?1=E3=80=81=E6=9C=AA=E8=81=94=E7=BD=91?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=8A=A5=E9=94=99=202=E3=80=81=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E6=8F=92=E4=BB=B6=E5=95=86=E5=BA=97=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/com/fr/design/extra/PluginHelper.java | 7 +- .../fr/design/extra/PluginManagerPane.java | 104 +++++++++++++----- .../fr/design/extra/PluginStoreConstants.java | 34 ++++++ 3 files changed, 111 insertions(+), 34 deletions(-) create mode 100644 designer_base/src/com/fr/design/extra/PluginStoreConstants.java diff --git a/designer_base/src/com/fr/design/extra/PluginHelper.java b/designer_base/src/com/fr/design/extra/PluginHelper.java index 86e5f49eb..8bab17e68 100644 --- a/designer_base/src/com/fr/design/extra/PluginHelper.java +++ b/designer_base/src/com/fr/design/extra/PluginHelper.java @@ -15,10 +15,7 @@ import com.fr.stable.project.ProjectConstants; import com.fr.stable.xml.XMLTools; import javax.swing.*; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.InputStream; +import java.io.*; import java.net.HttpURLConnection; import java.net.URLDecoder; import java.util.HashMap; @@ -61,6 +58,8 @@ public class PluginHelper { reader.close(); writer.flush(); writer.close(); + } else { + throw new com.fr.plugin.PluginVerifyException(Inter.getLocText("FR-Designer-Plugin_Connect_Server_Error")); } } diff --git a/designer_base/src/com/fr/design/extra/PluginManagerPane.java b/designer_base/src/com/fr/design/extra/PluginManagerPane.java index 26374d881..0704977f6 100644 --- a/designer_base/src/com/fr/design/extra/PluginManagerPane.java +++ b/designer_base/src/com/fr/design/extra/PluginManagerPane.java @@ -5,15 +5,20 @@ import com.fr.design.DesignerEnvManager; import com.fr.design.RestartHelper; import com.fr.design.dialog.BasicPane; import com.fr.design.gui.frpane.UITabbedPane; -import com.fr.general.GeneralUtils; +import com.fr.general.ComparatorUtils; import com.fr.general.IOUtils; import com.fr.general.Inter; +import com.fr.general.SiteCenter; +import com.fr.general.http.HttpClient; +import com.fr.plugin.PluginVerifyException; import com.fr.stable.StableUtils; import javax.swing.*; import java.awt.*; import java.io.File; +import java.net.HttpURLConnection; import java.net.URL; +import java.util.concurrent.ExecutionException; /** * @author richie @@ -28,6 +33,7 @@ import java.net.URL; */ public class PluginManagerPane extends BasicPane { + private static final String LATEST = "latest"; public PluginManagerPane() { setLayout(new BorderLayout()); @@ -37,20 +43,22 @@ public class PluginManagerPane extends BasicPane { URL url = ClassLoader.getSystemResource(""); installHome = url.getPath(); } else { - installHome = StableUtils.getInstallHome(); - File file = new File(StableUtils.pathJoin(installHome, "scripts")); - if (!file.exists()) { - int rv = JOptionPane.showConfirmDialog( - null, - Inter.getLocText("FR-Designer-Plugin_Shop_Need_Install"), - Inter.getLocText("FR-Designer-Plugin_Warning"), - JOptionPane.OK_CANCEL_OPTION, - JOptionPane.INFORMATION_MESSAGE - ); - if (rv == JOptionPane.OK_OPTION) { - downloadShopScripts(); - } + installHome = StableUtils.getInstallHome(); + File file = new File(StableUtils.pathJoin(installHome, "scripts")); + if (!file.exists()) { + int rv = JOptionPane.showConfirmDialog( + null, + Inter.getLocText("FR-Designer-Plugin_Shop_Need_Install"), + Inter.getLocText("FR-Designer-Plugin_Warning"), + JOptionPane.OK_CANCEL_OPTION, + JOptionPane.INFORMATION_MESSAGE + ); + if (rv == JOptionPane.OK_OPTION) { + downloadShopScripts(); } + } else { + updateShopScripts(); + } } PluginWebPane webPane = new PluginWebPane(new File(installHome).getAbsolutePath()); add(webPane, BorderLayout.CENTER); @@ -69,9 +77,9 @@ public class PluginManagerPane extends BasicPane { } private void downloadShopScripts() { - new SwingWorker() { + new SwingWorker() { @Override - protected Void doInBackground() throws Exception { + protected Boolean doInBackground() throws Exception { String id = "shop_scripts"; String username = DesignerEnvManager.getEnvManager().getBBSName(); String password = DesignerEnvManager.getEnvManager().getBBSPassword(); @@ -81,28 +89,64 @@ public class PluginManagerPane extends BasicPane { public void process(Double integer) { } }); + } catch (PluginVerifyException e) { + JOptionPane.showMessageDialog(null, e.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); + return false; } catch (Exception e) { FRContext.getLogger().error(e.getMessage(), e); + return false; } - return null; + return true; } @Override protected void done() { - IOUtils.unzip(new File(StableUtils.pathJoin(PluginHelper.DOWNLOAD_PATH, PluginHelper.TEMP_FILE)), StableUtils.getInstallHome()); - int rv = JOptionPane.showOptionDialog( - null, - Inter.getLocText("FR-Designer-Plugin_Shop_Installed"), - 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(); + + try { + if (get()) { + IOUtils.unzip(new File(StableUtils.pathJoin(PluginHelper.DOWNLOAD_PATH, PluginHelper.TEMP_FILE)), StableUtils.getInstallHome()); + int rv = JOptionPane.showOptionDialog( + null, + Inter.getLocText("FR-Designer-Plugin_Shop_Installed"), + 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 (InterruptedException | ExecutionException e) { + FRContext.getLogger().error(e.getMessage(), e); + } + + } + }.execute(); + } + + private void updateShopScripts() { + new SwingWorker() { + @Override + protected Void doInBackground() throws Exception { + HttpClient httpClient = new HttpClient(SiteCenter.getInstance().acquireUrlByKind("store.version") + "&version=" + PluginStoreConstants.VERSION); + if (httpClient.getResponseCode() == HttpURLConnection.HTTP_OK) { + if (!ComparatorUtils.equals(httpClient.getResponseText(), LATEST)) { + int rv = JOptionPane.showConfirmDialog( + null, + Inter.getLocText("FR-Designer-Plugin_Shop_Need_Update"), + Inter.getLocText("FR-Designer-Plugin_Warning"), + JOptionPane.OK_CANCEL_OPTION, + JOptionPane.INFORMATION_MESSAGE + ); + if (rv == JOptionPane.OK_OPTION) { + downloadShopScripts(); + } + } } + return null; } }.execute(); } diff --git a/designer_base/src/com/fr/design/extra/PluginStoreConstants.java b/designer_base/src/com/fr/design/extra/PluginStoreConstants.java new file mode 100644 index 000000000..8bd7740bf --- /dev/null +++ b/designer_base/src/com/fr/design/extra/PluginStoreConstants.java @@ -0,0 +1,34 @@ +package com.fr.design.extra; + +import com.fr.stable.StableUtils; +import com.fr.stable.StringUtils; + +import java.io.File; +import java.io.FileInputStream; +import java.util.Properties; + +/** + * Created by vito on 16/4/22. + */ +public class PluginStoreConstants { + + public static final String VERSION = loadAttribute("VERSION", ""); + + private static Properties PROP = null; + + private static String loadAttribute(String key, String defaultValue) { + if (PROP == null) { + PROP = new Properties(); + try { + PROP.load(new FileInputStream(StableUtils.pathJoin(new File(StableUtils.getInstallHome()).getAbsolutePath(), "scripts/store/web/plugin_store.properties"))); + } catch (Exception e) { + } + } + String p = PROP.getProperty(key); + if (StringUtils.isEmpty(p)) { + p = defaultValue; + } + return p; + } + +} From 949b1919c2e798bafa4ed481c31f6dd1e00329c9 Mon Sep 17 00:00:00 2001 From: vito Date: Sat, 23 Apr 2016 15:21:43 +0800 Subject: [PATCH 2/2] =?UTF-8?q?1=E3=80=81=E6=B7=BB=E5=8A=A0=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E5=95=86=E5=BA=97=E6=8E=88=E6=9D=83=E4=BF=A1=E6=81=AF?= =?UTF-8?q?api=202=E3=80=81=E5=87=8F=E5=B0=8F=E6=8F=92=E4=BB=B6=E5=95=86?= =?UTF-8?q?=E5=BA=97=E7=AA=97=E4=BD=93=E9=AB=98=E5=BA=A6=E4=BB=A5=E9=80=82?= =?UTF-8?q?=E9=85=8Dwin=E4=B8=8B=E5=87=BA=E7=8E=B0=E6=BB=9A=E5=8A=A8?= =?UTF-8?q?=E6=9D=A1=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/com/fr/design/extra/PluginShopDialog.java | 2 +- .../src/com/fr/design/extra/PluginWebBridge.java | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/designer_base/src/com/fr/design/extra/PluginShopDialog.java b/designer_base/src/com/fr/design/extra/PluginShopDialog.java index 5d04401b2..cc75e46e8 100644 --- a/designer_base/src/com/fr/design/extra/PluginShopDialog.java +++ b/designer_base/src/com/fr/design/extra/PluginShopDialog.java @@ -10,7 +10,7 @@ import java.awt.*; * Created by vito on 16/4/18. */ public class PluginShopDialog extends UIDialog { - private static final Dimension DEFAULT_SHOP = new Dimension(900, 710); + private static final Dimension DEFAULT_SHOP = new Dimension(900, 700); public PluginShopDialog(Frame frame, BasicPane pane) { super(frame, pane, false); diff --git a/designer_base/src/com/fr/design/extra/PluginWebBridge.java b/designer_base/src/com/fr/design/extra/PluginWebBridge.java index 69f65075f..25d9c20cf 100644 --- a/designer_base/src/com/fr/design/extra/PluginWebBridge.java +++ b/designer_base/src/com/fr/design/extra/PluginWebBridge.java @@ -8,6 +8,8 @@ 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.stable.ArrayUtils; import com.fr.stable.StringUtils; @@ -196,6 +198,16 @@ public class PluginWebBridge { return PluginLoader.getLoader().getInstalled(); } + + /** + * 获取已经安装的插件的授权情况 + * + * @return 已安装的插件授权对象 + */ + public PluginLicense getPluginLicenseByID(String pluginID ) { + return PluginLicenseManager.getInstance().getPluginLicenseByID(pluginID); + } + private String[] jsObjectToStringArray(JSObject obj) { if (obj == null) { return ArrayUtils.EMPTY_STRING_ARRAY;