Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
Expand Down Expand Up @@ -207,21 +206,26 @@ public SearchResult search(DownloadProvider downloadProvider, String gameVersion

@Override
public Optional<RemoteAddon.Version> getRemoteVersionByLocalFile(Path file) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
var murmur = new MurmurHash2(1);
try (InputStream stream = Files.newInputStream(file)) {
byte[] buf = new byte[1024];
byte[] input = new byte[1024];
byte[] hashBuffer = new byte[1024];
int len;
while ((len = stream.read(buf, 0, buf.length)) != -1) {
while ((len = stream.read(input, 0, input.length)) > 0) {
int hashBufferLen = 0;

for (int i = 0; i < len; i++) {
byte b = buf[i];
byte b = input[i];
if (b != 0x9 && b != 0xa && b != 0xd && b != 0x20) {
baos.write(b);
hashBuffer[hashBufferLen++] = b;
}
}

murmur.update(hashBuffer, 0, hashBufferLen);
}
}

long hash = Integer.toUnsignedLong(MurmurHash2.hash32(baos.toByteArray(), baos.size(), 1));
long hash = murmur.getValue();
if (hash == 811513880) { // Workaround for https://github.com/HMCL-dev/HMCL/issues/4597
return Optional.empty();
}
Expand Down
Loading