Skip to content

Commit 1fbc52d

Browse files
committed
1.8.1
Performance: Drastically improve mod pack extraction performance Add built in mods system for some weird modrinth modpacks
1 parent 8f791e8 commit 1fbc52d

File tree

12 files changed

+90
-25
lines changed

12 files changed

+90
-25
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ apply plugin: 'maven-publish'
44
apply plugin: 'signing'
55

66
group 'fr.flowarg'
7-
version '1.8.0'
7+
version '1.8.1'
88
archivesBaseName = "flowupdater"
99

1010
java {
@@ -35,7 +35,7 @@ dependencies {
3535

3636
// Only for internal tests
3737
testImplementation 'fr.flowarg:openlauncherlib:3.2.6'
38-
testImplementation 'org.junit.jupiter:junit-jupiter:5.9.3'
38+
testImplementation 'org.junit.jupiter:junit-jupiter:5.10.0'
3939
}
4040

4141
artifacts {

src/main/java/fr/flowarg/flowupdater/FlowUpdater.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
public class FlowUpdater
3737
{
3838
/** FlowUpdater's version string constant */
39-
public static final String FU_VERSION = "1.8.0";
39+
public static final String FU_VERSION = "1.8.1";
4040

4141
/** Vanilla version's object to update/install */
4242
private final VanillaVersion vanillaVersion;

src/main/java/fr/flowarg/flowupdater/integrations/IntegrationManager.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ public void loadModrinthIntegration(Path dir, IModrinthFeaturesUser modrinthFeat
156156
this.progressCallback.step(Step.MOD_PACK);
157157
final ModrinthModPack modPack = modrinthIntegration.getCurseModPack(modPackInfo);
158158
this.logger.info(String.format("Loading mod pack: %s (%s).", modPack.getName(), modPack.getVersion()));
159+
modrinthFeaturesUser.setModrinthModPack(modPack);
159160

160161
for (Mod mod : modPack.getMods())
161162
this.checkMod(mod, allModrinthMods, dir);

src/main/java/fr/flowarg/flowupdater/integrations/curseforgeintegration/CurseForgeIntegration.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.nio.charset.StandardCharsets;
2121
import java.nio.file.Files;
2222
import java.nio.file.Path;
23+
import java.nio.file.StandardCopyOption;
2324
import java.util.*;
2425
import java.util.concurrent.ConcurrentLinkedQueue;
2526
import java.util.concurrent.Executors;
@@ -309,13 +310,7 @@ private void transferAndClose(@NotNull Path flPath, ZipFile zipFile, ZipEntry en
309310
if(Files.notExists(flPath.getParent()))
310311
Files.createDirectories(flPath.getParent());
311312

312-
try(OutputStream pathStream = Files.newOutputStream(flPath);
313-
BufferedOutputStream fo = new BufferedOutputStream(pathStream);
314-
InputStream is = zipFile.getInputStream(entry)) {
315-
316-
while (is.available() > 0)
317-
fo.write(is.read());
318-
}
313+
Files.copy(zipFile.getInputStream(entry), flPath, StandardCopyOption.REPLACE_EXISTING);
319314
}
320315

321316
private static class ProjectMod extends CurseFileInfo

src/main/java/fr/flowarg/flowupdater/integrations/modrinthintegration/IModrinthFeaturesUser.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@ public interface IModrinthFeaturesUser
2020
*/
2121
ModrinthModPackInfo getModrinthModPackInfo();
2222

23+
/**
24+
* Get the modrinth mod pack.
25+
* @return the modrinth mod pack.
26+
*/
27+
ModrinthModPack getModrinthModPack();
28+
29+
/**
30+
* Define the modrinth mod pack.
31+
* @param modrinthModPack the modrinth mod pack.
32+
*/
33+
void setModrinthModPack(ModrinthModPack modrinthModPack);
34+
2335
/**
2436
* Define all modrinth mods to update.
2537
* @param modrinthMods modrinth mods to define.

src/main/java/fr/flowarg/flowupdater/integrations/modrinthintegration/ModrinthIntegration.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.nio.charset.StandardCharsets;
2424
import java.nio.file.Files;
2525
import java.nio.file.Path;
26+
import java.nio.file.StandardCopyOption;
2627
import java.util.ArrayList;
2728
import java.util.Enumeration;
2829
import java.util.List;
@@ -35,6 +36,8 @@ public class ModrinthIntegration extends Integration
3536
private static final String MODRINTH_VERSION_ENDPOINT = "version/{versionId}";
3637
private static final String MODRINTH_PROJECT_VERSION_ENDPOINT = "project/{projectId}/version";
3738

39+
private final List<Mod> builtInMods = new ArrayList<>();
40+
3841
/**
3942
* Default constructor of a basic Integration.
4043
*
@@ -130,8 +133,8 @@ private void extractModPack(@NotNull Path out, boolean installExtFiles) throws E
130133
while (entries.hasMoreElements())
131134
{
132135
final ZipEntry entry = entries.nextElement();
133-
final Path flPath = dirPath.resolve(StringUtils.empty(StringUtils.empty(entry.getName(), "client-overrides/"), "overrides/"));
134136
final String entryName = entry.getName();
137+
final Path flPath = dirPath.resolve(StringUtils.empty(StringUtils.empty(entryName, "client-overrides/"), "overrides/"));
135138

136139
if(entryName.equalsIgnoreCase("modrinth.index.json"))
137140
{
@@ -140,6 +143,15 @@ private void extractModPack(@NotNull Path out, boolean installExtFiles) throws E
140143
continue;
141144
}
142145

146+
final String withoutOverrides = StringUtils.empty(StringUtils.empty(entryName, "overrides/"), "client-overrides/");
147+
148+
if(withoutOverrides.startsWith("mods/") || withoutOverrides.startsWith("mods\\"))
149+
{
150+
final String modName = withoutOverrides.substring(withoutOverrides.lastIndexOf('/') + 1);
151+
final Mod mod = new Mod(modName, "", "", entry.getSize());
152+
this.builtInMods.add(mod);
153+
}
154+
143155
if(!installExtFiles || Files.exists(flPath)) continue;
144156

145157
if (flPath.getFileName().toString().endsWith(flPath.getFileSystem().getSeparator()))
@@ -163,7 +175,7 @@ private void extractModPack(@NotNull Path out, boolean installExtFiles) throws E
163175
final String modPackVersion = manifestObj.get("versionId").getAsString();
164176
final List<Mod> mods = this.parseManifest(manifestObj);
165177

166-
return new ModrinthModPack(modPackName, modPackVersion, mods);
178+
return new ModrinthModPack(modPackName, modPackVersion, mods, this.builtInMods);
167179
}
168180

169181
private @NotNull List<Mod> parseManifest(@NotNull JsonObject manifestObject)
@@ -178,7 +190,7 @@ private void extractModPack(@NotNull Path out, boolean installExtFiles) throws E
178190
if(file.getAsJsonObject("env").get("client").getAsString().equals("unsupported"))
179191
return;
180192

181-
final String name = StringUtils.empty(file.get("path").getAsString(), "mods/");
193+
final String name = StringUtils.empty(StringUtils.empty(file.get("path").getAsString(), "mods/"), "mods\\");
182194
final String downloadURL = file.getAsJsonArray("downloads").get(0).getAsString();
183195
final String sha1 = file.getAsJsonObject("hashes").get("sha1").getAsString();
184196
final long size = file.get("fileSize").getAsLong();
@@ -194,12 +206,6 @@ private void transferAndClose(@NotNull Path flPath, ZipFile zipFile, ZipEntry en
194206
if(Files.notExists(flPath.getParent()))
195207
Files.createDirectories(flPath.getParent());
196208

197-
try(OutputStream pathStream = Files.newOutputStream(flPath);
198-
BufferedOutputStream fo = new BufferedOutputStream(pathStream);
199-
InputStream is = zipFile.getInputStream(entry)) {
200-
201-
while (is.available() > 0)
202-
fo.write(is.read());
203-
}
209+
Files.copy(zipFile.getInputStream(entry), flPath, StandardCopyOption.REPLACE_EXISTING);
204210
}
205211
}

src/main/java/fr/flowarg/flowupdater/integrations/modrinthintegration/ModrinthModPack.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,27 @@
22

33
import fr.flowarg.flowupdater.download.json.Mod;
44

5+
import java.util.ArrayList;
56
import java.util.List;
67

78
public class ModrinthModPack
89
{
910
private final String name;
1011
private final String version;
1112
private final List<Mod> mods;
13+
private final List<Mod> builtInMods;
1214

1315
ModrinthModPack(String name, String version, List<Mod> mods)
16+
{
17+
this(name, version, mods, new ArrayList<>());
18+
}
19+
20+
ModrinthModPack(String name, String version, List<Mod> mods, List<Mod> builtInMods)
1421
{
1522
this.name = name;
1623
this.version = version;
1724
this.mods = mods;
25+
this.builtInMods = builtInMods;
1826
}
1927

2028
/**
@@ -44,4 +52,17 @@ public List<Mod> getMods()
4452
{
4553
return this.mods;
4654
}
55+
56+
/**
57+
* Get the built-in mods in the mod pack.
58+
* Built-in mods are mods directly put in the mods folder in the .mrpack file.
59+
* They are not downloaded from a remote server.
60+
* This is not a very good way to add mods because it disables some mod verification on these mods.
61+
* We recommend mod pack creators to use the built-in mods feature only for mods that are not available remotely.
62+
* @return the built-in mods in the mod pack.
63+
*/
64+
public List<Mod> getBuiltInMods()
65+
{
66+
return this.builtInMods;
67+
}
4768
}

src/main/java/fr/flowarg/flowupdater/utils/ModFileDeleter.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import fr.flowarg.flowio.FileUtils;
44
import fr.flowarg.flowupdater.download.json.Mod;
5+
import fr.flowarg.flowupdater.integrations.modrinthintegration.ModrinthModPack;
56
import fr.flowarg.flowupdater.integrations.optifineintegration.OptiFine;
67

78
import java.io.IOException;
@@ -33,17 +34,32 @@ public ModFileDeleter(String... modsToIgnore)
3334
* Delete all bad files in the provided directory.
3435
* @param modsDir the mod's folder.
3536
* @param mods the mods list.
36-
* @param optiFine the OptiFine object.
3737
* @throws Exception thrown if an error occurred
3838
*/
39-
public void delete(Path modsDir, List<Mod> mods, OptiFine optiFine) throws Exception
39+
public void delete(Path modsDir, List<Mod> mods) throws Exception
40+
{
41+
this.delete(modsDir, mods, null, null);
42+
}
43+
44+
/**
45+
* Delete all bad files in the provided directory.
46+
* @param modsDir the mod's folder.
47+
* @param mods the mods list.
48+
* @param optiFine the OptiFine object. (SPECIFIC USE CASE)
49+
* @param modrinthModPack the modrinth mod pack. (SPECIFIC USE CASE)
50+
* @throws Exception thrown if an error occurred
51+
*/
52+
public void delete(Path modsDir, List<Mod> mods, OptiFine optiFine, ModrinthModPack modrinthModPack) throws Exception
4053
{
4154
if(!this.isUseFileDeleter()) return;
4255

4356
final Set<Path> badFiles = new HashSet<>();
4457
final List<Path> verifiedFiles = new ArrayList<>();
4558
Arrays.stream(this.modsToIgnore).forEach(fileName -> verifiedFiles.add(modsDir.resolve(fileName)));
4659

60+
if(modrinthModPack != null)
61+
modrinthModPack.getBuiltInMods().forEach(mod -> verifiedFiles.add(modsDir.resolve(mod.getName())));
62+
4763
for(Path fileInDir : FileUtils.list(modsDir).stream().filter(path -> !Files.isDirectory(path)).collect(Collectors.toList()))
4864
{
4965
if(verifiedFiles.contains(fileInDir))

src/main/java/fr/flowarg/flowupdater/versions/AbstractForgeVersion.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ public void installMods(Path modsDir) throws Exception
269269
this.callback.update(this.downloadList.getDownloadInfo());
270270
}
271271

272-
this.fileDeleter.delete(modsDir, this.mods, ofObj);
272+
this.fileDeleter.delete(modsDir, this.mods, ofObj, this.modrinthModPack);
273273
}
274274

275275
/** This method packs the modified installer to a JAR file.

src/main/java/fr/flowarg/flowupdater/versions/AbstractModLoaderVersion.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import fr.flowarg.flowupdater.download.json.*;
88
import fr.flowarg.flowupdater.integrations.curseforgeintegration.ICurseFeaturesUser;
99
import fr.flowarg.flowupdater.integrations.modrinthintegration.IModrinthFeaturesUser;
10+
import fr.flowarg.flowupdater.integrations.modrinthintegration.ModrinthModPack;
1011
import fr.flowarg.flowupdater.utils.ModFileDeleter;
1112
import org.jetbrains.annotations.NotNull;
1213

@@ -27,6 +28,7 @@ public abstract class AbstractModLoaderVersion implements ICurseFeaturesUser, IM
2728
protected DownloadList downloadList;
2829
protected IProgressCallback callback;
2930
protected String javaPath;
31+
protected ModrinthModPack modrinthModPack;
3032

3133
public AbstractModLoaderVersion(List<Mod> mods, String modLoaderVersion, List<CurseFileInfo> curseMods,
3234
List<ModrinthVersionInfo> modrinthMods, ModFileDeleter fileDeleter, CurseModPackInfo curseModPackInfo,
@@ -162,4 +164,16 @@ public ModFileDeleter getFileDeleter()
162164
{
163165
return this.fileDeleter;
164166
}
167+
168+
@Override
169+
public void setModrinthModPack(ModrinthModPack modrinthModPack)
170+
{
171+
this.modrinthModPack = modrinthModPack;
172+
}
173+
174+
@Override
175+
public ModrinthModPack getModrinthModPack()
176+
{
177+
return this.modrinthModPack;
178+
}
165179
}

0 commit comments

Comments
 (0)