diff --git a/Launcher/src/main/java/ru/gravit/launcher/client/LauncherUpdateController.java b/Launcher/src/main/java/ru/gravit/launcher/client/LauncherUpdateController.java index 94b83434..b6cf06b6 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/LauncherUpdateController.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/LauncherUpdateController.java @@ -40,7 +40,7 @@ public void postDiff(UpdateRequest request, UpdateRequestEvent e, HashedDir.Diff AtomicReference lastEn = null; ArrayList removed = new ArrayList<>(); diff.mismatch.walk(File.separator, (path, name, entry) -> { - if(entry.getType() == HashedEntry.Type.DIR) return false; + if(entry.getType() == HashedEntry.Type.DIR) return HashedDir.WalkAction.CONTINUE; HashedFile file = (HashedFile) entry; //Первый экспериментальный способ - честно обходим все возможные Store Path ret = null; @@ -82,7 +82,7 @@ public void postDiff(UpdateRequest request, UpdateRequestEvent e, HashedDir.Diff removed.add(path.concat(File.separator).concat(name)); } } - return false; + return HashedDir.WalkAction.CONTINUE; }); for(String rem : removed) { @@ -94,7 +94,7 @@ public Path tryFind(NewLauncherSettings.HashedStoreEntry en, HashedFile file) th { AtomicReference ret = null; en.hdir.walk(File.separator, (path, name, entry) -> { - if(entry.getType() == HashedEntry.Type.DIR) return false; + if(entry.getType() == HashedEntry.Type.DIR) return HashedDir.WalkAction.CONTINUE; HashedFile tfile = (HashedFile) entry; if(tfile.isSame(file)) { @@ -105,14 +105,14 @@ public Path tryFind(NewLauncherSettings.HashedStoreEntry en, HashedFile file) th { LogHelper.debug("[DIR:%s] Confirmed file %s in %s", en.name, name, path); ret.set(tdir); - return true; + return HashedDir.WalkAction.STOP; } } catch (IOException e) { LogHelper.error("Check file error %s", e.getMessage()); } } - return false; + return HashedDir.WalkAction.CONTINUE; }); return ret.get(); } diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/UpdateRequest.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/UpdateRequest.java index 40ee57e2..308c2fe2 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/UpdateRequest.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/UpdateRequest.java @@ -204,7 +204,7 @@ public UpdateRequestEvent requestDo(StandartClientWebSocketService service) thro LogHelper.error(ex); } } - return false; + return HashedDir.WalkAction.CONTINUE; }); totalSize = diff.mismatch.size(); startTime = Instant.now(); diff --git a/libLauncher/src/main/java/ru/gravit/launcher/hasher/HashedDir.java b/libLauncher/src/main/java/ru/gravit/launcher/hasher/HashedDir.java index 53ed49ab..bb1327be 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/hasher/HashedDir.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/hasher/HashedDir.java @@ -342,28 +342,40 @@ public void walk(CharSequence separator, WalkCallback callback) throws IOExcepti String append = ""; walk(append, separator, callback, true); } + public enum WalkAction + { + STOP, CONTINUE + } @FunctionalInterface public interface WalkCallback { - boolean walked(String path, String name, HashedEntry entry) throws IOException; + WalkAction walked(String path, String name, HashedEntry entry) throws IOException; } - private boolean walk(String append, CharSequence separator, WalkCallback callback, boolean noSeparator) throws IOException { + private WalkAction walk(String append, CharSequence separator, WalkCallback callback, boolean noSeparator) throws IOException { for (Map.Entry entry : map.entrySet()) { HashedEntry e = entry.getValue(); if (e.getType() == Type.FILE) { if (noSeparator) - if(callback.walked(append + entry.getKey(), entry.getKey(), e)) return true; + { + WalkAction a = callback.walked(append + entry.getKey(), entry.getKey(), e); + if(a == WalkAction.STOP) return a; + } else - if(callback.walked(append + separator + entry.getKey(), entry.getKey(), e)) return true; + { + WalkAction a = callback.walked(append + separator + entry.getKey(), entry.getKey(), e); + if(a == WalkAction.STOP) return a; + } } else { String newAppend; if (noSeparator) newAppend = append + entry.getKey(); else newAppend = append + separator + entry.getKey(); - if(callback.walked(newAppend, entry.getKey(), e)) return true; - if(((HashedDir) e).walk(newAppend, separator, callback, false)) return true; + WalkAction a = callback.walked(newAppend, entry.getKey(), e); + if(a == WalkAction.STOP) return a; + a = ((HashedDir) e).walk(newAppend, separator, callback, false); + if(a == WalkAction.STOP) return a; } } - return false; + return WalkAction.CONTINUE; } }