mirror of
https://github.com/GravitLauncher/Launcher
synced 2025-01-05 15:28:18 +03:00
Compare commits
No commits in common. "fb2883d21562ecc12e064443db44062484b24eb5" and "eff739ce124ba2bad1b1d64e73695ebc2e41e60c" have entirely different histories.
fb2883d215
...
eff739ce12
2 changed files with 11 additions and 13 deletions
|
@ -33,6 +33,7 @@
|
||||||
import pro.gravit.launcher.utils.DirWatcher;
|
import pro.gravit.launcher.utils.DirWatcher;
|
||||||
import pro.gravit.utils.helper.*;
|
import pro.gravit.utils.helper.*;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.invoke.MethodHandle;
|
import java.lang.invoke.MethodHandle;
|
||||||
|
@ -45,7 +46,6 @@
|
||||||
import java.nio.file.SimpleFileVisitor;
|
import java.nio.file.SimpleFileVisitor;
|
||||||
import java.nio.file.attribute.BasicFileAttributes;
|
import java.nio.file.attribute.BasicFileAttributes;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
@ -241,23 +241,20 @@ public static void verifyHDir(Path dir, HashedDir hdir, FileNameMatcher matcher,
|
||||||
// Hash directory and compare (ignore update-only matcher entries, it will break offline-mode)
|
// Hash directory and compare (ignore update-only matcher entries, it will break offline-mode)
|
||||||
HashedDir currentHDir = new HashedDir(dir, matcher, true, digest);
|
HashedDir currentHDir = new HashedDir(dir, matcher, true, digest);
|
||||||
HashedDir.Diff diff = hdir.diff(currentHDir, matcher);
|
HashedDir.Diff diff = hdir.diff(currentHDir, matcher);
|
||||||
AtomicReference<String> latestPath = new AtomicReference<>("unknown");
|
|
||||||
if (!diff.mismatch.isEmpty() || (checkExtra && !diff.extra.isEmpty())) {
|
if (!diff.mismatch.isEmpty() || (checkExtra && !diff.extra.isEmpty())) {
|
||||||
diff.extra.walk(File.separator, (e, k, v) -> {
|
diff.extra.walk(File.separator, (e, k, v) -> {
|
||||||
if (v.getType().equals(HashedEntry.Type.FILE)) {
|
if (v.getType().equals(HashedEntry.Type.FILE)) {
|
||||||
LogHelper.error("Extra file %s", e);
|
LogHelper.error("Extra file %s", e);
|
||||||
latestPath.set(e);
|
|
||||||
} else LogHelper.error("Extra %s", e);
|
} else LogHelper.error("Extra %s", e);
|
||||||
return HashedDir.WalkAction.CONTINUE;
|
return HashedDir.WalkAction.CONTINUE;
|
||||||
});
|
});
|
||||||
diff.mismatch.walk(File.separator, (e, k, v) -> {
|
diff.mismatch.walk(File.separator, (e, k, v) -> {
|
||||||
if (v.getType().equals(HashedEntry.Type.FILE)) {
|
if (v.getType().equals(HashedEntry.Type.FILE)) {
|
||||||
LogHelper.error("Mismatch file %s", e);
|
LogHelper.error("Mismatch file %s", e);
|
||||||
latestPath.set(e);
|
|
||||||
} else LogHelper.error("Mismatch %s", e);
|
} else LogHelper.error("Mismatch %s", e);
|
||||||
return HashedDir.WalkAction.CONTINUE;
|
return HashedDir.WalkAction.CONTINUE;
|
||||||
});
|
});
|
||||||
throw new SecurityException(String.format("Forbidden modification: '%s' file '%s'", IOHelper.getFileName(dir), latestPath.get()));
|
throw new SecurityException(String.format("Forbidden modification: '%s'", IOHelper.getFileName(dir)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class Downloader {
|
public class Downloader {
|
||||||
|
@ -29,7 +28,7 @@ public class Downloader {
|
||||||
private static boolean isNoHttp2;
|
private static boolean isNoHttp2;
|
||||||
protected final HttpClient client;
|
protected final HttpClient client;
|
||||||
protected final ExecutorService executor;
|
protected final ExecutorService executor;
|
||||||
protected final Queue<DownloadTask> tasks = new ConcurrentLinkedDeque<>();
|
protected final LinkedList<DownloadTask> tasks = new LinkedList<>();
|
||||||
protected CompletableFuture<Void> future;
|
protected CompletableFuture<Void> future;
|
||||||
protected Downloader(HttpClient client, ExecutorService executor) {
|
protected Downloader(HttpClient client, ExecutorService executor) {
|
||||||
this.client = client;
|
this.client = client;
|
||||||
|
@ -129,13 +128,15 @@ protected DownloadTask sendAsync(AsyncDownloader.SizedFile file, URI baseUri, Pa
|
||||||
IOHelper.createParentDirs(targetDir.resolve(file.filePath));
|
IOHelper.createParentDirs(targetDir.resolve(file.filePath));
|
||||||
ProgressTrackingBodyHandler<Path> bodyHandler = makeBodyHandler(targetDir.resolve(file.filePath), callback);
|
ProgressTrackingBodyHandler<Path> bodyHandler = makeBodyHandler(targetDir.resolve(file.filePath), callback);
|
||||||
CompletableFuture<HttpResponse<Path>> future = client.sendAsync(makeHttpRequest(baseUri, file.urlPath), bodyHandler);
|
CompletableFuture<HttpResponse<Path>> future = client.sendAsync(makeHttpRequest(baseUri, file.urlPath), bodyHandler);
|
||||||
AtomicReference<DownloadTask> task = new AtomicReference<>(null);
|
var ref = new Object() {
|
||||||
task.set(new DownloadTask(bodyHandler, future.thenApply((e) -> {
|
DownloadTask task = null;
|
||||||
tasks.remove(task.get());
|
};
|
||||||
|
ref.task = new DownloadTask(bodyHandler, future.thenApply((e) -> {
|
||||||
|
tasks.remove(ref.task);
|
||||||
return e;
|
return e;
|
||||||
})));
|
}));
|
||||||
tasks.add(task.get());
|
tasks.add(ref.task);
|
||||||
return task.get();
|
return ref.task;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected HttpRequest makeHttpRequest(URI baseUri, String filePath) throws URISyntaxException {
|
protected HttpRequest makeHttpRequest(URI baseUri, String filePath) throws URISyntaxException {
|
||||||
|
|
Loading…
Reference in a new issue