aboutsummaryrefslogtreecommitdiff
path: root/src/wine.c
diff options
context:
space:
mode:
authorJan200101 <sentrycraft123@gmail.com>2020-07-31 17:26:09 +0200
committerJan200101 <sentrycraft123@gmail.com>2020-07-31 17:26:09 +0200
commit1db300d8815b5f997dd6f992e4ca416537018c2f (patch)
tree77cf0330be07b8553bc46f53f0e302a9cb81d561 /src/wine.c
parentaabfdfe3fcbcf718b30872c98568581d7e7e6cca (diff)
downloadpolecat-1db300d8815b5f997dd6f992e4ca416537018c2f.tar.gz
polecat-1db300d8815b5f997dd6f992e4ca416537018c2f.zip
implement running wine from polecat and more0.1.2
- implement running wine from polecat directly and pass all arguments to wine (default wine prefix is still $HOME/.wine) - add command to list installed wine versions (lists all directories, needs to be improved) - rename wine install to wine download - replace deprecated support_compression_all with support_filter_all - comment out DXVK command until its further implemented - use PATH_MAX for strings holding paths
Diffstat (limited to 'src/wine.c')
-rw-r--r--src/wine.c76
1 files changed, 68 insertions, 8 deletions
diff --git a/src/wine.c b/src/wine.c
index 82ab655..fe63644 100644
--- a/src/wine.c
+++ b/src/wine.c
@@ -1,8 +1,13 @@
+#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <json.h>
#include <libgen.h>
#include <unistd.h>
+#include <linux/limits.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <dirent.h>
#include "wine.h"
#include "net.h"
@@ -10,10 +15,13 @@
#include "common.h"
#include "config.h"
+
const static struct Command wine_commands[] = {
- { .name = "install", .func = wine_install, .description = "download and install a wine version from lutris" },
- { .name = "list", .func = wine_list, .description = "list available wine versions" },
- { .name = "help", .func = wine_help, .description = "shows this message" },
+ { .name = "download", .func = wine_download, .description = "download and extract a wine version from lutris" },
+ { .name = "list", .func = wine_list, .description = "list installable wine versions" },
+ { .name = "run", .func = wine_run, .description = "run a installed wine version" },
+ { .name = "list-installed", .func = wine_installed, .description = "list installed wine versions" },
+ { .name = "help", .func = wine_help, .description = "shows this message" },
};
int wine(int argc, char** argv)
@@ -29,7 +37,7 @@ int wine(int argc, char** argv)
return wine_help(argc, argv);
}
-int wine_install(int argc, char** argv)
+int wine_download(int argc, char** argv)
{
if (argc == 4)
{
@@ -54,8 +62,8 @@ int wine_install(int argc, char** argv)
json_object_object_get_ex(value, "url", &url);
char* name = basename((char*)json_object_get_string(url));
- char datadir[256];
- char downloadpath[256];
+ char datadir[PATH_MAX];
+ char downloadpath[PATH_MAX];
getDataDir(datadir);
makeDir(datadir);
@@ -74,7 +82,7 @@ int wine_install(int argc, char** argv)
}
else
{
- puts("Usage: polecat wine download <ID>\n\nIDs are obtained via `polecat wine list' ");
+ puts("Usage: " NAME " wine download <ID>\n\nIDs are obtained via `" NAME " wine list' ");
}
return 0;
}
@@ -101,9 +109,61 @@ int wine_list(int argc, char** argv)
return 0;
}
+int wine_run(int argc, char** argv)
+{
+ if (argc > 3)
+ {
+ char winepath[PATH_MAX];
+ getDataDir(winepath);
+ char* winever = argv[3];
+
+ strcat(winepath, "/");
+ strcat(winepath, winever);
+ strcat(winepath, "/bin/wine");
+
+ for (int i = 4; i < argc; ++i)
+ {
+ strcat(winepath, " ");
+ strcat(winepath, argv[i]);
+ }
+
+ return system(winepath);
+ }
+ else
+ {
+ fprintf(stderr, "Specify a what wine version to run.\nUse `" NAME " wine list-installed' to list available versions\n");
+ }
+
+ return 0;
+}
+
+int wine_installed(int argc, char** argv)
+{
+ char datadir[PATH_MAX];
+ getDataDir(datadir);
+
+ DIR *dir;
+ struct dirent *ent;
+
+ fprintf(stderr, "Installed wine versions:\n");
+ if ((dir = opendir(datadir)) != NULL)
+ {
+ while ((ent = readdir (dir)) != NULL)
+ {
+ if (ent->d_name[0] != '.' && ent->d_type == 4)
+ {
+ fprintf(stderr, " - %s\n", ent->d_name);
+ }
+ }
+ closedir (dir);
+ }
+
+ return 0;
+}
+
int wine_help(int argc, char** argv)
{
- puts("usage: polecat wine <command>\n\nList of commands:");
+ puts("usage: " NAME " wine <command>\n\nList of commands:");
print_help(wine_commands, ARRAY_LEN(wine_commands));