diff options
author | Jan200101 <sentrycraft123@gmail.com> | 2020-12-12 14:32:22 +0100 |
---|---|---|
committer | Jan200101 <sentrycraft123@gmail.com> | 2020-12-12 14:32:22 +0100 |
commit | 1d88aa80aae9f7aa8df58a54f7eea0f0d0e5541a (patch) | |
tree | bf33b04669b960eb0fe956998a8ec1800b19c5cd | |
parent | 28dc82c923d369f156008167237583f725e90375 (diff) | |
download | polecat-1d88aa80aae9f7aa8df58a54f7eea0f0d0e5541a.tar.gz polecat-1d88aa80aae9f7aa8df58a54f7eea0f0d0e5541a.zip |
change download routines to require a version name, not a random ID
-rw-r--r-- | src/dxvk.c | 48 | ||||
-rw-r--r-- | src/wine.c | 39 |
2 files changed, 57 insertions, 30 deletions
@@ -31,35 +31,43 @@ COMMAND(dxvk, download) if (runner) { - int choice = atoi(argv[1]); + struct json_object* value, *temp, *temp2; + uint8_t found = 0; - if (choice > json_object_array_length(runner) - 1 || choice < 0) + char* choice = argv[1]; + + for (int i = 0; i < json_object_array_length(runner); ++i) { - fprintf(stderr, "`%i' is not a valid ID\n\nrun `" NAME " dxvk list' to get a valid ID", choice); + value = json_object_array_get_idx(runner, i); + json_object_object_get_ex(value, "tag_name", &temp); + if (strcmp(json_object_get_string(temp), choice) == 0) + { + found = 1; + break; + } } - else + + if (found) { - struct json_object* version = json_object_array_get_idx(runner, choice); - struct json_object* assets; + json_object_object_get_ex(value, "assets", &temp); + temp2 = json_object_array_get_idx(temp, 0); - json_object_object_get_ex(version, "assets", &assets); - version =json_object_array_get_idx(assets, 0); + json_object_object_get_ex(temp2, "browser_download_url", &temp); - json_object_object_get_ex(version, "browser_download_url", &assets); + char* name = basename((char*)json_object_get_string(temp)); - char* name = basename((char*)json_object_get_string(assets)); + char dxvkdir[PATH_MAX]; struct MemoryStruct* archive; - char dxvkdir[PATH_MAX]; getDXVKDir(dxvkdir, sizeof(dxvkdir)); makeDir(dxvkdir); fprintf(stderr, "Downloading %s\n", name); - archive = downloadToRam(json_object_get_string(assets)); + archive = downloadToRam(json_object_get_string(temp)); if (archive) { - printf("Extracting %s\n", name); + fprintf(stderr, "Extracting %s\n", name); extract(archive, dxvkdir); fprintf(stderr, "Done\n"); } @@ -71,13 +79,17 @@ COMMAND(dxvk, download) free(archive->memory); free(archive); } + else + { + fprintf(stderr, "Could not find `%s'\n", choice); + } json_object_put(runner); } } else { - fprintf(stderr, USAGE_STR " dxvk download <ID>\n\nIDs are obtained via `" NAME " dxvk list'\n"); + fprintf(stderr, USAGE_STR " dxvk download <version>\n\nversions are obtained via `" NAME " dxvk list'\n"); } return 0; } @@ -125,15 +137,17 @@ COMMAND(dxvk, list) if (runner) { - if (isatty(STDOUT_FILENO)) puts("Installable DXVK versions:"); + int istty = isatty(STDOUT_FILENO); + if (istty) puts("Installable DXVK versions:"); for (size_t i = 0; i < json_object_array_length(runner); ++i) { struct json_object* version = json_object_array_get_idx(runner, i); struct json_object* name; - json_object_object_get_ex(version, "name", &name); - printf(" [%zu]\t%s\n", i, json_object_get_string(name)); + json_object_object_get_ex(version, "tag_name", &name); + if (istty) printf(" - "); + printf("%s\n", json_object_get_string(name)); } } @@ -33,22 +33,28 @@ COMMAND(wine, download) if (runner) { - struct json_object* versions; + struct json_object* versions, *value, *temp; + uint8_t found = 0; json_object_object_get_ex(runner, "versions", &versions); - int choice = atoi(argv[1]); + char* choice = argv[1]; - if (choice > json_object_array_length(versions) - 1 || choice < 0) + for (int i = 0; i < json_object_array_length(versions); ++i) { - fprintf(stderr, "`%i' is not a valid ID\n\nrun `polecat wine list' to get a valid ID\n", choice); + 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; + } } - else + + if (found) { - struct json_object* url; - struct json_object* value = json_object_array_get_idx(versions, choice); + json_object_object_get_ex(value, "url", &temp); - json_object_object_get_ex(value, "url", &url); - char* name = basename((char*)json_object_get_string(url)); + char* name = basename((char*)json_object_get_string(temp)); char winedir[PATH_MAX]; struct MemoryStruct* archive; @@ -58,7 +64,7 @@ COMMAND(wine, download) fprintf(stderr, "Downloading %s\n", name); - archive = downloadToRam(json_object_get_string(url)); + archive = downloadToRam(json_object_get_string(temp)); if (archive) { fprintf(stderr, "Extracting %s\n", name); @@ -73,13 +79,17 @@ COMMAND(wine, download) free(archive->memory); free(archive); } + else + { + fprintf(stderr, "Could not find `%s'\n", choice); + } json_object_put(runner); } } else { - fprintf(stderr, USAGE_STR " wine download <ID>\n\nIDs are obtained via `" NAME " wine list'\n"); + fprintf(stderr, USAGE_STR " wine download <version>\n\nversions are obtained via `" NAME " wine list'\n"); } return 0; } @@ -144,13 +154,16 @@ COMMAND(wine, list) struct json_object* versions, *value, *val; json_object_object_get_ex(runner, "versions", &versions); - if(isatty(STDOUT_FILENO)) puts("Installable wine versions:"); + int intty = isatty(STDOUT_FILENO); + + if(intty) puts("Installable wine versions:"); for (size_t i = 0; i < json_object_array_length(versions); ++i) { value = json_object_array_get_idx(versions, i); json_object_object_get_ex(value, "version", &val); - printf(" [%zu]\t%s\n", i, json_object_get_string(val)); + if (intty) printf(" - "); + printf("%s\n", json_object_get_string(val)); } json_object_put(runner); |