Some TODOs

This commit is contained in:
Johannes Frohnmeyer 2022-01-27 17:05:32 +01:00
parent 1e101d7239
commit 0eb72d859e
Signed by: Johannes
GPG Key ID: E76429612C2929F4
22 changed files with 323 additions and 414 deletions

View File

@ -10,6 +10,7 @@ stages:
- build
- portable
- deploy
- test
build_test:
stage: build
@ -90,3 +91,14 @@ pages:
- public
only:
- master
qodana:
stage: test
image:
name: jetbrains/qodana-jvm
entrypoint: ['']
script:
- /opt/idea/bin/entrypoint --results-dir=$CI_PROJECT_DIR/qodana --save-report --report-dir=$CI_PROJECT_DIR/qodana/report
artifacts:
paths:
- qodana

Binary file not shown.

View File

@ -1,5 +0,0 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

234
gradlew vendored
View File

@ -1,234 +0,0 @@
#!/bin/sh
#
# Copyright © 2015-2021 the original authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
##############################################################################
#
# Gradle start up script for POSIX generated by Gradle.
#
# Important for running:
#
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
# noncompliant, but you have some other compliant shell such as ksh or
# bash, then to run this script, type that shell name before the whole
# command line, like:
#
# ksh Gradle
#
# Busybox and similar reduced shells will NOT work, because this script
# requires all of these POSIX shell features:
# * functions;
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
# * compound commands having a testable exit status, especially «case»;
# * various built-in commands including «command», «set», and «ulimit».
#
# Important for patching:
#
# (2) This script targets any POSIX shell, so it avoids extensions provided
# by Bash, Ksh, etc; in particular arrays are avoided.
#
# The "traditional" practice of packing multiple parameters into a
# space-separated string is a well documented source of bugs and security
# problems, so this is (mostly) avoided, by progressively accumulating
# options in "$@", and eventually passing that to Java.
#
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
# see the in-line comments for details.
#
# There are tweaks for specific operating systems such as AIX, CygWin,
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
#
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
app_path=$0
# Need this for daisy-chained symlinks.
while
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
[ -h "$app_path" ]
do
ls=$( ls -ld "$app_path" )
link=${ls#*' -> '}
case $link in #(
/*) app_path=$link ;; #(
*) app_path=$APP_HOME$link ;;
esac
done
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
APP_NAME="Gradle"
APP_BASE_NAME=${0##*/}
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
warn () {
echo "$*"
} >&2
die () {
echo
echo "$*"
echo
exit 1
} >&2
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "$( uname )" in #(
CYGWIN* ) cygwin=true ;; #(
Darwin* ) darwin=true ;; #(
MSYS* | MINGW* ) msys=true ;; #(
NONSTOP* ) nonstop=true ;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD=$JAVA_HOME/jre/sh/java
else
JAVACMD=$JAVA_HOME/bin/java
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
fi
# Collect all arguments for the java command, stacking in reverse order:
# * args from the command line
# * the main class name
# * -classpath
# * -D...appname settings
# * --module-path (only if needed)
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
# For Cygwin or MSYS, switch paths to Windows format before running java
if "$cygwin" || "$msys" ; then
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
JAVACMD=$( cygpath --unix "$JAVACMD" )
# Now convert the arguments - kludge to limit ourselves to /bin/sh
for arg do
if
case $arg in #(
-*) false ;; # don't mess with options #(
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
[ -e "$t" ] ;; #(
*) false ;;
esac
then
arg=$( cygpath --path --ignore --mixed "$arg" )
fi
# Roll the args list around exactly as many times as the number of
# args, so each arg winds up back in the position where it started, but
# possibly modified.
#
# NB: a `for` loop captures its iteration list before it begins, so
# changing the positional parameters here affects neither the number of
# iterations, nor the values presented in `arg`.
shift # remove old arg
set -- "$@" "$arg" # push replacement arg
done
fi
# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.
set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
-classpath "$CLASSPATH" \
org.gradle.wrapper.GradleWrapperMain \
"$@"
# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
#
# In Bash we could simply go:
#
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
# set -- "${ARGS[@]}" "$@"
#
# but POSIX shell has neither arrays nor command substitution, so instead we
# post-process each arg (as a line of input to sed) to backslash-escape any
# character that might be a shell metacharacter, then use eval to reverse
# that process (while maintaining the separation between arguments), and wrap
# the whole thing up as a single "set" statement.
#
# This will of course break if any of these variables contains a newline or
# an unmatched quote.
#
eval "set -- $(
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
xargs -n1 |
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
tr '\n' ' '
)" '"$@"'
exec "$JAVACMD" "$@"

89
gradlew.bat vendored
View File

@ -1,89 +0,0 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

View File

@ -0,0 +1,33 @@
package io.gitlab.jfronny.inceptum.frontend.cli;
import io.gitlab.jfronny.inceptum.model.inceptum.Config;
import io.gitlab.jfronny.inceptum.model.inceptum.InstanceMeta;
import io.gitlab.jfronny.inceptum.util.ConfigHolder;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.transport.CredentialsProvider;
import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
import java.nio.file.Path;
import java.util.List;
public abstract class BaseGitCommand extends BaseInstanceCommand {
public BaseGitCommand(String help, String usage, String... aliases) {
super(help, usage, aliases);
}
public BaseGitCommand(String help, String usage, List<String> aliases, List<Command> subCommands) {
super(help, usage, aliases, subCommands);
}
@Override
protected void invoke(CommandArgs args, Path instancePath, InstanceMeta meta) throws Exception {
try (Git git = Git.open(instancePath.toFile())) {
Config.GitConfig.GitAuth config = ConfigHolder.CONFIG.git.instanceAuths.get(instancePath.getFileName().toString());
invoke(args.subArgs(), instancePath, meta, git, config.username != null && config.password != null
? new UsernamePasswordCredentialsProvider(config.username, config.password)
: CredentialsProvider.getDefault());
}
}
protected abstract void invoke(CommandArgs args, Path instancePath, InstanceMeta meta, Git git, CredentialsProvider credentials) throws Exception;
}

View File

@ -15,6 +15,7 @@ public class Commands {
new ListCommand(),
new ModCommand(),
new GitCommand(),
new ExportCommand(),
new UpdateCheckCommand(),
new JvmStateCommand(),
new BatchCommand(),

View File

@ -9,6 +9,7 @@ import io.gitlab.jfronny.inceptum.util.Utils;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.LinkedHashSet;
import java.util.Set;
@ -25,7 +26,7 @@ public class BatchCommand extends Command {
}
Set<CommandResolution> resolved = new LinkedHashSet<>();
for (String arg : args) {
Path p = Path.of(arg);
Path p = Paths.get(arg);
if (!Files.exists(p)) {
Utils.LOGGER.error("Could not find " + p);
return;

View File

@ -0,0 +1,54 @@
package io.gitlab.jfronny.inceptum.frontend.cli.commands;
import io.gitlab.jfronny.inceptum.frontend.cli.BaseGitCommand;
import io.gitlab.jfronny.inceptum.frontend.cli.Command;
import io.gitlab.jfronny.inceptum.frontend.cli.CommandArgs;
import io.gitlab.jfronny.inceptum.model.inceptum.InstanceMeta;
import io.gitlab.jfronny.inceptum.util.InstanceExporter;
import io.gitlab.jfronny.inceptum.util.ProcessState;
import io.gitlab.jfronny.inceptum.util.mds.ModsDirScanner;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.transport.CredentialsProvider;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
//TODO modrinth
public class ExportCommand extends BaseGitCommand {
public ExportCommand() {
this(List.of("export"), List.of(
new MultiMCExportCommand(List.of("multimc", "mmc"), List.of())
));
}
private ExportCommand(List<String> aliases, List<Command> subCommands) {
super("Export a CurseForge instance", "<export path>", List.of("export"), subCommands);
}
@Override
protected void invoke(CommandArgs args, Path instancePath, InstanceMeta meta, Git git, CredentialsProvider credentials) throws Exception {
if (args.length == 0) throw new IllegalAccessException("You must specify a target path");
if (args.length != 1) throw new IllegalAccessException("Too many arguments");
ProcessState state = new ProcessState();
ModsDirScanner mds = ModsDirScanner.get(instancePath.resolve("mods"), meta);
mds.runOnce((path, mod) -> {});
InstanceExporter.exportCurseZip(state, instancePath, meta, mds, git, Paths.get(args.get(0)));
}
private static class MultiMCExportCommand extends BaseGitCommand {
public MultiMCExportCommand(List<String> aliases, List<Command> subCommands) {
super("Export a MultiMC instance", "<export path>", aliases, subCommands);
}
@Override
protected void invoke(CommandArgs args, Path instancePath, InstanceMeta meta, Git git, CredentialsProvider credentials) throws Exception {
if (args.length == 0) throw new IllegalAccessException("You must specify a target path");
if (args.length != 1) throw new IllegalAccessException("Too many arguments");
ProcessState state = new ProcessState();
ModsDirScanner mds = ModsDirScanner.get(instancePath.resolve("mods"), meta);
mds.runOnce((path, mod) -> {});
InstanceExporter.exportMultiMCZip(state, instancePath, meta, mds, git, Paths.get(args.get(0)));
}
}
}

View File

@ -1,11 +1,9 @@
package io.gitlab.jfronny.inceptum.frontend.cli.commands;
import io.gitlab.jfronny.inceptum.frontend.cli.BaseInstanceCommand;
import io.gitlab.jfronny.inceptum.frontend.cli.BaseGitCommand;
import io.gitlab.jfronny.inceptum.frontend.cli.Command;
import io.gitlab.jfronny.inceptum.frontend.cli.CommandArgs;
import io.gitlab.jfronny.inceptum.model.inceptum.Config;
import io.gitlab.jfronny.inceptum.model.inceptum.InstanceMeta;
import io.gitlab.jfronny.inceptum.util.ProcessState;
import io.gitlab.jfronny.inceptum.util.install.Steps;
import io.gitlab.jfronny.inceptum.util.ConfigHolder;
import io.gitlab.jfronny.inceptum.util.MetaHolder;
@ -14,7 +12,6 @@ import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.transport.CredentialsProvider;
import org.eclipse.jgit.transport.URIish;
import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
import java.io.FileNotFoundException;
import java.io.IOException;
@ -40,31 +37,13 @@ public class GitCommand extends Command {
Utils.LOGGER.error("No known git command was specified");
}
private static abstract class BaseGitCommand extends BaseInstanceCommand {
public BaseGitCommand(String help, String usage, String... aliases) {
super(help, usage, aliases);
}
@Override
protected void invoke(CommandArgs args, Path instancePath, InstanceMeta meta) throws Exception {
try (Git git = Git.open(instancePath.toFile())) {
Config.GitConfig.GitAuth config = ConfigHolder.CONFIG.git.instanceAuths.get(instancePath.getFileName().toString());
invoke(args.subArgs(), instancePath, git, config.username != null && config.password != null
? new UsernamePasswordCredentialsProvider(config.username, config.password)
: CredentialsProvider.getDefault());
}
}
protected abstract void invoke(CommandArgs args, Path instancePath, Git git, CredentialsProvider credentials) throws Exception;
}
private static class CommitCommand extends BaseGitCommand {
public CommitCommand() {
super("Adds and commits all changes in the instance.", "[message...]", "commit");
}
@Override
protected void invoke(CommandArgs args, Path instancePath, Git git, CredentialsProvider credentials) throws GitAPIException {
protected void invoke(CommandArgs args, Path instancePath, InstanceMeta meta, Git git, CredentialsProvider credentials) throws GitAPIException {
git.commit()
.setAll(true)
.setMessage(args.length > 1
@ -83,7 +62,7 @@ public class GitCommand extends Command {
}
@Override
protected void invoke(CommandArgs args, Path instancePath, Git git, CredentialsProvider credentials) throws GitAPIException {
protected void invoke(CommandArgs args, Path instancePath, InstanceMeta meta, Git git, CredentialsProvider credentials) throws GitAPIException {
git.push()
.setCredentialsProvider(credentials)
.call();
@ -96,7 +75,7 @@ public class GitCommand extends Command {
}
@Override
protected void invoke(CommandArgs args, Path instancePath, Git git, CredentialsProvider credentials) throws GitAPIException {
protected void invoke(CommandArgs args, Path instancePath, InstanceMeta meta, Git git, CredentialsProvider credentials) throws GitAPIException {
git.pull()
.setRebase(true)
.setCredentialsProvider(credentials)
@ -110,7 +89,7 @@ public class GitCommand extends Command {
}
@Override
protected void invoke(CommandArgs args, Path instancePath, Git git, CredentialsProvider credentials) throws GitAPIException {
protected void invoke(CommandArgs args, Path instancePath, InstanceMeta meta, Git git, CredentialsProvider credentials) throws GitAPIException {
git.checkout()
.setAllPaths(true)
.call();

View File

@ -14,6 +14,7 @@ import io.gitlab.jfronny.inceptum.util.install.Steps;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@ -49,7 +50,7 @@ public class LaunchCommand extends BaseInstanceCommand {
return;
}
String pArg = args.get(0);
Path instanceDir = Files.exists(Path.of(pArg)) ? Path.of(pArg) : MetaHolder.INSTANCE_DIR.resolve(pArg);
Path instanceDir = Files.exists(Paths.get(pArg)) ? Paths.get(pArg) : MetaHolder.INSTANCE_DIR.resolve(pArg);
if (!Files.exists(instanceDir.resolve("instance.json"))) {
Utils.LOGGER.error("Not a valid instance");
return;

View File

@ -9,10 +9,14 @@ import io.gitlab.jfronny.inceptum.model.inceptum.InstanceMeta;
import io.gitlab.jfronny.inceptum.util.ModManager;
import io.gitlab.jfronny.inceptum.util.PathUtil;
import io.gitlab.jfronny.inceptum.util.Utils;
import io.gitlab.jfronny.inceptum.util.lambda.ThrowingBiFunction;
import io.gitlab.jfronny.inceptum.util.lambda.ThrowingFunction;
import io.gitlab.jfronny.inceptum.util.lambda.ThrowingSupplier;
import io.gitlab.jfronny.inceptum.util.mds.IWModDescription;
import io.gitlab.jfronny.inceptum.util.mds.ModsDirScanner;
import io.gitlab.jfronny.inceptum.util.source.ModSource;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
@ -127,30 +131,39 @@ public class ModCommand extends Command {
}
public static class ModUpdateCommand extends BaseInstanceCommand {
private final ThrowingBiFunction<CommandArgs, Path, Set<Path>, IOException> pathSupplier;
public ModUpdateCommand() {
super("Update mods in an instance", "<mod file>...", "update", "upgrade", "up");
this("Update mods in an instance", "<mod file>...", List.of("update", "upgrade", "up"), List.of(
new ModUpdateCommand("Update all mods in an instance", "", List.of("all"), List.of(), (args, instancePath) -> Set.copyOf(Utils.ls(instancePath)))
), (args, instancePath) -> {
Set<Path> mods = new HashSet<>();
for (String arg : args) {
Path p = instancePath.resolve("mods").resolve(arg);
if (!Files.exists(p)) p = instancePath.resolve("mods").resolve(arg + ".imod");
if (!Files.exists(p)) {
throw new FileNotFoundException("Nonexistant mod file: " + instancePath.resolve("mods").resolve(arg));
}
mods.add(p);
}
return mods;
});
}
private ModUpdateCommand(String help, String usage, List<String> aliases, List<Command> subCommands, ThrowingBiFunction<CommandArgs, Path, Set<Path>, IOException> pathSupplier) {
super(help, usage, aliases, subCommands);
this.pathSupplier = pathSupplier;
}
@Override
protected void invoke(CommandArgs args, Path instancePath, InstanceMeta meta) throws IOException {
if (!meta.isFabric()) {
Utils.LOGGER.error("This is not a fabric instance");
return;
throw new IOException("This is not a fabric instance");
}
if (args.length == 0) {
Utils.LOGGER.error("You must specify mods to remove");
return;
}
Set<Path> mods = new HashSet<>();
for (String arg : args) {
Path p = instancePath.resolve("mods").resolve(arg);
if (!Files.exists(p)) p = instancePath.resolve("mods").resolve(arg + ".imod");
if (!Files.exists(p)) {
Utils.LOGGER.error("Nonexistant mod file: " + instancePath.resolve("mods").resolve(arg));
return;
}
mods.add(p);
throw new IllegalArgumentException("You must specify mods to remove");
}
Set<Path> mods = pathSupplier.apply(args, instancePath);
ModsDirScanner mds = ModsDirScanner.get(instancePath.resolve("mods"), meta);
if (!mds.isComplete()) {
Utils.LOGGER.error("Scanning mods dir to search for dependencies. This might take a while");
@ -162,8 +175,7 @@ public class ModCommand extends Command {
ModManager.delete(mds.get(mod), instancePath.resolve("mods"), mds);
IWModDescription md = mds.get(mod);
if (md.mod().isEmpty()) {
Utils.LOGGER.error("Could not load mod description");
return;
throw new IOException("Could not load mod description");
}
boolean found = false;
for (Map.Entry<ModSource, Optional<ModSource>> source : md.mod().get().sources.entrySet()) {
@ -181,14 +193,13 @@ public class ModCommand extends Command {
Utils.LOGGER.info("Update completed");
found = true;
} catch (IOException e) {
Inceptum.showError("Update failed", e);
throw new IOException("Update failed", e);
}
}
}
if (!found) Utils.LOGGER.error("Could not find any update");
} catch (IOException e) {
Utils.LOGGER.error("Could not delete " + mod, e);
return;
throw new IOException("Could not delete " + mod, e);
}
}
}

View File

@ -41,7 +41,7 @@ public class NewInstanceWindow extends Window {
});
ImGui.endTabItem();
}
if (ImGui.beginTabItem("Inceptum")) {
if (ImGui.beginTabItem("Clone")) {
if (ImGui.inputTextWithHint("URL", "Repo to download", inceptumRepo)
&& (inceptumName.isEmpty() || inceptumName.get().isEmpty() || inceptumName.get().equals(inceptumNamePrev))) {
try {
@ -61,12 +61,9 @@ public class NewInstanceWindow extends Window {
}
ImGui.endTabItem();
}
if (ImGui.beginTabItem("CurseForge")) {
ImGui.text("Importing CurseForge packs is not yet implemented");
ImGui.endTabItem();
}
if (ImGui.beginTabItem("Modrinth")) {
ImGui.text("Importing Modrinth packs is not yet implemented");
if (ImGui.beginTabItem("Import")) {
ImGui.text("Importing CurseForge or Modrinth packs is not yet implemented");
//TODO generic importer based on zip contents and file name ("mrpack")
ImGui.endTabItem();
}
ImGui.endTabBar();

View File

@ -7,11 +7,15 @@ import io.gitlab.jfronny.inceptum.frontend.gui.control.Tab;
import io.gitlab.jfronny.inceptum.frontend.gui.window.dialog.ProcessStateWatcherWindow;
import io.gitlab.jfronny.inceptum.util.InstanceExporter;
import io.gitlab.jfronny.inceptum.util.ProcessState;
import io.gitlab.jfronny.inceptum.util.lambda.ThrowingBiConsumer;
import org.lwjgl.PointerBuffer;
import org.lwjgl.system.MemoryStack;
import org.lwjgl.util.tinyfd.TinyFileDialogs;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
public class ExportTab extends Tab {
private final InstanceEditWindow window;
@ -24,25 +28,34 @@ public class ExportTab extends Tab {
@Override
protected void renderInner() {
if (window.mds.isComplete()) {
if (ImGui.button("CurseForge")) {
try (MemoryStack stack = MemoryStack.stackPush()) {
PointerBuffer aFilterPatterns = stack.mallocPointer(2);
aFilterPatterns.put(stack.UTF8("*.zip"));
aFilterPatterns.flip();
String p = TinyFileDialogs.tinyfd_saveFileDialog("Export Pack", "", aFilterPatterns, "CurseForge packs (*.zip)");
if (p != null) {
ProcessState state = new ProcessState(InstanceExporter.STEP_COUNT, "Initializing...");
InceptumGui.open(new ProcessStateWatcherWindow("Exporting", "Could not export pack", state, cToken -> {
Path exportPath = Path.of(p);
InstanceExporter.exportCurseZip(state, window.path, window.instance, window.mds, window.git, exportPath);
Inceptum.showInfo(window.path.getFileName().toString() + " has been successfully exported to " + exportPath, "Successfully exported");
}, null));
}
}
}
exportVariant("CurseForge", "zip", (state, exportPath) -> {
InstanceExporter.exportCurseZip(state, window.path, window.instance, window.mds, window.git, exportPath);
});
exportVariant("MultiMC", "zip", (state, exportPath) -> {
InstanceExporter.exportMultiMCZip(state, window.path, window.instance, window.mds, window.git, exportPath);
});
}
else {
ImGui.text("The mods directory scan must be completed.\nThe progress for this can be observed in the mods tab");
}
}
private <T extends Throwable> void exportVariant(String name, String packExt, ThrowingBiConsumer<ProcessState, Path, T> export) {
if (ImGui.button(name)) {
try (MemoryStack stack = MemoryStack.stackPush()) {
PointerBuffer aFilterPatterns = stack.mallocPointer(2);
aFilterPatterns.put(stack.UTF8("*." + packExt));
aFilterPatterns.flip();
String p = TinyFileDialogs.tinyfd_saveFileDialog("Export Pack", "", aFilterPatterns, name + " packs (*." + packExt + ")");
if (p != null) {
ProcessState state = new ProcessState(InstanceExporter.STEP_COUNT, "Initializing...");
InceptumGui.open(new ProcessStateWatcherWindow("Exporting", "Could not export pack", state, cToken -> {
Path exportPath = Paths.get(p);
export.consume(state, exportPath);
Inceptum.showInfo(window.path.getFileName().toString() + " has been successfully exported to " + exportPath, "Successfully exported");
}, null));
}
}
}
}
}

View File

@ -0,0 +1,15 @@
package io.gitlab.jfronny.inceptum.model.multimc;
import java.util.List;
public class MMCPackMeta {
public List<Component> components;
public Integer formatVersion;
public static class Component {
public Boolean dependencyOnly;
public Boolean important;
public String uid;
public String version;
}
}

View File

@ -2,6 +2,7 @@ package io.gitlab.jfronny.inceptum.util;
import io.gitlab.jfronny.inceptum.model.curseforge.CurseforgeModpackManifest;
import io.gitlab.jfronny.inceptum.model.inceptum.InstanceMeta;
import io.gitlab.jfronny.inceptum.model.multimc.MMCPackMeta;
import io.gitlab.jfronny.inceptum.util.mds.IWModDescription;
import io.gitlab.jfronny.inceptum.util.mds.ModsDirScanner;
import io.gitlab.jfronny.inceptum.util.source.CurseforgeModSource;
@ -16,14 +17,19 @@ import java.net.URISyntaxException;
import java.nio.file.FileSystem;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Instant;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
//TODO deduplicate
//TODO modrinth export
public class InstanceExporter {
public static final int STEP_COUNT = 3;
private static final String OVERRIDES_DIR_DEFAULT = "overrides";
private static final String DOT_MINECRAFT = ".minecraft";
public static void exportCurseZip(ProcessState state, Path instanceDir, InstanceMeta meta, ModsDirScanner mds, Git git, Path exportPath) throws IOException, URISyntaxException, GitAPIException {
if (Files.exists(exportPath)) Files.delete(exportPath);
@ -101,4 +107,107 @@ public class InstanceExporter {
Utils.writeObject(fs.getPath("manifest.json"), manifest);
}
}
public static void exportMultiMCZip(ProcessState state, Path instanceDir, InstanceMeta meta, ModsDirScanner mds, Git git, Path exportPath) throws IOException, URISyntaxException, GitAPIException {
if (Files.exists(exportPath)) Files.delete(exportPath);
try (FileSystem fs = Utils.openZipFile(exportPath, true)) {
{
state.incrementStep("Preparing basic manifest");
MMCPackMeta manifest = new MMCPackMeta();
manifest.formatVersion = 1;
manifest.components = new ArrayList<>();
MMCPackMeta.Component lwjgl = new MMCPackMeta.Component();
lwjgl.dependencyOnly = true;
lwjgl.uid = "org.lwjgl3";
lwjgl.version = "3.2.2"; //TODO get automatically
manifest.components.add(lwjgl);
MMCPackMeta.Component minecraft = new MMCPackMeta.Component();
minecraft.important = true;
minecraft.uid = "net.minecraft";
minecraft.version = meta.getMinecraftVersion();
manifest.components.add(minecraft);
if (meta.isFabric()) {
MMCPackMeta.Component intermediary = new MMCPackMeta.Component();
intermediary.dependencyOnly = true;
intermediary.uid = "net.fabricmc.intermediary";
intermediary.version = meta.getMinecraftVersion();
manifest.components.add(intermediary);
MMCPackMeta.Component fabric = new MMCPackMeta.Component();
fabric.uid = "net.fabricmc.fabric-loader";
fabric.version = meta.getLoaderVersion();
manifest.components.add(fabric);
}
Utils.writeObject(fs.getPath("mmc-pack.json"), manifest);
}
{
state.updateStep("Preparing instance config");
Files.writeString(fs.getPath("instance.cfg"), String.format("""
ForgeVersion=
InstanceType=OneSix
IntendedVersion=
JoinServerOnLaunch=false
LWJGLVersion=
LiteloaderVersion=
LogPrePostOutput=true
MCLaunchMethod=LauncherPart
OverrideCommands=false
OverrideConsole=false
OverrideGameTime=false
OverrideJavaArgs=false
OverrideJavaLocation=false
OverrideMCLaunchMethod=false
OverrideMemory=false
OverrideNativeWorkarounds=false
OverrideWindow=false
iconKey=default
lastLaunchTime=%s
lastTimePlayed=0
name=%s
notes=
totalTimePlayed=0
""", Instant.now().toEpochMilli(), instanceDir.getFileName()));
}
Path overrides = fs.getPath(DOT_MINECRAFT);
Files.createDirectories(overrides);
if (meta.isFabric()) {
state.incrementStep("Adding mods");
if (!mds.isComplete()) throw new IOException("Mods dir scan is not yet completed");
modsLoop: for (IWModDescription mod : mds.getMods()) {
if (!PathUtil.isEnabled(mod.path())) return;
state.updateStep(mod.path().toString());
if (PathUtil.isImod(mod.path())) {
Set<ModSource> sources = mod.mod().get().sources.keySet();
for (ModSource source : sources) {
Path jarPath = source.getJarPath();
Files.copy(jarPath, jarPath.resolve(mod.path().getFileName().toString()));
continue modsLoop;
}
}
Path md = overrides.resolve("mods");
Files.createDirectories(md);
Files.copy(mod.path(), md.resolve(mod.path().getFileName().toString()));
}
}
state.incrementStep("Adding files");
List<Path> discovered = new ArrayList<>();
try (TreeWalk treeWalk = new TreeWalk(git.getRepository())) {
treeWalk.addTree(new FileTreeIterator(git.getRepository()));
treeWalk.setRecursive(false);
while (treeWalk.next()) {
if (treeWalk.getPathString().startsWith("mods")) continue;
discovered.add(instanceDir.resolve(treeWalk.getPathString()));
}
}
for (Path l : discovered) {
String fn = l.getFileName().toString();
if (fn.equals("mods") || fn.startsWith(".")) continue;
state.updateStep(fn);
Path target = overrides.resolve(fn);
if (Files.isDirectory(l)) {
Utils.copyContent(l, target);
}
else Files.copy(l, target);
}
}
}
}

View File

@ -3,6 +3,7 @@ package io.gitlab.jfronny.inceptum.util.mds;
import io.gitlab.jfronny.inceptum.model.inceptum.InstanceMeta;
import io.gitlab.jfronny.inceptum.util.PathUtil;
import io.gitlab.jfronny.inceptum.util.Utils;
import io.gitlab.jfronny.inceptum.util.lambda.ThrowingConsumer;
import java.io.Closeable;
import java.io.IOException;
@ -103,11 +104,6 @@ class ModsDirScannerImpl implements ModsDirScanner {
private void scanTaskInternal() {
while (!disposed) {
runOnce((path, iwModDescription) -> {});
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
@ -123,12 +119,12 @@ class ModsDirScannerImpl implements ModsDirScanner {
scannedPaths.add(path);
descriptions.put(path, iwModDescription);
});
List<Path> toScan;
Set<Path> toScan;
if (descriptions.isEmpty()) {
toScan = Utils.ls(modsDir);
toScan = Set.copyOf(Utils.ls(modsDir));
}
else {
toScan = new ArrayList<>();
toScan = new HashSet<>();
WatchKey key = service.poll();
if (key != null) {
for (WatchEvent<?> event : key.pollEvents()) {
@ -137,6 +133,10 @@ class ModsDirScannerImpl implements ModsDirScanner {
}
key.reset();
}
Utils.ls(modsDir, path -> {
if (!descriptions.containsKey(path))
toScan.add(path);
});
}
for (Path p : toScan) {
tasks.add(POOL.submit(new FileScanTask(p, discovered, mc)));

View File

@ -28,6 +28,6 @@ public class JvmUtils {
}
public static String getJvm() {
return getJvmMain(Path.of(System.getProperty("java.home"))).toAbsolutePath().toString();
return getJvmMain(Paths.get(System.getProperty("java.home"))).toAbsolutePath().toString();
}
}

View File

@ -13,6 +13,7 @@ import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
public class MetaHolder {
public static final InceptumVersion VERSION;
@ -32,7 +33,7 @@ public class MetaHolder {
: runDir;
}
else {
BASE_PATH = Path.of(System.getProperty("inceptum.base"));
BASE_PATH = Paths.get(System.getProperty("inceptum.base"));
}
} catch (IOException e) {
throw new RuntimeException("Could not get version info", e);
@ -49,14 +50,14 @@ public class MetaHolder {
private static Path getConfigPath() {
return switch (OSCheck.OS) {
case WINDOWS -> Path.of(System.getenv("APPDATA"));
case MAC_OS -> Path.of(System.getProperty("user.home")).resolve("Library").resolve("Application Support");
case WINDOWS -> Paths.get(System.getenv("APPDATA"));
case MAC_OS -> Paths.get(System.getProperty("user.home")).resolve("Library").resolve("Application Support");
case LINUX -> {
String s = System.getenv().get("XDG_CONFIG_HOME");
if (s == null)
yield Path.of(System.getProperty("user.home")).resolve(".config");
yield Paths.get(System.getProperty("user.home")).resolve(".config");
else
yield Path.of(s);
yield Paths.get(s);
}
};
}

View File

@ -0,0 +1,5 @@
package io.gitlab.jfronny.inceptum.util.lambda;
public interface ThrowingBiConsumer<T, U, TEx extends Throwable> {
void consume(T var1, U var2) throws TEx;
}

View File

@ -0,0 +1,5 @@
package io.gitlab.jfronny.inceptum.util.lambda;
public interface ThrowingBiFunction<TIn, UIn, TOut, TEx extends Throwable> {
TOut apply(TIn var1, UIn var2) throws TEx;
}

View File

@ -1,5 +1,5 @@
package io.gitlab.jfronny.inceptum.util.lambda;
public interface ThrowingConsumer<T, TEx extends Throwable> {
void consume(T val) throws TEx;
void consume(T var) throws TEx;
}