aboutsummaryrefslogtreecommitdiff
path: root/src/cli
diff options
context:
space:
mode:
authorJan200101 <sentrycraft123@gmail.com>2022-09-11 14:39:24 +0200
committerJan200101 <sentrycraft123@gmail.com>2022-09-11 14:39:24 +0200
commit37de0cc7b0eeeefcc25173913faaefa2a7673d2c (patch)
tree33a216d1c211e00aff2035e929d304768e5064e1 /src/cli
parent7809edab2aab5701f7be3f278b10e030e944477e (diff)
downloadOFQT-37de0cc7b0eeeefcc25173913faaefa2a7673d2c.tar.gz
OFQT-37de0cc7b0eeeefcc25173913faaefa2a7673d2c.zip
rename force update to verify, reorder updates, return rename retval
Diffstat (limited to 'src/cli')
-rw-r--r--src/cli/commands.c10
-rw-r--r--src/cli/updater.c59
2 files changed, 32 insertions, 37 deletions
diff --git a/src/cli/commands.c b/src/cli/commands.c
index 30d3bca..9ff4791 100644
--- a/src/cli/commands.c
+++ b/src/cli/commands.c
@@ -104,13 +104,13 @@ static int install(int c, char** v)
static int update(int c, char** v)
{
int exit_val = EXIT_SUCCESS;
- int force = 0;
+ int verify = 0;
char* of_dir = NULL;
char* remote = NULL;
for (int i = 1; i < c; ++i)
{
- if (!strcmp(v[i], "--force"))
- force = 1;
+ if (!strcmp(v[i], "--verify"))
+ verify = 1;
else if (!strcmp(v[i], "--dir"))
{
if (!v[++i])
@@ -138,7 +138,7 @@ static int update(int c, char** v)
puts(
"OFCL update\n"
- "\t--force\t\tforce update\n"
+ "\t--verify\t\tverify game files\n"
"\t--dir\t\tspecify where to download OpenFortress to\n"
"\t--remote\tspecify the server to use\n"
"\t--help\t\tshows this text"
@@ -151,7 +151,7 @@ static int update(int c, char** v)
of_dir = getOpenFortressDir();
int local_rev = getLocalRevision(of_dir);
- if (force)
+ if (verify)
{
local_rev = 0;
}
diff --git a/src/cli/updater.c b/src/cli/updater.c
index 519da29..f6120c7 100644
--- a/src/cli/updater.c
+++ b/src/cli/updater.c
@@ -56,7 +56,7 @@ void update_setup(char* of_dir, char* remote, int local_rev, int remote_rev)
if (leavesRelativePath(file->path))
{
- printf("Revision contains invalid path '%s'\n", file->path);
+ fprintf(stderr, "Revision contains invalid path '%s'\n", file->path);
freeRevision(rev);
return;
}
@@ -82,53 +82,48 @@ void update_setup(char* of_dir, char* remote, int local_rev, int remote_rev)
pool_free(pool);
free(thread_info);
+ puts("");
for (size_t i = 0; i < rev->file_count; ++i)
{
struct file_info* file = &rev->files[i];
- if (file->type != TYPE_MKDIR)
- continue;
+ if (file->type != TYPE_DELETE) continue;
+ fprintf(stderr, "\rDeleting %zu/%zu", i+1, rev->file_count);
size_t len = strlen(of_dir) + strlen(OS_PATH_SEP) + strlen(file->path) + 1;
char* buf = malloc(len);
snprintf(buf, len, "%s%s%s", of_dir, OS_PATH_SEP, file->path);
- makeDir(buf);
+ if (isFile(buf) && remove(buf))
+ {
+ fprintf(stderr, "\rFailed to delete %s\n", file->path);
+ }
+ free(buf);
+ }
+
+ for (size_t i = 0; i < rev->file_count; ++i)
+ {
+ struct file_info* file = &rev->files[i];
+
+ if (file->type != TYPE_MKDIR) continue;
+ size_t len = strlen(of_dir) + strlen(OS_PATH_SEP) + strlen(file->path) + 1;
+ char* buf = malloc(len);
+ fprintf(stderr, "\rCreating %zu/%zu", i+1, rev->file_count);
+ snprintf(buf, len, "%s%s%s", of_dir, OS_PATH_SEP, file->path);
+ if (!isDir(buf) && !makeDir(buf))
+ {
+ fprintf(stderr, "\nFailed to create %s\n", file->path);
+ }
free(buf);
}
- puts("");
for (size_t i = 0; i < rev->file_count; ++i)
{
struct file_info* file = &rev->files[i];
+ if (file->type != TYPE_WRITE) continue;
fprintf(stderr, "\rInstalling %zu/%zu (%s)", i+1, rev->file_count, file->object);
- switch (file->type)
+ if (applyObject(of_dir, file))
{
- case TYPE_WRITE:
- case TYPE_MKDIR:
- {
- if (applyObject(of_dir, file))
- {
- printf("\rFailed to write %s\n", file->path);
- }
- }
- break;
-
- case TYPE_DELETE:
- {
- size_t len = strlen(of_dir) + strlen(OS_PATH_SEP) + strlen(file->path) + 1;
- char* buf = malloc(len);
- snprintf(buf, len, "%s%s%s", of_dir, OS_PATH_SEP, file->path);
- if (isFile(buf) && remove(buf))
- {
- printf("\rFailed to delete %s\n", file->path);
- }
- free(buf);
- }
- break;
-
- default:
- assert(0);
- break;
+ fprintf(stderr, "\nFailed to write %s\n", file->path);
}
}