TO TEST: added order support
This commit is contained in:
+51
-31
@@ -543,6 +543,14 @@ int getInputCount(const char * input) {
|
|||||||
return elementCount;
|
return elementCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gint priorityCmp(gconstpointer a, gconstpointer b) {
|
||||||
|
const FOModFile_t * fileA = (const FOModFile_t *)a;
|
||||||
|
const FOModFile_t * fileB = (const FOModFile_t *)b;
|
||||||
|
|
||||||
|
return fileA->priority - fileB->priority;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
char * findFOModFolder(const char * modFolder) {
|
char * findFOModFolder(const char * modFolder) {
|
||||||
struct dirent * dir;
|
struct dirent * dir;
|
||||||
DIR *d = opendir(modFolder);
|
DIR *d = opendir(modFolder);
|
||||||
@@ -732,6 +740,7 @@ int installFOMod(const char * modFolder, const char * destination) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
GList * flagList = NULL;
|
GList * flagList = NULL;
|
||||||
|
GList * pendingFileOperations = NULL;
|
||||||
|
|
||||||
sortSteps(&fomod);
|
sortSteps(&fomod);
|
||||||
|
|
||||||
@@ -825,22 +834,10 @@ int installFOMod(const char * modFolder, const char * destination) {
|
|||||||
for(int i = 0; i < plugin.fileCount; i++) {
|
for(int i = 0; i < plugin.fileCount; i++) {
|
||||||
FOModFile_t * file = &plugin.files[i];
|
FOModFile_t * file = &plugin.files[i];
|
||||||
|
|
||||||
//TODO: support file->destination
|
FOModFile_t * fileCopy = malloc(sizeof(*file));
|
||||||
//no using link since priority is made to override files and link is annoying to deal with when overriding files.
|
*fileCopy = *file;
|
||||||
char * source = (char *) g_build_path("/", modFolder, file->source, NULL);
|
|
||||||
fixPath(source);
|
pendingFileOperations = g_list_append(pendingFileOperations, fileCopy);
|
||||||
int returnValue = EXIT_SUCCESS;
|
|
||||||
if(file->isFolder) {
|
|
||||||
returnValue = copy(source, destination, CP_NO_TARGET_DIR | CP_RECURSIVE);
|
|
||||||
} else {
|
|
||||||
returnValue = copy(source, destination, 0);
|
|
||||||
}
|
|
||||||
printf("source: %s, destination: %s\n", source, destination);
|
|
||||||
g_free(source);
|
|
||||||
if(returnValue != EXIT_SUCCESS) {
|
|
||||||
fprintf(stderr, "Copy failed, some file might be corrupted\n");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -866,26 +863,49 @@ int installFOMod(const char * modFolder, const char * destination) {
|
|||||||
if(areAllFlagsValid) {
|
if(areAllFlagsValid) {
|
||||||
for(int fileId = 0; fileId < condfile->flagCount; fileId++) {
|
for(int fileId = 0; fileId < condfile->flagCount; fileId++) {
|
||||||
FOModFile_t * file = &(condfile->files[fileId]);
|
FOModFile_t * file = &(condfile->files[fileId]);
|
||||||
//TODO: support destination
|
|
||||||
//TODO: handle error
|
FOModFile_t * fileCopy = malloc(sizeof(*file));
|
||||||
char * source = (char *) g_build_path("/", modFolder, file->source, NULL);
|
*fileCopy = *file;
|
||||||
fixPath(source);
|
|
||||||
int returnValue;
|
pendingFileOperations = g_list_append(pendingFileOperations, fileCopy);
|
||||||
if(file->isFolder) {
|
|
||||||
returnValue = copy(source, destination, CP_NO_TARGET_DIR | CP_RECURSIVE | CP_LINK);
|
|
||||||
} else {
|
|
||||||
returnValue = copy(source, destination, CP_LINK);
|
|
||||||
}
|
|
||||||
if(returnValue != EXIT_SUCCESS) {
|
|
||||||
fprintf(stderr, "Copy failed, some file might be corrupted\n");
|
|
||||||
}
|
|
||||||
printf("source: %s, destination: %s\n", source, destination);
|
|
||||||
g_free(source);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
pendingFileOperations = g_list_sort(pendingFileOperations, priorityCmp);
|
||||||
|
GList * currentFileOperation = pendingFileOperations;
|
||||||
|
|
||||||
|
while(currentFileOperation != NULL) {
|
||||||
|
//TODO: support destination
|
||||||
|
//TODO: handle error
|
||||||
|
//no using link since priority is made to override files and link is annoying to deal with when overriding files.
|
||||||
|
const FOModFile_t * file = (const FOModFile_t *)currentFileOperation->data;
|
||||||
|
char * source = g_build_path("/", modFolder, file->source, NULL);
|
||||||
|
|
||||||
|
//fix the / and \ windows - unix paths
|
||||||
|
fixPath(source);
|
||||||
|
|
||||||
|
int copyResult;
|
||||||
|
if(file->isFolder) {
|
||||||
|
copyResult = copy(source, destination, CP_NO_TARGET_DIR | CP_RECURSIVE);
|
||||||
|
} else {
|
||||||
|
copyResult = copy(source, destination, 0);
|
||||||
|
}
|
||||||
|
if(copyResult != EXIT_SUCCESS) {
|
||||||
|
fprintf(stderr, "Copy failed, some file might be corrupted\n");
|
||||||
|
}
|
||||||
|
printf("source: %s, destination: %s\n", source, destination);
|
||||||
|
g_free(source);
|
||||||
|
|
||||||
|
currentFileOperation = g_list_next(currentFileOperation);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
printf("FOMod successfully installed!\n");
|
printf("FOMod successfully installed!\n");
|
||||||
g_list_free(flagList);
|
g_list_free(flagList);
|
||||||
|
g_list_free_full(pendingFileOperations, free);
|
||||||
freeFOMod(&fomod);
|
freeFOMod(&fomod);
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user