From c29a8ec522984533e5f52de36f021f1d52bbf96f Mon Sep 17 00:00:00 2001 From: Caelan Sayler Date: Sat, 21 Dec 2024 09:48:43 +0000 Subject: [PATCH] add custom source example to CppWidgets --- samples/CPlusPlusWidgets/CMakeLists.txt | 14 ++++---- samples/CPlusPlusWidgets/main.cpp | 48 ++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 7 deletions(-) diff --git a/samples/CPlusPlusWidgets/CMakeLists.txt b/samples/CPlusPlusWidgets/CMakeLists.txt index 407a2f14..8d13144c 100644 --- a/samples/CPlusPlusWidgets/CMakeLists.txt +++ b/samples/CPlusPlusWidgets/CMakeLists.txt @@ -34,15 +34,17 @@ endif() # include the Velopack library (headers + precompiled lib) include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../../src/lib-cpp/include") +set(VELOPACK_CONFIG "debug") + if(WIN32) - set(VELOPACK_LIB_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../target/debug/velopack_libc.dll.lib") - set(VELOPACK_DLL_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../target/debug/velopack_libc.dll") + set(VELOPACK_LIB_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../target/${VELOPACK_CONFIG}/velopack_libc.dll.lib") + set(VELOPACK_DLL_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../target/${VELOPACK_CONFIG}/velopack_libc.dll") elseif(APPLE) - set(VELOPACK_LIB_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../target/debug/libvelopack_libc.dylib") - set(VELOPACK_DLL_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../target/debug/libvelopack_libc.dylib") + set(VELOPACK_LIB_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../target/${VELOPACK_CONFIG}/libvelopack_libc.dylib") + set(VELOPACK_DLL_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../target/${VELOPACK_CONFIG}/libvelopack_libc.dylib") else() - set(VELOPACK_LIB_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../target/debug/libvelopack_libc.so") - set(VELOPACK_DLL_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../target/debug/libvelopack_libc.so") + set(VELOPACK_LIB_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../target/${VELOPACK_CONFIG}/libvelopack_libc.so") + set(VELOPACK_DLL_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../target/${VELOPACK_CONFIG}/libvelopack_libc.so") endif() if(WIN32) diff --git a/samples/CPlusPlusWidgets/main.cpp b/samples/CPlusPlusWidgets/main.cpp index 737e5c15..babee61e 100644 --- a/samples/CPlusPlusWidgets/main.cpp +++ b/samples/CPlusPlusWidgets/main.cpp @@ -2,13 +2,59 @@ #include #include #include + +// Includes for MyExampleUpdateSource +#include +#include +#include +#include + #include "Velopack.hpp" using namespace Velopack; +/** + * This is just an example of how to create a fully custom update source + * Normally, you should use one of the built-ins instead, like FileSource or HttpSource. + */ +class MyExampleUpdateSource : public IUpdateSource +{ +public: + const std::string GetReleaseFeed(const std::string releasesName) override + { + std::string releasesFile = std::string(RELEASES_DIR) + "\\" + releasesName; + std::ifstream t(releasesFile); + std::stringstream buffer; + buffer << t.rdbuf(); + return buffer.str(); + } + bool DownloadReleaseEntry(const VelopackAsset& asset, const std::string localFilePath, vpkc_progress_send_t progress) override + { + using namespace std::chrono_literals; + std::string path = std::string(RELEASES_DIR) + "\\" + asset.FileName; + std::filesystem::copy_file(path, localFilePath); + + // simulate the download taking some time... + std::this_thread::sleep_for(1s); + progress(25); + std::this_thread::sleep_for(1s); + progress(50); + std::this_thread::sleep_for(1s); + progress(75); + std::this_thread::sleep_for(1s); + progress(100); + + return true; + } +}; + class MyFrame : public wxFrame { public: + ~MyFrame() + { + vpkc_set_logger(nullptr, nullptr); + } MyFrame() : wxFrame(nullptr, wxID_ANY, "VelopackCppWidgetsSample", wxDefaultPosition, wxSize(600, 600)) { vpkc_set_logger(&MyFrame::HandleVpkcLogStatic, this); @@ -56,7 +102,7 @@ public: // initialise velopack try { - updateManager = std::make_unique(RELEASES_DIR); + updateManager = std::make_unique(std::make_unique()); topText->SetLabel("Current Version: " + updateManager->GetCurrentVersion()); } catch (std::exception& ex)