Add mod failure identification

This commit is contained in:
JoJoDeveloping 2019-06-22 04:00:56 +02:00
parent 5a3b375147
commit b9e5dfd286
No known key found for this signature in database
GPG Key ID: 124FAA37C4711CBF
3 changed files with 88 additions and 1 deletions

View File

@ -0,0 +1,80 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2019.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.fml.loading.moddiscovery;
import cpw.mods.modlauncher.api.LamdbaExceptionUtils.Supplier_WithExceptions;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Optional;
import java.util.function.BiPredicate;
import java.util.zip.ZipFile;
import static cpw.mods.modlauncher.api.LamdbaExceptionUtils.*;
public enum InvalidModIdentifier {
OLDFORGE(filePresent("mcmod.info")),
FABRIC(filePresent("fabric.mod.json")),
LITELOADER(filePresent("litemod.json")),
OPTIFINE(filePresent("optifine/Installer.class")),
INVALIDZIP((f,zf) -> !zf.isPresent());
private BiPredicate<Path, Optional<ZipFile>> ident;
InvalidModIdentifier(BiPredicate<Path, Optional<ZipFile>> identifier)
{
this.ident = identifier;
}
private String getReason()
{
return "fml.modloading.brokenfile." + this.name().toLowerCase();
}
public static Optional<String> identifyJarProblem(Path path)
{
Optional<ZipFile> zfo = optionalFromException(() -> new ZipFile(path.toFile()));
Optional<String> result = Arrays.stream(values()).
filter(i -> i.ident.test(path, zfo)).
map(InvalidModIdentifier::getReason).
findAny();
zfo.ifPresent(rethrowConsumer(ZipFile::close));
return result;
}
private static BiPredicate<Path, Optional<ZipFile>> filePresent(String filename)
{
return (f, zfo) -> zfo.map(zf -> zf.getEntry(filename) != null).orElse(false);
}
private static <T> Optional<T> optionalFromException(Supplier_WithExceptions<T, ? extends Exception> supp)
{
try
{
return Optional.of(supp.get());
}
catch (Exception e)
{
return Optional.empty();
}
}
}

View File

@ -34,6 +34,7 @@ import net.minecraftforge.fml.event.lifecycle.ModLifecycleEvent;
import net.minecraftforge.fml.loading.FMLLoader;
import net.minecraftforge.fml.loading.FMLPaths;
import net.minecraftforge.fml.loading.LoadingModList;
import net.minecraftforge.fml.loading.moddiscovery.InvalidModIdentifier;
import net.minecraftforge.fml.loading.moddiscovery.ModFile;
import net.minecraftforge.fml.loading.moddiscovery.ModFileInfo;
import net.minecraftforge.fml.network.FMLNetworkConstants;
@ -109,7 +110,8 @@ public class ModLoader
this.loadingExceptions = FMLLoader.getLoadingModList().
getErrors().stream().flatMap(ModLoadingException::fromEarlyException).collect(Collectors.toList());
this.loadingWarnings = FMLLoader.getLoadingModList().
getBrokenFiles().stream().map(file -> new ModLoadingWarning(null, ModLoadingStage.VALIDATE, "fml.modloading.brokenfile", file.getFileName())).collect(Collectors.toList());
getBrokenFiles().stream().map(file -> new ModLoadingWarning(null, ModLoadingStage.VALIDATE,
InvalidModIdentifier.identifyJarProblem(file.getFilePath()).orElse("fml.modloading.brokenfile"), file.getFileName())).collect(Collectors.toList());
LOGGER.info(CORE, "Loading Network data for FML net version: {}", FMLNetworkConstants.NETVERSION);
}

View File

@ -49,6 +49,11 @@
"fml.modloading.cycle": "Detected a mod dependency cycle: {0}",
"fml.modloading.failedtoprocesswork":"{0,modinfo,name} ({0,modinfo,id}) encountered an error processing deferred work\n\u00a77{2,exc,msg}",
"fml.modloading.brokenfile": "File {2} is not a valid mod file",
"fml.modloading.brokenfile.oldforge": "File {2} is for an older version of Forge and cannot be loaded",
"fml.modloading.brokenfile.liteloader": "File {2} is a LiteLoader mod and cannot be loaded",
"fml.modloading.brokenfile.fabric": "File {2} is a Fabric mod and cannot be loaded",
"fml.modloading.brokenfile.optifine": "File {2} is OptiFine, which is unsupported",
"fml.modloading.brokenfile.invalidzip": "File {2} is not a jar file",
"fml.modloading.brokenresources": "File {2} failed to load a valid ResourcePackInfo",
"fml.messages.artifactversion.ornotinstalled":"{0,ornull,fml.messages.artifactversion.notinstalled}",