Write imod sources generated in ModsDirScanner
This commit is contained in:
parent
c3de25b125
commit
bce9a323f1
|
@ -22,7 +22,7 @@ public class ModDescription {
|
|||
public List<String> dependents; // by file name
|
||||
public List<String> dependencies; // by file name
|
||||
|
||||
public void initialize(String gameVersion) {
|
||||
public boolean initialize(String gameVersion) {
|
||||
boolean modrinth = false;
|
||||
boolean curseforge = false;
|
||||
for (ModSource source : sources.keySet().toArray(ModSource[]::new)) {
|
||||
|
@ -30,9 +30,11 @@ public class ModDescription {
|
|||
if (source instanceof CurseforgeModSource) curseforge = true;
|
||||
addSource(source, gameVersion);
|
||||
}
|
||||
boolean changed = false;
|
||||
if (!modrinth) {
|
||||
try {
|
||||
addSource(new ModrinthModSource(ModrinthApi.getVersionByHash(sha1).id), gameVersion);
|
||||
changed = true;
|
||||
}
|
||||
catch (IOException e) {
|
||||
// not found
|
||||
|
@ -44,12 +46,14 @@ public class ModDescription {
|
|||
if (!cf.exactMatches.isEmpty()) {
|
||||
CurseforgeFingerprint.Mod f = cf.exactMatches.get(0);
|
||||
addSource(new CurseforgeModSource(f.id, f.file.id), gameVersion);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
// not found
|
||||
}
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
|
||||
public static ModDescription of(Path mod) {
|
||||
|
|
|
@ -67,14 +67,14 @@ public class ModsDirScanner implements Closeable {
|
|||
descriptions.put(mods, new IWModDescription(mods));
|
||||
} else {
|
||||
if (mods.toString().endsWith(".jar") || mods.toString().endsWith(".jar.disabled")) {
|
||||
Optional<Path> imod = Optional.of(mods.getParent().resolve(mods.getFileName() + ".imod"));
|
||||
Path imod = mods.getParent().resolve(mods.getFileName() + ".imod");
|
||||
// mod description
|
||||
if (!Files.exists(imod.get())) {
|
||||
Utils.writeObject(imod.get(), ModDescription.of(mods));
|
||||
if (!Files.exists(imod)) {
|
||||
Utils.writeObject(imod, ModDescription.of(mods));
|
||||
}
|
||||
ModDescription md = Utils.loadObject(imod.get(), ModDescription.class);
|
||||
evaluateSources(md, mods);
|
||||
descriptions.put(imod.get(), new IWModDescription(mods, Optional.of(md), getFmj(mods, md), imod));
|
||||
ModDescription md = Utils.loadObject(imod, ModDescription.class);
|
||||
evaluateSources(md, mods, imod);
|
||||
descriptions.put(imod, new IWModDescription(mods, Optional.of(md), getFmj(mods, md), Optional.of(imod)));
|
||||
}
|
||||
else if (mods.toString().endsWith(".imod")) {
|
||||
//TODO ensure this is not called while downloading a pack
|
||||
|
@ -84,7 +84,7 @@ public class ModsDirScanner implements Closeable {
|
|||
String fn = mods.getFileName().toString();
|
||||
Path modFile = mods.getParent().resolve(fn.substring(0, fn.length() - 5));
|
||||
ModDescription md = Utils.loadObject(mods, ModDescription.class);
|
||||
evaluateSources(md, modFile);
|
||||
evaluateSources(md, modFile, mods);
|
||||
descriptions.put(mods, new IWModDescription(mods, Optional.of(md), getFmj(modFile, md), Optional.of(mods)));
|
||||
}
|
||||
else {
|
||||
|
@ -99,8 +99,10 @@ public class ModsDirScanner implements Closeable {
|
|||
}
|
||||
}
|
||||
|
||||
private void evaluateSources(ModDescription md, Path modFile) throws IOException {
|
||||
md.initialize(getGameVersion());
|
||||
private void evaluateSources(ModDescription md, Path modFile, Path imodFile) throws IOException {
|
||||
if (md.initialize(getGameVersion())) {
|
||||
Utils.writeObject(imodFile, md);
|
||||
}
|
||||
boolean hasSource = false;
|
||||
for (ModSource source : md.sources.keySet()) {
|
||||
//Optional<ModSource> ms = source.getUpdate(instance.getMinecraftVersion());
|
||||
|
|
Loading…
Reference in New Issue