add osx and add check os targer library

This commit is contained in:
Alexander Popov 2022-06-27 13:51:18 +00:00
parent cf3680f5da
commit 79fa1a86c1

View File

@ -4,7 +4,7 @@
void usage();
void info(cJSON *json);
void generate_library_list(cJSON *input_json, cJSON *output_json);
void generate_library_list(cJSON *input_json, cJSON *output_json, char output_system);
int main(int argc, char const *argv[])
{
@ -30,7 +30,7 @@ int main(int argc, char const *argv[])
cJSON *libraries = cJSON_CreateArray();
cJSON_AddItemToObject(launcher_libraries, "libraries", libraries);
generate_library_list(json, launcher_libraries);
generate_library_list(json, launcher_libraries, argv[2][0]);
int libraries_array_size = cJSON_GetArraySize(libraries);
switch (argv[2][0])
@ -49,7 +49,8 @@ int main(int argc, char const *argv[])
}
printf("%s", "%MC_DIR%/versions/%GAME_VERSION%/%GAME_VERSION%.jar");
break;
case 'u':
case 'l':
case 'x':
for (int i = 0; i < libraries_array_size; ++i)
{
cJSON *library = cJSON_GetArrayItem(libraries, i);
@ -68,7 +69,7 @@ void usage()
printf("%s\n\n", "Minecraft Libraries List Generator");
printf("%s\n", "Usage:");
printf(" %s\n\n", "make-libs-string <version.json> <system>");
printf(" %s\n\n", "<system> - w|u (windows or unix)");
printf(" %s\n\n", "<system> - w|l|x (windows or linux or osx)");
printf("%s\n", "Other:");
printf(" %s\n", "make-libs-string <version.json> s - to get info");
}
@ -83,12 +84,27 @@ void info(cJSON *json)
printf("Minecraft libraries count: %d\n", libraries_array_size);
}
void generate_library_list(cJSON *input_json, cJSON *output_json)
void generate_library_list(cJSON *input_json, cJSON *output_json, char output_system)
{
cJSON *input_libraries = cJSON_GetObjectItem(input_json, "libraries");
cJSON *output_libraries = cJSON_GetObjectItem(output_json, "libraries");
int libraries_array_size = cJSON_GetArraySize(input_libraries);
char *output_system_name;
switch (output_system)
{
case 'w':
output_system_name = "windows";
break;
case 'l':
output_system_name = "linux";
break;
case 'x':
output_system_name = "osx";
break;
}
for (int i = 0; i < libraries_array_size; i++)
{
cJSON *library = cJSON_GetArrayItem(input_libraries, i);
@ -98,9 +114,22 @@ void generate_library_list(cJSON *input_json, cJSON *output_json)
cJSON *downloads = cJSON_GetObjectItem(library, "downloads");
cJSON *artifact = cJSON_GetObjectItem(downloads, "artifact");
char *library_path = cJSON_GetStringValue(cJSON_GetObjectItem(artifact, "path"));
cJSON *rules = cJSON_GetObjectItem(library, "rules");
cJSON *rules_item = cJSON_GetArrayItem(rules, 0);
cJSON *os_type = cJSON_GetObjectItem(rules_item, "os");
char *os_name = cJSON_GetStringValue(cJSON_GetObjectItem(os_type, "name"));
cJSON_AddItemToArray(output_libraries, cJSON_CreateString(library_path));
if (os_name != 0) {
char *library_path = cJSON_GetStringValue(cJSON_GetObjectItem(artifact, "path"));
if (strcmp(output_system_name, os_name) == 0) {
cJSON_AddItemToArray(output_libraries, cJSON_CreateString(library_path));
}
}
else {
char *library_path = cJSON_GetStringValue(cJSON_GetObjectItem(artifact, "path"));
cJSON_AddItemToArray(output_libraries, cJSON_CreateString(library_path));
}
}
}
}