[FIX] Launcher update

This commit is contained in:
Gravita 2024-08-05 05:34:45 +07:00
parent 5e116a81e5
commit ca70ee78d1
No known key found for this signature in database
GPG key ID: 543A8F335C9CD633
3 changed files with 36 additions and 11 deletions

View file

@ -13,6 +13,7 @@
import java.nio.file.DirectoryStream; import java.nio.file.DirectoryStream;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.*; import java.util.*;
import java.util.stream.Stream; import java.util.stream.Stream;
@ -130,24 +131,41 @@ public HashedDir getUpdatesDir(String updateName) {
return updatesDirMap.get(updateName); return updatesDirMap.get(updateName);
} }
private Path resolveUpdateName(String updateName) {
if(updateName == null) {
return Path.of(updatesDir);
}
return Path.of(updatesDir).resolve(updateName);
}
@Override @Override
public void upload(String updateName, Map<String, Path> files, boolean deleteAfterUpload) throws IOException { public void upload(String updateName, Map<String, Path> files, boolean deleteAfterUpload) throws IOException {
var path = Path.of(updatesDir).resolve(updateName); var path = resolveUpdateName(updateName);
for(var e : files.entrySet()) { for(var e : files.entrySet()) {
var target = path.resolve(e.getKey()); var target = path.resolve(e.getKey());
var source = Path.of(e.getKey()); var source = e.getValue();
IOHelper.createParentDirs(target); IOHelper.createParentDirs(target);
if(deleteAfterUpload) { if(deleteAfterUpload) {
Files.move(source, target); Files.move(source, target, StandardCopyOption.REPLACE_EXISTING);
} else { } else {
Files.copy(source, target); Files.copy(source, target, StandardCopyOption.REPLACE_EXISTING);
} }
} }
} }
@Override
public Map<String, Path> download(String updateName, List<String> files) {
var path = resolveUpdateName(updateName);
Map<String, Path> map = new HashMap<>();
for(var e : files) {
map.put(e, path.resolve(e));
}
return map;
}
@Override @Override
public void delete(String updateName, List<String> files) throws IOException { public void delete(String updateName, List<String> files) throws IOException {
var path = Path.of(updatesDir).resolve(updateName); var path = resolveUpdateName(updateName);
for(var e : files) { for(var e : files) {
var target = path.resolve(e); var target = path.resolve(e);
Files.delete(target); Files.delete(target);
@ -156,13 +174,13 @@ public void delete(String updateName, List<String> files) throws IOException {
@Override @Override
public void delete(String updateName) throws IOException { public void delete(String updateName) throws IOException {
var path = Path.of(updatesDir).resolve(updateName); var path = resolveUpdateName(updateName);
IOHelper.deleteDir(path, true); IOHelper.deleteDir(path, true);
} }
@Override @Override
public void create(String updateName) throws IOException { public void create(String updateName) throws IOException {
var path = Path.of(updatesDir).resolve(updateName); var path = resolveUpdateName(updateName);
Files.createDirectories(path); Files.createDirectories(path);
} }
} }

View file

@ -37,6 +37,8 @@ public void sync() throws IOException {
public abstract void upload(String updateName, Map<String, Path> files, boolean deleteAfterUpload) throws IOException; public abstract void upload(String updateName, Map<String, Path> files, boolean deleteAfterUpload) throws IOException;
public abstract Map<String, Path> download(String updateName, List<String> files);
public abstract void delete(String updateName, List<String> files) throws IOException; public abstract void delete(String updateName, List<String> files) throws IOException;
public abstract void delete(String updateName) throws IOException; public abstract void delete(String updateName) throws IOException;

View file

@ -7,6 +7,7 @@
import java.io.IOException; import java.io.IOException;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.List;
import java.util.Map; import java.util.Map;
public abstract class LauncherBinary extends BinaryPipeline { public abstract class LauncherBinary extends BinaryPipeline {
@ -56,9 +57,13 @@ public void init() {
} }
public final boolean sync() throws IOException { public final boolean sync() throws IOException {
boolean exists = exists(); try {
digest = exists ? SecurityHelper.digest(SecurityHelper.DigestAlgorithm.SHA512, IOHelper.read(syncBinaryFile)) : null; var target = syncBinaryFile.toString();
var path = server.config.updatesProvider.download(null, List.of(target)).get(target);
return exists; digest = SecurityHelper.digest(SecurityHelper.DigestAlgorithm.SHA512, IOHelper.read(path));
return true;
} catch (Throwable e) {
return false;
}
} }
} }