diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 7 | ||||
-rw-r--r-- | src/mirror/main.c | 5 | ||||
-rw-r--r-- | src/net.c | 2 | ||||
-rw-r--r-- | src/net.h | 2 | ||||
-rw-r--r-- | src/qt/mainwindow.cpp | 2 | ||||
-rw-r--r-- | src/qt/workers.cpp | 75 | ||||
-rw-r--r-- | src/qt/workers.hpp | 1 | ||||
-rw-r--r-- | src/toast.c | 6 |
8 files changed, 38 insertions, 62 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d993dba..0fdcce5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,6 +1,6 @@ +find_package(json-c REQUIRED) find_package(Libcurl REQUIRED) -find_package(JsonC REQUIRED) add_subdirectory(hash) add_subdirectory(vdf) add_subdirectory(threading) @@ -14,7 +14,6 @@ set(CFLAGS -Wmissing-declarations -Wmissing-include-dirs -Wno-unused-parameter -Wuninitialized ${LIBCURL_CFLAGS} - ${JSONC_CFLAGS} ) list(APPEND @@ -33,12 +32,12 @@ add_library(tvn STATIC ${CORE_SOURCES}) target_compile_options(tvn PUBLIC ${CFLAGS}) target_include_directories(tvn PUBLIC ${LIBCURL_INCLUDE_DIRS}) -target_include_directories(tvn PUBLIC ${JSONC_INCLUDE_DIRS}) target_include_directories(tvn PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) target_link_libraries(tvn LINK_PUBLIC ${LIBCURL_LIBRARIES}) -target_link_libraries(tvn LINK_PUBLIC ${JSONC_LIBRARIES}) +target_link_libraries(tvn LINK_PUBLIC json-c::json-c) target_link_libraries(tvn LINK_PUBLIC md5) target_link_libraries(tvn LINK_PUBLIC vdf) + if (WIN32) target_link_libraries(tvn LINK_PUBLIC shlwapi) endif() diff --git a/src/mirror/main.c b/src/mirror/main.c index 51ce98a..89a085d 100644 --- a/src/mirror/main.c +++ b/src/mirror/main.c @@ -152,14 +152,9 @@ int main(int argc, char** argv) free(thread_info); } - char* buf = malloc(rev_len+1); - sprintf(buf, "%i", latest_rev); sprintf(revisions_dir_end, "%slatest", OS_PATH_SEP); - setLocalRevision(output_dir, latest_rev); symlink(".." OS_PATH_SEP TOAST_LOCAL_REVISION_PATH, revisions_dir); - - free(buf); free(revisions_dir); cleanup: @@ -4,7 +4,7 @@ #include <stdint.h> #include <unistd.h> #include <curl/curl.h> -#include <json.h> +#include <json-c/json.h> #include "net.h" #include "fs.h" @@ -6,7 +6,7 @@ extern "C" { #endif #include <curl/curl.h> -#include <json.h> +#include <json-c/json.h> struct MemoryStruct { uint8_t* memory; diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp index 12ddf3e..49cc09f 100644 --- a/src/qt/mainwindow.cpp +++ b/src/qt/mainwindow.cpp @@ -91,9 +91,11 @@ void MainWindow::workerResult(const enum Worker::Results_t& result) break; case Worker::RESULT_UPDATE_TEXT: + pthread_mutex_lock(&worker->textMutex); ui->progressBar->setValue(worker->progress); ui->infoLabel->setText(worker->infoText); worker->infoText.clear(); + pthread_mutex_unlock(&worker->textMutex); break; case Worker::RESULT_IS_INSTALLED: diff --git a/src/qt/workers.cpp b/src/qt/workers.cpp index 1642813..b0e18e8 100644 --- a/src/qt/workers.cpp +++ b/src/qt/workers.cpp @@ -47,15 +47,11 @@ static void* thread_download(void* pinfo) QString* threadString = &info->infoText; if (!threadString->isEmpty() && *do_work) { - pthread_mutex_lock(&worker->textMutex); - // allow the main thread to clear the string before we continue - while (!worker->infoText.isEmpty() && *do_work) {}; + int progress = (int)(((info->index * 100) + 1) / rev->file_count); + if (progress > worker->progress) + worker->progress = progress; - worker->progress = (int)(((info->index * 100) + 1) / rev->file_count); - - worker->infoText = *threadString; - emit worker->resultReady(Worker::RESULT_UPDATE_TEXT); - pthread_mutex_unlock(&worker->textMutex); + worker->setInfoText(*threadString); } } return NULL; @@ -104,6 +100,14 @@ QString Worker::getArguments() return settings.value("launchArguments", QString()).toString(); } +void Worker::setInfoText(QString infoTextArg) +{ + pthread_mutex_lock(&this->textMutex); + this->infoText = infoTextArg; + emit this->resultReady(Worker::RESULT_UPDATE_TEXT); + pthread_mutex_unlock(&this->textMutex); +} + void Worker::setArguments(QString argumentstr) { settings.setValue("launchArguments", argumentstr); @@ -141,7 +145,7 @@ int Worker::update_setup(int local_rev, int remote_rev) if (rev) { - for (size_t i = 0; i < rev->file_count; ++i) + for (size_t i = 0; i < rev->file_count && do_work; ++i) { struct file_info* file = &rev->files[i]; @@ -160,7 +164,7 @@ int Worker::update_setup(int local_rev, int remote_rev) struct pool_t* pool = pool_init(); pool->condition = &do_work; - for (size_t i = 0; i < rev->file_count; ++i) + for (size_t i = 0; i < rev->file_count && do_work; ++i) { struct thread_object_info* info = &thread_info[i]; @@ -178,24 +182,7 @@ int Worker::update_setup(int local_rev, int remote_rev) delete[] thread_info; progress = 0; - infoText = QString("Processing"); - emit resultReady(RESULT_UPDATE_TEXT); - - 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; - - progress = (int)(((i * 100) + 1) / rev->file_count); - emit resultReady(RESULT_UPDATE_TEXT); - - 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); - makeDir(buf); - free(buf); - } + this->setInfoText("Processing"); for (size_t i = 0; i < rev->file_count && do_work; ++i) { @@ -203,13 +190,14 @@ int Worker::update_setup(int local_rev, int remote_rev) 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); + char* buf = new char[len]; snprintf(buf, len, "%s%s%s", of_dir, OS_PATH_SEP, file->path); - if (isFile(buf) && remove(buf)) + if (isFile(buf)) { - printf("\nFailed to delete %s\n", file->path); + remove(buf); } - free(buf); + delete[] buf; + } for (size_t i = 0; i < rev->file_count && do_work; ++i) @@ -218,24 +206,18 @@ int Worker::update_setup(int local_rev, int remote_rev) 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); + char* buf = new char[len]; + snprintf(buf, len, "%s%s%s", of_dir, OS_PATH_SEP, file->path); + makeDir(buf); + delete[] buf; } - for (size_t i = 0; i < rev->file_count; ++i) + for (size_t i = 0; i < rev->file_count && do_work; ++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); - if (applyObject(of_dir, file)) - { - printf("\nFailed to write %s\n", file->path); - } + applyObject(of_dir, file); } if (do_work) @@ -245,13 +227,10 @@ int Worker::update_setup(int local_rev, int remote_rev) setLocalRevision(of_dir, remote_rev); } - progress = 0; - infoText = QString(""); - emit resultReady(RESULT_UPDATE_TEXT); - freeRevision(rev); } + this->setInfoText(""); update_in_progress = false; return retval; diff --git a/src/qt/workers.hpp b/src/qt/workers.hpp index 19d83f5..dbc2c7e 100644 --- a/src/qt/workers.hpp +++ b/src/qt/workers.hpp @@ -39,6 +39,7 @@ public: void setRemote(QString); QString getArguments(); void setArguments(QString); + void setInfoText(QString); int getRevision(); int getRemoteRevision(); diff --git a/src/toast.c b/src/toast.c index 0d3ac3a..9d184e5 100644 --- a/src/toast.c +++ b/src/toast.c @@ -3,7 +3,7 @@ #include <string.h> #include <stdio.h> #include <assert.h> -#include <json.h> +#include <json-c/json.h> #include <md5.h> #if defined(_WIN32) @@ -17,8 +17,8 @@ #include "net.h" #include "toast.h" -#ifdef TOAST_DEFAULT_REMOTE -#define TOAST_DEFAULT_REMOTE "http://toast.openfortress.fun/toast" +#ifndef TOAST_DEFAULT_REMOTE +#define TOAST_DEFAULT_REMOTE "https://toast.openfortress.fun/toast" #endif const char* TYPE_STRINGS[] = { |