mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 03:31:15 +03:00
[FEATURE] MakeProfileCommand
This commit is contained in:
parent
442ff9b752
commit
736aa93106
4 changed files with 64 additions and 14 deletions
|
@ -46,6 +46,7 @@ public static void registerCommands(pro.gravit.utils.command.CommandHandler hand
|
|||
updates.registerCommand("syncProfiles", new SyncProfilesCommand(server));
|
||||
updates.registerCommand("syncUP", new SyncUPCommand(server));
|
||||
updates.registerCommand("saveProfiles", new SaveProfilesCommand(server));
|
||||
updates.registerCommand("makeProfile", new MakeProfileCommand(server));
|
||||
Category updatesCategory = new Category(updates, "updates", "Update and Sync Management");
|
||||
handler.registerCategory(updatesCategory);
|
||||
|
||||
|
|
|
@ -60,18 +60,24 @@ public void invoke(String... args) throws IOException, CommandException {
|
|||
// Create profile file
|
||||
logger.info("Creaing profile file: '{}'", dirName);
|
||||
ClientProfile client = null;
|
||||
try {
|
||||
String internalVersion = versionName;
|
||||
if (internalVersion.contains("-")) {
|
||||
internalVersion = internalVersion.substring(0, versionName.indexOf('-'));
|
||||
if (!isMirrorClientDownload) {
|
||||
try {
|
||||
String internalVersion = versionName;
|
||||
if (internalVersion.contains("-")) {
|
||||
internalVersion = internalVersion.substring(0, versionName.indexOf('-'));
|
||||
}
|
||||
ClientProfile.Version version = ClientProfile.Version.byName(internalVersion);
|
||||
if (version.compareTo(ClientProfile.Version.MC164) <= 0) {
|
||||
logger.warn("Minecraft 1.6.4 and below not supported. Use at your own risk");
|
||||
}
|
||||
SaveProfilesCommand.MakeProfileOption[] options = SaveProfilesCommand.getMakeProfileOptionsFromDir(clientDir, version);
|
||||
for (SaveProfilesCommand.MakeProfileOption option : options) {
|
||||
logger.debug("Detected option {}", option);
|
||||
}
|
||||
client = SaveProfilesCommand.makeProfile(version, dirName, options);
|
||||
} catch (Throwable e) {
|
||||
isMirrorClientDownload = true;
|
||||
}
|
||||
ClientProfile.Version version = ClientProfile.Version.byName(internalVersion);
|
||||
if (version.compareTo(ClientProfile.Version.MC164) <= 0) {
|
||||
logger.warn("Minecraft 1.6.4 and below not supported. Use at your own risk");
|
||||
}
|
||||
client = SaveProfilesCommand.makeProfile(version, dirName, SaveProfilesCommand.getMakeProfileOptionsFromDir(clientDir, version));
|
||||
} catch (Throwable e) {
|
||||
isMirrorClientDownload = true;
|
||||
}
|
||||
if (isMirrorClientDownload) {
|
||||
JsonElement clientJson = server.mirrorManager.jsonRequest(null, "GET", "clients/%s.json", versionName);
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
package pro.gravit.launchserver.command.hash;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import pro.gravit.launcher.Launcher;
|
||||
import pro.gravit.launcher.profiles.ClientProfile;
|
||||
import pro.gravit.launchserver.LaunchServer;
|
||||
import pro.gravit.launchserver.command.Command;
|
||||
import pro.gravit.utils.helper.IOHelper;
|
||||
|
||||
import java.io.Writer;
|
||||
|
||||
public class MakeProfileCommand extends Command {
|
||||
private transient final Logger logger = LogManager.getLogger();
|
||||
|
||||
public MakeProfileCommand(LaunchServer server) {
|
||||
super(server);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getArgsDescription() {
|
||||
return "[name] [minecraft version] [dir]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsageDescription() {
|
||||
return "make profile for any minecraft versions";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(String... args) throws Exception {
|
||||
verifyArgs(args, 3);
|
||||
ClientProfile.Version version = ClientProfile.Version.byName(args[2]);
|
||||
SaveProfilesCommand.MakeProfileOption[] options = SaveProfilesCommand.getMakeProfileOptionsFromDir(server.updatesDir.resolve(args[2]), version);
|
||||
for (SaveProfilesCommand.MakeProfileOption option : options) {
|
||||
logger.info("Detected option {}", option);
|
||||
}
|
||||
ClientProfile profile = SaveProfilesCommand.makeProfile(ClientProfile.Version.byName(args[1]), args[0], options);
|
||||
try (Writer writer = IOHelper.newWriter(server.profilesDir.resolve(args[0].concat(".json")))) {
|
||||
Launcher.gsonManager.gson.toJson(profile, writer);
|
||||
}
|
||||
logger.info("Profile {} created", args[0]);
|
||||
server.syncProfilesDir();
|
||||
}
|
||||
}
|
|
@ -68,9 +68,7 @@ public static List<JavaVersion> findJava() {
|
|||
Path p1 = Paths.get(p);
|
||||
Path javaExecPath = JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE ? p1.resolve("java.exe") : p1.resolve("java");
|
||||
if (Files.exists(javaExecPath)) {
|
||||
if (Files.isSymbolicLink(javaExecPath)) {
|
||||
javaExecPath = javaExecPath.toRealPath();
|
||||
}
|
||||
javaExecPath = javaExecPath.toRealPath();
|
||||
p1 = javaExecPath.getParent().getParent();
|
||||
tryAddJava(javaPaths, result, JavaVersion.getByPath(p1));
|
||||
trySearchJava(javaPaths, result, p1.getParent());
|
||||
|
|
Loading…
Reference in a new issue