mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-23 00:51:01 +03:00
Merge pull request #637 from microwin7/patch-16
[FEATURE] Default value for client profile and assets dir
This commit is contained in:
commit
ebf25a65f7
3 changed files with 26 additions and 24 deletions
|
@ -40,11 +40,11 @@ public String getUsageDescription() {
|
|||
|
||||
@Override
|
||||
public void invoke(String... args) throws Exception {
|
||||
verifyArgs(args, 2);
|
||||
verifyArgs(args, 1);
|
||||
//Version version = Version.byName(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 dirName = IOHelper.verifyFileName(args[1]);
|
||||
Path assetDir = server.updatesDir.resolve(dirName);
|
||||
|
||||
// Create asset dir
|
||||
|
|
|
@ -41,18 +41,14 @@ public void invoke(String... args) throws IOException, CommandException {
|
|||
verifyArgs(args, 2);
|
||||
//Version version = Version.byName(args[0]);
|
||||
String versionName = args[0];
|
||||
String dirName = IOHelper.verifyFileName(args[1]);
|
||||
Path clientDir = server.updatesDir.resolve(args[1]);
|
||||
String dirName = IOHelper.verifyFileName(args[1] != null ? args[1] : args[0]);
|
||||
Path clientDir = server.updatesDir.resolve(dirName);
|
||||
|
||||
boolean isMirrorClientDownload = false;
|
||||
if (args.length > 2) {
|
||||
isMirrorClientDownload = args[2].equals("mirror");
|
||||
}
|
||||
|
||||
// Create client dir
|
||||
logger.info("Creating client dir: '{}'", dirName);
|
||||
Files.createDirectory(clientDir);
|
||||
|
||||
// Download required client
|
||||
logger.info("Downloading client, it may take some time");
|
||||
//HttpDownloader.downloadZip(server.mirrorManager.getDefaultMirror().getClientsURL(version.name), clientDir);
|
||||
|
@ -60,7 +56,25 @@ public void invoke(String... args) throws IOException, CommandException {
|
|||
|
||||
// Create profile file
|
||||
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) {
|
||||
try {
|
||||
String internalVersion = versionName;
|
||||
|
@ -75,27 +89,14 @@ public void invoke(String... args) throws IOException, CommandException {
|
|||
for (MakeProfileHelper.MakeProfileOption option : options) {
|
||||
logger.debug("Detected option {}", option.getClass().getSimpleName());
|
||||
}
|
||||
client = MakeProfileHelper.makeProfile(version, dirName, options);
|
||||
clientProfile = MakeProfileHelper.makeProfile(version, dirName, options);
|
||||
} catch (Throwable e) {
|
||||
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,
|
||||
dirName, "json"))) {
|
||||
Launcher.gsonManager.configGson.toJson(client, writer);
|
||||
Launcher.gsonManager.configGson.toJson(clientProfile, writer);
|
||||
}
|
||||
|
||||
// Finished
|
||||
|
|
|
@ -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 {
|
||||
try (ZipInputStream input = IOHelper.newZipInput(url)) {
|
||||
Files.createDirectory(dir);
|
||||
for (ZipEntry entry = input.getNextEntry(); entry != null; entry = input.getNextEntry()) {
|
||||
if (entry.isDirectory()) {
|
||||
Files.createDirectory(dir.resolve(IOHelper.toPath(entry.getName())));
|
||||
|
|
Loading…
Reference in a new issue