aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan200101 <sentrycraft123@gmail.com>2020-12-14 00:11:24 +0100
committerJan200101 <sentrycraft123@gmail.com>2020-12-14 00:11:24 +0100
commit7cfe6b1e6132e608fcc034bf97611e4b1eb57613 (patch)
tree33a125d4740f5668ddcb64d94500a38a2a6cd205
parent1d59162c13db8051badb1bb501faf8ccf42b10e9 (diff)
downloadpolecat-7cfe6b1e6132e608fcc034bf97611e4b1eb57613.tar.gz
polecat-7cfe6b1e6132e608fcc034bf97611e4b1eb57613.zip
allow downloading multiple wine versions at the same time
-rw-r--r--src/wine.c86
1 files changed, 46 insertions, 40 deletions
diff --git a/src/wine.c b/src/wine.c
index 0cfbfd2..9276459 100644
--- a/src/wine.c
+++ b/src/wine.c
@@ -1,6 +1,7 @@
#include <stdlib.h>
#include <stdio.h>
+#include <stdbool.h>
#include <string.h>
#include <json.h>
#include <libgen.h>
@@ -15,7 +16,7 @@
#include "common.h"
const static struct Command wine_commands[] = {
- { .name = "download", .func = wine_download, .description = "download and extract a wine version" },
+ { .name = "download", .func = wine_download, .description = "download and extract a wine versions" },
{ .name = "remove", .func = wine_remove, .description = "remove a wine version" },
{ .name = "list", .func = wine_list, .description = "list installable wine versions" },
{ .name = "run", .func = wine_run, .description = "run an installed wine version" },
@@ -28,61 +29,66 @@ COMMAND_GROUP_FUNC(wine)
COMMAND(wine, download)
{
- if (argc == 2)
+ if (argc >= 2)
{
struct json_object* runner = fetchJSON(WINE_API);
if (runner)
{
struct json_object* versions, *value, *temp;
- uint8_t found = 0;
+ bool found;
json_object_object_get_ex(runner, "versions", &versions);
- char* choice = argv[1];
-
- for (int i = 0; i < json_object_array_length(versions); ++i)
- {
- value = json_object_array_get_idx(versions, i);
- json_object_object_get_ex(value, "version", &temp);
- if (strcmp(json_object_get_string(temp), choice) == 0)
- {
- found = 1;
- break;
- }
- }
-
- if (found)
+ for (int i = 1; i < argc; ++i)
{
- json_object_object_get_ex(value, "url", &temp);
+ found = false;
+ char* choice = argv[i];
- char* name = basename((char*)json_object_get_string(temp));
- char winedir[PATH_MAX];
- struct MemoryStruct* archive;
-
- getWineDir(winedir, sizeof(winedir));
- makeDir(winedir);
-
- fprintf(stderr, "Downloading %s\n", name);
+ for (int i = 0; i < json_object_array_length(versions); ++i)
+ {
+ value = json_object_array_get_idx(versions, i);
+ json_object_object_get_ex(value, "version", &temp);
+ if (strcmp(json_object_get_string(temp), choice) == 0)
+ {
+ found = true;
+ break;
+ }
+ }
- archive = downloadToRam(json_object_get_string(temp));
- if (archive)
+ if (found)
{
- fprintf(stderr, "Extracting %s\n", name);
- extract(archive, winedir);
- fprintf(stderr, "Done\n");
+ json_object_object_get_ex(value, "url", &temp);
+
+ char* name = basename((char*)json_object_get_string(temp));
+
+ char winedir[PATH_MAX];
+ struct MemoryStruct* archive;
+
+ getWineDir(winedir, sizeof(winedir));
+ makeDir(winedir);
+
+ fprintf(stderr, "Downloading %s\n", name);
+
+ archive = downloadToRam(json_object_get_string(temp));
+ if (archive)
+ {
+ fprintf(stderr, "Extracting %s\n", name);
+ extract(archive, winedir);
+ fprintf(stderr, "Done\n");
+ }
+ else
+ {
+ fprintf(stderr, "Something went wrong. The archive went missing\n");
+ }
+
+ free(archive->memory);
+ free(archive);
}
else
{
- fprintf(stderr, "Something went wrong. The archive went missing\n");
+ fprintf(stderr, "Could not find `%s'\n", choice);
}
-
- free(archive->memory);
- free(archive);
- }
- else
- {
- fprintf(stderr, "Could not find `%s'\n", choice);
}
json_object_put(runner);
@@ -90,7 +96,7 @@ COMMAND(wine, download)
}
else
{
- fprintf(stderr, USAGE_STR " wine download <version>\n\nversions are obtained via `" NAME " wine list'\n");
+ fprintf(stderr, USAGE_STR " wine download [versions]\n\nversions are obtained via `" NAME " wine list'\n");
}
return 0;
}