indent
This commit is contained in:
parent
060c13a068
commit
a05035089a
1
Makefile
1
Makefile
@ -13,3 +13,4 @@ make-libs-list:
|
||||
|
||||
clean:
|
||||
rm make-libs-list
|
||||
rm conanbuild* conaninfo.txt graph_info.json
|
||||
|
152
make-libs-list.c
152
make-libs-list.c
@ -10,21 +10,19 @@
|
||||
|
||||
#define VERSION "1.0.1" // software version
|
||||
|
||||
void usage();
|
||||
void info(cJSON *json);
|
||||
void generate_library_list(cJSON *input_json, cJSON *output_json, char output_system);
|
||||
void usage();
|
||||
void info(cJSON * json);
|
||||
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();
|
||||
}
|
||||
else
|
||||
{
|
||||
FILE *fp;
|
||||
char str[900000];
|
||||
char buffer[100];
|
||||
} else {
|
||||
FILE *fp;
|
||||
char str[900000];
|
||||
char buffer[100];
|
||||
|
||||
fp = fopen(argv[1], "r");
|
||||
while (fgets(buffer, sizeof(buffer), fp)) {
|
||||
@ -32,50 +30,48 @@ int main(int argc, char const *argv[])
|
||||
}
|
||||
fclose(fp);
|
||||
|
||||
cJSON *json = cJSON_Parse(str);
|
||||
cJSON *json = cJSON_Parse(str);
|
||||
|
||||
cJSON *launcher_libraries = cJSON_CreateObject();
|
||||
cJSON *libraries = cJSON_CreateArray();
|
||||
cJSON *launcher_libraries = cJSON_CreateObject();
|
||||
cJSON *libraries = cJSON_CreateArray();
|
||||
cJSON_AddItemToObject(launcher_libraries, "libraries", libraries);
|
||||
|
||||
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])
|
||||
{
|
||||
default:
|
||||
usage();
|
||||
break;
|
||||
case 'i':
|
||||
info(json);
|
||||
break;
|
||||
case 'w':
|
||||
for (int i = 0; i < libraries_array_size; ++i)
|
||||
{
|
||||
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;
|
||||
case 'l':
|
||||
case 'x':
|
||||
for (int i = 0; i < libraries_array_size; ++i)
|
||||
{
|
||||
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;
|
||||
switch (argv[2][0]) {
|
||||
default:
|
||||
usage();
|
||||
break;
|
||||
case 'i':
|
||||
info(json);
|
||||
break;
|
||||
case 'w':
|
||||
for (int i = 0; i < libraries_array_size; ++i) {
|
||||
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;
|
||||
case 'l':
|
||||
case 'x':
|
||||
for (int i = 0; i < libraries_array_size; ++i) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void usage()
|
||||
void
|
||||
usage()
|
||||
{
|
||||
printf("%s\n%s: %s\n\n", "Minecraft Libraries List Generator",
|
||||
"Version", VERSION);
|
||||
"Version", VERSION);
|
||||
printf("%s\n", "Usage:");
|
||||
printf(" %s\n\n", "make-libs-string <version.json> <system>");
|
||||
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");
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
cJSON *libraries = cJSON_GetObjectItem(json, "libraries");
|
||||
int libraries_array_size = cJSON_GetArraySize(libraries);
|
||||
cJSON *libraries = cJSON_GetObjectItem(json, "libraries");
|
||||
int libraries_array_size = cJSON_GetArraySize(libraries);
|
||||
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 *output_libraries = cJSON_GetObjectItem(output_json, "libraries");
|
||||
int libraries_array_size = cJSON_GetArraySize(input_libraries);
|
||||
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;
|
||||
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;
|
||||
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);
|
||||
for (int i = 0; i < libraries_array_size; i++) {
|
||||
cJSON *library = cJSON_GetArrayItem(input_libraries, i);
|
||||
|
||||
if (library != NULL)
|
||||
{
|
||||
cJSON *downloads = cJSON_GetObjectItem(library, "downloads");
|
||||
cJSON *artifact = cJSON_GetObjectItem(downloads, "artifact");
|
||||
if (library != NULL) {
|
||||
cJSON *downloads = cJSON_GetObjectItem(library, "downloads");
|
||||
cJSON *artifact = cJSON_GetObjectItem(downloads, "artifact");
|
||||
|
||||
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 *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"));
|
||||
|
||||
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) {
|
||||
cJSON_AddItemToArray(output_libraries, cJSON_CreateString(library_path));
|
||||
}
|
||||
}
|
||||
else {
|
||||
char *library_path = cJSON_GetStringValue(cJSON_GetObjectItem(artifact, "path"));
|
||||
} else {
|
||||
char *library_path = cJSON_GetStringValue(cJSON_GetObjectItem(artifact, "path"));
|
||||
cJSON_AddItemToArray(output_libraries, cJSON_CreateString(library_path));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user