Browse Source

REPORT-22779 更新后无法重启

feature/big-screen
Bryant 5 years ago
parent
commit
1bca44b7c7
  1. 60
      designer-base/src/main/java/com/fr/design/RestartHelper.java
  2. 11
      designer-base/src/main/java/com/fr/design/os/impl/RestartAction.java
  3. 8
      designer-base/src/main/java/com/fr/design/update/ui/dialog/UpdateMainDialog.java
  4. 2
      designer-realize/src/main/java/com/fr/start/module/DesignerActivator.java

60
designer-base/src/main/java/com/fr/design/RestartHelper.java

@ -8,11 +8,10 @@ import com.fr.log.FineLoggerFactory;
import com.fr.stable.ArrayUtils;
import com.fr.stable.StableUtils;
import com.fr.stable.StringUtils;
import com.fr.stable.os.OperatingSystem;
import com.fr.stable.os.support.OSBasedAction;
import com.fr.stable.os.support.OSSupportCenter;
import com.fr.workspace.WorkContext;
import javax.swing.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
@ -20,8 +19,6 @@ import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
@ -34,7 +31,7 @@ public class RestartHelper {
public static final String RECORD_FILE = StableUtils.pathJoin(StableUtils.getInstallHome(), "delete.properties");
public static final String MOVE_FILE = StableUtils.pathJoin(StableUtils.getInstallHome(), "move.properties");
private static OSBasedAction restartAction;
private static final OSBasedAction restartAction = new RestartAction();
/**
* 把要删除的文件都记录到delete.properties中
@ -147,58 +144,19 @@ public class RestartHelper {
restart(ArrayUtils.EMPTY_STRING_ARRAY);
}
public static void restartForUpdate(String installHome) {
public static void restartForUpdate(JFrame frame) {
try {
if (OperatingSystem.isMacos()) {
restartInMacOS(installHome, ArrayUtils.EMPTY_STRING_ARRAY);
} else if (OperatingSystem.isLinux()){
restartInLinux(installHome, ArrayUtils.EMPTY_STRING_ARRAY);
} else {
restartInWindows(installHome,ArrayUtils.EMPTY_STRING_ARRAY);
}
restartAction.execute(ArrayUtils.EMPTY_STRING_ARRAY);
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage());
} finally {
WorkContext.getCurrent().close();
frame.dispose();
System.exit(0);
}
}
private static void restartInMacOS(String installHome, String[] filesToBeDelete) throws Exception {
ProcessBuilder builder = new ProcessBuilder();
List<String> commands = new ArrayList<>();
commands.add("open");
commands.add(installHome + File.separator + "bin" + File.separator + "restart.app");
if (ArrayUtils.isNotEmpty(filesToBeDelete)) {
commands.add("--args");
commands.add(StableUtils.join(filesToBeDelete, "+"));
}
builder.command(commands);
builder.start();
}
private static void restartInWindows(String installHome, String[] filesToBeDelete) throws Exception {
ProcessBuilder builder = new ProcessBuilder();
List<String> commands = new ArrayList<>();
commands.add(installHome + File.separator + "bin" + File.separator + "restart.exe");
if (ArrayUtils.isNotEmpty(filesToBeDelete)) {
commands.add(StableUtils.join(filesToBeDelete, "+"));
}
builder.command(commands);
builder.start();
}
private static void restartInLinux(String installHome, String[] filesToBeDelete) throws Exception {
ProcessBuilder builder = new ProcessBuilder();
List<String> commands = new ArrayList<>();
//现在先写的是restart.sh
commands.add(installHome + File.separator + "bin" + File.separator + "restart.sh");
if (ArrayUtils.isNotEmpty(filesToBeDelete)) {
commands.add(StableUtils.join(filesToBeDelete, "+"));
}
builder.command(commands);
builder.start();
}
/**
* 重启设计器并删除某些特定的文件
@ -239,12 +197,4 @@ public class RestartHelper {
DesignerContext.getDesignerFrame().exit();
}
}
/**
* 提前初始化重启动作
*/
public static void initRestartAction(){
restartAction = OSSupportCenter.getAction(RestartAction.class);
}
}

11
designer-base/src/main/java/com/fr/design/os/impl/RestartAction.java

@ -10,10 +10,19 @@ import java.util.ArrayList;
import java.util.List;
public class RestartAction implements OSBasedAction {
private static String installHome;
public RestartAction() {
installHome = StableUtils.getInstallHome();
}
@Override
public void execute(Object... objects) {
String[] filesToBeDelete = (String[])objects;
String installHome = StableUtils.getInstallHome();
if (installHome == null) {
installHome = StableUtils.getInstallHome();
}
try{
if (OperatingSystem.isMacos()) {
restartInMacOS(installHome, filesToBeDelete);

8
designer-base/src/main/java/com/fr/design/update/ui/dialog/UpdateMainDialog.java

@ -30,7 +30,6 @@ import com.fr.json.JSONArray;
import com.fr.json.JSONObject;
import com.fr.log.FineLoggerFactory;
import com.fr.stable.*;
import com.fr.stable.project.ProjectConstants;
import com.fr.third.org.apache.http.client.methods.CloseableHttpResponse;
import com.fr.third.org.apache.http.client.methods.HttpGet;
import com.fr.third.org.apache.http.impl.client.CloseableHttpClient;
@ -594,20 +593,21 @@ public class UpdateMainDialog extends UIDialog {
updateButton.setEnabled(false);
updateLabel.setVisible(false);
RestoreResultDialog.deletePreviousPropertyFile();
final String installHome = StableUtils.getInstallHome();
final JFrame frame = DesignerContext.getDesignerFrame();
final RestartHelper helper = new RestartHelper();
new FileProcess(callBack) {
@Override
public void onDownloadSuccess() {
progressBar.setVisible(false);
deleteForDesignerUpdate();
RestartHelper.restartForUpdate(installHome);
helper.restartForUpdate(frame);
}
@Override
public void onDownloadFailed() {
progressBar.setVisible(false);
deleteForDesignerUpdate();
JOptionPane.showMessageDialog(getParent(), Toolkit.i18nText("Fine-Design_Update_Info_Failed_Message"));
RestartHelper.restartForUpdate(installHome);
helper.restartForUpdate(frame);
}
}.execute();
}

2
designer-realize/src/main/java/com/fr/start/module/DesignerActivator.java

@ -11,7 +11,6 @@ import com.fr.config.MarketConfig;
import com.fr.decision.update.backup.RecoverManager;
import com.fr.design.DesignerEnvManager;
import com.fr.design.ExtraDesignClassManager;
import com.fr.design.RestartHelper;
import com.fr.design.actions.NewFormAction;
import com.fr.design.actions.core.ActionFactory;
import com.fr.design.actions.insert.cell.BiasCellAction;
@ -140,7 +139,6 @@ public class DesignerActivator extends Activator {
storePassport();
AlphaFineHelper.switchConfig4Locale();
RecoverManager.register(new RecoverForDesigner());
RestartHelper.initRestartAction();
}
@Override

Loading…
Cancel
Save