diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/command.h | 4 | ||||
-rw-r--r-- | src/common.c | 20 | ||||
-rw-r--r-- | src/common.h | 10 | ||||
-rw-r--r-- | src/config.c | 9 | ||||
-rw-r--r-- | src/dxvk.c | 23 | ||||
-rw-r--r-- | src/lutris.c | 19 | ||||
-rw-r--r-- | src/main.c | 6 | ||||
-rw-r--r-- | src/tar.c | 2 | ||||
-rw-r--r-- | src/wine.c | 21 |
9 files changed, 82 insertions, 32 deletions
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)); } @@ -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: @@ -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"} }; @@ -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" @@ -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; |