Skip to content

Commit

Permalink
split mappings to update from only if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaceWalkerRS committed Sep 22, 2024
1 parent 89d8b12 commit 65f3470
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/main/java/net/fabricmc/stitch/commands/GenStateSplit.java
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,10 @@ public void prepareUpdateFromSplit(File clientMappings, File serverMappings, Fil
File client = null;
File server = null;

if (clientMappings != null) {
boolean splitClient = clientMappings != null && needsSplitting(clientMappings);
boolean splitServer = clientMappings != null && needsSplitting(serverMappings);

if (splitClient) {
tmp = new File(clientMappings.getParentFile(), ".tmp");
client = new File(tmp, "client.tiny");

Expand All @@ -694,8 +697,10 @@ public void prepareUpdateFromSplit(File clientMappings, File serverMappings, Fil
} catch (Exception e) {
throw new IOException(e);
}
} else {
client = clientMappings;
}
if (serverMappings != null) {
if (splitServer) {
tmp = new File(serverMappings.getParentFile(), ".tmp");
server = new File(tmp, "server.tiny");

Expand All @@ -710,15 +715,17 @@ public void prepareUpdateFromSplit(File clientMappings, File serverMappings, Fil
} catch (Exception e) {
throw new IOException(e);
}
} else {
server = serverMappings;
}

prepareUpdateFromSplitInternal(client, server, clientMatches, serverMatches, clientServerMatches, invertClientMatches, invertServerMatches, invertClientServerMatches);

if (clientMappings != null) {
if (splitClient) {
client.delete();
tmp.delete();
}
if (serverMappings != null) {
if (splitServer) {
server.delete();
tmp.delete();
}
Expand Down Expand Up @@ -765,4 +772,17 @@ public void prepareUpdateFromSplitInternal(File clientMappings, File serverMappi
}
}
}

private boolean needsSplitting(File mappings) {
try (BufferedReader br = new BufferedReader(new FileReader(mappings))) {
String header = br.readLine();

if (header != null) {
return !header.startsWith("v1\tofficial");
}
} catch (IOException e) {
}

return false;
}
}

0 comments on commit 65f3470

Please sign in to comment.