|
|
|
@ -447,36 +447,35 @@ public abstract class JTemplate<T extends BaseBook, U extends BaseUndoState<?>>
|
|
|
|
|
* @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]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|