From 0349c6d6572f59770898d3f40287ebdcd2f8ed30 Mon Sep 17 00:00:00 2001 From: Gentoo Date: Sat, 27 Mar 2021 10:36:05 +1100 Subject: initial commit --- source/install-mod.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 source/install-mod.c (limited to 'source/install-mod.c') diff --git a/source/install-mod.c b/source/install-mod.c new file mode 100644 index 0000000..09ded12 --- /dev/null +++ b/source/install-mod.c @@ -0,0 +1,76 @@ +#include +#include +#include + +#include "install-zip.h" +#include "gecko.h" + +//these are in main.h +void create_folders(char path[]); +void download_file(char file[], char savefile[], int status); + +void install_mod(char file[], int row) +{ +FILE *fp = fopen(file, "r"); +if (!fp) + { + printf("Could not open %s\n", file); + gprintf("Could not open %s", file); + exit(1); + } + +fseek(fp, 0L, SEEK_END);//seek to the end of the file +int size = ftell(fp);//store lenght of file +rewind(fp);//seek back to start of file + +char buff[size+1];//a little excessive perhaps, but such size is required if the file only contains 1 line +buff[size] = '\0';//add null char to end of buff + +char *colon;//location of colon + +int count = 0; +char *result; +while(1) + { + result = fgets(buff, size, fp);//copy a line from fp into buff + if (!result) + { + printf("%s malformed0\n", file); + gprintf("%s malformed0", file); + exit(1); + } + + if (count == row) + { + //replace a found newline with a null char. Also, stop if a null char is found + for (int i = 0; i