fix(gui): add file end line feed for exported code (PR #2836)

chore: add file end line feed for export code
This commit is contained in:
ewt45
2026-03-30 03:07:04 +08:00
committed by GitHub
parent cdd5bf536d
commit 57fd9b5bdb
2 changed files with 4 additions and 15 deletions
@@ -1,8 +1,5 @@
package jadx.gui.ui.popupmenu;
import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collections;
import java.util.List;
@@ -16,6 +13,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import jadx.api.DecompilationMode;
import jadx.core.dex.visitors.SaveCode;
import jadx.gui.treemodel.JClass;
import jadx.gui.treemodel.JNode;
import jadx.gui.ui.MainWindow;
@@ -85,11 +83,7 @@ public class JClassPopupMenu extends JPopupMenu {
}
public static void saveJClass(JClass jClass, Path savePath, JClassExportType exportType) {
try (Writer writer = Files.newBufferedWriter(savePath, StandardCharsets.UTF_8)) {
writer.write(getCode(jClass, exportType));
} catch (Exception e) {
throw new RuntimeException("Error saving project", e);
}
SaveCode.save(getCode(jClass, exportType), savePath.toFile());
}
private static String getCode(JClass jClass, JClassExportType exportType) {
@@ -1,8 +1,6 @@
package jadx.gui.ui.popupmenu;
import java.io.IOException;
import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collections;
@@ -16,6 +14,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import jadx.api.plugins.utils.CommonFileUtils;
import jadx.core.dex.visitors.SaveCode;
import jadx.gui.treemodel.JResource;
import jadx.gui.ui.MainWindow;
import jadx.gui.ui.filedialog.FileDialogWrapper;
@@ -147,11 +146,7 @@ public class JResourcePopupMenu extends JPopupMenu {
}
private static void exportString(JResource resource, Path savePath) {
try (Writer writer = Files.newBufferedWriter(savePath, StandardCharsets.UTF_8)) {
writer.write(resource.getCodeInfo().getCodeStr());
} catch (Exception e) {
throw new RuntimeException("Error saving file " + resource.getName(), e);
}
SaveCode.save(resource.getCodeInfo().getCodeStr(), savePath.toFile());
}
}