fix: 修复导出配置乱码并格式化输出

This commit is contained in:
lkqm 2022-01-07 21:03:20 +08:00
parent be02d792b5
commit 7e65744ef2
2 changed files with 3 additions and 2 deletions

View File

@ -25,7 +25,7 @@ public class ClipboardExportImportSettingsServiceImpl implements ExportImportSet
*/ */
@Override @Override
public void exportConfig(SettingsStorageDTO settingsStorage) { public void exportConfig(SettingsStorageDTO settingsStorage) {
String json = JSON.toJson(settingsStorage); String json = JSON.toJsonByFormat(settingsStorage);
CopyPasteManager.getInstance().setContents(new TextTransferable(json)); CopyPasteManager.getInstance().setContents(new TextTransferable(json));
Messages.showInfoMessage("Config info success write to clipboard", GlobalDict.TITLE_INFO); Messages.showInfoMessage("Config info success write to clipboard", GlobalDict.TITLE_INFO);
} }

View File

@ -25,6 +25,7 @@ import org.jetbrains.annotations.NotNull;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets;
/** /**
* 本地文件导入导出设置服务实现 * 本地文件导入导出设置服务实现
@ -52,7 +53,7 @@ public class LocalFileExportImportSettingsServiceImpl implements ExportImportSet
FileUtil.createIfDoesntExist(file); FileUtil.createIfDoesntExist(file);
WriteCommandAction.runWriteCommandAction(ProjectUtils.getCurrProject(), () -> { WriteCommandAction.runWriteCommandAction(ProjectUtils.getCurrProject(), () -> {
try { try {
byte[] bytes = JSON.toJson(settingsStorage).getBytes(); byte[] bytes = JSON.toJsonByFormat(settingsStorage).getBytes(StandardCharsets.UTF_8);
VirtualFile virtualFile = VfsUtil.findFileByIoFile(file, true); VirtualFile virtualFile = VfsUtil.findFileByIoFile(file, true);
if (virtualFile != null) { if (virtualFile != null) {
virtualFile.setBinaryContent(bytes); virtualFile.setBinaryContent(bytes);