FOMOD: add support for the order parameter

This commit is contained in:
Marc barbier
2022-10-02 10:01:26 +02:00
parent 8c486e27dd
commit 29c8f3b068
3 changed files with 70 additions and 7 deletions
+1
View File
@@ -3,3 +3,4 @@
build build
build/* build/*
compile_commands.json compile_commands.json
.buildconfig
+5 -3
View File
@@ -13,14 +13,16 @@ add_compile_options(-Wall -Wextra -pedantic -Werror)
find_package(PkgConfig REQUIRED) find_package(PkgConfig REQUIRED)
pkg_search_module(GLIB REQUIRED glib-2.0) 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) 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_compile_options(-fsanitize=address)
add_link_options(-fsanitize=address) add_link_options(-fsanitize=address)
target_link_libraries(ModManager ${GLIB_LDFLAGS}) target_link_libraries(ModManager ${GLIB_LDFLAGS})
target_link_libraries(ModManager ${AUDIT_LIBRARIES})
target_link_libraries(ModManager ${LIBXML_LIBRARIES}) target_link_libraries(ModManager ${LIBXML_LIBRARIES})
target_link_libraries(ModManager ${AUDIT_LIBRARIES})
install(TARGETS ModManager DESTINATION bin)
+64 -4
View File
@@ -491,6 +491,7 @@ int parseFOMod(const char * fomodFile, FOMod_t* fomod) {
} }
xmlFreeDoc(doc); xmlFreeDoc(doc);
return EXIT_SUCCESS;
} }
int getInputCount(const char * input) { int getInputCount(const char * input) {
@@ -633,21 +634,75 @@ void freeFOMod(FOMod_t * fomod) {
} }
} }
//TODO: support order parameters
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 //TODO: support priority
//TODO: error support //TODO: error support
int installFOMod(const char * modFolder, const char * destination) { int installFOMod(const char * modFolder, const char * destination) {
char * fomodFolder = findFOModFolder(modFolder); char * fomodFolder = findFOModFolder(modFolder);
if(fomodFolder == NULL) { 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 -1; return EXIT_FAILURE;
} }
char * fomodFile = findFOModFile(fomodFolder); char * fomodFile = findFOModFile(fomodFolder);
if(fomodFile == NULL) { if(fomodFile == NULL) {
fprintf(stderr, "Fomod file not found, are you sure this is a fomod mod ?\n"); fprintf(stderr, "Fomod file not found, are you sure this is a fomod mod ?\n");
g_free(fomodFolder); g_free(fomodFolder);
return -1; return EXIT_FAILURE;
} }
FOMod_t fomod; FOMod_t fomod;
@@ -658,6 +713,8 @@ int installFOMod(const char * modFolder, const char * destination) {
GList * flagList = NULL; GList * flagList = NULL;
sortSteps(&fomod);
for(int i = 0; i < fomod.stepCount; i++) { for(int i = 0; i < fomod.stepCount; i++) {
FOModStep_t * step = &fomod.steps[i]; FOModStep_t * step = &fomod.steps[i];
@@ -675,13 +732,14 @@ int installFOMod(const char * modFolder, const char * destination) {
for(int groupId = 0; groupId < step->groupCount; groupId++ ) { for(int groupId = 0; groupId < step->groupCount; groupId++ ) {
FOModGroup_t group = step->groups[groupId]; FOModGroup_t group = step->groups[groupId];
sortGroup(&group);
u_int8_t min; u_int8_t min;
u_int8_t max; u_int8_t max;
int inputCount = 0; int inputCount = 0;
char *inputBuffer = NULL; char *inputBuffer = NULL;
size_t bufferSize = 0; size_t bufferSize = 0;
while(true) { while(true) {
printfOptionsInOrder(group); printfOptionsInOrder(group);
switch(group.type) { switch(group.type) {
@@ -809,5 +867,7 @@ int installFOMod(const char * modFolder, const char * destination) {
} }
printf("FOMod successfully installed!\n"); printf("FOMod successfully installed!\n");
g_list_free(flagList); g_list_free(flagList);
g_list_free(pendingFileOperations);
freeFOMod(&fomod); freeFOMod(&fomod);
return EXIT_SUCCESS;
} }