mirror of
https://github.com/velopack/velopack.git
synced 2025-10-25 15:19:22 +00:00
add custom source example to CppWidgets
This commit is contained in:
@@ -34,15 +34,17 @@ endif()
|
|||||||
# include the Velopack library (headers + precompiled lib)
|
# include the Velopack library (headers + precompiled lib)
|
||||||
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../../src/lib-cpp/include")
|
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../../src/lib-cpp/include")
|
||||||
|
|
||||||
|
set(VELOPACK_CONFIG "debug")
|
||||||
|
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
set(VELOPACK_LIB_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../target/debug/velopack_libc.dll.lib")
|
set(VELOPACK_LIB_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../target/${VELOPACK_CONFIG}/velopack_libc.dll.lib")
|
||||||
set(VELOPACK_DLL_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../target/debug/velopack_libc.dll")
|
set(VELOPACK_DLL_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../target/${VELOPACK_CONFIG}/velopack_libc.dll")
|
||||||
elseif(APPLE)
|
elseif(APPLE)
|
||||||
set(VELOPACK_LIB_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/debug/libvelopack_libc.dylib")
|
set(VELOPACK_DLL_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../target/${VELOPACK_CONFIG}/libvelopack_libc.dylib")
|
||||||
else()
|
else()
|
||||||
set(VELOPACK_LIB_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/debug/libvelopack_libc.so")
|
set(VELOPACK_DLL_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../target/${VELOPACK_CONFIG}/libvelopack_libc.so")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
|
|||||||
@@ -2,13 +2,59 @@
|
|||||||
#include <optional>
|
#include <optional>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
|
// Includes for MyExampleUpdateSource
|
||||||
|
#include <fstream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <filesystem>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
#include "Velopack.hpp"
|
#include "Velopack.hpp"
|
||||||
|
|
||||||
using namespace Velopack;
|
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
|
class MyFrame : public wxFrame
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
~MyFrame()
|
||||||
|
{
|
||||||
|
vpkc_set_logger(nullptr, nullptr);
|
||||||
|
}
|
||||||
MyFrame() : wxFrame(nullptr, wxID_ANY, "VelopackCppWidgetsSample", wxDefaultPosition, wxSize(600, 600))
|
MyFrame() : wxFrame(nullptr, wxID_ANY, "VelopackCppWidgetsSample", wxDefaultPosition, wxSize(600, 600))
|
||||||
{
|
{
|
||||||
vpkc_set_logger(&MyFrame::HandleVpkcLogStatic, this);
|
vpkc_set_logger(&MyFrame::HandleVpkcLogStatic, this);
|
||||||
@@ -56,7 +102,7 @@ public:
|
|||||||
// initialise velopack
|
// initialise velopack
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
updateManager = std::make_unique<UpdateManager>(RELEASES_DIR);
|
updateManager = std::make_unique<UpdateManager>(std::make_unique<MyExampleUpdateSource>());
|
||||||
topText->SetLabel("Current Version: " + updateManager->GetCurrentVersion());
|
topText->SetLabel("Current Version: " + updateManager->GetCurrentVersion());
|
||||||
}
|
}
|
||||||
catch (std::exception& ex)
|
catch (std::exception& ex)
|
||||||
|
|||||||
Reference in New Issue
Block a user