diff options
author | Jan200101 <sentrycraft123@gmail.com> | 2022-09-11 14:39:24 +0200 |
---|---|---|
committer | Jan200101 <sentrycraft123@gmail.com> | 2022-09-11 14:39:24 +0200 |
commit | 37de0cc7b0eeeefcc25173913faaefa2a7673d2c (patch) | |
tree | 33a216d1c211e00aff2035e929d304768e5064e1 | |
parent | 7809edab2aab5701f7be3f278b10e030e944477e (diff) | |
download | OFQT-37de0cc7b0eeeefcc25173913faaefa2a7673d2c.tar.gz OFQT-37de0cc7b0eeeefcc25173913faaefa2a7673d2c.zip |
rename force update to verify, reorder updates, return rename retval
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/cli/commands.c | 10 | ||||
-rw-r--r-- | src/cli/updater.c | 59 | ||||
-rw-r--r-- | src/qt/workers.cpp | 56 | ||||
-rw-r--r-- | src/toast.c | 6 |
5 files changed, 68 insertions, 65 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index f9c2a32..51ef549 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,7 +23,7 @@ if (ENABLE_TESTS) endif() -set(TOAST_DEFAULT_REMOTE "http://toast.openfortress.fun/toast" CACHE STRING +set(TOAST_DEFAULT_REMOTE "https://toast.openfortress.fun/toast" CACHE STRING "Default Mirror to get OpenFortress files from") add_compile_definitions(NAME="${CMAKE_PROJECT_NAME}") 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); } } diff --git a/src/qt/workers.cpp b/src/qt/workers.cpp index a54509f..1642813 100644 --- a/src/qt/workers.cpp +++ b/src/qt/workers.cpp @@ -201,32 +201,40 @@ int Worker::update_setup(int local_rev, int remote_rev) { struct file_info* file = &rev->files[i]; - progress = (int)(((i * 100) + 1) / rev->file_count); - emit resultReady(RESULT_UPDATE_TEXT); + if (file->type != TYPE_DELETE) continue; + size_t len = strlen(of_dir) + strlen(OS_PATH_SEP) + strlen(file->path) + 1; + char* buf = (char*)malloc(len); + snprintf(buf, len, "%s%s%s", of_dir, OS_PATH_SEP, file->path); + if (isFile(buf) && remove(buf)) + { + printf("\nFailed to delete %s\n", file->path); + } + free(buf); + } + + for (size_t i = 0; i < rev->file_count && do_work; ++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 = (char*)malloc(len); + if (!isDir(buf) && makeDir(buf)) + { + printf("\nFailed to create %s\n", file->path); + } + free(buf); + } + + for (size_t i = 0; i < rev->file_count; ++i) + { + struct file_info* file = &rev->files[i]; - switch (file->type) + if (file->type != TYPE_WRITE) continue; + fprintf(stderr, "\rInstalling %zu/%zu (%s)", i+1, rev->file_count, file->object); + if (applyObject(of_dir, file)) { - case TYPE_WRITE: - case TYPE_MKDIR: - { - retval += applyObject(of_dir, file); - } - break; - - case TYPE_DELETE: - { - size_t len = strlen(of_dir) + strlen(OS_PATH_SEP) + strlen(file->path) + 1; - char* buf = (char*)malloc(len); - snprintf(buf, len, "%s%s%s", of_dir, OS_PATH_SEP, file->path); - if (isFile(buf)) - retval += remove(buf); - free(buf); - } - break; - - default: - assert(0); - break; + printf("\nFailed to write %s\n", file->path); } } diff --git a/src/toast.c b/src/toast.c index c054e2f..0d3ac3a 100644 --- a/src/toast.c +++ b/src/toast.c @@ -149,7 +149,7 @@ void setLocalRevision(char* dir, int rev) return; // cleanup legacy behavior - { + { char* old_revision_path = malloc(strlen(revision_path) + strlen(OLD_TOAST_LOCAL_REVISION_PATH)); strcpy(old_revision_path, revision_path); @@ -542,12 +542,12 @@ int applyObject(char* path, struct file_info* info) char* buf_file = malloc(len); snprintf(buf_file, len, "%s%s%s", path, OS_PATH_SEP, file); - rename(buf_obj, buf_file); + int retval = rename(buf_obj, buf_file); free(buf_obj); free(buf_file); - return 0; + return retval; } /** |