mirror of
https://github.com/velopack/velopack.git
synced 2025-10-25 15:19:22 +00:00
Add build script and readme to C++ sample
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include <memory.h>
|
||||
#include <tchar.h>
|
||||
|
||||
#include "constants.h"
|
||||
#include "velopack.hpp"
|
||||
|
||||
#pragma comment(linker, \
|
||||
@@ -20,7 +21,6 @@
|
||||
HINSTANCE hInst;
|
||||
const WCHAR szTitle[] = L"Velopack C++ Sample App";
|
||||
const WCHAR szWindowClass[] = L"VeloCppWinSample";
|
||||
const CHAR szUpdateUrl[] = "C:\\Source\\velopack\\build\\Debug\\net6.0\\Releases";
|
||||
velo_update_info updInfo = velo_update_info();
|
||||
std::string updPath = "";
|
||||
std::string currentVersion = "";
|
||||
@@ -132,7 +132,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
if ((HWND)lParam == hCheckButton)
|
||||
{
|
||||
try {
|
||||
velo_update_info info = velo_check_for_updates(szUpdateUrl);
|
||||
velo_update_info info = velo_check_for_updates(UPDATE_URL);
|
||||
if (info.is_update_available) {
|
||||
// this is a hack to convert ascii to wide string
|
||||
std::wstring message = L"Update available: " + std::wstring(info.version.begin(), info.version.end());
|
||||
@@ -153,7 +153,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
if (updInfo.is_update_available) {
|
||||
try {
|
||||
velo_download_updates(szUpdateUrl, updInfo.file_name.c_str(), [](int x) {}, [&hWnd](std::string path)
|
||||
velo_download_updates(UPDATE_URL, updInfo.file_name.c_str(), [](int x) {}, [&hWnd](std::string path)
|
||||
{
|
||||
updPath = path;
|
||||
std::wstring message = L"Downloaded successfully to: " + std::wstring(path.begin(), path.end());
|
||||
|
||||
1
examples/VeloCppWinSample/constants.h
Normal file
1
examples/VeloCppWinSample/constants.h
Normal file
@@ -0,0 +1 @@
|
||||
#define UPDATE_URL "REPLACE_ME"
|
||||
53
examples/VeloCppWinSample/dev-build.bat
Normal file
53
examples/VeloCppWinSample/dev-build.bat
Normal file
@@ -0,0 +1,53 @@
|
||||
@echo off
|
||||
REM This script requires several tools to be installed for it to work:
|
||||
REM cargo (rust): winget install Rustlang.Rustup
|
||||
REM Nerdbank.GitVersioning (nbgv): dotnet tool install --global nbgv
|
||||
REM C++ Build Tools, typically installed via "Desktop development with C++" workload.
|
||||
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
if "%~1"=="" (
|
||||
echo Version number is required.
|
||||
echo Usage: build.bat [version] [extra_args...]
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
echo.
|
||||
echo Building Velopack Rust
|
||||
cd %~dp0..\..\src\Rust
|
||||
cargo build --features windows
|
||||
|
||||
echo.
|
||||
echo Building Velopack Vpk
|
||||
cd %~dp0..\..\
|
||||
dotnet build src/Velopack.Vpk/Velopack.Vpk.csproj
|
||||
|
||||
cd %~dp0
|
||||
|
||||
set VSWHERE_PATH="%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe"
|
||||
|
||||
echo.
|
||||
echo Locating MSBuild using vswhere
|
||||
for /f "usebackq tokens=*" %%i in (`%VSWHERE_PATH% -latest -requires Microsoft.Component.MSBuild -find MSBuild\**\Bin\MSBuild.exe`) do (
|
||||
set "MSBUILD_PATH=%%i"
|
||||
goto :buildCpp
|
||||
)
|
||||
|
||||
:buildCpp
|
||||
if not defined MSBUILD_PATH (
|
||||
echo MSBuild not found, make sure Visual Studio is installed with C++ Build Tools.
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
echo #define UPDATE_URL R"(%~dp0releases)" > constants.h
|
||||
|
||||
echo.
|
||||
echo Building VeloCppWinSample
|
||||
cd %~dp0
|
||||
"%MSBUILD_PATH%" VeloCppWinSample.sln /p:Configuration=Release
|
||||
|
||||
echo #define UPDATE_URL "REPLACE_ME" > constants.h
|
||||
|
||||
echo.
|
||||
echo Building Velopack Release v%~1
|
||||
%~dp0..\..\build\Debug\net8.0\vpk pack -u VeloCppWinSample -o releases -p x64\Release -f net8-x64-desktop -v %*
|
||||
8
examples/VeloCppWinSample/readme.md
Normal file
8
examples/VeloCppWinSample/readme.md
Normal file
@@ -0,0 +1,8 @@
|
||||
# VeloCppWinSample
|
||||
_Prerequisites: Rust/Cargo, Dotnet, Msbuild_
|
||||
|
||||
This app is purely a proof of concept at this time, `velopack.hpp` currently only works on windows and needs testing / fixes for other operating systems, and probably also needs fixing for unicode/strings. This sample is made up of a simple Win32 desktop app, generated via a Visual Studio template, and it includes `velopack.hpp` and [`subprocess.h`](https://github.com/sheredom/subprocess.h).
|
||||
|
||||
Also, this is using command line features not currently exposed in the main Velopack releases, so you can only build releases from source by using the `dev-build.bat [version]` script. Trying to build/use this sample with the mainstream `vpk` tool is not guarenteed to work at this time.
|
||||
|
||||
If you are interested in using Velopack for your C++ project and are willing to help with the design of `velopack.hpp` (either with suggestions, or code), please drop in our Discord and I would be happy to discuss / work with you to polish this up.
|
||||
@@ -252,7 +252,7 @@ void velo_download_updates(const char* url_or_path, const char* release_name,
|
||||
uint8_t progress = static_cast<uint8_t>(std::stoi(line));
|
||||
progress_fn(progress);
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
catch (const std::exception&) {
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user