diff --git a/.gitignore b/.gitignore index a896241..84994b2 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ build build/* compile_commands.json +.buildconfig \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 1305d88..c40af69 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,14 +13,16 @@ add_compile_options(-Wall -Wextra -pedantic -Werror) find_package(PkgConfig REQUIRED) pkg_search_module(GLIB REQUIRED glib-2.0) -pkg_search_module(audit REQUIRED libaudit) +pkg_search_module(AUDIT REQUIRED audit) pkg_search_module(LIBXML REQUIRED libxml-2.0) -target_include_directories(ModManager PRIVATE ${GLIB_INCLUDE_DIRS} ${LIBXML_INCLUDE_DIRS}) +target_include_directories(ModManager PRIVATE ${GLIB_INCLUDE_DIRS} ${LIBXML_INCLUDE_DIRS} ${AUDIT_INCLUDE_DIRS}) add_compile_options(-fsanitize=address) add_link_options(-fsanitize=address) target_link_libraries(ModManager ${GLIB_LDFLAGS}) -target_link_libraries(ModManager ${AUDIT_LIBRARIES}) target_link_libraries(ModManager ${LIBXML_LIBRARIES}) +target_link_libraries(ModManager ${AUDIT_LIBRARIES}) + +install(TARGETS ModManager DESTINATION bin) \ No newline at end of file diff --git a/src/fomod.c b/src/fomod.c index 5b4f890..49cb9e3 100644 --- a/src/fomod.c +++ b/src/fomod.c @@ -514,6 +514,7 @@ int parseFOMod(const char * fomodFile, FOMod_t* fomod) { } xmlFreeDoc(doc); + return EXIT_SUCCESS; } int getInputCount(const char * input) { @@ -656,10 +657,64 @@ void freeFOMod(FOMod_t * fomod) { } } +int stepCmpAsc(const void * stepA, const void * stepB) { + const FOModStep_t * step1 = (const FOModStep_t *)stepA; + const FOModStep_t * step2 = (const FOModStep_t *)stepB; + return strcmp(step1->name, step2->name); +} + +int stepCmpDesc(const void * stepA, const void * stepB) { + const FOModStep_t * step1 = (const FOModStep_t *)stepA; + const FOModStep_t * step2 = (const FOModStep_t *)stepB; + return 1 - strcmp(step1->name, step2->name); +} + + +void sortSteps(FOMod_t * fomod) { + switch(fomod->stepOrder) { + case ASC: + qsort(fomod->steps, fomod->stepCount, sizeof(*fomod->steps), stepCmpAsc); + break; + case DESC: + qsort(fomod->steps, fomod->stepCount, sizeof(*fomod->steps), stepCmpDesc); + break; + case ORD: + //ord mean that we keep the curent order, so no need to sort anything. + break; + } +} + +int groupCmpAsc(const void * stepA, const void * stepB) { + const FOModGroup_t * step1 = (const FOModGroup_t *)stepA; + const FOModGroup_t * step2 = (const FOModGroup_t *)stepB; + return strcmp(step1->name, step2->name); +} + +int groupCmpDesc(const void * stepA, const void * stepB) { + const FOModGroup_t * step1 = (const FOModGroup_t *)stepA; + const FOModGroup_t * step2 = (const FOModGroup_t *)stepB; + return 1 - strcmp(step1->name, step2->name); +} + +void sortGroup(FOModGroup_t * group) { + switch(group->order) { + case ASC: + qsort(group->plugins, group->pluginCount, sizeof(*group->plugins), groupCmpAsc); + break; + case DESC: + qsort(group->plugins, group->pluginCount, sizeof(*group->plugins), groupCmpDesc); + break; + case ORD: + //ord mean that we keep the curent order, so no need to sort anything. + break; + } +} + +//TODO: support priority int installFOMod(const char * modFolder, const char * destination) { char * fomodFolder = findFOModFolder(modFolder); if(fomodFolder == NULL) { - fprintf(stderr, "FOMod folder not found, are you sure this is a fomod mod ?\n"); + fprintf(stderr, "Fomod folder not found, are you sure this is a fomod mod ?\n"); return EXIT_FAILURE; } @@ -678,6 +733,8 @@ int installFOMod(const char * modFolder, const char * destination) { GList * flagList = NULL; + sortSteps(&fomod); + for(int i = 0; i < fomod.stepCount; i++) { FOModStep_t * step = &fomod.steps[i]; @@ -695,13 +752,14 @@ int installFOMod(const char * modFolder, const char * destination) { for(int groupId = 0; groupId < step->groupCount; groupId++ ) { FOModGroup_t group = step->groups[groupId]; + sortGroup(&group); + u_int8_t min; u_int8_t max; int inputCount = 0; char *inputBuffer = NULL; size_t bufferSize = 0; - while(true) { printfOptionsInOrder(group); switch(group.type) { @@ -829,4 +887,5 @@ int installFOMod(const char * modFolder, const char * destination) { printf("FOMod successfully installed!\n"); g_list_free(flagList); freeFOMod(&fomod); + return EXIT_SUCCESS; }