Skip to content

Commit de747ca

Browse files
committed
Update LavaNativeManager.java
1 parent d1e86e0 commit de747ca

File tree

1 file changed

+34
-13
lines changed

1 file changed

+34
-13
lines changed

common/src/main/java/dev/felnull/imp/client/lava/LavaNativeManager.java

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -131,23 +131,24 @@ private boolean checked(File file) {
131131
return false;
132132
}
133133

134-
// 2. Build file list, ignoring hidden/junk files
134+
// 2. Filter only actual native files and hash.json
135135
List<File> fls = Arrays.stream(fs)
136-
.filter(f -> !f.isHidden()) // skip hidden files (.DS_Store, etc.)
136+
.filter(f -> !f.isHidden())
137137
.filter(f -> !f.getName().equalsIgnoreCase("Thumbs.db"))
138138
.collect(Collectors.toList());
139139

140140
// 3. Find hash.json
141141
Optional<File> hf = fls
142142
.stream()
143-
.filter(n -> n.getName().equals("hash.json"))
143+
.filter(f -> f.getName().equals("hash.json"))
144144
.findAny();
145+
145146
if (hf.isEmpty()) {
146147
LOGGER.error("Missing hash.json in directory: {}", file);
147148
return false;
148149
}
149150

150-
// 4. Parse JSON
151+
// 4. Parse hash.json
151152
JsonObject jo;
152153
try (
153154
BufferedReader reader = new BufferedReader(
@@ -166,17 +167,37 @@ private boolean checked(File file) {
166167
return false;
167168
}
168169

169-
// 6. Remove hash.json from file list
170+
// 6. Remove hash.json from the list
170171
fls.remove(hf.get());
171172

173+
// 7. Filter native binaries based on OS
174+
fls = fls
175+
.stream()
176+
.filter(f -> {
177+
if (os.contains("linux") && f.getName().endsWith(".so")) return true;
178+
if (os.contains("mac") && f.getName().endsWith(".dylib")) return true;
179+
if (os.contains("win") && f.getName().endsWith(".dll")) return true;
180+
return false;
181+
})
182+
.collect(Collectors.toList());
183+
172184
if (fls.isEmpty()) {
173-
LOGGER.error("No native files found (only hash.json present)");
174-
return false;
185+
if (os.contains("win")) {
186+
LOGGER.error(
187+
"No native files found for Windows (only hash.json present)"
188+
);
189+
return false;
190+
} else {
191+
LOGGER.warn(
192+
"No native files found for {} — proceeding anyway (single-file archive expected)",
193+
os
194+
);
195+
}
175196
}
176197

177198
JsonElement hashElem = jo.get("hash");
178199

179-
// 7. Case A: Single hash string → validate first file
200+
// 8. Case A: Single hash string → validate first file
180201
if (hashElem.isJsonPrimitive()) {
181202
if (fls.size() != 1) {
182203
LOGGER.warn(
@@ -214,13 +235,13 @@ private boolean checked(File file) {
214235
}
215236
}
216237

217-
// 8. Case B: Object of hashes → validate each file
238+
// 9. Case B: Object of hashes → validate each file
218239
if (hashElem.isJsonObject()) {
219240
JsonObject hjo = hashElem.getAsJsonObject();
220241

221242
if (hjo.size() != fls.size()) {
222243
LOGGER.error(
223-
"Mismatch between hash entries ({}) and file count ({})",
244+
"Mismatch between hash entries ({}) and native files ({})",
224245
hjo.size(),
225246
fls.size()
226247
);
@@ -233,9 +254,8 @@ private boolean checked(File file) {
233254

234255
Optional<File> lf = fls
235256
.stream()
236-
.filter(n -> n.getName().equals(filename))
257+
.filter(f -> f.getName().equals(filename))
237258
.findAny();
238-
239259
if (lf.isEmpty()) {
240260
LOGGER.error("Expected file {} not found in directory", filename);
241261
return false;
@@ -265,10 +285,11 @@ private boolean checked(File file) {
265285
return false;
266286
}
267287
}
288+
268289
return true;
269290
}
270291

271-
// 9. Fallback
292+
// 10. Fallback
272293
LOGGER.error(
273294
"Invalid 'hash' format in hash.json (expected string or object). Found: {}",
274295
hashElem

0 commit comments

Comments
 (0)