Browse Source

1、未联网更新报错

2、添加插件商店脚本更新。
master
vito 8 years ago
parent
commit
4d6a064864
  1. 7
      designer_base/src/com/fr/design/extra/PluginHelper.java
  2. 104
      designer_base/src/com/fr/design/extra/PluginManagerPane.java
  3. 34
      designer_base/src/com/fr/design/extra/PluginStoreConstants.java

7
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 com.fr.stable.xml.XMLTools;
import javax.swing.*; import javax.swing.*;
import java.io.File; import java.io.*;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.util.HashMap; import java.util.HashMap;
@ -61,6 +58,8 @@ public class PluginHelper {
reader.close(); reader.close();
writer.flush(); writer.flush();
writer.close(); writer.close();
} else {
throw new com.fr.plugin.PluginVerifyException(Inter.getLocText("FR-Designer-Plugin_Connect_Server_Error"));
} }
} }

104
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.RestartHelper;
import com.fr.design.dialog.BasicPane; import com.fr.design.dialog.BasicPane;
import com.fr.design.gui.frpane.UITabbedPane; 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.IOUtils;
import com.fr.general.Inter; 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 com.fr.stable.StableUtils;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.io.File; import java.io.File;
import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.util.concurrent.ExecutionException;
/** /**
* @author richie * @author richie
@ -28,6 +33,7 @@ import java.net.URL;
*/ */
public class PluginManagerPane extends BasicPane { public class PluginManagerPane extends BasicPane {
private static final String LATEST = "latest";
public PluginManagerPane() { public PluginManagerPane() {
setLayout(new BorderLayout()); setLayout(new BorderLayout());
@ -37,20 +43,22 @@ public class PluginManagerPane extends BasicPane {
URL url = ClassLoader.getSystemResource(""); URL url = ClassLoader.getSystemResource("");
installHome = url.getPath(); installHome = url.getPath();
} else { } else {
installHome = StableUtils.getInstallHome(); installHome = StableUtils.getInstallHome();
File file = new File(StableUtils.pathJoin(installHome, "scripts")); File file = new File(StableUtils.pathJoin(installHome, "scripts"));
if (!file.exists()) { if (!file.exists()) {
int rv = JOptionPane.showConfirmDialog( int rv = JOptionPane.showConfirmDialog(
null, null,
Inter.getLocText("FR-Designer-Plugin_Shop_Need_Install"), Inter.getLocText("FR-Designer-Plugin_Shop_Need_Install"),
Inter.getLocText("FR-Designer-Plugin_Warning"), Inter.getLocText("FR-Designer-Plugin_Warning"),
JOptionPane.OK_CANCEL_OPTION, JOptionPane.OK_CANCEL_OPTION,
JOptionPane.INFORMATION_MESSAGE JOptionPane.INFORMATION_MESSAGE
); );
if (rv == JOptionPane.OK_OPTION) { if (rv == JOptionPane.OK_OPTION) {
downloadShopScripts(); downloadShopScripts();
}
} }
} else {
updateShopScripts();
}
} }
PluginWebPane webPane = new PluginWebPane(new File(installHome).getAbsolutePath()); PluginWebPane webPane = new PluginWebPane(new File(installHome).getAbsolutePath());
add(webPane, BorderLayout.CENTER); add(webPane, BorderLayout.CENTER);
@ -69,9 +77,9 @@ public class PluginManagerPane extends BasicPane {
} }
private void downloadShopScripts() { private void downloadShopScripts() {
new SwingWorker<Void, Void>() { new SwingWorker<Boolean, Void>() {
@Override @Override
protected Void doInBackground() throws Exception { protected Boolean doInBackground() throws Exception {
String id = "shop_scripts"; String id = "shop_scripts";
String username = DesignerEnvManager.getEnvManager().getBBSName(); String username = DesignerEnvManager.getEnvManager().getBBSName();
String password = DesignerEnvManager.getEnvManager().getBBSPassword(); String password = DesignerEnvManager.getEnvManager().getBBSPassword();
@ -81,28 +89,64 @@ public class PluginManagerPane extends BasicPane {
public void process(Double integer) { 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) { } catch (Exception e) {
FRContext.getLogger().error(e.getMessage(), e); FRContext.getLogger().error(e.getMessage(), e);
return false;
} }
return null; return true;
} }
@Override @Override
protected void done() { protected void done() {
IOUtils.unzip(new File(StableUtils.pathJoin(PluginHelper.DOWNLOAD_PATH, PluginHelper.TEMP_FILE)), StableUtils.getInstallHome());
int rv = JOptionPane.showOptionDialog( try {
null, if (get()) {
Inter.getLocText("FR-Designer-Plugin_Shop_Installed"), IOUtils.unzip(new File(StableUtils.pathJoin(PluginHelper.DOWNLOAD_PATH, PluginHelper.TEMP_FILE)), StableUtils.getInstallHome());
Inter.getLocText("FR-Designer-Plugin_Warning"), int rv = JOptionPane.showOptionDialog(
JOptionPane.YES_NO_OPTION, null,
JOptionPane.INFORMATION_MESSAGE, Inter.getLocText("FR-Designer-Plugin_Shop_Installed"),
null, Inter.getLocText("FR-Designer-Plugin_Warning"),
new String[]{Inter.getLocText("FR-Designer-Basic_Restart_Designer"), Inter.getLocText("FR-Designer-Basic_Restart_Designer_Later")}, JOptionPane.YES_NO_OPTION,
null JOptionPane.INFORMATION_MESSAGE,
); null,
if (rv == JOptionPane.OK_OPTION) { new String[]{Inter.getLocText("FR-Designer-Basic_Restart_Designer"), Inter.getLocText("FR-Designer-Basic_Restart_Designer_Later")},
RestartHelper.restart(); null
);
if (rv == JOptionPane.OK_OPTION) {
RestartHelper.restart();
}
}
} catch (InterruptedException | ExecutionException e) {
FRContext.getLogger().error(e.getMessage(), e);
}
}
}.execute();
}
private void updateShopScripts() {
new SwingWorker<Void, Void>() {
@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(); }.execute();
} }

34
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;
}
}
Loading…
Cancel
Save