diff options
author | Jan200101 <sentrycraft123@gmail.com> | 2021-02-03 00:29:50 +0100 |
---|---|---|
committer | Jan200101 <sentrycraft123@gmail.com> | 2021-02-03 00:29:50 +0100 |
commit | 9c45dcd0ff02f6aa07927a40a13d050e64cca4ed (patch) | |
tree | 484b8d0ac575c83856bf62a7e36b680025fee020 | |
parent | baca7635a3db27bae911ab6ebe928e5c2cc5a155 (diff) | |
download | polecat-9c45dcd0ff02f6aa07927a40a13d050e64cca4ed.tar.gz polecat-9c45dcd0ff02f6aa07927a40a13d050e64cca4ed.zip |
clean up logic some more
-rw-r--r-- | CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/dxvk.c | 5 | ||||
-rw-r--r-- | src/net.c | 24 | ||||
-rw-r--r-- | src/net.h | 1 | ||||
-rw-r--r-- | src/tar.c | 4 | ||||
-rw-r--r-- | src/wine.c | 7 |
6 files changed, 34 insertions, 11 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 37c8c08..92e863e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,10 +16,10 @@ message(STATUS "Version: ${CMAKE_PROJECT_VERSION}") set(FILES common config dxvk lutris main net tar wine) foreach(FILE ${FILES}) - set(SOURCES ${SOURCES} ${CMAKE_CURRENT_LIST_DIR}/src/${FILE}.c ${CMAKE_CURRENT_LIST_DIR}/src/${FILE}.h) + set(SOURCES ${SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/src/${FILE}.c ${CMAKE_CURRENT_SOURCE_DIR}/src/${FILE}.h) endforeach() -list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") find_package(Libcurl REQUIRED) find_package(JsonC REQUIRED) @@ -70,14 +70,15 @@ COMMAND(dxvk, download) fprintf(stderr, "Extracting %s\n", name); extract(archive, dxvkdir); fprintf(stderr, "Done\n"); + + free(archive->memory); + free(archive); } else { fprintf(stderr, "Something went wrong. The archive went missing\n"); } - free(archive->memory); - free(archive); } else { @@ -10,7 +10,7 @@ #include "net.h" #include "common.h" -static size_t memoryCallback(void* contents, size_t size, size_t nmemb, void* userp) +static inline size_t memoryCallback(void* contents, size_t size, size_t nmemb, void* userp) { size_t realsize = size * nmemb; struct MemoryStruct* mem = (struct MemoryStruct*)userp; @@ -30,7 +30,7 @@ static size_t memoryCallback(void* contents, size_t size, size_t nmemb, void* us return realsize; } -static int xferinfo(UNUSED void *p, curl_off_t dltotal, curl_off_t dlnow, UNUSED curl_off_t ultotal, UNUSED curl_off_t ulnow) +static inline int xferinfo(UNUSED void *p, curl_off_t dltotal, curl_off_t dlnow, UNUSED curl_off_t ultotal, UNUSED curl_off_t ulnow) { curl_off_t progress = 0; if (dltotal != 0) @@ -99,6 +99,25 @@ struct MemoryStruct* downloadToRam(const char* URL, long noprogress) return chunk; } +void downloadToFile(const char* URL, const char* path) +{ + struct MemoryStruct* chunk = downloadToRam(URL, 1L); + + if (chunk) + { + FILE* fp = fopen(path, "wb"); + + if (fp) + { + fwrite(chunk->memory, sizeof(uint8_t), chunk->size, fp); + fclose(fp); + } + + free(chunk->memory); + free(chunk); + } +} + struct json_object* fetchJSON(const char* URL) { struct MemoryStruct* chunk = downloadToRam(URL, 1L); @@ -111,7 +130,6 @@ struct json_object* fetchJSON(const char* URL) free(chunk->memory); free(chunk); - } return json; @@ -8,6 +8,7 @@ size_t WriteMemoryCallback(void*, size_t, size_t, void*); struct MemoryStruct* downloadToRam(const char* URL, long); +void downloadToFile(const char*, const char*); struct json_object* fetchJSON(const char*); #endif @@ -9,7 +9,7 @@ #include "common.h" #include "tar.h" -static int copy_data(struct archive* ar, struct archive* aw) +static inline int copy_data(struct archive* ar, struct archive* aw) { int r; const void *buff; @@ -63,7 +63,7 @@ void extract(const struct MemoryStruct* tar, const char* outputdir) archive_write_disk_set_options(ext, flags); archive_write_disk_set_standard_lookup(ext); - if ((r = archive_read_open_memory(a, tar->memory, tar->size))) return; + if (archive_read_open_memory(a, tar->memory, tar->size)) return; for (;;) { @@ -76,14 +76,15 @@ COMMAND(wine, download) fprintf(stderr, "Extracting %s\n", name); extract(archive, winedir); fprintf(stderr, "Done\n"); + + free(archive->memory); + free(archive); } else { fprintf(stderr, "Something went wrong. The archive went missing\n"); } - free(archive->memory); - free(archive); } else { @@ -397,6 +398,8 @@ enum wine_type_t check_wine_ver(char* winepath, size_t size) free(winepathcopy); return WINE_PROTON; } + + free(winepathcopy); } else { |