forked from fanruan/design
vito
9 years ago
8 changed files with 128 additions and 24 deletions
@ -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…
Reference in new issue