[FEATURE] Default value for client profile and assets dir

This commit is contained in:
microwin7 2023-02-18 07:00:35 +03:00
parent fbaf9ab87f
commit 5588b4aac1
3 changed files with 26 additions and 24 deletions

View file

@ -40,11 +40,11 @@ public String getUsageDescription() {
@Override @Override
public void invoke(String... args) throws Exception { public void invoke(String... args) throws Exception {
verifyArgs(args, 2); verifyArgs(args, 1);
//Version version = Version.byName(args[0]); //Version version = Version.byName(args[0]);
String versionName = args[0]; String versionName = args[0];
String dirName = IOHelper.verifyFileName(args[1] != null ? args[1] : "assets");
String type = args.length > 2 ? args[2] : "mojang"; String type = args.length > 2 ? args[2] : "mojang";
String dirName = IOHelper.verifyFileName(args[1]);
Path assetDir = server.updatesDir.resolve(dirName); Path assetDir = server.updatesDir.resolve(dirName);
// Create asset dir // Create asset dir

View file

@ -41,18 +41,14 @@ public void invoke(String... args) throws IOException, CommandException {
verifyArgs(args, 2); verifyArgs(args, 2);
//Version version = Version.byName(args[0]); //Version version = Version.byName(args[0]);
String versionName = args[0]; String versionName = args[0];
String dirName = IOHelper.verifyFileName(args[1]); String dirName = IOHelper.verifyFileName(args[1] != null ? args[1] : args[0]);
Path clientDir = server.updatesDir.resolve(args[1]); Path clientDir = server.updatesDir.resolve(dirName);
boolean isMirrorClientDownload = false; boolean isMirrorClientDownload = false;
if (args.length > 2) { if (args.length > 2) {
isMirrorClientDownload = args[2].equals("mirror"); isMirrorClientDownload = args[2].equals("mirror");
} }
// Create client dir
logger.info("Creating client dir: '{}'", dirName);
Files.createDirectory(clientDir);
// Download required client // Download required client
logger.info("Downloading client, it may take some time"); logger.info("Downloading client, it may take some time");
//HttpDownloader.downloadZip(server.mirrorManager.getDefaultMirror().getClientsURL(version.name), clientDir); //HttpDownloader.downloadZip(server.mirrorManager.getDefaultMirror().getClientsURL(version.name), clientDir);
@ -60,7 +56,25 @@ public void invoke(String... args) throws IOException, CommandException {
// Create profile file // Create profile file
logger.info("Creaing profile file: '{}'", dirName); logger.info("Creaing profile file: '{}'", dirName);
ClientProfile client = null; ClientProfile clientProfile = null;
if (isMirrorClientDownload) {
try {
JsonElement clientJson = server.mirrorManager.jsonRequest(null, "GET", "clients/%s.json", versionName);
clientProfile = Launcher.gsonManager.configGson.fromJson(clientJson, ClientProfile.class);
clientProfile.setTitle(dirName);
clientProfile.setDir(dirName);
clientProfile.setUUID(UUID.randomUUID());
if (clientProfile.getServers() != null) {
ClientProfile.ServerProfile serverProfile = clientProfile.getDefaultServerProfile();
if (serverProfile != null) {
serverProfile.name = dirName;
}
}
} catch (Exception e) {
logger.error("Filed download clientProfile from mirror: '{}' Generation through MakeProfileHelper", versionName);
isMirrorClientDownload = false;
}
}
if (!isMirrorClientDownload) { if (!isMirrorClientDownload) {
try { try {
String internalVersion = versionName; String internalVersion = versionName;
@ -75,27 +89,14 @@ public void invoke(String... args) throws IOException, CommandException {
for (MakeProfileHelper.MakeProfileOption option : options) { for (MakeProfileHelper.MakeProfileOption option : options) {
logger.debug("Detected option {}", option.getClass().getSimpleName()); logger.debug("Detected option {}", option.getClass().getSimpleName());
} }
client = MakeProfileHelper.makeProfile(version, dirName, options); clientProfile = MakeProfileHelper.makeProfile(version, dirName, options);
} catch (Throwable e) { } catch (Throwable e) {
isMirrorClientDownload = true; isMirrorClientDownload = true;
} }
} }
if (isMirrorClientDownload) {
JsonElement clientJson = server.mirrorManager.jsonRequest(null, "GET", "clients/%s.json", versionName);
client = Launcher.gsonManager.configGson.fromJson(clientJson, ClientProfile.class);
client.setTitle(dirName);
client.setDir(dirName);
client.setUUID(UUID.randomUUID());
if (client.getServers() != null) {
ClientProfile.ServerProfile serverProfile = client.getDefaultServerProfile();
if (serverProfile != null) {
serverProfile.name = dirName;
}
}
}
try (BufferedWriter writer = IOHelper.newWriter(IOHelper.resolveIncremental(server.profilesDir, try (BufferedWriter writer = IOHelper.newWriter(IOHelper.resolveIncremental(server.profilesDir,
dirName, "json"))) { dirName, "json"))) {
Launcher.gsonManager.configGson.toJson(client, writer); Launcher.gsonManager.configGson.toJson(clientProfile, writer);
} }
// Finished // Finished

View file

@ -56,6 +56,7 @@ public static void downloadFile(URL url, Path file, Consumer<Integer> chanheTrac
public static void downloadZip(URL url, Path dir) throws IOException { public static void downloadZip(URL url, Path dir) throws IOException {
try (ZipInputStream input = IOHelper.newZipInput(url)) { try (ZipInputStream input = IOHelper.newZipInput(url)) {
Files.createDirectory(dir);
for (ZipEntry entry = input.getNextEntry(); entry != null; entry = input.getNextEntry()) { for (ZipEntry entry = input.getNextEntry(); entry != null; entry = input.getNextEntry()) {
if (entry.isDirectory()) { if (entry.isDirectory()) {
Files.createDirectory(dir.resolve(IOHelper.toPath(entry.getName()))); Files.createDirectory(dir.resolve(IOHelper.toPath(entry.getName())));