💀
This commit is contained in:
commit
e505fd8cfc
17
.editorconfig
Normal file
17
.editorconfig
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 4
|
||||||
|
end_of_line = lf
|
||||||
|
charset = utf-8
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
insert_final_newline = true
|
||||||
|
|
||||||
|
[{*.c,*.h}]
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 4
|
||||||
|
|
||||||
|
[Makefile]
|
||||||
|
indent_style = tab
|
||||||
|
indent_size = 4
|
16
LICENSE
Normal file
16
LICENSE
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
MIT No Attribution
|
||||||
|
|
||||||
|
Copyright 2022 Alexander Popov
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||||
|
software and associated documentation files (the "Software"), to deal in the Software
|
||||||
|
without restriction, including without limitation the rights to use, copy, modify,
|
||||||
|
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
permit persons to whom the Software is furnished to do so.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||||
|
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||||
|
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||||
|
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
8
Makefile
Normal file
8
Makefile
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
CC = clang
|
||||||
|
CFLAGS = -O2 -lcjson
|
||||||
|
|
||||||
|
all:
|
||||||
|
${CC} -O2 -lcjson main.c -o make-libs-string
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f *.o
|
3
README.md
Normal file
3
README.md
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
Parse `version.json` file and return libs
|
||||||
|
|
||||||
|
Паритет с версией на [Python](https://github.com/iiiypuk/minecraft-libs-parser)
|
106
main.c
Normal file
106
main.c
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <cjson/cJSON.h>
|
||||||
|
|
||||||
|
void usage();
|
||||||
|
void info(cJSON *json);
|
||||||
|
void generate_library_list(cJSON *input_json, cJSON *output_json);
|
||||||
|
|
||||||
|
int main(int argc, char const *argv[])
|
||||||
|
{
|
||||||
|
if (argc < 2 || argc > 3)
|
||||||
|
{
|
||||||
|
usage();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
FILE *fp;
|
||||||
|
char str[900000];
|
||||||
|
char buffer[100];
|
||||||
|
|
||||||
|
fp = fopen(argv[1], "r");
|
||||||
|
while (fgets(buffer, sizeof(buffer), fp)) {
|
||||||
|
strcat(str, buffer);
|
||||||
|
}
|
||||||
|
fclose(fp);
|
||||||
|
|
||||||
|
cJSON *json = cJSON_Parse(str);
|
||||||
|
|
||||||
|
cJSON *launcher_libraries = cJSON_CreateObject();
|
||||||
|
cJSON *libraries = cJSON_CreateArray();
|
||||||
|
cJSON_AddItemToObject(launcher_libraries, "libraries", libraries);
|
||||||
|
|
||||||
|
generate_library_list(json, launcher_libraries);
|
||||||
|
int libraries_array_size = cJSON_GetArraySize(libraries);
|
||||||
|
|
||||||
|
switch (argv[2][0])
|
||||||
|
{
|
||||||
|
default:
|
||||||
|
usage();
|
||||||
|
break;
|
||||||
|
case 's':
|
||||||
|
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", "%MC_DIR%/versions/%GAME_VERSION%/%GAME_VERSION%.jar");
|
||||||
|
break;
|
||||||
|
case 'u':
|
||||||
|
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", "$MC_DIR/versions/$GAME_VERSION/$GAME_VERSION.jar");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
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", "Other:");
|
||||||
|
printf(" %s\n", "make-libs-string <version.json> s - to get info");
|
||||||
|
}
|
||||||
|
|
||||||
|
void info(cJSON *json)
|
||||||
|
{
|
||||||
|
char *assets_version = cJSON_GetStringValue(cJSON_GetObjectItem(json, "id"));
|
||||||
|
printf("Minecraft Assets Version: %s\n", assets_version);
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
cJSON *input_libraries = cJSON_GetObjectItem(input_json, "libraries");
|
||||||
|
cJSON *output_libraries = cJSON_GetObjectItem(output_json, "libraries");
|
||||||
|
int libraries_array_size = cJSON_GetArraySize(input_libraries);
|
||||||
|
|
||||||
|
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");
|
||||||
|
|
||||||
|
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