From 7f84ec2d299fc6e9799e77420218485e32a6c19c Mon Sep 17 00:00:00 2001 From: Bryant Date: Wed, 9 Oct 2019 14:26:37 +0800 Subject: [PATCH] =?UTF-8?q?KERNEL-418=20=E6=9B=B4=E6=96=B0=E5=8D=87?= =?UTF-8?q?=E7=BA=A7=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../update/ui/dialog/RestoreResultDialog.java | 38 ++++--- .../update/ui/dialog/UpdateMainDialog.java | 106 ++++-------------- 2 files changed, 45 insertions(+), 99 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/update/ui/dialog/RestoreResultDialog.java b/designer-base/src/main/java/com/fr/design/update/ui/dialog/RestoreResultDialog.java index 76e256af5..83ffbe5fe 100644 --- a/designer-base/src/main/java/com/fr/design/update/ui/dialog/RestoreResultDialog.java +++ b/designer-base/src/main/java/com/fr/design/update/ui/dialog/RestoreResultDialog.java @@ -7,10 +7,10 @@ import com.fr.design.gui.ilable.UILabel; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.utils.gui.GUICoreUtils; import com.fr.general.ComparatorUtils; -import com.fr.stable.ProductConstants; import com.fr.stable.StableUtils; import com.fr.stable.StringUtils; import com.fr.stable.project.ProjectConstants; +import com.fr.workspace.WorkContext; import javax.swing.AbstractAction; import javax.swing.BorderFactory; @@ -45,7 +45,7 @@ public class RestoreResultDialog extends JDialog { initCommonComponents(); } - public RestoreResultDialog(Frame parent, boolean modal, String jarDir) { + RestoreResultDialog(Frame parent, boolean modal, String jarDir) { super(parent, modal); this.jarRestoreDir = jarDir; if (ComparatorUtils.equals(jarDir, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Updater_Restore_Old_Version"))) { @@ -100,7 +100,7 @@ public class RestoreResultDialog extends JDialog { this.setTitle(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Updater_Jar_Restore")); } - public static boolean deletePreviousPropertyFile() { + static boolean deletePreviousPropertyFile() { File moveFile = new File(RestartHelper.MOVE_FILE); File delFile = new File(RestartHelper.RECORD_FILE); if (StableUtils.mkdirs(moveFile) && StableUtils.mkdirs(delFile)) { @@ -159,7 +159,7 @@ public class RestoreResultDialog extends JDialog { private void putJarBackupFiles() { Map map = new HashMap<>(); - java.util.List list = new ArrayList<>(); + List list = new ArrayList<>(); String installHome = StableUtils.getInstallHome(); putJarBackupFilesToInstallLib(installHome, map, list); @@ -168,23 +168,29 @@ public class RestoreResultDialog extends JDialog { RestartHelper.saveFilesWhichToDelete(list.toArray(new String[list.size()])); } - private void putJarBackupFilesToInstallLib(String installHome, Map map, java.util.List list) { - List files = UpdateConstants.JARS_FOR_DESIGNER_X; + private void putJarBackupFilesToInstallLib(String installHome, Map map, List list) { String backupDir = UpdateConstants.DESIGNER_BACKUP_DIR; - for (String file : files) { - map.put(StableUtils.pathJoin(installHome, backupDir, jarRestoreDir, file), - StableUtils.pathJoin(installHome, ProjectConstants.LIB_NAME, file)); - list.add(StableUtils.pathJoin(installHome, ProjectConstants.LIB_NAME, file)); + File installLib = new File(StableUtils.pathJoin(installHome, backupDir, jarRestoreDir, UpdateConstants.DESIGNERBACKUPPATH)); + File[] files = installLib.listFiles(); + if (files != null) { + for (File file : files) { + map.put(file.getAbsolutePath(), + StableUtils.pathJoin(installHome, ProjectConstants.LIB_NAME, file.getName())); + list.add(StableUtils.pathJoin(installHome, ProjectConstants.LIB_NAME, file.getName())); + } } } - private void putJarBackupFilesToInstallEnv(String installHome, Map map, java.util.List list) { - List files = UpdateConstants.JARS_FOR_SERVER_X; + private void putJarBackupFilesToInstallEnv(String installHome, Map map, List list) { String backupDir = UpdateConstants.DESIGNER_BACKUP_DIR; - for (String file : files) { - map.put(StableUtils.pathJoin(installHome, backupDir, jarRestoreDir, file), - StableUtils.pathJoin(installHome, UpdateConstants.APPS_FOLDER_NAME, ProductConstants.getAppFolderName(), ProjectConstants.WEBINF_NAME, ProjectConstants.LIB_NAME, file)); - list.add(StableUtils.pathJoin(installHome, UpdateConstants.APPS_FOLDER_NAME, ProductConstants.getAppFolderName(), ProjectConstants.WEBINF_NAME, ProjectConstants.LIB_NAME, file)); + File installEnv = new File(StableUtils.pathJoin(installHome, backupDir, jarRestoreDir, UpdateConstants.BACKUPPATH)); + File[] files = installEnv.listFiles(); + if (files != null) { + for (File file : files) { + map.put(file.getAbsolutePath(), + StableUtils.pathJoin(WorkContext.getCurrent().getPath(), ProjectConstants.LIB_NAME, file.getName())); + list.add(StableUtils.pathJoin(WorkContext.getCurrent().getPath(), ProjectConstants.LIB_NAME, file.getName())); + } } } } \ No newline at end of file diff --git a/designer-base/src/main/java/com/fr/design/update/ui/dialog/UpdateMainDialog.java b/designer-base/src/main/java/com/fr/design/update/ui/dialog/UpdateMainDialog.java index 6b9dc22e3..50329a46f 100644 --- a/designer-base/src/main/java/com/fr/design/update/ui/dialog/UpdateMainDialog.java +++ b/designer-base/src/main/java/com/fr/design/update/ui/dialog/UpdateMainDialog.java @@ -1,7 +1,6 @@ package com.fr.design.update.ui.dialog; import com.fr.decision.update.data.UpdateConstants; -import com.fr.decision.update.exception.UpdateException; import com.fr.decision.update.info.UpdateCallBack; import com.fr.decision.update.info.UpdateProgressCallBack; import com.fr.design.RestartHelper; @@ -31,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; @@ -586,40 +584,29 @@ public class UpdateMainDialog extends UIDialog { updateButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - if (backup()) { - int a = JOptionPane.showConfirmDialog(getParent(), Toolkit.i18nText("Fine-Design_Update_Info_Information"),Toolkit.i18nText("Fine-Design_Update_Info_Title"), JOptionPane.OK_CANCEL_OPTION); - if (a == 0) { - progressBar.setVisible(true); - progressBar.setString(Toolkit.i18nText("Fine-Design_Update_Info_Wait_Message")); - UpdateCallBack callBack = new UpdateProgressCallBack(progressBar); - updateButton.setEnabled(false); - updateLabel.setVisible(false); - new FileProcess(callBack) { - @Override - public void onDownloadSuccess() { - progressBar.setVisible(false); - deleteForDesignerUpdate(); - RestartHelper.restart(); - } - @Override - public void onDownloadFailed() { - progressBar.setVisible(false); - try { - IOUtils.copyFilesInDirByPath(StableUtils.pathJoin(StableUtils.getInstallHome(),UpdateConstants.DESIGNERBACKUPPATH), - StableUtils.pathJoin(StableUtils.getInstallHome(),ProjectConstants.LIB_NAME)); - } catch (IOException e) { - UpdateException exception = new UpdateException(e.getMessage()); - FineLoggerFactory.getLogger().error(exception.getMessage() + "recover for design failed"); - } finally { - deleteForDesignerUpdate(); - } - JOptionPane.showMessageDialog(getParent(), Toolkit.i18nText("Fine-Design_Update_Info_Failed_Message")); - RestartHelper.restart(); - } - }.execute(); - } - } else { - JOptionPane.showMessageDialog(getParent(),Toolkit.i18nText("Fine-Design_Update_Info_Backup_Message")); + jarCurrentLabel.setText(downloadFileConfig.optString("buildNO")); + int a = JOptionPane.showConfirmDialog(getParent(), Toolkit.i18nText("Fine-Design_Update_Info_Information"),Toolkit.i18nText("Fine-Design_Update_Info_Title"), JOptionPane.OK_CANCEL_OPTION); + if (a == 0) { + progressBar.setVisible(true); + progressBar.setString(Toolkit.i18nText("Fine-Design_Update_Info_Wait_Message")); + UpdateCallBack callBack = new UpdateProgressCallBack(progressBar); + updateButton.setEnabled(false); + updateLabel.setVisible(false); + new FileProcess(callBack) { + @Override + public void onDownloadSuccess() { + progressBar.setVisible(false); + deleteForDesignerUpdate(); + RestartHelper.restart(); + } + @Override + public void onDownloadFailed() { + progressBar.setVisible(false); + deleteForDesignerUpdate(); + JOptionPane.showMessageDialog(getParent(), Toolkit.i18nText("Fine-Design_Update_Info_Failed_Message")); + RestartHelper.restart(); + } + }.execute(); } } }); @@ -632,53 +619,6 @@ public class UpdateMainDialog extends UIDialog { CommonUtils.deleteFile(downloadForDesigner); } - /** - * Jar还原按钮兼容 - */ - private boolean backup() { - String installHome = StableUtils.getInstallHome(); - //jar包备份文件的目录为"backup/"+jar包当前版本号 - String todayBackupDir = StableUtils.pathJoin(installHome, getBackupDirectory(), (GeneralUtils.readBuildNO())); - backupFilesFromInstallEnv(installHome, todayBackupDir); - backupFilesFromInstallLib(installHome, todayBackupDir); - jarCurrentLabel.setText(downloadFileConfig.optString("buildNO")); - try { - File file = new File(StableUtils.pathJoin(installHome, UpdateConstants.DOWNLOADPATH)); - CommonUtils.mkdirs(file); - IOUtils.copyFilesInDirByPath(StableUtils.pathJoin(installHome,ProjectConstants.LIB_NAME), - StableUtils.pathJoin(installHome, UpdateConstants.DESIGNERBACKUPPATH)); - return true; - }catch (IOException e) { - UpdateException exception = new UpdateException("Backup Exception for designer" + e.getMessage()); - FineLoggerFactory.getLogger().error(exception.getMessage(),exception); - return false; - } - } - - private void backupFilesFromInstallEnv(String installHome, String todayBackupDir) { - for (String file : UpdateConstants.JARS_FOR_SERVER_X) { - try { - IOUtils.copy( - new File(StableUtils.pathJoin(installHome, UpdateConstants.APPS_FOLDER_NAME, ProductConstants.getAppFolderName(), ProjectConstants.WEBINF_NAME, ProjectConstants.LIB_NAME, file)), - new File(StableUtils.pathJoin(todayBackupDir))); - } catch (IOException e) { - FineLoggerFactory.getLogger().error(e.getMessage()); - } - } - } - - private void backupFilesFromInstallLib(String installHome, String todayBackupDir) { - for (String file : UpdateConstants.JARS_FOR_DESIGNER_X) { - try { - IOUtils.copy( - new File(StableUtils.pathJoin(installHome, ProjectConstants.LIB_NAME, file)), - new File(StableUtils.pathJoin(todayBackupDir))); - } catch (IOException e) { - FineLoggerFactory.getLogger().error(e.getMessage()); - } - } - } - //获取备份目录 private String getBackupDirectory() { return UpdateConstants.DESIGNER_BACKUP_DIR;