From 1741b2705b1b896172eb18eb6ed216a5810ad710 Mon Sep 17 00:00:00 2001 From: Yvan Date: Fri, 27 May 2022 10:24:42 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-70481=20=E8=BF=9C=E7=A8=8B=E8=AE=BE?= =?UTF-8?q?=E8=AE=A1=E5=88=87=E6=8D=A2=E6=A0=A1=E9=AA=8C=E6=9C=BA=E5=88=B6?= =?UTF-8?q?=E4=BC=98=E5=8C=96=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=EF=BC=8C=E9=81=BF=E5=85=8D=E7=9B=B4=E6=8E=A5=E4=BF=AE=E6=94=B9?= =?UTF-8?q?templateToStashFile=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../design/file/HistoryTemplateListCache.java | 2 +- .../com/fr/design/mainframe/JTemplate.java | 31 +++++++++---------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java b/designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java index 37c8043cf8..cb38ea8bd9 100644 --- a/designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java +++ b/designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java @@ -431,7 +431,7 @@ public class HistoryTemplateListCache implements CallbackEvent { FILE file = template.getEditingFILE(); boolean needReload = context == null || needReloadTemplate(context, template); if (needReload) { - FILE stashFile = template.templateToStashFile4Other(); + FILE stashFile = template.templateToStashFile(); if (stashFile != null) { FineLoggerFactory.getLogger().info("{} is being reloaded", file.getName()); template.refreshResource(stashFile); diff --git a/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java b/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java index d11b8bf1d5..b8e5468dbc 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java @@ -447,36 +447,35 @@ public abstract class JTemplate> * @return */ public FILE templateToStashFile4Envchange() { - return templateToStashFile(true); + FILE file = this.getEditingFILE(); + if (file.isEnvFile() && !isSaved()) { + // 切换工作目录时,存在未保存的环境文件时,将其转化为与环境无关的内存文件,再创建暂存文件 + return new StashedFILE(new MemFILE(file.getName()), exportBaseBook2ByteArray(), template.suffix()); + } else { + // 其它情况下,直接创建暂存文件 + return templateToStashFile(); + } } - /** - * 用于 其它情况 的模板资源暂存 - * 例如 插件插件安装/启用 - * @return - */ - public FILE templateToStashFile4Other() { - return templateToStashFile(false); + public FILE templateToStashFile() { + FILE file = this.getEditingFILE(); + return new StashedFILE(file, exportBaseBook2ByteArray(), template.suffix()); } - private FILE templateToStashFile(boolean envChange) { - FILE file = this.getEditingFILE(); + private byte[] exportBaseBook2ByteArray() { try { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); BaseBook target = this.getTarget(); if (target != null) { target.export(outputStream); - return envChange && file.isEnvFile() && !isSaved()? - // 切换工作目录时,未保存的环境文件转化为与环境无关的内存文件,再创建暂存文件 - new StashedFILE(new MemFILE(file.getName()), outputStream.toByteArray(), template.suffix()) : - // 其它情况下,直接创建暂存文件 - new StashedFILE(file, outputStream.toByteArray(), template.suffix()); + return outputStream.toByteArray(); } // 如果 target == null 那么这个模板是被模板内存优化功能处理过的,不用处理 } catch (Exception e) { + FineLoggerFactory.getLogger().error("Export BaseBook to Byte Array Failed"); FineLoggerFactory.getLogger().error(e.getMessage(), e); } - return null; + return new byte[0]; }