Skip to content

Commit

Permalink
ci: fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenvukhang committed Feb 5, 2023
1 parent ea21610 commit 8174e43
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 92 deletions.
15 changes: 12 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ../..
Expand Down
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
80 changes: 35 additions & 45 deletions app/canvas.cc
Original file line number Diff line number Diff line change
@@ -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());
Expand Down Expand Up @@ -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;
}
45 changes: 18 additions & 27 deletions app/canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 &param);

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
16 changes: 5 additions & 11 deletions test/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8174e43

Please sign in to comment.