From 4bd8a7b66d37c502b4144e9cdd9167ce87f7fa3a Mon Sep 17 00:00:00 2001 From: Jan200101 Date: Sat, 25 Dec 2021 21:01:20 +0100 Subject: add Proton support --- src/CMakeLists.txt | 13 ++++++++ src/config.c | 10 +++++++ src/config.h | 2 ++ src/defines.h | 4 ++- src/main.c | 6 ++++ src/proton.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/proton.h | 17 +++++++++++ 7 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 src/proton.c create mode 100644 src/proton.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index de3d40c..42ba5ee 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -67,6 +67,19 @@ list(APPEND ) endif() +if (ENABLE_PROTON AND NOT WIN32) +add_compile_definitions(PROTON_ENABLED) +add_library(proton OBJECT + ${CMAKE_CURRENT_SOURCE_DIR}/proton.c + ${CMAKE_CURRENT_SOURCE_DIR}/proton.h +) + +list(APPEND + SOURCES + $ +) +endif() + set(CFLAGS -Wall -Wextra -pedantic -Wconversion -Wshadow -Wstrict-aliasing diff --git a/src/config.c b/src/config.c index f05f5c1..4fb5f01 100644 --- a/src/config.c +++ b/src/config.c @@ -45,6 +45,10 @@ void getCacheDir(char* config, const size_t size) { getXDGDir("XDG_CACHE_HOME", "/.cache/" NAME, config, size); } +void getSteamDir(char* config, const size_t size) +{ + getXDGDir("XDG_DATA_HOME", "/.local/share/Steam", config, size); +} void getWineDir(char* config, const size_t size) { @@ -57,3 +61,9 @@ void getDXVKDir(char* config, const size_t size) getDataDir(config, size); strncat(config, "/dxvk", size - strlen(config) - 1); } + +void getProtonDir(char* config, const size_t size) +{ + getSteamDir(config, size); + strncat(config, "/compatibilitytools.d", size - strlen(config) - 1); +} diff --git a/src/config.h b/src/config.h index 39fb4d8..b2ee87d 100644 --- a/src/config.h +++ b/src/config.h @@ -6,8 +6,10 @@ void getConfigDir(char*, const size_t); void getDataDir(char*, const size_t); void getCacheDir(char*, const size_t); +void getSteamDir(char*, const size_t); void getWineDir(char*, const size_t); void getDXVKDir(char*, const size_t); +void getProtonDir(char*, const size_t); #endif diff --git a/src/defines.h b/src/defines.h index eb9989f..546fedb 100644 --- a/src/defines.h +++ b/src/defines.h @@ -5,8 +5,10 @@ #define GITHUB_API "https://api.github.com" #define LUTRIS_API "https://lutris.net/api" +#define GITHUB_RELEASE(repo) GITHUB_API"/repos/" repo "/releases" + #define WINE_API LUTRIS_API "/runners/wine" -#define DXVK_API GITHUB_API"/repos/lutris/dxvk/releases" +#define DXVK_API GITHUB_RELEASE("lutris/dxvk") #define INSTALLER_API LUTRIS_API "/installers/" #define LUTRIS_GAME_API LUTRIS_API "/games" #define LUTRIS_GAME_SEARCH_API LUTRIS_GAME_API "?search=%s" diff --git a/src/main.c b/src/main.c index 67f99db..a1b0577 100644 --- a/src/main.c +++ b/src/main.c @@ -7,6 +7,9 @@ #ifdef WINE_ENABLED #include "wine.h" #endif +#ifdef PROTON_ENABLED +#include "proton.h" +#endif #ifdef DXVK_ENABLED #include "dxvk.h" #endif @@ -27,6 +30,9 @@ static const struct Command main_commands[] = { #ifdef WINE_ENABLED { .name = "wine", .func = winecmd, .description = "manage wine versions" }, #endif +#ifdef PROTON_ENABLED + { .name = "proton", .func = proton, .description = "manage Proton installations" }, +#endif #ifdef DXVK_ENABLED { .name = "dxvk", .func = dxvk, .description = "manage DXVK versions" }, #endif diff --git a/src/proton.c b/src/proton.c new file mode 100644 index 0000000..0b0f289 --- /dev/null +++ b/src/proton.c @@ -0,0 +1,87 @@ +#include +#include +#include + +#include "proton.h" +#include "config.h" + +static const struct Command proton_commands[] = { + { .name = "download", .func = proton_download, .description = "download and extract a third.party Proton release" }, + { .name = "list", .func = proton_list, .description = "list installable Proton version" }, + { .name = "installed", .func = proton_installed, .description = "list already installed Proton versions" }, + { .name = "remove", .func = proton_remove, .description = "remove a Proton release" }, +}; + +static const struct Flag proton_flags[] = { + { .name = "no-net", .variant = TWO, .returns = 0, .func = set_no_net, .description = "run commands without commitment"} +}; + +char* repos[] = { + GITHUB_RELEASE("GloriousEggroll/proton-ge-custom"), + GITHUB_RELEASE("Frogging-Family/wine-tkg-git"), + NULL +}; + +COMMAND_GROUP_FUNC(proton) + +COMMAND(proton, download) +{ + return 0; +} + +COMMAND(proton, list) +{ + char** repo_index = repos; + + do + { + puts(*repo_index); + ++repo_index; + } + while(*repo_index); + + return 0; +} + +COMMAND(proton, installed) +{ + char protondir[PATH_MAX]; + getProtonDir(protondir, sizeof(protondir)); + + size_t protonlen = strlen(protondir)+1; + protondir[protonlen-1] = '/'; + + DIR *dir; + struct dirent *ent; + + int intty = isatty(STDOUT_FILENO); + + if (intty) puts("Installed Proton versions:"); + + if ((dir = opendir(protondir)) != NULL) + { + while ((ent = readdir (dir)) != NULL) + { + if (ent->d_name[0] == '.') continue; + strncat(protondir, ent->d_name, sizeof(protondir) - protonlen - 1); + int isdirec = isDir(protondir); + protondir[protonlen] = '\0'; + + if (!isdirec) continue; + + if (intty) printf(" - "); + printf("%s\n", ent->d_name); + } + closedir(dir); + } + + return EXIT_SUCCESS; +} + +COMMAND(proton, remove) +{ + return 0; +} + + +COMMAND_HELP(proton, " proton") diff --git a/src/proton.h b/src/proton.h new file mode 100644 index 0000000..c5d87d5 --- /dev/null +++ b/src/proton.h @@ -0,0 +1,17 @@ +#ifndef PROTON_H +#define PROTON_H + +#include + +#include "command.h" + +extern char* repos[]; + +COMMAND_GROUP(proton); +COMMAND(proton, download); +COMMAND(proton, list); +COMMAND(proton, installed); +COMMAND(proton, remove); +COMMAND(proton, help); + +#endif \ No newline at end of file -- cgit v1.2.3