diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5767415..aec30ad 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -109,16 +109,25 @@ jobs: - name: Use windeployqt to load libraries shell: bash run: | - mv build/CanvasSync.exe \ - deploy/windows/packages/com.nguyenvukhang.canvassync/data - cd deploy/windows/packages/com.nguyenvukhang.canvassync/data + cd build + mv CanvasSync.exe .. + rm -rf * + mv ../CanvasSync.exe . $Qt6_DIR/bin/windeployqt.exe CanvasSync.exe + cd .. + + rm -rf deploy/windows/packages/com.nguyenvukhang.canvassync/data + mv build deploy/windows/packages/com.nguyenvukhang.canvassync/data + cd deploy/windows/packages/com.nguyenvukhang.canvassync/data mv CanvasSync.exe 'Canvas Sync.exe' - name: Package the installer shell: bash run: | cd deploy/windows + echo '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~' + ls + echo '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~' $IQTA_TOOLS/QtInstallerFramework/4.5/bin/binarycreator.exe \ -c config/config.xml -p packages CanvasSyncInstaller.exe mv CanvasSyncInstaller.exe ../.. diff --git a/CMakeLists.txt b/CMakeLists.txt index 4a95f9c..c0fb20e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,11 +36,12 @@ endif() qt_add_executable(CanvasSync MANUAL_FINALIZATION main.cc) include_directories( - ${PROJECT_SOURCE_DIR}/app - ${PROJECT_SOURCE_DIR}/build/app/CanvasSyncLib_autogen/include + ${CMAKE_SOURCE_DIR}/app + ${CMAKE_SOURCE_DIR}/build/app/CanvasSyncLib_autogen/include ) target_link_libraries(CanvasSync PRIVATE Qt6::Widgets Qt6::Network CanvasSyncLib) + set_target_properties(CanvasSync PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Canvas Sync" MACOSX_BUNDLE_GUI_IDENTIFIER canvassync.nguyenvukhang.com diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 02a1433..f6b77f6 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -25,8 +25,5 @@ include_directories( option(BUILD_STATIC_LIBS ON) option(BUILD_SHARED_LIBS OFF) -qt_add_library(CanvasSyncLib MANUAL_FINALIZATION ${PROJECT_SOURCES}) +qt_add_library(CanvasSyncLib STATIC MANUAL_FINALIZATION ${PROJECT_SOURCES}) target_link_libraries(CanvasSyncLib PRIVATE Qt6::Widgets Qt6::Network) -install(TARGETS CanvasSyncLib - BUNDLE DESTINATION . - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) diff --git a/app/canvas.cc b/app/canvas.cc index bd9ee11..6d12cca 100644 --- a/app/canvas.cc +++ b/app/canvas.cc @@ -1,5 +1,40 @@ #include "canvas.h" +void ICanvas::reset_counts() +{ + for (size_t i = 0; i < 4; i++) + count[i] = 0; +} + +size_t ICanvas::increment_total_downloads(size_t n) +{ + size_t x; + count_mtx.lock(); + count[DOWNLOAD_TOTAL] += n; + x = count[DOWNLOAD_TOTAL]; + count_mtx.unlock(); + return x; +} + +size_t ICanvas::increment_done_downloads() +{ + size_t x; + count_mtx.lock(); + count[DOWNLOAD_DONE]++; + x = count[DOWNLOAD_DONE]; + count_mtx.unlock(); + return x; +} + +bool ICanvas::is_done_downloading() +{ + bool x; + count_mtx.lock(); + x = count[DOWNLOAD_DONE] == count[DOWNLOAD_TOTAL]; + count_mtx.unlock(); + return x; +} + void write_file(const std::filesystem::path &path, const QByteArray &data) { QString file = QString::fromStdString(path.string()); @@ -128,48 +163,3 @@ void Canvas::download(const File &file, const Folder &folder) if (done) emit all_download_done(); }); } - -bool Canvas::has_downloads() -{ - return count[DOWNLOAD_TOTAL] > 0; -} - -void Canvas::reset_counts() -{ - for (size_t i = 0; i < 4; i++) - count[i] = 0; -} - -void Canvas::set_total_fetches(size_t n) -{ - count[FETCH_TOTAL] = n; -} - -size_t Canvas::increment_total_downloads(size_t n) -{ - size_t x; - count_mtx.lock(); - count[DOWNLOAD_TOTAL] += n; - x = count[DOWNLOAD_TOTAL]; - count_mtx.unlock(); - return x; -} - -size_t Canvas::increment_done_downloads() -{ - size_t x; - count_mtx.lock(); - count[DOWNLOAD_DONE]++; - x = count[DOWNLOAD_DONE]; - count_mtx.unlock(); - return x; -} - -bool Canvas::is_done_downloading() -{ - bool x; - count_mtx.lock(); - x = count[DOWNLOAD_DONE] == count[DOWNLOAD_TOTAL]; - count_mtx.unlock(); - return x; -} diff --git a/app/canvas.h b/app/canvas.h index 96227a0..f293f40 100644 --- a/app/canvas.h +++ b/app/canvas.h @@ -20,24 +20,28 @@ class ICanvas : public QObject protected: QString base_url, token_inner; + size_t count[4]; + enum Count { FETCH_DONE, FETCH_TOTAL, DOWNLOAD_DONE, DOWNLOAD_TOTAL }; + std::mutex count_mtx; public: ICanvas(const QString &u) : base_url(u){}; ICanvas() = delete; - virtual const QString &token() const { return this->token_inner; }; - virtual void set_token(const QString &t) { this->token_inner = t; }; virtual void authenticate() = 0; virtual void fetch_courses() = 0; virtual void fetch_folders(const Course &) = 0; virtual void fetch_files(const Folder &) = 0; virtual void download(const File &, const Folder &) = 0; - virtual void reset_counts() = 0; - virtual void set_total_fetches(size_t) = 0; - virtual size_t increment_total_downloads(size_t) = 0; - virtual size_t increment_done_downloads() = 0; - virtual bool is_done_downloading() = 0; - virtual bool has_downloads() = 0; + + const QString &token() const { return this->token_inner; }; + void set_token(const QString &t) { this->token_inner = t; }; + void set_total_fetches(size_t n) { count[FETCH_TOTAL] = n; }; + bool has_downloads() { return count[DOWNLOAD_TOTAL] > 0; }; + void reset_counts(); + size_t increment_total_downloads(size_t); + size_t increment_done_downloads(); + bool is_done_downloading(); signals: void authenticate_done(bool success); @@ -56,33 +60,20 @@ class Canvas : public ICanvas QNetworkAccessManager nw; void terminate(QNetworkReply *r); - // fetch done, fetch expected, donwload done, download expected - size_t count[4]; - enum Count { FETCH_DONE, FETCH_TOTAL, DOWNLOAD_DONE, DOWNLOAD_TOTAL }; - std::mutex count_mtx; QNetworkReply *get_full(const QString &url); QNetworkReply *get(const QString &url); QNetworkReply *get(const QString &fmt, const int ¶m); public: - Canvas(const QString &u) : ICanvas(u) - { - std::cout << "CONSTRCUTED REAL" << std::endl; - }; + Canvas(const QString &u) : ICanvas(u){}; Canvas() = delete; bool has_network_err(QNetworkReply *r); - void authenticate(); - void fetch_courses(); - void fetch_folders(const Course &); - void fetch_files(const Folder &); - void download(const File &, const Folder &); - void reset_counts(); - void set_total_fetches(size_t); - size_t increment_total_downloads(size_t); - size_t increment_done_downloads(); - bool is_done_downloading(); - bool has_downloads(); + void authenticate() override; + void fetch_courses() override; + void fetch_folders(const Course &) override; + void fetch_files(const Folder &) override; + void download(const File &, const Folder &) override; }; #endif // CANVAS_H diff --git a/test/main.h b/test/main.h index a703938..f2983f8 100644 --- a/test/main.h +++ b/test/main.h @@ -16,17 +16,11 @@ class FakeCanvas : public ICanvas public: FakeCanvas() : ICanvas(""){}; - void authenticate() { emit authenticate_done(token() == "valid"); }; - void fetch_courses(){}; - void fetch_folders(const Course &){}; - void fetch_files(const Folder &){}; - void download(const File &, const Folder &){}; - void reset_counts(){}; - void set_total_fetches(size_t){}; - size_t increment_total_downloads(size_t) { return 0; }; - size_t increment_done_downloads() { return 0; }; - bool is_done_downloading() { return true; }; - bool has_downloads() { return true; }; + void authenticate() override { emit authenticate_done(token() == "valid"); }; + void fetch_courses() override{}; + void fetch_folders(const Course &) override{}; + void fetch_files(const Folder &) override{}; + void download(const File &, const Folder &) override{}; }; class TestGui : public QObject