55 lines
2.1 KiB
Java
55 lines
2.1 KiB
Java
package io.gitlab.jfronny.inceptum.install.steps;
|
|
|
|
import io.gitlab.jfronny.inceptum.Inceptum;
|
|
import io.gitlab.jfronny.inceptum.install.SetupStepInfo;
|
|
import io.gitlab.jfronny.inceptum.install.Step;
|
|
import io.gitlab.jfronny.inceptum.model.inceptum.InstanceMeta;
|
|
import io.gitlab.jfronny.inceptum.util.Utils;
|
|
import org.eclipse.jgit.api.Git;
|
|
import org.eclipse.jgit.api.errors.GitAPIException;
|
|
|
|
import java.io.IOException;
|
|
import java.nio.file.Files;
|
|
import java.nio.file.Path;
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
|
public class WriteMetadataStep implements Step {
|
|
@Override
|
|
public void execute(SetupStepInfo info, AtomicBoolean stopThread) throws IOException {
|
|
info.setState("Writing metadata");
|
|
Path instance = Inceptum.INSTANCE_DIR.resolve(info.name());
|
|
Path metaDir = instance.resolve("instance.json");
|
|
InstanceMeta meta = new InstanceMeta();
|
|
meta.version = info.version().id;
|
|
Utils.writeObject(metaDir, meta);
|
|
Path lock = instance.resolve("inceptum.setup.lock");
|
|
if (Files.exists(lock)) Files.delete(lock);
|
|
if (!Files.exists(instance.resolve(".gitignore"))) {
|
|
Files.writeString(instance.resolve(".gitignore"), """
|
|
realms_persistence.json
|
|
saves/
|
|
screenshots/
|
|
logs/
|
|
.mixin.out/
|
|
.fabric/
|
|
*.lock
|
|
eula.txt""");
|
|
}
|
|
Path gitDir = instance.resolve(".git");
|
|
if (!Files.exists(gitDir)) {
|
|
try (Git git = Git.init()
|
|
.setDirectory(instance.toFile())
|
|
.setGitDir(gitDir.toFile())
|
|
.call()) {
|
|
//TODO use proper git identity
|
|
git.add().addFilepattern(".").call();
|
|
git.commit().setMessage("Initial commit")
|
|
.setSign(false)
|
|
.setAuthor("Inceptum", "inceptum@jfronny.gitlab.io").call();
|
|
} catch (GitAPIException e) {
|
|
Inceptum.showError("Could not initialize Git", e);
|
|
}
|
|
}
|
|
}
|
|
}
|