[FIX] Расширение логики HashedDirStore

This commit is contained in:
Gravit 2019-04-14 00:15:12 +07:00
parent c700ec2791
commit 477798e30c
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
4 changed files with 42 additions and 19 deletions

View file

@ -264,14 +264,14 @@ function doUpdate(profile, pp, accessToken) {
makeSetProfileRequest(profile, function() {
ClientLauncher.setProfile(profile);
makeUpdateRequest(assetDirName, assetDir, assetMatcher, digest, function(assetHDir) {
settings.lastHDirs.put(assetDirName, assetHDir.hdir);
settings.putHDir(assetDirName, assetDir, assetHDir.hdir);
update.resetOverlay("Обновление файлов клиента");
var clientDirName = profile.getDir();
var clientDir = settings.updatesDir.resolve(clientDirName);
var clientMatcher = profile.getClientUpdateMatcher();
makeUpdateRequest(clientDirName, clientDir, clientMatcher, digest, function(clientHDir) {
settings.lastHDirs.put(clientDirName, clientHDir.hdir);
settings.putHDir(clientDirName, clientDir, clientHDir.hdir);
doLaunchClient(assetDir, assetHDir.hdir, clientDir, clientHDir.hdir, profile, pp, accessToken);
});
});

View file

@ -67,13 +67,14 @@ var update = {
function offlineUpdateRequest(dirName, dir, matcher, digest) {
return function() {
var hdir = settings.lastHDirs.get(dirName);
if (hdir === null) {
Request.requestError(java.lang.String.format("Директории '%s' нет в кэше", dirName));
return;
}
LogHelper.error("Unsupported operation");
//var hdir = settings.lastHDirs.get(dirName);
//if (hdir === null) {
// Request.requestError(java.lang.String.format("Директории '%s' нет в кэше", dirName));
// return;
//}
return FunctionalBridge.offlineUpdateRequest(dir, hdir, matcher, digest).run();
//return FunctionalBridge.offlineUpdateRequest(dir, hdir, matcher, digest).run();
};
}

View file

@ -4,10 +4,7 @@
import ru.gravit.launcher.profiles.ClientProfile;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.*;
public class NewLauncherSettings {
@LauncherAPI
@ -33,6 +30,31 @@ public class NewLauncherSettings {
public byte[] lastDigest;
@LauncherAPI
public List<ClientProfile> lastProfiles = new LinkedList<>();
public static class HashedStoreEntry
{
@LauncherAPI
public HashedDir hdir;
@LauncherAPI
public String name;
@LauncherAPI
public String fullPath;
public HashedStoreEntry(HashedDir hdir, String name, String fullPath) {
this.hdir = hdir;
this.name = name;
this.fullPath = fullPath;
}
}
@LauncherAPI
public transient Map<String, HashedDir> lastHDirs = new HashMap<>(16);
public transient List<HashedStoreEntry> lastHDirs = new ArrayList<>(16);
@LauncherAPI
public void putHDir(String name, Path path, HashedDir dir)
{
String fullPath = path.toAbsolutePath().toString();
for(HashedStoreEntry e : lastHDirs)
{
if(e.fullPath.equals(fullPath) && e.name.equals(name)) return;
}
lastHDirs.add(new HashedStoreEntry(dir, name, fullPath));
}
}

View file

@ -27,7 +27,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
String dirName = input.readString(128);
String fullPath = input.readString(1024);
HashedDir dir = new HashedDir(input);
settings.lastHDirs.put(dirName, dir);
settings.lastHDirs.add(new NewLauncherSettings.HashedStoreEntry(dir, dirName, fullPath));
}
return super.visitFile(file, attrs);
}
@ -68,14 +68,14 @@ public void loadHDirStore(Path storePath) throws IOException
public void saveHDirStore(Path storeProjectPath) throws IOException
{
Files.createDirectories(storeProjectPath);
for(Map.Entry<String, HashedDir> e : settings.lastHDirs.entrySet())
for(NewLauncherSettings.HashedStoreEntry e : settings.lastHDirs)
{
Path file = Files.createFile(storeProjectPath.resolve(e.getKey().concat(".bin")));
Path file = Files.createFile(storeProjectPath.resolve(e.name.concat(".bin")));
try(HOutput output = new HOutput(IOHelper.newOutput(file)))
{
output.writeString(e.getKey(), 128);
output.writeString("", 1024);
e.getValue().write(output);
output.writeString(e.name, 128);
output.writeString(e.fullPath, 1024);
e.hdir.write(output);
}
}
}