This commit is contained in:
Alexander Popov 2023-01-22 18:41:20 +03:00
parent 060c13a068
commit a05035089a
Signed by: iiiypuk
GPG Key ID: D8C9B59A9F04A70C
2 changed files with 74 additions and 79 deletions

View File

@ -13,3 +13,4 @@ make-libs-list:
clean: clean:
rm make-libs-list rm make-libs-list
rm conanbuild* conaninfo.txt graph_info.json

View File

@ -10,21 +10,19 @@
#define VERSION "1.0.1" // software version #define VERSION "1.0.1" // software version
void usage(); void usage();
void info(cJSON *json); void info(cJSON * json);
void generate_library_list(cJSON *input_json, cJSON *output_json, char output_system); void generate_library_list(cJSON * input_json, cJSON * output_json, char output_system);
int main(int argc, char const *argv[]) int
main(int argc, char const * argv[])
{ {
if (argc != 3) if (argc != 3) {
{
usage(); usage();
} } else {
else FILE *fp;
{ char str[900000];
FILE *fp; char buffer[100];
char str[900000];
char buffer[100];
fp = fopen(argv[1], "r"); fp = fopen(argv[1], "r");
while (fgets(buffer, sizeof(buffer), fp)) { while (fgets(buffer, sizeof(buffer), fp)) {
@ -32,50 +30,48 @@ int main(int argc, char const *argv[])
} }
fclose(fp); fclose(fp);
cJSON *json = cJSON_Parse(str); cJSON *json = cJSON_Parse(str);
cJSON *launcher_libraries = cJSON_CreateObject(); cJSON *launcher_libraries = cJSON_CreateObject();
cJSON *libraries = cJSON_CreateArray(); cJSON *libraries = cJSON_CreateArray();
cJSON_AddItemToObject(launcher_libraries, "libraries", libraries); cJSON_AddItemToObject(launcher_libraries, "libraries", libraries);
generate_library_list(json, launcher_libraries, argv[2][0]); generate_library_list(json, launcher_libraries, argv[2][0]);
int libraries_array_size = cJSON_GetArraySize(libraries); int libraries_array_size = cJSON_GetArraySize(libraries);
switch (argv[2][0]) switch (argv[2][0]) {
{ default:
default: usage();
usage(); break;
break; case 'i':
case 'i': info(json);
info(json); break;
break; case 'w':
case 'w': for (int i = 0; i < libraries_array_size; ++i) {
for (int i = 0; i < libraries_array_size; ++i) cJSON *library = cJSON_GetArrayItem(libraries, i);
{ printf("%%MC_DIR%%/libraries/%s;", cJSON_GetStringValue(library));
cJSON *library = cJSON_GetArrayItem(libraries, i); }
printf("%%MC_DIR%%/libraries/%s;", cJSON_GetStringValue(library)); printf("%s\n", "%MC_DIR%/versions/%GAME_VERSION%/%GAME_VERSION%.jar");
} break;
printf("%s\n", "%MC_DIR%/versions/%GAME_VERSION%/%GAME_VERSION%.jar"); case 'l':
break; case 'x':
case 'l': for (int i = 0; i < libraries_array_size; ++i) {
case 'x': cJSON *library = cJSON_GetArrayItem(libraries, i);
for (int i = 0; i < libraries_array_size; ++i) printf("$MC_DIR/libraries/%s:", cJSON_GetStringValue(library));
{ }
cJSON *library = cJSON_GetArrayItem(libraries, i); printf("%s\n", "$MC_DIR/versions/$GAME_VERSION/$GAME_VERSION.jar");
printf("$MC_DIR/libraries/%s:", cJSON_GetStringValue(library)); break;
}
printf("%s\n", "$MC_DIR/versions/$GAME_VERSION/$GAME_VERSION.jar");
break;
} }
} }
return 0; return 0;
} }
void usage() void
usage()
{ {
printf("%s\n%s: %s\n\n", "Minecraft Libraries List Generator", printf("%s\n%s: %s\n\n", "Minecraft Libraries List Generator",
"Version", VERSION); "Version", VERSION);
printf("%s\n", "Usage:"); printf("%s\n", "Usage:");
printf(" %s\n\n", "make-libs-string <version.json> <system>"); printf(" %s\n\n", "make-libs-string <version.json> <system>");
printf(" %s\n\n", "<system> - w|l|x (windows or linux or osx)"); printf(" %s\n\n", "<system> - w|l|x (windows or linux or osx)");
@ -83,63 +79,61 @@ void usage()
printf(" %s\n", "make-libs-string <version.json> i - to get version info"); printf(" %s\n", "make-libs-string <version.json> i - to get version info");
} }
void info(cJSON *json) void
info(cJSON * json)
{ {
char *minecraft_version = cJSON_GetStringValue(cJSON_GetObjectItem(json, "id")); char *minecraft_version = cJSON_GetStringValue(cJSON_GetObjectItem(json, "id"));
printf("Minecraft Version: %s\n", minecraft_version); printf("Minecraft Version: %s\n", minecraft_version);
char *assets_version = cJSON_GetStringValue(cJSON_GetObjectItem(json, "assets")); char *assets_version = cJSON_GetStringValue(cJSON_GetObjectItem(json, "assets"));
printf("Minecraft Assets Version: %s\n", assets_version); printf("Minecraft Assets Version: %s\n", assets_version);
cJSON *libraries = cJSON_GetObjectItem(json, "libraries"); cJSON *libraries = cJSON_GetObjectItem(json, "libraries");
int libraries_array_size = cJSON_GetArraySize(libraries); int libraries_array_size = cJSON_GetArraySize(libraries);
printf("Minecraft libraries count: %d\n", libraries_array_size); printf("Minecraft libraries count: %d\n", libraries_array_size);
} }
void generate_library_list(cJSON *input_json, cJSON *output_json, char output_system) void
generate_library_list(cJSON * input_json, cJSON * output_json, char output_system)
{ {
cJSON *input_libraries = cJSON_GetObjectItem(input_json, "libraries"); cJSON *input_libraries = cJSON_GetObjectItem(input_json, "libraries");
cJSON *output_libraries = cJSON_GetObjectItem(output_json, "libraries"); cJSON *output_libraries = cJSON_GetObjectItem(output_json, "libraries");
int libraries_array_size = cJSON_GetArraySize(input_libraries); int libraries_array_size = cJSON_GetArraySize(input_libraries);
char *output_system_name; char *output_system_name;
switch (output_system) switch (output_system) {
{ case 'w':
case 'w': output_system_name = "windows";
output_system_name = "windows"; break;
break; case 'l':
case 'l': output_system_name = "linux";
output_system_name = "linux"; break;
break; case 'x':
case 'x': output_system_name = "osx";
output_system_name = "osx"; break;
break;
} }
for (int i = 0; i < libraries_array_size; i++) for (int i = 0; i < libraries_array_size; i++) {
{ cJSON *library = cJSON_GetArrayItem(input_libraries, i);
cJSON *library = cJSON_GetArrayItem(input_libraries, i);
if (library != NULL) if (library != NULL) {
{ cJSON *downloads = cJSON_GetObjectItem(library, "downloads");
cJSON *downloads = cJSON_GetObjectItem(library, "downloads"); cJSON *artifact = cJSON_GetObjectItem(downloads, "artifact");
cJSON *artifact = cJSON_GetObjectItem(downloads, "artifact");
cJSON *rules = cJSON_GetObjectItem(library, "rules"); cJSON *rules = cJSON_GetObjectItem(library, "rules");
cJSON *rules_item = cJSON_GetArrayItem(rules, 0); cJSON *rules_item = cJSON_GetArrayItem(rules, 0);
cJSON *os_type = cJSON_GetObjectItem(rules_item, "os"); cJSON *os_type = cJSON_GetObjectItem(rules_item, "os");
char *os_name = cJSON_GetStringValue(cJSON_GetObjectItem(os_type, "name")); char *os_name = cJSON_GetStringValue(cJSON_GetObjectItem(os_type, "name"));
if (os_name != 0) { if (os_name != 0) {
char *library_path = cJSON_GetStringValue(cJSON_GetObjectItem(artifact, "path")); char *library_path = cJSON_GetStringValue(cJSON_GetObjectItem(artifact, "path"));
if (strcmp(output_system_name, os_name) == 0) { if (strcmp(output_system_name, os_name) == 0) {
cJSON_AddItemToArray(output_libraries, cJSON_CreateString(library_path)); cJSON_AddItemToArray(output_libraries, cJSON_CreateString(library_path));
} }
} } else {
else { char *library_path = cJSON_GetStringValue(cJSON_GetObjectItem(artifact, "path"));
char *library_path = cJSON_GetStringValue(cJSON_GetObjectItem(artifact, "path"));
cJSON_AddItemToArray(output_libraries, cJSON_CreateString(library_path)); cJSON_AddItemToArray(output_libraries, cJSON_CreateString(library_path));
} }
} }