From e6cf95ef5e709e9a4339f139ea86575e845d4f53 Mon Sep 17 00:00:00 2001 From: kerry Date: Thu, 22 Jun 2017 10:19:55 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-2354=20=E5=95=86=E5=9F=8E=E8=84=9A?= =?UTF-8?q?=E6=9C=AC=E4=B8=8B=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/design/extra/PluginStoreConstants.java | 4 +- .../src/com/fr/design/extra/PluginUtils.java | 9 +- .../com/fr/design/extra/WebViewDlgHelper.java | 83 +++++++++++++------ 3 files changed, 67 insertions(+), 29 deletions(-) diff --git a/designer_base/src/com/fr/design/extra/PluginStoreConstants.java b/designer_base/src/com/fr/design/extra/PluginStoreConstants.java index 8bd7740bf8..84416fb256 100644 --- a/designer_base/src/com/fr/design/extra/PluginStoreConstants.java +++ b/designer_base/src/com/fr/design/extra/PluginStoreConstants.java @@ -1,9 +1,9 @@ package com.fr.design.extra; +import com.fr.base.FRContext; import com.fr.stable.StableUtils; import com.fr.stable.StringUtils; -import java.io.File; import java.io.FileInputStream; import java.util.Properties; @@ -20,7 +20,7 @@ public class PluginStoreConstants { if (PROP == null) { PROP = new Properties(); try { - PROP.load(new FileInputStream(StableUtils.pathJoin(new File(StableUtils.getInstallHome()).getAbsolutePath(), "scripts/store/web/plugin_store.properties"))); + PROP.load(new FileInputStream(StableUtils.pathJoin(FRContext.getCurrentEnv().getWebReportPath(), "scripts/store/web/plugin_store.properties"))); } catch (Exception e) { } } diff --git a/designer_base/src/com/fr/design/extra/PluginUtils.java b/designer_base/src/com/fr/design/extra/PluginUtils.java index 20f19c144e..cda7e286a1 100644 --- a/designer_base/src/com/fr/design/extra/PluginUtils.java +++ b/designer_base/src/com/fr/design/extra/PluginUtils.java @@ -105,12 +105,15 @@ public class PluginUtils { map.put("id", id); map.put("username", username); map.put("password", password); - HttpClient httpClient = new HttpClient(SiteCenter.getInstance().acquireUrlByKind("plugin.download"), map); + HttpClient httpClient = new HttpClient(SiteCenter.getInstance().acquireUrlByKind("shop.plugin.scripts")); + httpClient.asGet(); String resText = httpClient.getResponseText(); + JSONObject resultJSONObject = new JSONObject(resText); + String scriptUrl = resultJSONObject.optString("result"); String charSet = EncodeConstants.ENCODING_UTF_8; - resText = URLDecoder.decode(URLDecoder.decode(resText, charSet), charSet); + scriptUrl = URLDecoder.decode(URLDecoder.decode(scriptUrl, charSet), charSet); - return resText; + return scriptUrl; } public static boolean isPluginMatch(PluginView pluginView, String text) { diff --git a/designer_base/src/com/fr/design/extra/WebViewDlgHelper.java b/designer_base/src/com/fr/design/extra/WebViewDlgHelper.java index bccc259f2d..7580a45ace 100644 --- a/designer_base/src/com/fr/design/extra/WebViewDlgHelper.java +++ b/designer_base/src/com/fr/design/extra/WebViewDlgHelper.java @@ -12,12 +12,16 @@ import com.fr.general.IOUtils; 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.PluginVerifyException; import com.fr.stable.StableUtils; import javax.swing.*; import java.awt.*; import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.InputStream; import java.net.HttpURLConnection; import java.util.concurrent.ExecutionException; @@ -33,23 +37,26 @@ public class WebViewDlgHelper { public static void createPluginDialog() { if (StableUtils.getMajorJavaVersion() >= VERSION_8) { - String relativePath = "index.html"; + String relativePath = "/scripts/store/web/index.html"; String mainJsPath = StableUtils.pathJoin(FRContext.getCurrentEnv().getWebReportPath(), relativePath); File file = new File(mainJsPath); 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(SHOP_SCRIPTS); -// } + 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(SHOP_SCRIPTS); + } } else { + String indexPath = "index.html"; + String mainIndexPath = StableUtils.pathJoin(FRContext.getCurrentEnv().getWebReportPath(), indexPath); + checkAndCopyMainFile(mainIndexPath, mainJsPath); updateShopScripts(SHOP_SCRIPTS); - showPluginDlg(mainJsPath); + showPluginDlg(mainIndexPath); } } else { BasicPane traditionalStorePane = new BasicPane() { @@ -65,6 +72,31 @@ public class WebViewDlgHelper { } } + /** + * 检查script文件夹中的index.html文件 + * + */ + public static void checkAndCopyMainFile(String indexPath, String mainJsPath){ + File file = new File(indexPath); + if (!file.exists()) { + try { + File mainJsFile = new File(mainJsPath); + int byteread = 0; + if (mainJsFile.exists()) { + InputStream inStream = new FileInputStream(mainJsPath); + FileOutputStream fs = new FileOutputStream(indexPath); + byte[] buffer = new byte[1444]; + while ((byteread = inStream.read(buffer)) != -1) { + fs.write(buffer, 0, byteread); + } + inStream.close(); + } + } catch (Exception e) { + FRContext.getLogger().error(e.getMessage()); + } + } + } + /** * 以关键词打开设计器商店 * @@ -181,20 +213,23 @@ public class WebViewDlgHelper { new SwingWorker() { @Override protected Void doInBackground() throws Exception { - HttpClient httpClient = new HttpClient(SiteCenter.getInstance().acquireUrlByKind("store.version") + "&version=" + PluginStoreConstants.VERSION); + HttpClient httpClient = new HttpClient(SiteCenter.getInstance().acquireUrlByKind("shop.plugin.checkversion") + "&version=" + PluginStoreConstants.VERSION); + httpClient.asGet(); if (httpClient.getResponseCode() == HttpURLConnection.HTTP_OK) { String text = httpClient.getResponseText(); - if (!ComparatorUtils.equals(text, 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(scriptsId); -// } + JSONObject resultJSONObject = new JSONObject(text); + String isLatest = resultJSONObject.optString("result"); + if (!ComparatorUtils.equals(isLatest, 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(scriptsId); + } } } return null;