aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore4
-rw-r--r--CMakeLists.txt9
-rw-r--r--cmake/FindJsonC.cmake4
-rw-r--r--cmake/FindLibarchive.cmake14
-rw-r--r--cmake/FindLibcurl.cmake7
-rw-r--r--src/command.h4
-rw-r--r--src/common.c20
-rw-r--r--src/common.h10
-rw-r--r--src/config.c9
-rw-r--r--src/dxvk.c23
-rw-r--r--src/lutris.c19
-rw-r--r--src/main.c6
-rw-r--r--src/tar.c2
-rw-r--r--src/wine.c21
14 files changed, 110 insertions, 42 deletions
diff --git a/.gitignore b/.gitignore
index 0c6441d..af57f11 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,3 @@
-build
+build*
*.tar*
zig-cache
-.cache
-.vscode
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 92e863e..145b89f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -13,7 +13,10 @@ add_compile_definitions(VERSION="${CMAKE_PROJECT_VERSION}")
message(STATUS "Name: ${CMAKE_PROJECT_NAME}")
message(STATUS "Version: ${CMAKE_PROJECT_VERSION}")
-set(FILES common config dxvk lutris main net tar wine)
+set(FILES common config dxvk lutris main net tar)
+if(NOT WIN32)
+ set(FILES ${FILES} wine)
+endif()
foreach(FILE ${FILES})
set(SOURCES ${SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/src/${FILE}.c ${CMAKE_CURRENT_SOURCE_DIR}/src/${FILE}.h)
@@ -39,6 +42,10 @@ target_include_directories(${CMAKE_PROJECT_NAME} PUBLIC ${LIBCURL_INCLUDE_DIRS})
target_include_directories(${CMAKE_PROJECT_NAME} PUBLIC ${JSONC_INCLUDE_DIRS})
target_include_directories(${CMAKE_PROJECT_NAME} PUBLIC ${LIBARCHIVE_INCLUDE_DIRS})
+if (BUILD_STATIC)
+ add_compile_definitions(CURL_STATICLIB)
+endif()
+
target_compile_options(${CMAKE_PROJECT_NAME} PRIVATE -Wall -Wextra -Wpedantic -Wconversion)
install(TARGETS ${CMAKE_PROJECT_NAME})
diff --git a/cmake/FindJsonC.cmake b/cmake/FindJsonC.cmake
index cada971..f3c90df 100644
--- a/cmake/FindJsonC.cmake
+++ b/cmake/FindJsonC.cmake
@@ -28,6 +28,7 @@ find_library(JSONC_LIB
ENV jsoncPath${_lib_suffix}
ENV jsoncPath
${_JSONC_LIBRARY_DIRS}
+ ${_JSONC_STATIC_LIBRARY_DIRS}
PATHS
/usr/lib /usr/local/lib)
@@ -38,4 +39,7 @@ mark_as_advanced(JSONC_INC JSONC_LIB)
if(JSONC_FOUND)
set(JSONC_INCLUDE_DIRS ${JSONC_INC})
set(JSONC_LIBRARIES ${JSONC_LIB})
+ if (BUILD_STATIC)
+ set(JSONC_LIBRARIES ${JSONC_LIBRARIES} ${_JSONC_STATIC_LIBRARY_DIRS})
+ endif()
endif() \ No newline at end of file
diff --git a/cmake/FindLibarchive.cmake b/cmake/FindLibarchive.cmake
index bba3a35..37ac6bb 100644
--- a/cmake/FindLibarchive.cmake
+++ b/cmake/FindLibarchive.cmake
@@ -16,18 +16,19 @@ endif()
find_path(LIBARCHIVE_INC
NAMES archive.h archive_entry.h
HINTS
- ENV libarcguvePath${_lib_suffix}
- ENV libarcguvePath
- ${_JSONC_INCLUDE_DIRS}
+ ENV libarchivePath${_lib_suffix}
+ ENV libarchivePath
+ ${_LIBARCHIVE_INCLUDE_DIRS}
PATHS
/usr/include /usr/local/include)
find_library(LIBARCHIVE_LIB
NAMES ${_LIBARCHIVE_LIBRARIES} archive
HINTS
- ENV libarcguvePath${_lib_suffix}
- ENV libarcguvePath
+ ENV libarchivePath${_lib_suffix}
+ ENV libarchivePath
${_LIBARCHIVE_LIBRARY_DIRS}
+ ${_LIBARCHIVE_STATIC_LIBRARY_DIRS}
PATHS
/usr/lib /usr/local/lib)
@@ -38,4 +39,7 @@ mark_as_advanced(LIBARCHIVE_INC LIBARCHIVE_LIB)
if(LIBARCHIVE_FOUND)
set(LIBARCHIVE_INCLUDE_DIRS ${LIBARCHIVE_INC})
set(LIBARCHIVE_LIBRARIES ${LIBARCHIVE_LIB})
+ if (BUILD_STATIC)
+ set(LIBARCHIVE_LIBRARIES ${LIBARCHIVE_LIBRARIES} ${_LIBARCHIVE_STATIC_LIBRARIES})
+ endif()
endif() \ No newline at end of file
diff --git a/cmake/FindLibcurl.cmake b/cmake/FindLibcurl.cmake
index 9be1b9d..fbe6505 100644
--- a/cmake/FindLibcurl.cmake
+++ b/cmake/FindLibcurl.cmake
@@ -4,7 +4,7 @@
find_package(PkgConfig QUIET)
if (PKG_CONFIG_FOUND)
- pkg_check_modules(_CURL QUIET curl)
+ pkg_check_modules(_CURL REQUIRED QUIET libcurl)
endif()
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
@@ -28,6 +28,7 @@ find_library(CURL_LIB
ENV curlPath${_lib_suffix}
ENV curlPath
${_CURL_LIBRARY_DIRS}
+ ${_CURL_STATIC_LIBRARY_DIRS}
PATHS
/usr/lib /usr/local/lib)
@@ -38,4 +39,8 @@ mark_as_advanced(CURL_INC CURL_LIB)
if(LIBCURL_FOUND)
set(LIBCURL_INCLUDE_DIRS ${CURL_INC})
set(LIBCURL_LIBRARIES ${CURL_LIB})
+ if (BUILD_STATIC)
+ set(LIBCURL_LIBRARIES ${LIBCURL_LIBRARIES} ${_CURL_STATIC_LIBRARIES})
+ add_compile_definitions(CURL_STATICLIB)
+ endif()
endif() \ No newline at end of file
diff --git a/src/command.h b/src/command.h
index 7460d59..f4cd9fe 100644
--- a/src/command.h
+++ b/src/command.h
@@ -65,8 +65,8 @@
\
for (unsigned long i = 0; i < ARRAY_LEN(GROUP##_flags); ++i) \
{ \
- if ((GROUP##_flags[i].variant & SINGLE && argv[j][1] == GROUP##_flags[i].name[0]) || \
- (GROUP##_flags[i].variant & DOUBLE && argv[j][1] == '-' \
+ if ((GROUP##_flags[i].variant & ONE && argv[j][1] == GROUP##_flags[i].name[0]) || \
+ (GROUP##_flags[i].variant & TWO && argv[j][1] == '-' \
&& !strcmp(GROUP##_flags[i].name, argv[j]+2))) \
{ \
return GROUP##_flags[i].func(0, NULL); \
diff --git a/src/common.c b/src/common.c
index ae2087e..b17848b 100644
--- a/src/common.c
+++ b/src/common.c
@@ -48,14 +48,14 @@ void print_help(const struct Command* commands, const size_t commands_size,
for (size_t i = 0; i < flags_size; ++i)
{
fprintf(stderr, "\t");
- if (flags[i].variant & SINGLE)
+ if (flags[i].variant & ONE)
fprintf(stderr, "-%c", flags[i].name[0]);
else
fprintf(stderr, " ");
- if (flags[i].variant & DOUBLE)
+ if (flags[i].variant & TWO)
{
- if (flags[i].variant & SINGLE) fprintf(stderr, ",");
+ if (flags[i].variant & ONE) fprintf(stderr, ",");
fprintf(stderr, " --%-*s", (int)longestStr, flags[i].name);
}
@@ -80,14 +80,22 @@ int isFile(const char* path)
{
struct stat sb = getStat(path);
- return S_ISREG(sb.st_mode) || S_ISLNK(sb.st_mode);
+ return S_ISREG(sb.st_mode)
+#ifndef _WIN32
+ || S_ISLNK(sb.st_mode)
+#endif
+ ;
}
int isDir(const char* path)
{
struct stat sb = getStat(path);
- return S_ISDIR(sb.st_mode) || S_ISLNK(sb.st_mode);
+ return S_ISDIR(sb.st_mode)
+#ifndef _WIN32
+ || S_ISLNK(sb.st_mode)
+#endif
+ ;
}
int makeDir(const char* path)
@@ -145,8 +153,10 @@ int removeDir(const char *path)
if (!stat(buf, &statbuf)) {
if (S_ISDIR(statbuf.st_mode))
r = removeDir(buf);
+#ifndef _WIN32
else if (S_ISLNK(statbuf.st_mode))
r = unlink(buf);
+#endif
else
r = remove(buf);
}
diff --git a/src/common.h b/src/common.h
index 5f09c07..17b372c 100644
--- a/src/common.h
+++ b/src/common.h
@@ -53,6 +53,10 @@
#define JSON_LENGTH_TYPE int
#endif
+#ifdef _WIN32
+#define mkdir(path, perm) mkdir(path)
+#endif
+
struct MemoryStruct {
uint8_t* memory;
@@ -66,9 +70,9 @@ struct Command {
};
enum flag_variants {
- SINGLE = 1,
- DOUBLE = 2,
- BOTH = SINGLE + DOUBLE
+ ONE = 1 << 0,
+ TWO = 1 << 1,
+ BOTH = ONE + TWO,
};
struct Flag {
diff --git a/src/config.c b/src/config.c
index 85aaf40..ac2f82b 100644
--- a/src/config.c
+++ b/src/config.c
@@ -8,6 +8,12 @@
#include "config.h"
#include "common.h"
+#ifdef _WIN32
+#define HOMEVAR "USERPROFILE"
+#else
+#define HOMEVAR "HOME"
+#endif
+
static void getXDGDir(const char* envvar, const char* homeext, char* config, const size_t size)
{
char* xdg_var = getenv(envvar);
@@ -18,7 +24,8 @@ static void getXDGDir(const char* envvar, const char* homeext, char* config, con
}
else
{
- char* home = getenv("HOME");
+ char* home = getenv(HOMEVAR);
+ if (!home) home = "";
strncpy(config, home, size);
strncat(config, homeext, size - strlen(config));
}
diff --git a/src/dxvk.c b/src/dxvk.c
index 34790cd..fd288c2 100644
--- a/src/dxvk.c
+++ b/src/dxvk.c
@@ -4,7 +4,7 @@
#include <json.h>
#include <libgen.h>
#include <unistd.h>
-#include <linux/limits.h>
+#include <limits.h>
#include <dirent.h>
#include "dxvk.h"
@@ -21,7 +21,7 @@ static const struct Command dxvk_commands[] = {
};
static const struct Flag dxvk_flags[] = {
- { .name = "help", .variant = DOUBLE, .func = dxvk_help, .description = "show this message"}
+ { .name = "help", .variant = TWO, .func = dxvk_help, .description = "show this message"}
};
COMMAND_GROUP_FUNC(dxvk)
@@ -215,6 +215,9 @@ COMMAND(dxvk, installed)
char dxvkdir[PATH_MAX];
getDXVKDir(dxvkdir, sizeof(dxvkdir));
+ size_t dxvklen = strlen(dxvkdir)+1;
+ dxvkdir[dxvklen-1] = '/';
+
DIR *dir;
struct dirent *ent;
@@ -225,13 +228,17 @@ COMMAND(dxvk, installed)
{
while ((ent = readdir(dir)) != NULL)
{
- if (ent->d_name[0] != '.' && ent->d_type == DT_DIR)
- {
- if (intty) printf(" - ");
- printf("%s\n", ent->d_name);
- }
+ if (ent->d_name[0] == '.') continue;
+ strncat(dxvkdir, ent->d_name, sizeof(dxvkdir) - dxvklen - 1);
+ int isdirec = isDir(dxvkdir);
+ dxvkdir[dxvklen] = '\0';
+
+ if (!isdirec) continue;
+
+ if (intty) printf(" - ");
+ printf("%s\n", ent->d_name);
}
- closedir (dir);
+ closedir(dir);
}
return 0;
diff --git a/src/lutris.c b/src/lutris.c
index da893d1..b43d20c 100644
--- a/src/lutris.c
+++ b/src/lutris.c
@@ -3,7 +3,8 @@
#include <stdio.h>
#include <string.h>
#include <unistd.h>
-#include <linux/limits.h>
+#include <limits.h>
+#include <sys/stat.h>
#include <libgen.h>
#include "lutris.h"
#include "net.h"
@@ -16,7 +17,7 @@ static const struct Command lutris_commands[] = {
};
static const struct Flag lutris_flags[] = {
- { .name = "help", .variant = DOUBLE, .func = lutris_help, .description = "show this message"}
+ { .name = "help", .variant = TWO, .func = lutris_help, .description = "show this message"}
};
char* getpwd()
@@ -180,7 +181,7 @@ COMMAND(lutris, install)
// TODO
break;
case CHMODX:
- // TODO
+ chmod(installer.directives[i]->arguments[0], S_IXUSR);
break;
case EXECUTE:
// TODO
@@ -210,7 +211,11 @@ COMMAND(lutris, install)
case TASK:
parseVar(&installer.directives[i]->arguments[0], installer.variables, installer.variablecount);
+ #ifdef _WIN32
+ #warning TODO
+ #else
setenv("WINEPREFIX", installer.directives[i]->arguments[0], 1);
+ #endif
switch(installer.directives[i]->task)
{
case WINEEXEC:
@@ -223,9 +228,17 @@ COMMAND(lutris, install)
case CREATE_PREFIX:
printf("CREATE_PREFIX\n");
+ #ifdef _WIN32
+ #warning TODO
+ #else
setenv("WINEDEBUG", "-all", 1);
+ #endif
system("wineboot");
+ #ifdef _WIN32
+ #warning TODO
+ #else
unsetenv("WINEDEBUG");
+ #endif
break;
case SET_REGEDIT:
diff --git a/src/main.c b/src/main.c
index 5f7426d..c188ae8 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,7 +1,7 @@
#include <stdio.h>
#include <string.h>
-#include <linux/limits.h>
+#include <limits.h>
#include "main.h"
#include "wine.h"
@@ -11,14 +11,16 @@
#include "config.h"
static const struct Command main_commands[] = {
+#ifndef _WIN32
{ .name = "wine", .func = wine, .description = "manage wine versions" },
+#endif
{ .name = "dxvk", .func = dxvk, .description = "manage DXVK versions" },
{ .name = "lutris", .func = lutris, .description = "run lutris instraller"},
{ .name = "env", .func = main_env, .description = "show some information about polecat" },
};
static const struct Flag main_flags[] = {
- { .name = "help", .variant = DOUBLE, .func = main_help, .description = "show this message"},
+ { .name = "help", .variant = TWO, .func = main_help, .description = "show this message"},
{ .name = "version", .variant = BOTH, .func = main_version, .description = "prints the program version"}
};
diff --git a/src/tar.c b/src/tar.c
index d11728b..bd6e9fe 100644
--- a/src/tar.c
+++ b/src/tar.c
@@ -4,7 +4,7 @@
#include <archive.h>
#include <archive_entry.h>
#include <fcntl.h>
-#include <linux/limits.h>
+#include <limits.h>
#include "common.h"
#include "tar.h"
diff --git a/src/wine.c b/src/wine.c
index 08d67e5..956416b 100644
--- a/src/wine.c
+++ b/src/wine.c
@@ -25,7 +25,7 @@ static const struct Command wine_commands[] = {
};
static const struct Flag wine_flags[] = {
- { .name = "help", .variant = DOUBLE, .func = wine_help, .description = "show this message"}
+ { .name = "help", .variant = TWO, .func = wine_help, .description = "show this message"}
};
COMMAND_GROUP_FUNC(wine)
@@ -257,6 +257,9 @@ COMMAND(wine, installed)
char winedir[PATH_MAX];
getWineDir(winedir, sizeof(winedir));
+ size_t winelen = strlen(winedir)+1;
+ winedir[winelen-1] = '/';
+
DIR *dir;
struct dirent *ent;
@@ -268,13 +271,17 @@ COMMAND(wine, installed)
{
while ((ent = readdir (dir)) != NULL)
{
- if (ent->d_name[0] != '.' && ent->d_type == DT_DIR)
- {
- if (intty) printf(" - ");
- printf("%s\n", ent->d_name);
- }
+ if (ent->d_name[0] == '.') continue;
+ strncat(winedir, ent->d_name, sizeof(winedir) - winelen - 1);
+ int isdirec = isDir(winedir);
+ winedir[winelen] = '\0';
+
+ if (!isdirec) continue;
+
+ if (intty) printf(" - ");
+ printf("%s\n", ent->d_name);
}
- closedir (dir);
+ closedir(dir);
}
return 0;