Skip to content

Commit

Permalink
do NOT use VSC to edit Java code
Browse files Browse the repository at this point in the history
  • Loading branch information
maddie480 authored Jun 21, 2024
1 parent cdf2f05 commit 2ed5a93
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,13 @@ static void updateDatabaseYaml(boolean full) throws IOException {
long startMillis = System.currentTimeMillis();

boolean somethingChanged;
int numberOfModsDownloaded;

{ // run the updater!
DatabaseUpdater updater = new DatabaseUpdater();
updater.updateDatabaseYamlInner(full);
somethingChanged = !updater.database.isEmpty();
numberOfModsDownloaded = !updater.numberOfModsDownloaded.isEmpty();
}

if (somethingChanged) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package ovh.maddie480.everest.updatechecker;

import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collection;
Expand Down Expand Up @@ -39,7 +44,7 @@ public static void cleanup() throws IOException {
}

private static Path downloadFile(String url, Integer expectedSize, Collection<String> expectedHashes) throws IOException {
if (alreadyDownloadedFiles.contains(url)) {
if (alreadyDownloadedFiles.containsKey(url)) {
Path path = alreadyDownloadedFiles.get(url);
log.debug("File {} found in cache: {}", url, path.toAbsolutePath());
return path;
Expand All @@ -50,8 +55,10 @@ private static Path downloadFile(String url, Integer expectedSize, Collection<St
try {
return ConnectionUtils.runWithRetry(() -> {
log.debug("Starting download of {} to {}", url, target.toAbsolutePath());
try (OutputStream os = new BufferedOutputStream(Files.newOutputStream(target))) {
IOUtils.copy(new BufferedInputStream(ConnectionUtils.openStreamWithTimeout(fileUrl)), os);
try (InputStream is = new BufferedInputStream(ConnectionUtils.openStreamWithTimeout(url));
OutputStream os = new BufferedOutputStream(Files.newOutputStream(target))) {

IOUtils.copy(is, os);
}

if (expectedSize != null) {
Expand All @@ -65,7 +72,7 @@ private static Path downloadFile(String url, Integer expectedSize, Collection<St
if (expectedHashes != null) {
String xxHash = DatabaseUpdater.computeXXHash(target.toAbsolutePath().toString());
if (!expectedHashes.contains(xxHash)) {
throw new IOException("xxHash checksum failure on file with id " + fileId + " @ " + modUrl + "!");
throw new IOException("xxHash checksum failure on file " + url + "!");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,11 @@ private void checkAhornFilesDatabase(String mod, Path modFolder, String version)
List<String> ahornEffects = new LinkedList<>();

// download file
Path file = FileDownloader.downloadFile("https://gamebanana.com/mmdl/" + version);
Path zipFilePath = FileDownloader.downloadFile("https://gamebanana.com/mmdl/" + version);

// scan its contents, opening Ahorn plugin files
try (ZipFile zipFile = ZipFileWithAutoEncoding.open(file.toAbsolutePath().toString())) {
checkZipSignature(file);
try (ZipFile zipFile = ZipFileWithAutoEncoding.open(zipFilePath.toAbsolutePath().toString())) {
checkZipSignature(zipFilePath);

for (String file : fileList) {
if (file.startsWith("Ahorn/") && file.endsWith(".jl")) {
Expand Down

0 comments on commit 2ed5a93

Please sign in to comment.