From 72232e4cc7d5a4a840728a7f91b75add829163b9 Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Tue, 14 Apr 2020 18:29:01 +0300 Subject: [PATCH] =?UTF-8?q?[FIX]=20=D0=9F=D0=B5=D1=80=D0=B5=D0=BD=D0=BE?= =?UTF-8?q?=D1=81=20=D0=BF=D0=B0=D0=BF=D0=BE=D0=BA=20=D0=B2=20IOHelper.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pro/gravit/launcher/client/DirBridge.java | 6 ++- .../pro/gravit/utils/helper/IOHelper.java | 37 +++++++++++++++++-- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/DirBridge.java b/Launcher/src/main/java/pro/gravit/launcher/client/DirBridge.java index b5b9bcb0..dc6fb4b5 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/DirBridge.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/DirBridge.java @@ -52,9 +52,9 @@ public static void move(Path newDir) throws IOException { LogHelper.dev(LogHelper.toString(new Throwable("Check stack of call DirBridge with null path..."))); return; } + dirUpdates = newDir; LogHelper.dev(newDir.toString()); IOHelper.move(dirUpdates, newDir); - dirUpdates = newDir; } public static Path getAppDataDir() throws IOException { @@ -74,6 +74,10 @@ public static Path getAppDataDir() throws IOException { return local; } } else if (JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE) { + if (System.getenv().containsKey("appdata")) + return Paths.get(System.getenv().get("appdata")).toAbsolutePath(); + if (System.getenv().containsKey("APPDATA")) // Because it is windows + return Paths.get(System.getenv().get("APPDATA")).toAbsolutePath(); Path appdata = IOHelper.HOME_DIR.resolve("AppData").resolve("Roaming"); if (!IOHelper.isDir(appdata)) Files.createDirectories(appdata); return appdata; diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/IOHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/IOHelper.java index d788da16..1e8aeb5d 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/IOHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/IOHelper.java @@ -41,9 +41,7 @@ public final class IOHelper { public static final String PLATFORM_SEPARATOR = FS.getSeparator(); public static final boolean POSIX = FS.supportedFileAttributeViews().contains("posix") || FS.supportedFileAttributeViews().contains("Posix"); public static final Path JVM_DIR = Paths.get(System.getProperty("java.home")); - // Увидел исключение на NetBSD beta добавил public static final Path HOME_DIR = Paths.get(System.getProperty("user.home")); - // Paths public static final Path WORKING_DIR = Paths.get(System.getProperty("user.dir")); public static final String USER_AGENT = System.getProperty("launcher.userAgentDefault", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"); // Open options - as arrays @@ -188,8 +186,39 @@ public static boolean isValidTextureBounds(int width, int height, boolean cloak) } public static void move(Path source, Path target) throws IOException { - createParentDirs(target); - Files.move(source, target, COPY_OPTIONS); + IOHelper.walk(source, new MoveFileVisitor(source, target), true); + } + + private static class MoveFileVisitor implements FileVisitor { + private final Path from, to; + + private MoveFileVisitor(Path from, Path to) { + this.from = from; + this.to = to; + } + + @Override + public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { + if (!IOHelper.isDir(dir)) Files.createDirectories(dir); + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + IOHelper.move(file, to.resolve(from.relativize(file))); + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException { + throw exc; + } + + @Override + public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { + Files.delete(dir); + return FileVisitResult.CONTINUE; + } } public static byte[] newBuffer() {