|
|
|
@ -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); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |