Compare commits

...

12 Commits

Author SHA1 Message Date
Alexander Popov 095ec61214
changed argv order 2023-07-31 23:17:53 +03:00
Alexander Popov 7812b19878
format code by clang-format 2023-07-31 23:12:24 +03:00
Alexander Popov 13ca75a3bf
1.0.2 update 2023-07-31 18:10:34 +03:00
Alexander Popov a0778de28a
update exec name 2023-07-31 18:05:20 +03:00
Alexander Popov 53782a2988
build with tcc 2023-07-31 17:36:48 +03:00
Alexander Popov 23bb1c0fd6
update script 2023-07-31 17:34:43 +03:00
Alexander Popov 8d43f69367
update source filename 2023-07-13 02:40:18 +03:00
Alexander Popov 682d57c954
fix title & link 2023-06-25 21:26:27 +03:00
Alexander Popov a051590826
update readme 2023-06-25 21:25:18 +03:00
Alexander Popov 2461420f15
fucking conan 2023-06-14 23:50:46 +03:00
Alexander Popov a05035089a
indent 2023-01-22 18:41:20 +03:00
Alexander Popov 060c13a068 Windows build with Conan 2022-09-14 00:34:25 +03:00
13 changed files with 239 additions and 234 deletions

View File

@ -2,7 +2,7 @@ root = true
[*]
indent_style = space
indent_size = 4
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
@ -10,8 +10,10 @@ insert_final_newline = true
[{*.c,*.h}]
indent_style = space
indent_size = 4
[Makefile]
indent_style = tab
indent_size = 4
[.gitmodules]
indent_style = tab

9
.gitignore vendored
View File

@ -1,4 +1,5 @@
conan.lock
conanbuild*
conaninfo.txt
graph_info.json
mc-libs-string
# export data
*.json
*.txt

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "cJSON"]
path = cJSON
url = https://github.com/DaveGamble/cJSON

View File

@ -8,6 +8,19 @@
> This project use Semantic Versioning 2.0.0 https://semver.org/
## 13/09/2022 - (1.0.1)
## 31/07/2023 - (1.0.3)
- ♻️ - Format code via `clang-format --style=LLVM`
- ♻️ - Changed arguments order
## 31/07/2023 - (1.0.2)
- ♻️ - Update software executable name
- ♻️ - Update Makefile
- ♻️ - Format code via `indent`
- - Added cJSON library as submodule
- - Added building with `tcc`
- ❌ - Removed Conan building system
## 14/09/2022 - (1.0.1)
- - Added [Conan](https://conan.io/) for Windows
- ✔️ - Fixed bad returned value of `assets_version`
- ♻️ - Changed the letter argument of the program to return version information from `s` to `i`

View File

@ -1,15 +1,18 @@
include conanbuildinfo.mak
CC = clang
CFLAGS = -O2
CC = gcc
CFLAGS = -O3
LIBS = -lcjson
EXEC = mc-libs-string
all: make-libs-list
all: $(EXEC)
make-libs-list:
$(CC) $(CFLAGS) make-libs-list.c \
$(LIBS) -I$(CONAN_INCLUDE_DIRS_CJSON) -L$(CONAN_LIB_DIRS_CJSON) \
-o $@
$(EXEC):
$(CC) $(CFLAGS) -o $(EXEC) ./src/main.c $(LIBS)
tcc:
tcc -O3 -o $(EXEC) ./src/main.c $(LIBS)
tcc-static:
tcc -O3 -o $(EXEC) ./src/main.c ./cJSON/libcjson.a
clean:
rm make-libs-list
rm $(EXEC)

View File

@ -1,18 +1,11 @@
# Parse `version.json` file and return libs
# Parse `version.json` file and return libraries list
## English
[Russian](README.ru.md) |
[English](README.md)
**About:**
Utility parse Minecraft JE game version file (`version.json`) and returns
libraries list for specified operation system.
**How to build from source:**
```sh
conan install .
make
```
Utility for parse Minecraft JE game version file (`version.json`).
**How to use:**
@ -20,63 +13,24 @@ make
Minecraft Libraries List Generator
Usage:
make-libs-string <version.json> <system>
mc-libs-string <system> <version.json>
<system> - w|l|x (windows or linux or osx)
Other:
make-libs-string <version.json> i - to get version info
mc-libs-string i <version.json> - to get version info
```
Utility has two required arguments,
`<version.json>` and `<system>`.
* `version.json` - takes the path to the file.
* `system` - takes one of three values `w` `l` `x`, the letter of which corresponds to one of the operating systems.
* `system` - takes one of three values `w, l, x`, the letter of which corresponds to one of the operating systems.
_**version.json**_ example for 1.19.2 version.
**Example for
[1.20.1](https://piston-meta.mojang.com/v1/packages/715ccf3330885e75b205124f09f8712542cbe7e0/1.20.1.json)
version:**
```sh
wget https://piston-meta.mojang.com/v1/packages/68cded4616fba9fbefb3f895033c261126c5f89c/1.19.2.json
```
## Русский
**Описание:**
Утилита парсит файл версий (`version.json`) Minecraft JE и возвращает
список библиотек для указанной операционной системы.
**Как скомпилировать:**
```sh
conan install .
make
```
**Как использовать:**
```
Minecraft Libraries List Generator
Usage:
make-libs-string <version.json> <system>
<system> - w|l|x (windows or linux or osx)
Other:
make-libs-string <version.json> i - to get version info
```
Программа имеет два обязательных аргумента,
`<version.json>` и `<system>`.
* `version.json` - принимает путь к файлу
* `system` - принимает одно из трёх значений `w` `l` `x`, буква которых соответствует одной из операционных систем.
Пример _**version.json**_ для версии 1.19.2.
```sh
wget https://piston-meta.mojang.com/v1/packages/68cded4616fba9fbefb3f895033c261126c5f89c/1.19.2.json
./mc-libs-string ./1.20.1.json x
```

35
README.ru.md Normal file
View File

@ -0,0 +1,35 @@
# Парсит файла `version.json` и вовращает список библиотек
[English](README.md) |
[Russian](README.ru.md)
**Описание:**
Утилита для парсинга файлов версий Minecraft JE (`version.json`).
**Как использовать:**
```
Minecraft Libraries List Generator
Usage:
mc-libs-string <system> <version.json>
<system> - w|l|x (windows or linux or osx)
Other:
mc-libs-string i <version.json> - to get version info
```
Программа имеет два обязательных аргумента,
`<version.json>` и `<system>`.
* `version.json` - принимает путь к файлу
* `system` - принимает одно из трёх значений `w, l, x`, буква которых соответствует одной из операционных систем.
**Пример для версии
[1.20.1](https://piston-meta.mojang.com/v1/packages/715ccf3330885e75b205124f09f8712542cbe7e0/1.20.1.json)**:
```sh
./mc-libs-string ./1.20.1.json x
```

1
cJSON Submodule

@ -0,0 +1 @@
Subproject commit cb8693b058ba302f4829ec6d03f609ac6f848546

View File

@ -1,5 +0,0 @@
[requires]
cjson/1.7.15
[generators]
make

10
format-code Executable file
View File

@ -0,0 +1,10 @@
#!/bin/sh
files=(
"src/main.c"
)
for file in "${files[@]}"
do
clang-format -i --style=LLVM --sort-includes=false $file
done

View File

@ -1,147 +0,0 @@
/*
AUTHOR: Alexander Popov <iiiypuk {at} fastmail.fm>
LICENSE: MIT-0
REPO: https://git.a2s.su/iiiypuk/minecraft-launcher-libs
*/
#include <stdio.h>
#include <string.h>
#include <cjson/cJSON.h>
#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);
int main(int argc, char const *argv[])
{
if (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, argv[2][0]);
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;
}
}
return 0;
}
void usage()
{
printf("%s\n%s: %s\n\n", "Minecraft Libraries List Generator",
"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)");
printf("%s\n", "Other:");
printf(" %s\n", "make-libs-string <version.json> i - to get version info");
}
void info(cJSON *json)
{
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"));
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, 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);
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"));
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));
}
}
}
}

View File

@ -25,20 +25,13 @@
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Link>
<AdditionalLibraryDirectories>.\</AdditionalLibraryDirectories>
<AdditionalDependencies>cjson.lib</AdditionalDependencies>
</Link>
<ClCompile>
<AdditionalIncludeDirectories>.\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ItemGroup>
<ClInclude Include="cjson/cjson.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="make-libs-list.c" />
<ClCompile Include="src\main.c" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Targets" />
</Project>

142
src/main.c Normal file
View File

@ -0,0 +1,142 @@
/*
AUTHOR: Alexander Popov <iiiypuk {at} fastmail.fm>
LICENSE: MIT-0
REPO: https://git.a2s.su/iiiypuk/minecraft-launcher-libs
*/
#include <stdio.h>
#include <string.h>
#include <cjson/cJSON.h>
#define VERSION "1.1.0" // software version
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[]) {
if (argc != 3) {
usage();
} else {
FILE *fp;
char str[900000];
char buffer[100];
fp = fopen(argv[2], "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, argv[2][0]);
int libraries_array_size = cJSON_GetArraySize(libraries);
switch (argv[1][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() {
printf("%s\n%s: %s\n\n", "Minecraft Libraries List Generator", "Version",
VERSION);
printf("%s\n", "Usage:");
printf(" %s\n\n", "mc-libs-string <system> <version.json>");
printf(" %s\n\n", "<system> - w|l|x (windows or linux or osx)");
printf("%s\n", "Other:");
printf(" %s\n", "mc-libs-string i <version.json> - to get version info");
}
void info(cJSON *json) {
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"));
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,
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);
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"));
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));
}
}
}
}