package com.xiaoboluo.d2r; import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.util.List; /** 只在临时目录里造假存档,不碰玩家目录。 | Builds fake saves in a temporary directory only; never touches a player's directory. */ public final class SaveTransferTest { private static int checks; private static final String VAULT = "ModernSharedStashSoftCoreV2.swvault"; private static void check(boolean value, String label) { ++checks; if (!value) throw new AssertionError(label); } private static void write(File f, String text) throws IOException { f.getParentFile().mkdirs(); Files.write(f.toPath(), text.getBytes(StandardCharsets.UTF_8)); } private static String read(File f) throws IOException { return new String(Files.readAllBytes(f.toPath()), StandardCharsets.UTF_8); } private static void character(File dir, String name, String body) throws IOException { write(new File(dir, name + "/" + name + ".d2s"), body); write(new File(dir, name + "/" + name + ".key"), "key " + name); } private static void stash(File dir, String body) throws IOException { write(new File(dir, "ModernSharedStashSoftCoreV2/ModernSharedStashSoftCoreV2.d2i"), body); } private static File fresh(File base, String name) { File d = new File(base, name); new File(d, "D2R Mobile").mkdirs(); new File(d, "files").mkdirs(); return d; } private static void copyDir(File from, File to) throws IOException { if (!from.isDirectory()) { to.getParentFile().mkdirs(); Files.copy(from.toPath(), to.toPath()); return; } to.mkdirs(); for (File c : from.listFiles()) copyDir(c, new File(to, c.getName())); } public static void main(String[] args) throws IOException { File base = Files.createTempDirectory("dm-save-transfer").toFile(); // 没有记号:什么都不做 | No marker: nothing happens { File d = fresh(base, "none"), game = new File(d, "D2R Mobile"), save = new File(d, "files/save"); character(save, "yyc", "v1"); check(SaveTransfer.run(game, save, "20261101-120000").isEmpty(), "no markers, no results"); check(!new File(game, "save-export").exists() && read(new File(save, "yyc/yyc.d2s")).equals("v1"), "nothing written"); } // 导出:整份拷到 save-export/<时间>/,记号删掉,原存档不动;同一时刻再导出一次换名 -2 // Export: a full copy to save-export/