Техническая реализация поиска модов в других клиентах

Не тестировалась на работоспособность
Вычисление хеша и обход всех папок обновлений - затратная по диску и процессору операция
This commit is contained in:
Gravit 2018-12-20 16:37:46 +07:00
parent 3654a450f8
commit 4db1bd6d75
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
4 changed files with 92 additions and 7 deletions

View file

@ -8,6 +8,8 @@
import ru.gravit.launcher.HWID;
import ru.gravit.launcher.LauncherAPI;
import ru.gravit.launcher.RequestWorker;
import ru.gravit.launcher.managers.HasherManager;
import ru.gravit.launcher.managers.HasherStore;
import ru.gravit.launcher.hasher.FileNameMatcher;
import ru.gravit.launcher.hasher.HashedDir;
import ru.gravit.launcher.hwid.OshiHWIDProvider;
@ -75,6 +77,11 @@ public static long getTotalMemory()
{
return hwidProvider.getTotalMemory() >> 20;
}
@LauncherAPI
public static HasherStore getDefaultHasherStore()
{
return HasherManager.getDefaultStore();
}
@FunctionalInterface
public interface HashedDirRunnable {

View file

@ -0,0 +1,9 @@
package ru.gravit.launcher.managers;
public class HasherManager {
public static final HasherStore defaultStore = new HasherStore();
public static HasherStore getDefaultStore() {
return defaultStore;
}
}

View file

@ -0,0 +1,72 @@
package ru.gravit.launcher.managers;
import ru.gravit.launcher.LauncherAPI;
import ru.gravit.launcher.hasher.FileNameMatcher;
import ru.gravit.launcher.hasher.HashedDir;
import ru.gravit.launcher.hasher.HashedEntry;
import ru.gravit.launcher.profiles.ClientProfile;
import ru.gravit.utils.helper.IOHelper;
import ru.gravit.utils.helper.LogHelper;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collection;
import java.util.LinkedList;
import java.util.Map;
public class HasherStore {
public Map<String, HasherStoreEnity> store;
public class HasherStoreEnity
{
@LauncherAPI
public HashedDir hdir;
@LauncherAPI
public Path dir;
@LauncherAPI
public Collection<String> shared;
}
@LauncherAPI
public void addProfileUpdateDir(ClientProfile profile, Path dir, HashedDir hdir)
{
HasherStoreEnity e = new HasherStoreEnity();
e.hdir = hdir;
e.dir = dir;
e.shared = profile.getShared();
store.put(profile.getTitle(),e);
}
@LauncherAPI
public void copyCompareFilesTo(String name, Path targetDir, HashedDir targetHDir, String[] shared)
{
store.forEach((key,e) -> {
if(key.equals(name)) return;
FileNameMatcher nm = new FileNameMatcher(shared,null,null);
HashedDir compare = targetHDir.sideCompare(e.hdir,nm, new LinkedList<>(), true);
compare.map().forEach((arg1,arg2) -> recurseCopy(arg1,arg2,name,targetDir,e.dir));
});
}
@LauncherAPI
public void recurseCopy(String filename, HashedEntry entry, String name, Path targetDir, Path sourceDir)
{
if(!IOHelper.isDir(targetDir)) {
try {
Files.createDirectories(targetDir);
} catch (IOException e1) {
LogHelper.error(e1);
}
}
if(entry.getType().equals(HashedEntry.Type.DIR))
{
((HashedDir)entry).map().forEach((arg1,arg2) -> recurseCopy(arg1,arg2,name,targetDir.resolve(filename),sourceDir.resolve(filename)));
}
else if(entry.getType().equals(HashedEntry.Type.FILE))
{
try {
IOHelper.copy(sourceDir.resolve(filename),targetDir.resolve(filename));
} catch (IOException e) {
LogHelper.error(e);
}
}
}
}

View file

@ -2,13 +2,7 @@
import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.*;
import ru.gravit.launcher.LauncherAPI;
import ru.gravit.launcher.hasher.FileNameMatcher;
@ -233,6 +227,9 @@ public Set<MarkedString> getOptional() {
return updateOptional;
}
@LauncherAPI
public Collection<String> getShared() { return updateShared; }
@LauncherAPI
public void markOptional(String opt) {
if (!updateOptional.contains(new MarkedString(opt)))