From 1586f20b0d89895d0ee3643a353cedf8385306d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E6=94=80?= Date: Fri, 19 Aug 2016 10:38:27 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E6=A1=86=E9=83=A8=E5=88=86?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E5=AE=89=E8=A3=85=E6=83=85=E5=86=B5=E4=B8=8B?= =?UTF-8?q?=E7=9A=84=E4=B8=8B=E8=BD=BDscripts=E9=83=A8=E5=88=86=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/com/fr/design/extra/LoginPane.java | 102 ++++++++++++++++- .../fr/design/extra/PluginManagerPane.java | 2 +- .../src/com/fr/design/extra/QQLoginPane.java | 105 +++++++++++++++++- 3 files changed, 205 insertions(+), 4 deletions(-) diff --git a/designer_base/src/com/fr/design/extra/LoginPane.java b/designer_base/src/com/fr/design/extra/LoginPane.java index f49088af2..c8c231b24 100644 --- a/designer_base/src/com/fr/design/extra/LoginPane.java +++ b/designer_base/src/com/fr/design/extra/LoginPane.java @@ -1,12 +1,23 @@ package com.fr.design.extra; +import com.fr.base.FRContext; +import com.fr.design.DesignerEnvManager; +import com.fr.design.RestartHelper; import com.fr.design.dialog.BasicPane; +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; /** * Created by zhaohehe on 16/7/27. @@ -25,6 +36,21 @@ public class LoginPane extends BasicPane { } else { installHome = StableUtils.getInstallHome(); File file = new File(StableUtils.pathJoin(installHome, "scripts")); + if (!file.exists()) { + int rv = JOptionPane.showConfirmDialog( + this, + 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 { + addPane(installHome); + updateShopScripts(); + } } } else { } @@ -35,9 +61,83 @@ public class LoginPane extends BasicPane { add(webPane, BorderLayout.CENTER); } - @Override protected String title4PopupWindow() { return Inter.getLocText("FR-Designer-Plugin_Manager"); } + + private void downloadShopScripts() { + new SwingWorker() { + @Override + protected Boolean doInBackground() throws Exception { + String id = "shop_scripts"; + String username = DesignerEnvManager.getEnvManager().getBBSName(); + String password = DesignerEnvManager.getEnvManager().getBBSPassword(); + try { + PluginHelper.downloadPluginFile(id, username, password, new Process() { + @Override + public void process(Double integer) { + } + }); + } catch (PluginVerifyException e) { + JOptionPane.showMessageDialog(LoginPane.this, 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 true; + } + + @Override + protected void done() { + + try { + if (get()) { + IOUtils.unzip(new File(StableUtils.pathJoin(PluginHelper.DOWNLOAD_PATH, PluginHelper.TEMP_FILE)), StableUtils.getInstallHome()); + int rv = JOptionPane.showOptionDialog( + LoginPane.this, + 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( + LoginPane.this, + 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(); + } } \ No newline at end of file diff --git a/designer_base/src/com/fr/design/extra/PluginManagerPane.java b/designer_base/src/com/fr/design/extra/PluginManagerPane.java index 64ceea369..1c9f7aafa 100644 --- a/designer_base/src/com/fr/design/extra/PluginManagerPane.java +++ b/designer_base/src/com/fr/design/extra/PluginManagerPane.java @@ -37,7 +37,7 @@ public class PluginManagerPane extends BasicPane { public PluginManagerPane() { setLayout(new BorderLayout()); - if (System.getProperty("java.version").startsWith("1.8")) { + if (StableUtils.getMajorJavaVersion() == 8) { String installHome; if (StableUtils.isDebug()) { URL url = ClassLoader.getSystemResource(""); diff --git a/designer_base/src/com/fr/design/extra/QQLoginPane.java b/designer_base/src/com/fr/design/extra/QQLoginPane.java index e93c611fe..2bbdd7e53 100644 --- a/designer_base/src/com/fr/design/extra/QQLoginPane.java +++ b/designer_base/src/com/fr/design/extra/QQLoginPane.java @@ -1,12 +1,23 @@ package com.fr.design.extra; +import com.fr.base.FRContext; +import com.fr.design.DesignerEnvManager; +import com.fr.design.RestartHelper; import com.fr.design.dialog.BasicPane; +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; /** * Created by zhaohehe on 16/7/28. @@ -16,7 +27,7 @@ public class QQLoginPane extends BasicPane { public QQLoginPane() { setLayout(new BorderLayout()); - if (System.getProperty("java.version").startsWith("1.8")) { + if (StableUtils.getMajorJavaVersion() == 8) { String installHome; if (StableUtils.isDebug()) { URL url = ClassLoader.getSystemResource(""); @@ -25,7 +36,21 @@ public class QQLoginPane extends BasicPane { } else { installHome = StableUtils.getInstallHome(); File file = new File(StableUtils.pathJoin(installHome, "scripts")); - + if (!file.exists()) { + int rv = JOptionPane.showConfirmDialog( + this, + 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 { + addPane(installHome); + updateShopScripts(); + } } } else { } @@ -41,4 +66,80 @@ public class QQLoginPane extends BasicPane { protected String title4PopupWindow() { return Inter.getLocText("FR-Designer-Plugin_Manager"); } + + + private void downloadShopScripts() { + new SwingWorker() { + @Override + protected Boolean doInBackground() throws Exception { + String id = "shop_scripts"; + String username = DesignerEnvManager.getEnvManager().getBBSName(); + String password = DesignerEnvManager.getEnvManager().getBBSPassword(); + try { + PluginHelper.downloadPluginFile(id, username, password, new Process() { + @Override + public void process(Double integer) { + } + }); + } catch (PluginVerifyException e) { + JOptionPane.showMessageDialog(QQLoginPane.this, 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 true; + } + + @Override + protected void done() { + + try { + if (get()) { + IOUtils.unzip(new File(StableUtils.pathJoin(PluginHelper.DOWNLOAD_PATH, PluginHelper.TEMP_FILE)), StableUtils.getInstallHome()); + int rv = JOptionPane.showOptionDialog( + QQLoginPane.this, + 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( + QQLoginPane.this, + 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(); + } } \ No newline at end of file