diff options
author | Gentoo <installgentoo@endianness.com> | 2021-03-27 10:36:05 +1100 |
---|---|---|
committer | Gentoo <installgentoo@endianness.com> | 2021-03-27 10:36:05 +1100 |
commit | 0349c6d6572f59770898d3f40287ebdcd2f8ed30 (patch) | |
tree | 4f55d594e5343a7d4f4e6d4dea34d9c35caa0b99 /source/install-mod.c | |
download | YetAnotherModLoader-0349c6d6572f59770898d3f40287ebdcd2f8ed30.tar.gz YetAnotherModLoader-0349c6d6572f59770898d3f40287ebdcd2f8ed30.tar.bz2 YetAnotherModLoader-0349c6d6572f59770898d3f40287ebdcd2f8ed30.zip |
Diffstat (limited to 'source/install-mod.c')
-rw-r--r-- | source/install-mod.c | 76 |
1 files changed, 76 insertions, 0 deletions
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 <stdio.h> +#include <stdlib.h> +#include <string.h> + +#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<size; ++i) + { + if (buff[i] == '\n' || buff[i] == '\0'){buff[i] = '\0'; break;} + } + + colon = strstr(buff,":");//find colon in buff + if (!colon) + { + printf("%s malformed1!\n", file); + gprintf("%s malformed1!", file); + exit(1); + } + *colon = '\0';//replace colon with null char + +// create_folders(colon+1);//create the destination folders + + //save as sd:/root.zip and extract if the file to download has ".zip" in it, otherwise save the file to sd:/boot.elf + if (strstr(buff,".zip")) + { + download_file(buff, "root.zip", 1); + unZip("root.zip"); + } + else {download_file(buff, "boot.elf", 1);} + break; + } + + ++count; + } + +fclose(fp); +} |