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

View file

@ -67,13 +67,14 @@ var update = {
function offlineUpdateRequest(dirName, dir, matcher, digest) { function offlineUpdateRequest(dirName, dir, matcher, digest) {
return function() { return function() {
var hdir = settings.lastHDirs.get(dirName); LogHelper.error("Unsupported operation");
if (hdir === null) { //var hdir = settings.lastHDirs.get(dirName);
Request.requestError(java.lang.String.format("Директории '%s' нет в кэше", dirName)); //if (hdir === null) {
return; // 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 ru.gravit.launcher.profiles.ClientProfile;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.HashMap; import java.util.*;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
public class NewLauncherSettings { public class NewLauncherSettings {
@LauncherAPI @LauncherAPI
@ -33,6 +30,31 @@ public class NewLauncherSettings {
public byte[] lastDigest; public byte[] lastDigest;
@LauncherAPI @LauncherAPI
public List<ClientProfile> lastProfiles = new LinkedList<>(); public List<ClientProfile> lastProfiles = new LinkedList<>();
public static class HashedStoreEntry
{
@LauncherAPI @LauncherAPI
public transient Map<String, HashedDir> lastHDirs = new HashMap<>(16); 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 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 dirName = input.readString(128);
String fullPath = input.readString(1024); String fullPath = input.readString(1024);
HashedDir dir = new HashedDir(input); HashedDir dir = new HashedDir(input);
settings.lastHDirs.put(dirName, dir); settings.lastHDirs.add(new NewLauncherSettings.HashedStoreEntry(dir, dirName, fullPath));
} }
return super.visitFile(file, attrs); return super.visitFile(file, attrs);
} }
@ -68,14 +68,14 @@ public void loadHDirStore(Path storePath) throws IOException
public void saveHDirStore(Path storeProjectPath) throws IOException public void saveHDirStore(Path storeProjectPath) throws IOException
{ {
Files.createDirectories(storeProjectPath); 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))) try(HOutput output = new HOutput(IOHelper.newOutput(file)))
{ {
output.writeString(e.getKey(), 128); output.writeString(e.name, 128);
output.writeString("", 1024); output.writeString(e.fullPath, 1024);
e.getValue().write(output); e.hdir.write(output);
} }
} }
} }