aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan200101 <sentrycraft123@gmail.com>2021-02-03 00:29:50 +0100
committerJan200101 <sentrycraft123@gmail.com>2021-02-03 00:29:50 +0100
commit9c45dcd0ff02f6aa07927a40a13d050e64cca4ed (patch)
tree484b8d0ac575c83856bf62a7e36b680025fee020
parentbaca7635a3db27bae911ab6ebe928e5c2cc5a155 (diff)
downloadpolecat-9c45dcd0ff02f6aa07927a40a13d050e64cca4ed.tar.gz
polecat-9c45dcd0ff02f6aa07927a40a13d050e64cca4ed.zip
clean up logic some more
-rw-r--r--CMakeLists.txt4
-rw-r--r--src/dxvk.c5
-rw-r--r--src/net.c24
-rw-r--r--src/net.h1
-rw-r--r--src/tar.c4
-rw-r--r--src/wine.c7
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)
diff --git a/src/dxvk.c b/src/dxvk.c
index 9b0a921..6b05ebb 100644
--- a/src/dxvk.c
+++ b/src/dxvk.c
@@ -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
{
diff --git a/src/net.c b/src/net.c
index b2851db..96e09ca 100644
--- a/src/net.c
+++ b/src/net.c
@@ -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;
diff --git a/src/net.h b/src/net.h
index 722c6bb..8282706 100644
--- a/src/net.h
+++ b/src/net.h
@@ -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
diff --git a/src/tar.c b/src/tar.c
index cbaf875..0daf657 100644
--- a/src/tar.c
+++ b/src/tar.c
@@ -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 (;;)
{
diff --git a/src/wine.c b/src/wine.c
index 1a21eb8..80defa1 100644
--- a/src/wine.c
+++ b/src/wine.c
@@ -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
{