mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-23 00:51:01 +03:00
[FIX] Исправлена работа HashedDir.walk
This commit is contained in:
parent
1b80f4f7aa
commit
3af66f6280
3 changed files with 25 additions and 13 deletions
|
@ -40,7 +40,7 @@ public void postDiff(UpdateRequest request, UpdateRequestEvent e, HashedDir.Diff
|
|||
AtomicReference<NewLauncherSettings.HashedStoreEntry> lastEn = null;
|
||||
ArrayList<String> 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<Path> 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();
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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<String, HashedEntry> 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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue