Browse Source

插件商店的一些java数据API

master
vito 9 years ago
parent
commit
1987927759
  1. 15
      designer_base/src/com/fr/design/extra/PluginTask.java
  2. 4
      designer_base/src/com/fr/design/extra/exe/Command.java
  3. 15
      designer_base/src/com/fr/design/extra/exe/InstallFromDiskExecutor.java
  4. 14
      designer_base/src/com/fr/design/extra/exe/InstallOnlineExecutor.java
  5. 3
      designer_base/src/com/fr/design/extra/exe/ModifyStatusExecutor.java
  6. 3
      designer_base/src/com/fr/design/extra/exe/UninstallExecutor.java
  7. 3
      designer_base/src/com/fr/design/extra/exe/UpdateFromDiskExecutor.java
  8. 95
      designer_base/src/com/fr/design/extra/exe/UpdateOnlineExecutor.java

15
designer_base/src/com/fr/design/extra/PluginTask.java

@ -2,6 +2,7 @@ package com.fr.design.extra;
import com.fr.design.extra.exe.Executor; import com.fr.design.extra.exe.Executor;
import com.fr.design.extra.exe.Command; import com.fr.design.extra.exe.Command;
import com.fr.stable.StringUtils;
import javafx.beans.value.ChangeListener; import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue; import javafx.beans.value.ObservableValue;
import javafx.concurrent.Task; import javafx.concurrent.Task;
@ -10,6 +11,7 @@ import netscape.javascript.JSObject;
/** /**
* 插件安装,卸载,更新等任务 * 插件安装,卸载,更新等任务
*
* @param <T> * @param <T>
*/ */
public class PluginTask<T> extends Task<T> { public class PluginTask<T> extends Task<T> {
@ -40,8 +42,17 @@ public class PluginTask<T> extends Task<T> {
Command[] commands = executor.getCommands(); Command[] commands = executor.getCommands();
for (Command command : commands) { for (Command command : commands) {
String message = command.getExecuteMessage(); String message = command.getExecuteMessage();
updateMessage(message); if (StringUtils.isNotBlank(message)) {
command.run(); updateMessage(message);
}
command.run(new Process<String>() {
@Override
public void process(String s) {
if (StringUtils.isNotBlank(s)) {
updateMessage(s);
}
}
});
} }
return null; return null;
} }

4
designer_base/src/com/fr/design/extra/exe/Command.java

@ -1,5 +1,7 @@
package com.fr.design.extra.exe; package com.fr.design.extra.exe;
import com.fr.design.extra.Process;
/** /**
* Created by richie on 16/3/19. * Created by richie on 16/3/19.
*/ */
@ -7,5 +9,5 @@ public interface Command {
String getExecuteMessage(); String getExecuteMessage();
void run(); void run(Process<String> process);
} }

15
designer_base/src/com/fr/design/extra/exe/InstallFromDiskExecutor.java

@ -1,12 +1,12 @@
package com.fr.design.extra.exe; package com.fr.design.extra.exe;
import com.fr.design.RestartHelper;
import com.fr.design.extra.After; import com.fr.design.extra.After;
import com.fr.design.extra.PluginHelper; import com.fr.design.extra.PluginHelper;
import com.fr.design.extra.PluginWebBridge; import com.fr.design.extra.PluginWebBridge;
import com.fr.design.extra.Process;
import com.fr.general.FRLogger; import com.fr.general.FRLogger;
import com.fr.general.Inter; import com.fr.general.Inter;
import org.apache.poi.poifs.crypt.AgileDecryptor; import com.fr.plugin.PluginVerifyException;
import javax.swing.*; import javax.swing.*;
import java.io.File; import java.io.File;
@ -37,7 +37,8 @@ public class InstallFromDiskExecutor implements Executor {
} }
@Override @Override
public void run() { public void run(Process<java.lang.String> process) {
} }
}, },
new Command() { new Command() {
@ -47,7 +48,7 @@ public class InstallFromDiskExecutor implements Executor {
} }
@Override @Override
public void run() { public void run(Process<String> process) {
try { try {
PluginHelper.installPluginFromDisk(new File(filePath), new After() { PluginHelper.installPluginFromDisk(new File(filePath), new After() {
@Override @Override
@ -56,8 +57,10 @@ public class InstallFromDiskExecutor implements Executor {
PluginWebBridge.getHelper().showRestartMessage(Inter.getLocText("FR-Designer-Plugin_Install_Successful")); PluginWebBridge.getHelper().showRestartMessage(Inter.getLocText("FR-Designer-Plugin_Install_Successful"));
} }
}); });
} catch (Exception e1) { } catch (PluginVerifyException e) {
FRLogger.getLogger().error(e1.getMessage()); JOptionPane.showMessageDialog(null, e.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
} catch (Exception e) {
FRLogger.getLogger().error(e.getMessage());
} }
} }
} }

14
designer_base/src/com/fr/design/extra/exe/InstallOnlineExecutor.java

@ -2,12 +2,12 @@ package com.fr.design.extra.exe;
import com.fr.base.FRContext; import com.fr.base.FRContext;
import com.fr.design.DesignerEnvManager; import com.fr.design.DesignerEnvManager;
import com.fr.design.RestartHelper;
import com.fr.design.extra.After; import com.fr.design.extra.After;
import com.fr.design.extra.PluginHelper; import com.fr.design.extra.PluginHelper;
import com.fr.design.extra.PluginWebBridge; import com.fr.design.extra.PluginWebBridge;
import com.fr.design.extra.Process; import com.fr.design.extra.Process;
import com.fr.general.Inter; import com.fr.general.Inter;
import com.fr.plugin.PluginVerifyException;
import javax.swing.*; import javax.swing.*;
@ -24,7 +24,7 @@ public class InstallOnlineExecutor implements Executor {
@Override @Override
public String getTaskFinishMessage() { public String getTaskFinishMessage() {
return "已成功安裝"; return "task succeed";
} }
@Override @Override
@ -37,14 +37,14 @@ public class InstallOnlineExecutor implements Executor {
} }
@Override @Override
public void run() { public void run(final Process<String> process) {
String username = DesignerEnvManager.getEnvManager().getBBSName(); String username = DesignerEnvManager.getEnvManager().getBBSName();
String password = DesignerEnvManager.getEnvManager().getBBSPassword(); String password = DesignerEnvManager.getEnvManager().getBBSPassword();
try { try {
PluginHelper.downloadPluginFile(pluginID,username,password, new Process<Double>() { PluginHelper.downloadPluginFile(pluginID, username, password, new Process<Double>() {
@Override @Override
public void process(Double integer) { public void process(Double integer) {
process.process(Math.round(integer * 100) + "%");
} }
}); });
} catch (Exception e) { } catch (Exception e) {
@ -59,7 +59,7 @@ public class InstallOnlineExecutor implements Executor {
} }
@Override @Override
public void run() { public void run(Process<String> process) {
try { try {
PluginHelper.installPluginFromDisk(PluginHelper.getDownloadTempFile(), new After() { PluginHelper.installPluginFromDisk(PluginHelper.getDownloadTempFile(), new After() {
@Override @Override
@ -67,6 +67,8 @@ public class InstallOnlineExecutor implements Executor {
PluginWebBridge.getHelper().showRestartMessage(Inter.getLocText("FR-Designer-Plugin_Update_Successful")); PluginWebBridge.getHelper().showRestartMessage(Inter.getLocText("FR-Designer-Plugin_Update_Successful"));
} }
}); });
} catch (PluginVerifyException e) {
JOptionPane.showMessageDialog(null, e.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} catch (Exception e) { } catch (Exception e) {

3
designer_base/src/com/fr/design/extra/exe/ModifyStatusExecutor.java

@ -2,6 +2,7 @@ package com.fr.design.extra.exe;
import com.fr.base.FRContext; import com.fr.base.FRContext;
import com.fr.design.extra.PluginWebBridge; import com.fr.design.extra.PluginWebBridge;
import com.fr.design.extra.Process;
import com.fr.general.Inter; import com.fr.general.Inter;
import com.fr.plugin.Plugin; import com.fr.plugin.Plugin;
import com.fr.plugin.PluginLoader; import com.fr.plugin.PluginLoader;
@ -34,7 +35,7 @@ public class ModifyStatusExecutor implements Executor {
return StringUtils.EMPTY; return StringUtils.EMPTY;
} }
@Override @Override
public void run() { public void run(Process<String> process) {
plugin = PluginLoader.getLoader().getPluginById(pluginID); plugin = PluginLoader.getLoader().getPluginById(pluginID);
active = !plugin.isActive(); active = !plugin.isActive();
plugin.setActive(active); plugin.setActive(active);

3
designer_base/src/com/fr/design/extra/exe/UninstallExecutor.java

@ -3,6 +3,7 @@ package com.fr.design.extra.exe;
import com.fr.base.FRContext; import com.fr.base.FRContext;
import com.fr.design.RestartHelper; import com.fr.design.RestartHelper;
import com.fr.design.extra.PluginHelper; import com.fr.design.extra.PluginHelper;
import com.fr.design.extra.Process;
import com.fr.general.Inter; import com.fr.general.Inter;
import com.fr.plugin.Plugin; import com.fr.plugin.Plugin;
import com.fr.plugin.PluginLoader; import com.fr.plugin.PluginLoader;
@ -35,7 +36,7 @@ public class UninstallExecutor implements Executor {
} }
@Override @Override
public void run() { public void run(Process<String> process) {
int rv = JOptionPane.showOptionDialog( int rv = JOptionPane.showOptionDialog(
null, null,
Inter.getLocText("FR-Designer-Plugin_Will_Be_Delete"), Inter.getLocText("FR-Designer-Plugin_Will_Be_Delete"),

3
designer_base/src/com/fr/design/extra/exe/UpdateFromDiskExecutor.java

@ -1,6 +1,7 @@
package com.fr.design.extra.exe; package com.fr.design.extra.exe;
import com.fr.design.extra.PluginWebBridge; import com.fr.design.extra.PluginWebBridge;
import com.fr.design.extra.Process;
import java.io.File; import java.io.File;
@ -30,7 +31,7 @@ public class UpdateFromDiskExecutor implements Executor {
} }
@Override @Override
public void run() { public void run(Process<String> process) {
PluginWebBridge.getHelper().updateFileFromDisk(new File(filePath)); PluginWebBridge.getHelper().updateFileFromDisk(new File(filePath));
} }
} }

95
designer_base/src/com/fr/design/extra/exe/UpdateOnlineExecutor.java

@ -1,23 +1,106 @@
package com.fr.design.extra.exe; package com.fr.design.extra.exe;
import com.fr.base.FRContext;
import com.fr.design.DesignerEnvManager;
import com.fr.design.RestartHelper;
import com.fr.design.extra.After;
import com.fr.design.extra.PluginHelper;
import com.fr.design.extra.Process;
import com.fr.general.Inter;
import com.fr.plugin.Plugin;
import com.fr.plugin.PluginLoader;
import javax.swing.*;
import java.io.File;
/** /**
* Created by richie on 16/3/19. * Created by richie on 16/3/19.
*/ */
public class UpdateOnlineExecutor implements Executor { public class UpdateOnlineExecutor implements Executor {
private String pluginID; private String[] pluginIDs;
private static final int PERCENT_100 = 100;
public UpdateOnlineExecutor(String pluginID) {
this.pluginID = pluginID;
public UpdateOnlineExecutor(String[] pluginIDs) {
this.pluginIDs = pluginIDs;
} }
@Override @Override
public String getTaskFinishMessage() { public String getTaskFinishMessage() {
return "插件已更新完毕:" + pluginID; return "task succeed";
} }
@Override @Override
public Command[] getCommands() { public Command[] getCommands() {
return new Command[0]; return new Command[]{
new Command() {
@Override
public String getExecuteMessage() {
return null;
}
@Override
public void run(Process<String> process) {
for (int i = 0; i < pluginIDs.length; i++) {
Plugin plugin = PluginLoader.getLoader().getPluginById(pluginIDs[i]);
String id = null;
if (plugin != null) {
id = plugin.getId();
}
String username = DesignerEnvManager.getEnvManager().getBBSName();
String password = DesignerEnvManager.getEnvManager().getBBSPassword();
try {
PluginHelper.downloadPluginFile(id, username, password, new Process<Double>() {
@Override
public void process(Double integer) {
}
});
updateFileFromDisk(PluginHelper.getDownloadTempFile());
process.process(PERCENT_100 / pluginIDs.length * (i + 1) + "%");
} catch (Exception e) {
FRContext.getLogger().error(e.getMessage(), e);
}
}
int rv = JOptionPane.showOptionDialog(
null,
Inter.getLocText("FR-Designer-Plugin_Update_Successful"),
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();
}
}
}
};
}
private void updateFileFromDisk(File fileOnDisk){
try {
Plugin plugin = PluginHelper.readPlugin(fileOnDisk);
if (plugin == null) {
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Illegal_Plugin_Zip"), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
return;
}
Plugin oldPlugin = PluginLoader.getLoader().getPluginById(plugin.getId());
if (oldPlugin != null) {
String[] files = PluginHelper.uninstallPlugin(FRContext.getCurrentEnv(), oldPlugin);
PluginHelper.installPluginFromUnzippedTempDir(FRContext.getCurrentEnv(), plugin, new After() {
@Override
public void done() {
}
});
} else {
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Cannot_Update_Not_Install"), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
}
} catch (Exception e1) {
JOptionPane.showMessageDialog(null, e1.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
}
} }
} }

Loading…
Cancel
Save