mirror of
https://github.com/GravitLauncher/Launcher
synced 2025-04-19 14:33:04 +03:00
[FIX] Модернизация алгоритма: проверка среднего объёма и кол-ва файлов.
This commit is contained in:
parent
394e1ae670
commit
6a76321f20
4 changed files with 44 additions and 3 deletions
|
@ -37,6 +37,7 @@
|
|||
import pro.gravit.launcher.Launcher;
|
||||
import pro.gravit.launcher.LauncherConfig;
|
||||
import pro.gravit.launcher.NeedGarbageCollection;
|
||||
import pro.gravit.launcher.downloader.UpdateData;
|
||||
import pro.gravit.launcher.hasher.HashedDir;
|
||||
import pro.gravit.launcher.hasher.HashedEntry;
|
||||
import pro.gravit.launcher.hwid.HWIDProvider;
|
||||
|
@ -915,7 +916,7 @@ public void syncUpdatesDir(Collection<String> dirs) throws IOException {
|
|||
private void processUpdate(Path updateDir, HashedDir updateHDir, String name) throws IOException {
|
||||
updateHDir.walk(IOHelper.CROSS_SEPARATOR, (path, filename, entry) -> {
|
||||
if (entry.getType().equals(HashedEntry.Type.DIR)) {
|
||||
if (entry.size() < IOHelper.MB16) {
|
||||
if (UpdateData.needsZip((HashedDir) entry)) {
|
||||
Path p = updateDir.resolve(path);
|
||||
Path out = optimizedUpdatesDir.resolve(name).resolve(path);
|
||||
try (ZipOutputStream compressed = new ZipOutputStream(IOHelper.newOutput(out))) {
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
package pro.gravit.launcher.downloader;
|
||||
|
||||
import java.io.IOError;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import pro.gravit.launcher.hasher.HashedDir;
|
||||
import pro.gravit.launcher.hasher.HashedEntry;
|
||||
import pro.gravit.utils.helper.IOHelper;
|
||||
|
||||
public final class UpdateData {
|
||||
public static final int COUNT_LIMIT = 4;
|
||||
public static final long AVG_LIMIT = IOHelper.MB*4;
|
||||
public static final long TOTAL_LIMIT = IOHelper.MB*16;
|
||||
|
||||
private UpdateData() {
|
||||
}
|
||||
|
||||
public static boolean needsZip(HashedDir hDir) {
|
||||
AtomicLong size = new AtomicLong();
|
||||
AtomicInteger cnt = new AtomicInteger();
|
||||
try {
|
||||
hDir.walk(IOHelper.CROSS_SEPARATOR, (p,n,e) -> {
|
||||
if (e.getType().equals(HashedEntry.Type.FILE)) {
|
||||
cnt.incrementAndGet();
|
||||
size.addAndGet(e.size());
|
||||
}
|
||||
return HashedDir.WalkAction.CONTINUE;
|
||||
});
|
||||
} catch (IOException e) {
|
||||
throw new IOError(e); // never happen
|
||||
}
|
||||
long avg = size.get()/(long)cnt.get();
|
||||
return size.get() < TOTAL_LIMIT && avg < AVG_LIMIT && cnt.get() > COUNT_LIMIT;
|
||||
}
|
||||
}
|
|
@ -11,11 +11,14 @@
|
|||
import java.util.Map.Entry;
|
||||
import java.util.Objects;
|
||||
import java.util.StringTokenizer;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import pro.gravit.launcher.Launcher;
|
||||
import pro.gravit.launcher.LauncherAPI;
|
||||
import pro.gravit.launcher.LauncherNetworkAPI;
|
||||
import pro.gravit.launcher.downloader.ListDownloader;
|
||||
import pro.gravit.launcher.downloader.UpdateData;
|
||||
import pro.gravit.launcher.events.request.UpdateRequestEvent;
|
||||
import pro.gravit.launcher.hasher.FileNameMatcher;
|
||||
import pro.gravit.launcher.hasher.HashedDir;
|
||||
|
@ -212,7 +215,7 @@ public UpdateRequestEvent requestDo(StandartClientWebSocketService service) thro
|
|||
} catch (IOException ex) {
|
||||
LogHelper.error(ex);
|
||||
}
|
||||
if (getPathed(name, e.hdir).size() < IOHelper.MB16) {
|
||||
if (UpdateData.needsZip((HashedDir)getPathed(name, e.hdir))) {
|
||||
adds.add(new ListDownloader.DownloadTask(path, -1, true));
|
||||
return HashedDir.WalkAction.SKIP_DIR;
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@
|
|||
import pro.gravit.launcher.LauncherAPI;
|
||||
|
||||
public final class IOHelper {
|
||||
public static final long MB16 = 1 << 24;
|
||||
public static final long MB = 1 << 20;
|
||||
private static final class DeleteDirVisitor extends SimpleFileVisitor<Path> {
|
||||
private final Path dir;
|
||||
private final boolean self;
|
||||
|
|
Loading…
Reference in a new issue