aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt61
-rw-r--r--src/lutris.c2
-rw-r--r--src/mock/CMakeLists.txt19
-rw-r--r--src/mock/libcurl/libcurl.c93
-rw-r--r--src/net.c20
-rw-r--r--src/wine.c4
6 files changed, 190 insertions, 9 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
new file mode 100644
index 0000000..16d1b5e
--- /dev/null
+++ b/src/CMakeLists.txt
@@ -0,0 +1,61 @@
+set(C_STANDARD 99)
+
+set(SOURCES
+ ${CMAKE_CURRENT_SOURCE_DIR}/command.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/common.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/common.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/config.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/config.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/dxvk.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/dxvk.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/lutris.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/lutris.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/main.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/main.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/net.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/net.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/tar.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/tar.h
+)
+
+
+if (NOT WIN32)
+set(SOURCES
+ ${SOURCES}
+ ${CMAKE_CURRENT_SOURCE_DIR}/wine.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/wine.h
+)
+endif()
+
+find_package(Libcurl REQUIRED)
+find_package(JsonC REQUIRED)
+find_package(Libarchive REQUIRED)
+
+add_executable(${CMAKE_PROJECT_NAME} ${SOURCES})
+
+target_link_libraries(${CMAKE_PROJECT_NAME} LINK_PUBLIC ${JSONC_LIBRARIES})
+target_link_libraries(${CMAKE_PROJECT_NAME} LINK_PUBLIC ${LIBARCHIVE_LIBRARIES})
+target_link_libraries(${CMAKE_PROJECT_NAME} LINK_PUBLIC ${LIBCURL_LIBRARIES})
+
+target_include_directories(${CMAKE_PROJECT_NAME} PUBLIC ${JSONC_INCLUDE_DIRS})
+target_include_directories(${CMAKE_PROJECT_NAME} PUBLIC ${LIBARCHIVE_INCLUDE_DIRS})
+target_include_directories(${CMAKE_PROJECT_NAME} PUBLIC ${LIBCURL_INCLUDE_DIRS})
+
+set(CFLAGS
+ -Wall -Wextra -pedantic
+ -Wconversion -Wshadow -Wstrict-aliasing
+ -Winit-self -Wcast-align -Wpointer-arith
+ -Wmissing-declarations -Wmissing-include-dirs
+ -Wno-unused-parameter -Wuninitialized
+ ${JSONC_CFLAGS}
+ ${LIBARCHIVE_CFLAGS}
+ ${LIBCURL_CFLAGS}
+)
+
+target_compile_options(${CMAKE_PROJECT_NAME} PUBLIC ${CFLAGS})
+
+install(TARGETS ${CMAKE_PROJECT_NAME})
+
+if(BUILD_MOCK)
+ add_subdirectory(mock)
+endif() \ No newline at end of file
diff --git a/src/lutris.c b/src/lutris.c
index 0dd999b..b7c4da6 100644
--- a/src/lutris.c
+++ b/src/lutris.c
@@ -20,7 +20,7 @@ static const struct Flag lutris_flags[] = {
{ .name = "help", .variant = TWO, .func = lutris_help, .description = "show this message"}
};
-char* getpwd()
+static char* getpwd()
{
char* pwd = malloc(255);
pwd = getcwd(pwd, 255);
diff --git a/src/mock/CMakeLists.txt b/src/mock/CMakeLists.txt
new file mode 100644
index 0000000..c2634d5
--- /dev/null
+++ b/src/mock/CMakeLists.txt
@@ -0,0 +1,19 @@
+SET(CURL_SOURCES
+ ${CMAKE_CURRENT_SOURCE_DIR}/libcurl/libcurl.c
+)
+
+add_library(mockcurl STATIC ${CURL_SOURCES})
+target_include_directories(mockcurl PUBLIC ${LIBCURL_INCLUDE_DIRS})
+
+set(NAME ${CMAKE_PROJECT_NAME}_mock)
+add_executable(${NAME} ${SOURCES})
+
+target_link_libraries(${NAME} LINK_PUBLIC ${JSONC_LIBRARIES})
+target_link_libraries(${NAME} LINK_PUBLIC ${LIBARCHIVE_LIBRARIES})
+target_link_libraries(${NAME} LINK_PUBLIC mockcurl)
+
+target_include_directories(${NAME} PUBLIC ${JSONC_INCLUDE_DIRS})
+target_include_directories(${NAME} PUBLIC ${LIBARCHIVE_INCLUDE_DIRS})
+target_include_directories(${NAME} PUBLIC ${LIBCURL_INCLUDE_DIRS})
+
+target_compile_options(${NAME} PUBLIC ${CFLAGS}) \ No newline at end of file
diff --git a/src/mock/libcurl/libcurl.c b/src/mock/libcurl/libcurl.c
new file mode 100644
index 0000000..b4f332c
--- /dev/null
+++ b/src/mock/libcurl/libcurl.c
@@ -0,0 +1,93 @@
+#include <stdio.h>
+#include <stdarg.h>
+#include <curl/curl.h>
+
+char* url = NULL;
+void* data = NULL;
+
+#ifdef curl_easy_setopt
+#undef curl_easy_setopt
+#endif
+
+CURLcode curl_global_init(long flags)
+{
+ puts("[MOCK] curl_global_init(...)");
+ return CURLE_OK;
+}
+
+CURL* curl_easy_init()
+{
+ puts("[MOCK] curl_easy_init(...)");
+ return NULL;
+}
+
+CURLcode curl_easy_setopt(CURL *handle, CURLoption option, ...)
+{
+ puts("[MOCK] curl_easy_setopt(...)");
+
+ va_list arg;
+ va_start(arg, option);
+
+ switch (option)
+ {
+ case CURLOPT_URL:
+ url = va_arg(arg, char*);
+ printf("CURLOPT_URL\t%s\n", url);
+ break;
+
+ case CURLOPT_WRITEDATA:
+ data = va_arg(arg, void*);
+ printf("CURLOPT_WRITEDATA\t%p\n", data);
+ break;
+
+ default:
+ break;
+ }
+
+ va_end(arg);
+
+ return CURLE_OK;
+}
+
+CURLcode curl_easy_perform(CURL *easy_handle)
+{
+ puts("[MOCK] curl_easy_perform(...)");
+ return CURLE_OK;
+}
+
+#ifdef curl_easy_getinfo
+#undef curl_easy_getinfo
+#endif
+
+CURLcode curl_easy_getinfo(CURL *curl, CURLINFO info, ...)
+{
+ puts("[MOCK] curl_easy_getinfo(...)");
+
+ if (info == CURLINFO_RESPONSE_CODE)
+ {
+ va_list arg;
+ va_start(arg, info);
+ long* http_code = va_arg(arg, long*);
+ *http_code = 200;
+ va_end(arg);
+ }
+
+
+ return CURLE_OK;
+}
+
+const char* curl_easy_strerror(CURLcode error)
+{
+ puts("[MOCK] curl_easy_strerror(...)");
+ return "error";
+}
+
+void curl_easy_cleanup(CURL *handle)
+{
+ puts("[MOCK] curl_easy_cleanup(...)");
+}
+
+void curl_global_cleanup()
+{
+ puts("[MOCK] curl_global_cleanup(...)");
+} \ No newline at end of file
diff --git a/src/net.c b/src/net.c
index 2e3319d..bf03a07 100644
--- a/src/net.c
+++ b/src/net.c
@@ -54,8 +54,13 @@ struct MemoryStruct* downloadToRam(const char* URL, int progress)
if (chunk)
{
- // if we managed to allocate the chunk lets assume we can allocate at least 1 byte
chunk->memory = malloc(1);
+ if (!chunk->memory)
+ {
+ free(chunk);
+ return NULL;
+ }
+ chunk->memory[0] = 0;
chunk->size = 0;
curl_global_init(CURL_GLOBAL_ALL);
@@ -73,18 +78,22 @@ struct MemoryStruct* downloadToRam(const char* URL, int progress)
res = curl_easy_perform(curl_handle);
long http_code = 0;
- curl_easy_getinfo (curl_handle, CURLINFO_RESPONSE_CODE, &http_code);
+ curl_easy_getinfo(curl_handle, CURLINFO_RESPONSE_CODE, &http_code);
if(res != CURLE_OK) {
+ free(chunk->memory);
+ free(chunk);
puts(curl_easy_strerror(res));
- return NULL;
+ chunk = NULL;
}
else if (http_code != 200)
{
+ free(chunk->memory);
+ free(chunk);
#ifdef DEBUG
printf("HTTP Error %li\n", http_code);
#endif
- return NULL;
+ chunk = NULL;
}
curl_easy_cleanup(curl_handle);
@@ -119,9 +128,8 @@ void downloadToFile(const char* URL, const char* path, int progress)
struct json_object* fetchJSON(const char* URL)
{
- struct MemoryStruct* chunk = downloadToRam(URL, 0);
-
struct json_object* json = NULL;
+ struct MemoryStruct* chunk = downloadToRam(URL, 0);
if (chunk)
{
diff --git a/src/wine.c b/src/wine.c
index 88819b4..65cbd34 100644
--- a/src/wine.c
+++ b/src/wine.c
@@ -48,9 +48,9 @@ COMMAND(wine, download)
char* choice = argv[i];
- for (JSON_LENGTH_TYPE i = 0; i < json_object_array_length(versions); ++i)
+ for (JSON_LENGTH_TYPE j = 0; j < json_object_array_length(versions); ++j)
{
- value = json_object_array_get_idx(versions, i);
+ value = json_object_array_get_idx(versions, j);
json_object_object_get_ex(value, "version", &temp);
if (strcmp(json_object_get_string(temp), choice) == 0)
{