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