Skip to content

A native macOS / windows / Linux database IDE built with Swift and AppKit. Connect to PostgreSQL, MySQL, SQLite, and Redis from a single app with a fast, keyboard-driven interface.

C++

feat(windows): auto-update via Velopack C++ SDK + query result column resize

DangHuynhcad9c74413bb
diff --git a/.github/workflows/windows-release.yml b/.github/workflows/windows-release.yml
deleted file mode 100644
index 9973127..0000000
--- a/.github/workflows/windows-release.yml
+++ /dev/null
@@ -1,128 +0,0 @@
-# Windows Release pipeline for Gridex
-# ---------------------------------------------------------------------
-# Triggers on any git tag matching `v*.*.*` (semver). Delegates build +
-# pack to the phase 01 PowerShell scripts in windows/scripts/ so the
-# workflow stays a thin orchestration layer (single source of truth for
-# MSBuild flags lives in build-unpackaged.ps1).
-#
-# Produces an unsigned Velopack release uploaded to the GitHub Release
-# for the pushed tag. Signing is added in phase 05 via SignPath.
-# ---------------------------------------------------------------------
-
-name: Windows Release
-
-on:
- push:
- tags:
- - 'v*.*.*'
- workflow_dispatch:
- inputs:
- version:
- description: "Version to pack (e.g. 0.1.0). Only used for manual runs."
- required: false
- default: "0.0.0-manual"
-
-permissions:
- contents: write # needed for Release creation via vpk upload github
-
-env:
- # vpk 0.0.1298 targets net9.0; allow running on any newer .NET runtime
- # installed on the runner (setup-dotnet pins 9.0.x below, but leave the
- # roll-forward on as a safety net for future vpk updates).
- DOTNET_ROLL_FORWARD: Major
-
-jobs:
- release:
- runs-on: windows-2022
- timeout-minutes: 60
-
- steps:
- - name: Checkout
- uses: actions/checkout@v4
- with:
- fetch-depth: 0 # full history; vpk may inspect git metadata
-
- - name: Setup .NET 9 SDK
- uses: actions/setup-dotnet@v4
- with:
- dotnet-version: '9.0.x'
-
- - name: Setup MSBuild
- uses: microsoft/setup-msbuild@v2
-
- - name: Extract version from tag
- id: ver
- shell: pwsh
- run: |
- if ($env:GITHUB_REF -like 'refs/tags/v*') {
- $tag = "${{ github.ref_name }}"
- $version = $tag.TrimStart('v')
- } else {
- # workflow_dispatch fallback
- $version = "${{ github.event.inputs.version }}"
- $tag = "v$version"
- }
- Write-Host "Tag: $tag / Version: $version"
- "version=$version" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
- "tag=$tag" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
-
- - name: Install vpk CLI
- shell: pwsh
- run: .\windows\scripts\install-vpk-tool.ps1
-
- # Gridex.vcxproj hardcodes C:\vcpkg\installed\x64-windows\{include,lib}
- # and links against sqlite3/libpq/libmariadb/openssl/hiredis. GitHub
- # runners ship vcpkg at C:\vcpkg but do NOT pre-install these packages,
- # so we install them explicitly. Cache the installed tree to avoid
- # re-building openssl/libpq from source on every run.
- - name: Cache vcpkg installed tree
- id: vcpkg-cache
- uses: actions/cache@v4
- with:
- path: C:\vcpkg\installed
- # Bump v-suffix when changing the package list below so the
- # cache invalidates cleanly.
- key: vcpkg-x64-windows-v4-sqlite3-libpq-libmariadb-openssl-hiredis-nlohmann-httplib-mongocxx-libssh2
-
- - name: Install vcpkg dependencies
- if: steps.vcpkg-cache.outputs.cache-hit != 'true'
- shell: pwsh
- run: |
- & C:\vcpkg\vcpkg.exe install `
- sqlite3 libpq libmariadb openssl hiredis `
- nlohmann-json cpp-httplib `
- mongo-cxx-driver libssh2 `
- --triplet x64-windows `
- --recurse
- if ($LASTEXITCODE -ne 0) { throw "vcpkg install failed" }
-
- - name: Build unpackaged (Release x64)
- shell: pwsh
- run: .\windows\scripts\build-unpackaged.ps1 -Version ${{ steps.ver.outputs.version }}
-
- - name: Velopack pack
- shell: pwsh
- run: .\windows\scripts\pack-velopack.ps1 -Version ${{ steps.ver.outputs.version }}
-
- # TODO(phase 05): insert SignPath signing step here, between pack
- # and upload, once the SignPath Foundation cert is approved.
- # The step will submit windows/Releases/*.nupkg + Setup.exe to the
- # SignPath webhook and download signed artifacts back before upload.
-
- - name: Upload Setup.exe to GitHub Releases
- shell: pwsh
- env:
- GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: |
- # Only upload Gridex-stable-Setup.exe — users download and
- # run it directly. The nupkg/json/RELEASES files are Velopack
- # auto-update artifacts not needed when auto-update is disabled.
- $setup = "windows\Releases\Gridex-stable-Setup.exe"
- if (-not (Test-Path $setup)) {
- throw "Setup.exe not found at $setup"
- }
- gh release create ${{ steps.ver.outputs.tag }} `
- $setup `
- --title "${{ steps.ver.outputs.tag }}" `
- --notes "Gridex ${{ steps.ver.outputs.tag }} Windows Installer" `
- --latest
diff --git a/.gitignore b/.gitignore
index 6b40daa..eb657fe 100644
--- a/.gitignore
+++ b/.gitignore
@@ -91,9 +91,12 @@ screenshot_mac/
# Velopack release artifacts (Setup.exe, *.nupkg, releases.*.json, RELEASES)
windows/Releases/
-# Cached vendor binaries (WebView2 bootstrap, etc.) — downloaded on demand
-# by build-unpackaged.ps1, refreshed by CI on each run.
-windows/vendor/
+# Cached vendor binaries downloaded on demand by build-unpackaged.ps1.
+# The Velopack C++ SDK is vendored in windows/vendor/velopack/ and must
+# be tracked (header files + static lib) so clones can build without a
+# separate fetch step. WebView2 bootstrap is fetched at build time.
+windows/vendor/webview2/
+!windows/vendor/velopack/lib/velopack_libc_win_x64_msvc.lib
# Generated version header — written by build-unpackaged.ps1 -Version
# from the CI tag, falls back to 0.0.0-dev locally via __has_include.
diff --git a/windows/Gridex/App.xaml.cpp b/windows/Gridex/App.xaml.cpp
index 9dc3d61..1fe8d64 100644
--- a/windows/Gridex/App.xaml.cpp
+++ b/windows/Gridex/App.xaml.cpp
@@ -2,6 +2,7 @@
#include "xaml-includes.h"
#include "App.xaml.h"
#include "MainWindow.xaml.h"
+#include "UpdateService.h"
#include <shellapi.h>
#include <string>
#include <cwchar>
@@ -13,57 +14,6 @@ using namespace Microsoft::UI::Xaml;
namespace winrt::Gridex::implementation
{
- // Handle Velopack lifecycle hook flags passed by Setup.exe / Update.exe.
- //
- // When the Velopack installer runs, it launches the main app exe with
- // one of these flags and expects the process to exit cleanly within
- // 30 seconds. Without this handler the app tries to launch its full
- // WinUI main window instead, which:
- // - Shows a visible Gridex window while Setup.exe is still running
- // - Never exits the hook process
- // - Causes Velopack to display the error:
- // "Installation has completed, but the application install
- // hook failed. It may not have installed correctly."
- //
- // Hook flags that MUST exit-on-sight:
- // --veloapp-install first-time install, after files extracted
- // --veloapp-updated after auto-update applied (new version)
- // --veloapp-obsolete before old version is removed post-update
- // --veloapp-uninstall user uninstalling via Add/Remove Programs
- //
- // --veloapp-firstrun is a normal launch (just with a flag) and must
- // NOT exit -- the app should start as usual.
- //
- // We avoid linking the full Velopack C++ SDK for v1 and just probe
- // argv directly via CommandLineToArgvW. This is enough to silence
- // the install-hook error dialog; full update orchestration would
- // require the real SDK (phase 02 of the installer plan).
- static void HandleVelopackLifecycleFlags()
- {
- int argc = 0;
- LPWSTR* argv = CommandLineToArgvW(GetCommandLineW(), &argc);
- if (!argv) return;
-
- bool exitNow = false;
- for (int i = 1; i < argc; ++i)
- {
- if (wcscmp(argv[i], L"--veloapp-install") == 0 ||
- wcscmp(argv[i], L"--veloapp-updated") == 0 ||
- wcscmp(argv[i], L"--veloapp-obsolete") == 0 ||
- wcscmp(argv[i], L"--veloapp-uninstall") == 0)
- {
- exitNow = true;
- break;
- }
- }
- LocalFree(argv);
-
- if (exitNow)
- {
- ::ExitProcess(0);
- }
- }
-
// Detect whether the Microsoft Edge WebView2 Runtime is installed.
// Gridex bundles Microsoft.Web.WebView2.Core.dll (the projection) but
// the actual WebView2 runtime is a separate system component. On
@@ -140,11 +90,12 @@ namespace winrt::Gridex::implementation
/// </summary>
App::App()
{
- // CRITICAL: run BEFORE anything else. If the process was launched
- // by Velopack as an install/uninstall/updated/obsolete hook, exit
- // immediately so the installer's hook wait completes successfully
- // and the full WinUI main window never opens during an install.
- HandleVelopackLifecycleFlags();
+ // CRITICAL: run BEFORE anything else. VelopackApp::Build().Run()
+ // handles --veloapp-install / --veloapp-updated / --veloapp-obsolete
+ // / --veloapp-uninstall lifecycle hooks and may call ExitProcess
+ // itself so the installer's hook wait completes successfully and
+ // the full WinUI main window never opens during an install.
+ ::Gridex::InitVelopackApp();
// Bootstrap the WebView2 Runtime before any XAML / WinAppSDK code
// touches WebView2. Fast no-op (single registry probe) once the
diff --git a/windows/Gridex/Gridex.vcxproj b/windows/Gridex/Gridex.vcxproj
index 22bd6cf..a6d28fe 100644
--- a/windows/Gridex/Gridex.vcxproj
+++ b/windows/Gridex/Gridex.vcxproj
@@ -97,14 +97,14 @@
<LanguageStandard Condition="'$(VisualStudioVersion)' &gt;= '18.0'">stdcpp20</LanguageStandard>
<LanguageStandard Condition="'$(VisualStudioVersion)' &lt; '18.0'">stdcpp17</LanguageStandard>
<AdditionalOptions>%(AdditionalOptions) /bigobj /Zm500</AdditionalOptions>
- <AdditionalIncludeDirectories>$(ProjectDir);C:\vcpkg\installed\x64-windows\include;C:\vcpkg\installed\x64-windows\include\mongocxx\v_noabi;C:\vcpkg\installed\x64-windows\include\bsoncxx\v_noabi;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <AdditionalIncludeDirectories>$(ProjectDir);$(ProjectDir)..\vendor\velopack\include;C:\vcpkg\installed\x64-windows\include;C:\vcpkg\installed\x64-windows\include\mongocxx\v_noabi;C:\vcpkg\installed\x64-windows\include\bsoncxx\v_noabi;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Link>
<!-- Shared libs — names that are the same in both Debug and Release vcpkg.
hiredis and mongocxx/bsoncxx have different names per config
and are added in the config-specific ItemDefinitionGroup below. -->
- <AdditionalDependencies>Shell32.lib;Comdlg32.lib;Advapi32.lib;libpq.lib;libmariadb.lib;sqlite3.lib;libssl.lib;libcrypto.lib;crypt32.lib;ws2_32.lib;odbc32.lib;libssh2.lib;mongoc2.dll.lib;bson2.dll.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <AdditionalDependencies>Shell32.lib;Comdlg32.lib;Advapi32.lib;libpq.lib;libmariadb.lib;sqlite3.lib;libssl.lib;libcrypto.lib;crypt32.lib;ws2_32.lib;odbc32.lib;libssh2.lib;mongoc2.dll.lib;bson2.dll.lib;velopack_libc_win_x64_msvc.lib;userenv.lib;ntdll.lib;bcrypt.lib;Dbghelp.lib;Propsys.lib;Ole32.lib;OleAut32.lib;RuntimeObject.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<!-- Debug: link against vcpkg debug libs + mongocxx debug variant -->
@@ -113,7 +113,7 @@
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
- <AdditionalLibraryDirectories>C:\vcpkg\installed\x64-windows\debug\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+ <AdditionalLibraryDirectories>C:\vcpkg\installed\x64-windows\debug\lib;$(ProjectDir)..\vendor\velopack\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>mongocxx-v_noabi-dhi-mdd.lib;bsoncxx-v_noabi-dhi-mdd.lib;hiredisd.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
@@ -123,7 +123,7 @@
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
- <AdditionalLibraryDirectories>C:\vcpkg\installed\x64-windows\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+ <AdditionalLibraryDirectories>C:\vcpkg\installed\x64-windows\lib;$(ProjectDir)..\vendor\velopack\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>mongocxx-v_noabi-rhi-md.lib;bsoncxx-v_noabi-rhi-md.lib;hiredis.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Link>
@@ -169,6 +169,7 @@
<ClInclude Include="Models\ExportService.h" />
<ClInclude Include="Models\ImportService.h" />
<ClInclude Include="xaml-includes.h" />
+ <ClInclude Include="UpdateService.h" />
<ClInclude Include="SettingsPage.h">
<DependentUpon>SettingsPage.xaml</DependentUpon>
<SubType>Code</SubType>
@@ -398,6 +399,9 @@
<DependentUpon>SettingsPage.xaml</DependentUpon>
<SubType>Code</SubType>
</ClCompile>
+ <ClCompile Include="UpdateService.cpp">
+ <PrecompiledHeader>NotUsing</PrecompiledHeader>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<Midl Include="MainWindow.idl">
diff --git a/windows/Gridex/MainWindow.xaml b/windows/Gridex/MainWindow.xaml
index 59fddf9..0b53c2f 100644
--- a/windows/Gridex/MainWindow.xaml
+++ b/windows/Gridex/MainWindow.xaml
@@ -12,5 +12,23 @@
<Grid Background="Transparent">
<Frame x:Name="ContentFrame" />
+
+ <!-- Startup update-check overlay. Shown before the ContentFrame
+ navigates so the main app never appears while the network
+ check is in flight. Hidden by MainWindow once the check
+ completes (with or without an update). -->
+ <Grid x:Name="UpdateCheckOverlay"
+ Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
+ <StackPanel VerticalAlignment="Center"
+ HorizontalAlignment="Center"
+ Spacing="16">
+ <ProgressRing IsActive="True" Width="48" Height="48" />
+ <TextBlock x:Name="UpdateCheckStatusText"
+ Text="Checking for updates..."
+ HorizontalAlignment="Center"
+ FontSize="13"
+ Foreground="{ThemeResource TextFillColorSecondaryBrush}" />
+ </StackPanel>
+ </Grid>
</Grid>
</Window>
diff --git a/windows/Gridex/MainWindow.xaml.cpp b/windows/Gridex/MainWindow.xaml.cpp
index 4247cc7..a1df456 100644
--- a/windows/Gridex/MainWindow.xaml.cpp
+++ b/windows/Gridex/MainWindow.xaml.cpp
@@ -12,6 +12,9 @@
#include "HomePage.h"
#include "WorkspacePage.h"
#include "Models/AppSettings.h"
+#include "UpdateService.h"
+#include <winrt/Microsoft.UI.Dispatching.h>
+#include <winrt/Microsoft.UI.Xaml.Controls.h>
namespace winrt::Gridex::implementation
{
@@ -81,10 +84,103 @@ namespace winrt::Gridex::implementation
content.KeyboardAccelerators().Append(homeAccel);
}
- NavigateTo(L"Gridex.HomePage");
+ // Blocking update check BEFORE navigating to HomePage.
+ //
+ // The UpdateCheckOverlay from MainWindow.xaml is visible until
+ // we call DismissUpdateOverlayAndEnterApp(). Flow:
+ // 1. Run CheckForUpdateAsync on a background thread.
+ // 2. On the UI thread, if an update is available, show a
+ // ContentDialog. Primary -> DownloadAndApplyAsync (process
+ // exits). Close / error / no-update -> proceed to HomePage.
+ // Errors (no network, running uninstalled from dev, etc.) are
+ // treated as "no update" so the user still enters the app.
+ //
+ // This replaces the previous 5-second silent-check timer --
+ // no more background auto-check once the user is inside. Manual
+ // check remains available via Settings > Check Now.
+ auto dispatcher = this->DispatcherQueue();
+ ::Gridex::CheckForUpdateAsync(
+ [this, dispatcher](::Gridex::UpdateCheckResult r)
+ {
+ dispatcher.TryEnqueue([this, r]()
+ {
+ if (!r.hasUpdate)
+ {
+ EnterAppAfterUpdateCheck();
+ return;
+ }
+
+ auto content = this->Content().try_as<mux::FrameworkElement>();
+ auto xamlRoot = content ? content.XamlRoot() : nullptr;
+ if (!xamlRoot)
+ {
+ EnterAppAfterUpdateCheck();
+ return;
+ }
+
+ std::wstring msg = L"Current: " + r.currentVersion +
+ L"\nNew: " + r.newVersion +
+ L"\n\nDownload and install now? The app will restart.";
+ winrt::Microsoft::UI::Xaml::Controls::ContentDialog dlg;
+ dlg.Title(winrt::box_value(winrt::hstring(
+ L"Gridex " + r.newVersion + L" is available")));
+ dlg.Content(winrt::box_value(winrt::hstring(msg)));
+ dlg.PrimaryButtonText(L"Install");
+ dlg.CloseButtonText(L"Later");
+ dlg.DefaultButton(
+ winrt::Microsoft::UI::Xaml::Controls::ContentDialogButton::Primary);
+ dlg.XamlRoot(xamlRoot);
+
+ try
+ {
+ auto op = dlg.ShowAsync();
+ op.Completed([this](auto const& asyncOp,
+ winrt::Windows::Foundation::AsyncStatus status)
+ {
+ bool install = false;
+ if (status == winrt::Windows::Foundation::AsyncStatus::Completed)
+ {
+ try
+ {
+ install = asyncOp.GetResults() ==
+ winrt::Microsoft::UI::Xaml::Controls::ContentDialogResult::Primary;
+ }
+ catch (...) {}
+ }
+ if (install)
+ {
+ // Status text on overlay while the download
+ // runs; process exits from inside the worker.
+ UpdateCheckStatusText().Text(L"Downloading update...");
+ ::Gridex::DownloadAndApplyAsync(
+ [](std::wstring) {},
+ [](std::wstring) {});
+ // Do NOT call EnterAppAfterUpdateCheck --
+ // the worker will ExitProcess and Velopack
+ // restarts us on the new version.
+ return;
+ }
+ EnterAppAfterUpdateCheck();
+ });
+ }
+ catch (...)
+ {
+ EnterAppAfterUpdateCheck();
+ }
+ });
+ });
});
}
+ // Hide the update-check overlay and navigate ContentFrame to HomePage.
+ // Called exactly once, either after a completed check with no update,
+ // or after the user dismisses the update dialog with "Later".
+ void MainWindow::EnterAppAfterUpdateCheck()
+ {
+ UpdateCheckOverlay().Visibility(mux::Visibility::Collapsed);
+ NavigateTo(L"Gridex.HomePage");
+ }
+
void MainWindow::NavigateTo(const wchar_t* pageTypeName)
{
winrt::Windows::UI::Xaml::Interop::TypeName pageType;
diff --git a/windows/Gridex/MainWindow.xaml.h b/windows/Gridex/MainWindow.xaml.h
index 0144689..ae258da 100644
--- a/windows/Gridex/MainWindow.xaml.h
+++ b/windows/Gridex/MainWindow.xaml.h
@@ -23,6 +23,7 @@ namespace winrt::Gridex::implementation
private:
void NavigateTo(const wchar_t* pageTypeName);
+ void EnterAppAfterUpdateCheck();
};
}
diff --git a/windows/Gridex/QueryEditorView.cpp b/windows/Gridex/QueryEditorView.cpp
index 46d9bac..5e60a3c 100644
--- a/windows/Gridex/QueryEditorView.cpp
+++ b/windows/Gridex/QueryEditorView.cpp
@@ -582,8 +582,12 @@ namespace winrt::Gridex::implementation
if (result.columnNames.empty()) return;
- size_t nCols = result.columnNames.size();
- double colWidth = 150.0;
+ // Initialize per-column widths: distribute the container width evenly,
+ // clamped to [RESULT_COL_MIN_WIDTH, RESULT_COL_MAX_WIDTH]. Stored in
+ // resultColumnWidths_ so resize drags can mutate them without
+ // recomputing the initial layout.
+ const size_t nCols = result.columnNames.size();
+ double colWidth = RESULT_COL_DEFAULT_WIDTH;
double availWidth = this->ActualWidth() - 20.0;
if (availWidth > 0 && nCols > 0)
{
@@ -591,30 +595,164 @@ namespace winrt::Gridex::implementation
if (colWidth < 80.0) colWidth = 80.0;
if (colWidth > 400.0) colWidth = 400.0;
}
+ resultColumnWidths_.assign(nCols, colWidth);
+ BuildResultHeaders(result);
+ BuildResultRows(result);
+ }
+
+ // ── Result-grid headers with drag-to-resize grip ──────────────
+ //
+ // Mirrors DataGridView::BuildHeaders but without sort / row-number
+ // column. Each header cell is a 2-column Grid: [label *] [grip 8px].
+ // The grip captures pointer events, updates its own header Grid.Width
+ // on PointerMoved for immediate visual feedback, and rebuilds the row
+ // StackPanels once on PointerReleased.
+ void QueryEditorView::BuildResultHeaders(const DBModels::QueryResult& result)
+ {
muxc::StackPanel headerRow;
headerRow.Orientation(muxc::Orientation::Horizontal);
headerRow.Background(muxm::SolidColorBrush(
winrt::Windows::UI::ColorHelper::FromArgb(15, 128, 128, 128)));
- for (auto& col : result.columnNames)
+
+ for (size_t ci = 0; ci < result.columnNames.size(); ++ci)
{
- muxc::Border cell;
- cell.Width(colWidth);
- cell.Padding(mux::Thickness{ 8, 4, 8, 4 });
- cell.BorderBrush(muxm::SolidColorBrush(
+ const double w = (ci < resultColumnWidths_.size())
+ ? resultColumnWidths_[ci] : RESULT_COL_DEFAULT_WIDTH;
+
+ muxc::Grid cellGrid;
+ cellGrid.Width(w);
+
+ muxc::ColumnDefinition contentCd, gripCd;
+ contentCd.Width(mux::GridLength{ 1.0, mux::GridUnitType::Star });
+ gripCd.Width(mux::GridLength{ 8.0, mux::GridUnitType::Pixel });
+ cellGrid.ColumnDefinitions().Append(contentCd);
+ cellGrid.ColumnDefinitions().Append(gripCd);
+
+ // Header label
+ muxc::Border labelWrap;
+ labelWrap.Padding(mux::Thickness{ 8, 4, 4, 4 });
+ labelWrap.BorderBrush(muxm::SolidColorBrush(
winrt::Windows::UI::ColorHelper::FromArgb(40, 128, 128, 128)));
- cell.BorderThickness(mux::Thickness{ 0, 0, 1, 1 });
+ labelWrap.BorderThickness(mux::Thickness{ 0, 0, 0, 1 });
+ muxc::Grid::SetColumn(labelWrap, 0);
+
muxc::TextBlock lbl;
- lbl.Text(winrt::hstring(col));
+ lbl.Text(winrt::hstring(result.columnNames[ci]));
lbl.FontSize(11.0);
lbl.FontWeight(winrt::Windows::UI::Text::FontWeights::SemiBold());
lbl.TextTrimming(mux::TextTrimming::CharacterEllipsis);
- cell.Child(lbl);
- headerRow.Children().Append(cell);
+ lbl.TextWrapping(mux::TextWrapping::NoWrap);
+ labelWrap.Child(lbl);
+ cellGrid.Children().Append(labelWrap);
+
+ // Resize grip (transparent 8px hit area with 1px centered line).
+ muxc::Grid resizeGrip;
+ resizeGrip.Background(muxm::SolidColorBrush(winrt::Windows::UI::Colors::Transparent()));
+ muxc::Grid::SetColumn(resizeGrip, 1);
+
+ muxc::Border gripLine;
+ gripLine.Width(1.0);
+ gripLine.HorizontalAlignment(mux::HorizontalAlignment::Center);
+ gripLine.Background(muxm::SolidColorBrush(
+ winrt::Windows::UI::ColorHelper::FromArgb(50, 128, 128, 128)));
+ gripLine.IsHitTestVisible(false);
+ resizeGrip.Children().Append(gripLine);
+
+ // Cursor via ProtectedCursor (same rationale as DataGridView).
+ resizeGrip.Loaded(
+ [](winrt::Windows::Foundation::IInspectable const& sender,
+ mux::RoutedEventArgs const&)
+ {
+ static auto sizeWECursor =
+ winrt::Microsoft::UI::Input::InputSystemCursor::Create(
+ winrt::Microsoft::UI::Input::InputSystemCursorShape::SizeWestEast);
+ if (auto el = sender.try_as<mux::UIElement>())
+ el.as<winrt::Microsoft::UI::Xaml::IUIElementProtected>()
+ .ProtectedCursor(sizeWECursor);
+ });
+
+ const int colIndex = static_cast<int>(ci);
+ // Capture result by value so PointerReleased can rebuild rows
+ // even if the outer ShowResult stack frame is long gone.
+ DBModels::QueryResult resultCopy = result;
+
+ resizeGrip.PointerPressed(
+ [this, colIndex](winrt::Windows::Foundation::IInspectable const& sender,
+ mux::Input::PointerRoutedEventArgs const& e)
+ {
+ resizingResultCol_ = colIndex;
+ auto point = e.GetCurrentPoint(this->try_as<mux::UIElement>());
+ resizeResultStartX_ = point.Position().X;
+ resizeResultStartWidth_ = (colIndex < static_cast<int>(resultColumnWidths_.size()))
+ ? resultColumnWidths_[colIndex] : RESULT_COL_DEFAULT_WIDTH;
+ if (auto el = sender.try_as<mux::UIElement>()) el.CapturePointer(e.Pointer());
+ e.Handled(true);
+ });
+
+ resizeGrip.PointerMoved(
+ [this](winrt::Windows::Foundation::IInspectable const&,
+ mux::Input::PointerRoutedEventArgs const& e)
+ {
+ if (resizingResultCol_ < 0) return;
+ auto point = e.GetCurrentPoint(this->try_as<mux::UIElement>());
+ double delta = point.Position().X - resizeResultStartX_;
+ double newWidth = resizeResultStartWidth_ + delta;
+ if (newWidth < RESULT_COL_MIN_WIDTH) newWidth = RESULT_COL_MIN_WIDTH;
+ if (newWidth > RESULT_COL_MAX_WIDTH) newWidth = RESULT_COL_MAX_WIDTH;
+ if (resizingResultCol_ < static_cast<int>(resultColumnWidths_.size()))
+ {
+ resultColumnWidths_[resizingResultCol_] = newWidth;
+ // Live-update the header cell width. Row #0 inside
+ // ResultsContainer is the header StackPanel; its
+ // child ci is this column's cell Grid.
+ auto container = ResultsContainer();
+ if (container.Children().Size() > 0)
+ {
+ auto hdr = container.Children().GetAt(0)
+ .try_as<muxc::StackPanel>();
+ if (hdr && static_cast<uint32_t>(resizingResultCol_) < hdr.Children().Size())
+ {
+ auto cell = hdr.Children().GetAt(resizingResultCol_)
+ .try_as<muxc::Grid>();
+ if (cell) cell.Width(newWidth);
+ }
+ }
+ }
+ e.Handled(true);
+ });
+
+ resizeGrip.PointerReleased(
+ [this, resultCopy](winrt::Windows::Foundation::IInspectable const& sender,
+ mux::Input::PointerRoutedEventArgs const& e)
+ {
+ if (resizingResultCol_ >= 0)
+ {
+ if (auto el = sender.try_as<mux::UIElement>())
+ el.ReleasePointerCapture(e.Pointer());
+ resizingResultCol_ = -1;
+ // Rebuild rows only -- keeping the header avoids
+ // rewiring every grip's pointer handlers.
+ BuildResultRows(resultCopy);
+ }
+ e.Handled(true);
+ });
+
+ cellGrid.Children().Append(resizeGrip);
+ headerRow.Children().Append(cellGrid);
}
+
ResultsContainer().Children().Append(headerRow);
+ }
- for (int i = 0; i < static_cast<int>(result.rows.size()); i++)
+ // ── Result-grid rows (header-independent, rebuilt on resize end) ──
+ void QueryEditorView::BuildResultRows(const DBModels::QueryResult& result)
+ {
+ // Remove any existing row StackPanels but keep the header (index 0).
+ auto children = ResultsContainer().Children();
+ while (children.Size() > 1) children.RemoveAt(1);
+
+ for (int i = 0; i < static_cast<int>(result.rows.size()); ++i)
{
auto& row = result.rows[i];
muxc::StackPanel rowPanel;
@@ -623,17 +761,20 @@ namespace winrt::Gridex::implementation
rowPanel.Background(muxm::SolidColorBrush(
winrt::Windows::UI::ColorHelper::FromArgb(8, 128, 128, 128)));
- for (auto& col : result.columnNames)
+ for (size_t ci = 0; ci < result.columnNames.size(); ++ci)
{
+ const auto& col = result.columnNames[ci];
+ const double w = (ci < resultColumnWidths_.size())
+ ? resultColumnWidths_[ci] : RESULT_COL_DEFAULT_WIDTH;
+
std::wstring val;
auto it = row.find(col);
if (it != row.end()) val = it->second;
- // Render NULL sentinel as visible "NULL" with dim opacity
const bool isNull = DBModels::isNullCell(val);
const std::wstring display = isNull ? std::wstring(L"NULL") : val;
muxc::Border cell;
- cell.Width(colWidth);
+ cell.Width(w);
cell.Padding(mux::Thickness{ 8, 4, 8, 4 });
cell.BorderBrush(muxm::SolidColorBrush(
winrt::Windows::UI::ColorHelper::FromArgb(20, 128, 128, 128)));
diff --git a/windows/Gridex/QueryEditorView.h b/windows/Gridex/QueryEditorView.h
index be994d7..233e43c 100644
--- a/windows/Gridex/QueryEditorView.h
+++ b/windows/Gridex/QueryEditorView.h
@@ -50,10 +50,26 @@ namespace winrt::Gridex::implementation
// SQL keywords for suggestion
static const std::vector<std::wstring>& SqlKeywords();
+ // Result grid column-width state (drag-to-resize, same pattern as
+ // DataGridView). `resultColumnWidths_` is the source of truth; header
+ // cells are updated live on PointerMoved and rows are rebuilt on
+ // PointerReleased so we only pay the per-row re-render cost once per
+ // drag gesture.
+ std::vector<double> resultColumnWidths_;
+ int resizingResultCol_ = -1;
+ double resizeResultStartX_ = 0.0;
+ double resizeResultStartWidth_ = 0.0;
+
+ static constexpr double RESULT_COL_MIN_WIDTH = 60.0;
+ static constexpr double RESULT_COL_MAX_WIDTH = 600.0;
+ static constexpr double RESULT_COL_DEFAULT_WIDTH = 150.0;
+
void EnsureEditorCreated();
void ExecuteCurrentQuery();
void ShowResult(const DBModels::QueryResult& result);
void ShowError(const std::wstring& message);
+ void BuildResultHeaders(const DBModels::QueryResult& result);
+ void BuildResultRows(const DBModels::QueryResult& result);
void OnEditorTextChanged();
void ForceShowSuggestions();
void ShowSuggestions(const std::vector<std::wstring>& items);
diff --git a/windows/Gridex/SettingsPage.cpp b/windows/Gridex/SettingsPage.cpp
index 49f1c8b..2b9c338 100644
--- a/windows/Gridex/SettingsPage.cpp
+++ b/windows/Gridex/SettingsPage.cpp
@@ -5,6 +5,7 @@
#include "SettingsPage.h"
#include "Models/AppSettings.h"
#include "GridexVersion.h"
+#include "UpdateService.h"
#if __has_include("SettingsPage.g.cpp")
#include "SettingsPage.g.cpp"
#endif
@@ -72,6 +73,86 @@ namespace winrt::Gridex::implementation
nullptr, nullptr, SW_SHOWNORMAL);
});
+ // Check for Updates — hit the R2 feed via Velopack SDK. Runs
+ // on a background thread; results are marshalled back to the
+ // UI via the page's DispatcherQueue.
+ CheckUpdateButton().Click(
+ [this](winrt::Windows::Foundation::IInspectable const&, mux::RoutedEventArgs const&)
+ {
+ CheckUpdateButton().IsEnabled(false);
+ UpdateStatusText().Text(L"Checking...");
+
+ auto dispatcher = this->DispatcherQueue();
+ auto xamlRoot = this->XamlRoot();
+
+ ::Gridex::CheckForUpdateAsync(
+ [this, dispatcher, xamlRoot](::Gridex::UpdateCheckResult r)
+ {
+ dispatcher.TryEnqueue([this, r, xamlRoot, dispatcher]()
+ {
+ CheckUpdateButton().IsEnabled(true);
+
+ if (!r.errorMessage.empty())
+ {
+ UpdateStatusText().Text(winrt::hstring(L"Error: " + r.errorMessage));
+ return;
+ }
+ if (!r.hasUpdate)
+ {
+ UpdateStatusText().Text(
+ winrt::hstring(L"You're on the latest version (" + r.currentVersion + L")."));
+ return;
+ }
+
+ // Confirm with user before downloading.
+ std::wstring msg = L"Current: " + r.currentVersion +
+ L"\nNew: " + r.newVersion +
+ L"\n\nDownload and install now? The app will restart.";
+ UpdateStatusText().Text(
+ winrt::hstring(L"Update available: " + r.newVersion));
+
+ muxc::ContentDialog dlg;
+ dlg.Title(winrt::box_value(winrt::hstring(L"Update Available")));
+ dlg.Content(winrt::box_value(winrt::hstring(msg)));
+ dlg.PrimaryButtonText(L"Install");
+ dlg.CloseButtonText(L"Later");
+ dlg.DefaultButton(muxc::ContentDialogButton::Primary);
+ dlg.XamlRoot(xamlRoot);
+
+ auto op = dlg.ShowAsync();
+ op.Completed([this, dispatcher](
+ winrt::Windows::Foundation::IAsyncOperation<muxc::ContentDialogResult> const& asyncOp,
+ winrt::Windows::Foundation::AsyncStatus)
+ {
+ if (asyncOp.GetResults() != muxc::ContentDialogResult::Primary) return;
+
+ dispatcher.TryEnqueue([this]()
+ {
+ CheckUpdateButton().IsEnabled(false);
+ UpdateStatusText().Text(L"Downloading update...");
+ });
+
+ ::Gridex::DownloadAndApplyAsync(
+ [this, dispatcher](std::wstring status)
+ {
+ dispatcher.TryEnqueue([this, status]()
+ {
+ UpdateStatusText().Text(winrt::hstring(status));
+ });
+ },
+ [this, dispatcher](std::wstring err)
+ {
+ dispatcher.TryEnqueue([this, err]()
+ {
+ CheckUpdateButton().IsEnabled(true);
+ UpdateStatusText().Text(winrt::hstring(L"Update failed: " + err));
+ });
+ });
+ });
+ });
+ });
+ });
+
// Back button — navigate back to the page user came from
BackBtn().Click(
[this](winrt::Windows::Foundation::IInspectable const&, mux::RoutedEventArgs const&)
diff --git a/windows/Gridex/SettingsPage.xaml b/windows/Gridex/SettingsPage.xaml
index 854c8cc..992debb 100644
--- a/windows/Gridex/SettingsPage.xaml
+++ b/windows/Gridex/SettingsPage.xaml
@@ -149,6 +149,36 @@
</Grid>
</StackPanel>
+ <!-- Updates -->
+ <StackPanel Spacing="12">
+ <TextBlock Text="Updates" FontSize="16" FontWeight="SemiBold" />
+
+ <Grid Padding="16"
+ Background="{ThemeResource CardBackgroundFillColorDefaultBrush}"
+ CornerRadius="8"
+ BorderBrush="{ThemeResource CardStrokeColorDefaultBrush}"
+ BorderThickness="1">
+ <Grid.ColumnDefinitions>
+ <ColumnDefinition Width="*" />
+ <ColumnDefinition Width="Auto" />
+ </Grid.ColumnDefinitions>
+
+ <StackPanel Grid.Column="0" Spacing="2">
+ <TextBlock Text="Check for updates" FontSize="14" />
+ <TextBlock x:Name="UpdateStatusText"
+ Text="Click the button to check."
+ FontSize="12"
+ TextWrapping="Wrap"
+ Foreground="{ThemeResource TextFillColorSecondaryBrush}" />
+ </StackPanel>
+ <Button x:Name="CheckUpdateButton"
+ Grid.Column="1"
+ Content="Check Now"
+ Padding="16,6"
+ VerticalAlignment="Center" />
+ </Grid>
+ </StackPanel>
+
<!-- About -->
<StackPanel Spacing="8">
<TextBlock Text="About" FontSize="16" FontWeight="SemiBold" />
diff --git a/windows/Gridex/UpdateService.cpp b/windows/Gridex/UpdateService.cpp
new file mode 100644
index 0000000..46b9388
--- /dev/null
+++ b/windows/Gridex/UpdateService.cpp
@@ -0,0 +1,132 @@
+#include "pch.h"
+#include "UpdateService.h"
+#include "GridexVersion.h"
+
+#include <thread>
+#include <stdexcept>
+
+// Velopack C++ SDK -- vendored under windows/vendor/velopack/include/.
+// Velopack.hpp is the thin C++ wrapper over the C API (Velopack.h).
+// Static lib velopack_libc_win_x64_msvc.lib is linked via vcxproj.
+#include "Velopack.hpp"
+
+namespace Gridex
+{
+ // R2 public feed -- trailing slash required so Velopack can append
+ // releases.stable.json / RELEASES-stable / *.nupkg cleanly.
+ const wchar_t* const kUpdateFeedUrl = L"https://cdn.gridex.app/windows/";
+
+ static std::string WideToUtf8(const std::wstring& w)
+ {
+ if (w.empty()) return {};
+ int need = ::WideCharToMultiByte(CP_UTF8, 0, w.data(), (int)w.size(),
+ nullptr, 0, nullptr, nullptr);
+ std::string out(need, '\0');
+ ::WideCharToMultiByte(CP_UTF8, 0, w.data(), (int)w.size(),
+ out.data(), need, nullptr, nullptr);
+ return out;
+ }
+
+ static std::wstring Utf8ToWide(const std::string& s)
+ {
+ if (s.empty()) return {};
+ int need = ::MultiByteToWideChar(CP_UTF8, 0, s.data(), (int)s.size(),
+ nullptr, 0);
+ std::wstring out(need, L'\0');
+ ::MultiByteToWideChar(CP_UTF8, 0, s.data(), (int)s.size(),
+ out.data(), need);
+ return out;
+ }
+
+ void InitVelopackApp()
+ {
+ // Handles --veloapp-install / --veloapp-updated / --veloapp-obsolete
+ // / --veloapp-uninstall lifecycle flags. May call ExitProcess itself.
+ // Safe to call even when app isn't installed via Velopack (no-op).
+ try
+ {
+ Velopack::VelopackApp::Build().Run();
+ }
+ catch (...)
+ {
+ // Swallow -- startup must never be blocked by updater init.
+ }
+ }
+
+ void CheckForUpdateAsync(std::function<void(UpdateCheckResult)> onComplete)
+ {
+ std::thread([onComplete = std::move(onComplete)]()
+ {
+ UpdateCheckResult r;
+ const std::string feedUtf8 = WideToUtf8(kUpdateFeedUrl);
+ try
+ {
+ Velopack::UpdateManager mgr(feedUtf8);
+ r.currentVersion = Utf8ToWide(mgr.GetCurrentVersion());
+
+ auto updInfo = mgr.CheckForUpdates();
+ if (updInfo.has_value())
+ {
+ r.hasUpdate = true;
+ r.newVersion = Utf8ToWide(updInfo->TargetFullRelease.Version);
+ }
+ }
+ catch (const std::exception& e)
+ {
+ // UpdateManager ctor throws when the app is NOT installed
+ // via Velopack (dev/debug runs); CheckForUpdates throws on
+ // network / parse errors. Both land here.
+ r.errorMessage = Utf8ToWide(e.what());
+ }
+ catch (...)
+ {
+ r.errorMessage = L"Unknown error during update check";
+ }
+ onComplete(r);
+ }).detach();
+ }
+
+ void DownloadAndApplyAsync(
+ std::function<void(std::wstring)> onStatus,
+ std::function<void(std::wstring)> onError)
+ {
+ std::thread([onStatus = std::move(onStatus),
+ onError = std::move(onError)]()
+ {
+ const std::string feedUtf8 = WideToUtf8(kUpdateFeedUrl);
+ try
+ {
+ Velopack::UpdateManager mgr(feedUtf8);
+
+ onStatus(L"Checking for updates...");
+ auto updInfo = mgr.CheckForUpdates();
+ if (!updInfo.has_value())
+ {
+ onError(L"No update available");
+ return;
+ }
+
+ onStatus(L"Downloading update...");
+ mgr.DownloadUpdates(*updInfo);
+
+ onStatus(L"Installing update...");
+ // Spawns the updater and tells it to wait for this process
+ // to exit. We must ExitProcess shortly after.
+ mgr.WaitExitThenApplyUpdates(*updInfo);
+
+ // Give the updater a brief moment to start watching our
+ // PID, then quit so it can swap files and relaunch us.
+ ::Sleep(500);
+ ::ExitProcess(0);
+ }
+ catch (const std::exception& e)
+ {
+ onError(Utf8ToWide(e.what()));
+ }
+ catch (...)
+ {
+ onError(L"Unknown error during update");
+ }
+ }).detach();
+ }
+}
diff --git a/windows/Gridex/UpdateService.h b/windows/Gridex/UpdateService.h
new file mode 100644
index 0000000..964001d
--- /dev/null
+++ b/windows/Gridex/UpdateService.h
@@ -0,0 +1,51 @@
+#pragma once
+// UpdateService -- thin wrapper around Velopack C++ SDK.
+//
+// Responsibilities:
+// 1. Early-startup hook via VelopackApp::Build().Run() (called from App::App()).
+// 2. Async "check for updates" that hits the R2 feed without blocking UI.
+// 3. "Download + apply + restart" flow triggered from user consent dialog.
+//
+// Feed URL (kUpdateFeedUrl) must point at the directory containing
+// releases.stable.json / RELEASES-stable / *.nupkg on R2. The final '/'
+// is required.
+//
+// All async entry points run the Velopack calls on a std::thread so the
+// WinUI dispatcher stays responsive. Callbacks fire on that background
+// thread -- the caller is responsible for marshalling back to the UI
+// via DispatcherQueue().TryEnqueue() when touching XAML.
+
+#include <string>
+#include <functional>
+
+namespace Gridex
+{
+ // R2 feed URL (hardcoded -- single source of truth).
+ extern const wchar_t* const kUpdateFeedUrl;
+
+ struct UpdateCheckResult
+ {
+ bool hasUpdate = false;
+ std::wstring currentVersion; // always filled
+ std::wstring newVersion; // filled when hasUpdate == true
+ std::wstring errorMessage; // filled when check failed
+ };
+
+ // Run VelopackApp::Build().Run() -- handles --veloapp-install /
+ // --veloapp-updated / --veloapp-obsolete / --veloapp-uninstall hooks
+ // and may terminate the process. MUST be called as the very first
+ // line of App::App() before any WinUI initialization.
+ void InitVelopackApp();
+
+ // Fire-and-forget check. `onComplete` runs on a background thread.
+ void CheckForUpdateAsync(std::function<void(UpdateCheckResult)> onComplete);
+
+ // Download + apply + restart. Caller should confirm with the user
+ // first. `onStatus` receives progress messages ("Downloading...",
+ // "Installing..."), `onError` receives failure reason. Both run on
+ // a background thread. On success the process exits inside this
+ // call and the Velopack updater takes over.
+ void DownloadAndApplyAsync(
+ std::function<void(std::wstring)> onStatus,
+ std::function<void(std::wstring)> onError);
+}
diff --git a/windows/vendor/velopack/include/Velopack.h b/windows/vendor/velopack/include/Velopack.h
new file mode 100644
index 0000000..2c5e2ee
--- /dev/null
+++ b/windows/vendor/velopack/include/Velopack.h
@@ -0,0 +1,429 @@
+#ifndef VELOPACK_H
+#define VELOPACK_H
+
+/* Generated with cbindgen:0.28.0 */
+
+/* THIS FILE IS AUTO-GENERATED - DO NOT EDIT */
+
+#include <stdarg.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+/**
+ * The result of a call to check for updates. This can indicate that an update is available, or that an error occurred.
+ */
+enum vpkc_update_check_t
+#ifdef __cplusplus
+ : int8_t
+#endif // __cplusplus
+ {
+ UPDATE_ERROR = -1,
+ UPDATE_AVAILABLE = 0,
+ NO_UPDATE_AVAILABLE = 1,
+ REMOTE_IS_EMPTY = 2,
+};
+#ifndef __cplusplus
+typedef int8_t vpkc_update_check_t;
+#endif // __cplusplus
+
+/**
+ * Opaque type for a Velopack UpdateSource. Must be freed with `vpkc_free_update_source`.
+ */
+typedef void vpkc_update_source_t;
+
+/**
+ * User delegate for to fetch a release feed. This function should return the raw JSON string of the release.json feed.
+ */
+typedef char *(*vpkc_release_feed_delegate_t)(void *p_user_data, const char *psz_releases_name);
+
+/**
+ * User delegate for freeing a release feed. This function should free the feed string returned by `vpkc_release_feed_delegate_t`.
+ */
+typedef void (*vpkc_free_release_feed_t)(void *p_user_data, char *psz_feed);
+
+/**
+ * An individual Velopack asset, could refer to an asset on-disk or in a remote package feed.
+ */
+typedef struct vpkc_asset_t {
+ /**
+ * The name or Id of the package containing this release.
+ */
+ char *PackageId;
+ /**
+ * The version of this release.
+ */
+ char *Version;
+ /**
+ * The type of asset (eg. "Full" or "Delta").
+ */
+ char *Type;
+ /**
+ * The filename of the update package containing this release.
+ */
+ char *FileName;
+ /**
+ * The SHA1 checksum of the update package containing this release.
+ */
+ char *SHA1;
+ /**
+ * The SHA256 checksum of the update package containing this release.
+ */
+ char *SHA256;
+ /**
+ * The size in bytes of the update package containing this release.
+ */
+ uint64_t Size;
+ /**
+ * The release notes in markdown format, as passed to Velopack when packaging the release. This may be an empty string.
+ */
+ char *NotesMarkdown;
+ /**
+ * The release notes in HTML format, transformed from Markdown when packaging the release. This may be an empty string.
+ */
+ char *NotesHtml;
+} vpkc_asset_t;
+
+/**
+ * User delegate for downloading an asset file. This function is expected to download the provided asset
+ * to the provided local file path. Througout, you can use the progress callback to write progress reports.
+ * The function should return true if the download was successful, false otherwise.
+ * Progress
+ */
+typedef bool (*vpkc_download_asset_delegate_t)(void *p_user_data,
+ const struct vpkc_asset_t *p_asset,
+ const char *psz_local_path,
+ size_t progress_callback_id);
+
+/**
+ * Options to customise the behaviour of UpdateManager.
+ */
+typedef struct vpkc_update_options_t {
+ /**
+ * Allows UpdateManager to update to a version that's lower than the current version (i.e. downgrading).
+ * This could happen if a release has bugs and was retracted from the release feed, or if you're using
+ * ExplicitChannel to switch channels to another channel where the latest version on that
+ * channel is lower than the current version.
+ */
+ bool AllowVersionDowngrade;
+ /**
+ * **This option should usually be left None**.
+ * Overrides the default channel used to fetch updates.
+ * The default channel will be whatever channel was specified on the command line when building this release.
+ * For example, if the current release was packaged with '--channel beta', then the default channel will be 'beta'.
+ * This allows users to automatically receive updates from the same channel they installed from. This options
+ * allows you to explicitly switch channels, for example if the user wished to switch back to the 'stable' channel
+ * without having to reinstall the application.
+ */
+ char *ExplicitChannel;
+ /**
+ * Sets the maximum number of deltas to consider before falling back to a full update.
+ * The default is 10. Set to a negative number (eg. -1) to disable deltas.
+ */
+ int32_t MaximumDeltasBeforeFallback;
+} vpkc_update_options_t;
+
+/**
+ * VelopackLocator provides some utility functions for locating the current app important paths (eg. path to packages, update binary, and so forth).
+ */
+typedef struct vpkc_locator_config_t {
+ /**
+ * The root directory of the current app.
+ */
+ char *RootAppDir;
+ /**
+ * The path to the Update.exe binary.
+ */
+ char *UpdateExePath;
+ /**
+ * The path to the packages' directory.
+ */
+ char *PackagesDir;
+ /**
+ * The current app manifest.
+ */
+ char *ManifestPath;
+ /**
+ * The directory containing the application's user binaries.
+ */
+ char *CurrentBinaryDir;
+ /**
+ * Whether the current application is portable or installed.
+ */
+ bool IsPortable;
+} vpkc_locator_config_t;
+
+/**
+ * Opaque type for the Velopack UpdateManager. Must be freed with `vpkc_free_update_manager`.
+ */
+typedef void vpkc_update_manager_t;
+
+/**
+ * Holds information about the current version and pending updates, such as how many there are, and access to release notes.
+ */
+typedef struct vpkc_update_info_t {
+ /**
+ * The available version that we are updating to.
+ */
+ struct vpkc_asset_t *TargetFullRelease;
+ /**
+ * The base release that this update is based on. This is only available if the update is a delta update.
+ */
+ struct vpkc_asset_t *BaseRelease;
+ /**
+ * The list of delta updates that can be applied to the base version to get to the target version.
+ */
+ struct vpkc_asset_t **DeltasToTarget;
+ /**
+ * The number of elements in the DeltasToTarget array.
+ */
+ size_t DeltasToTargetCount;
+ /**
+ * True if the update is a version downgrade or lateral move (such as when switching channels to the same version number).
+ * In this case, only full updates are allowed, and any local packages on disk newer than the downloaded version will be
+ * deleted.
+ */
+ bool IsDowngrade;
+} vpkc_update_info_t;
+
+/**
+ * Progress callback function.
+ */
+typedef void (*vpkc_progress_callback_t)(void *p_user_data, size_t progress);
+
+/**
+ * VelopackApp startup hook callback function.
+ */
+typedef void (*vpkc_hook_callback_t)(void *p_user_data, const char *psz_app_version);
+
+/**
+ * Log callback function.
+ */
+typedef void (*vpkc_log_callback_t)(void *p_user_data,
+ const char *psz_level,
+ const char *psz_message);
+
+#ifdef __cplusplus
+extern "C" {
+#endif // __cplusplus
+
+/**
+ * Create a new FileSource update source for a given file path.
+ */
+vpkc_update_source_t *vpkc_new_source_file(const char *psz_file_path);
+
+/**
+ * Create a new HttpSource update source for a given HTTP URL.
+ */
+vpkc_update_source_t *vpkc_new_source_http_url(const char *psz_http_url);
+
+/**
+ * Create a new _CUSTOM_ update source with user-provided callbacks to fetch release feeds and download assets.
+ * You can report download progress using `vpkc_source_report_progress`. Note that the callbacks must be valid
+ * for the lifetime of any UpdateManager's that use this source. You should call `vpkc_free_source` to free the source,
+ * but note that if the source is still in use by an UpdateManager, it will not be freed until the UpdateManager is freed.
+ * Therefore to avoid possible issues, it is recommended to create this type of source once for the lifetime of your application.
+ */
+vpkc_update_source_t *vpkc_new_source_custom_callback(vpkc_release_feed_delegate_t cb_release_feed,
+ vpkc_free_release_feed_t cb_free_release_feed,
+ vpkc_download_asset_delegate_t cb_download_entry,
+ void *p_user_data);
+
+/**
+ * Sends a progress update to the callback with the specified ID. This is used by custom
+ * update sources created with `vpkc_new_source_custom_callback` to report download progress.
+ */
+void vpkc_source_report_progress(size_t progress_callback_id, int16_t progress);
+
+/**
+ * Frees a vpkc_update_source_t instance.
+ */
+void vpkc_free_source(vpkc_update_source_t *p_source);
+
+/**
+ * Create a new UpdateManager instance.
+ * @param urlOrPath Location of the update server or path to the local update directory.
+ * @param options Optional extra configuration for update manager.
+ * @param locator Override the default locator configuration (usually used for testing / mocks).
+ */
+bool vpkc_new_update_manager(const char *psz_url_or_path,
+ struct vpkc_update_options_t *p_options,
+ struct vpkc_locator_config_t *p_locator,
+ vpkc_update_manager_t **p_manager);
+
+/**
+ * Create a new UpdateManager instance with a custom UpdateSource.
+ * @param urlOrPath Location of the update server or path to the local update directory.
+ * @param options Optional extra configuration for update manager.
+ * @param locator Override the default locator configuration (usually used for testing / mocks).
+ */
+bool vpkc_new_update_manager_with_source(vpkc_update_source_t *p_source,
+ struct vpkc_update_options_t *p_options,
+ struct vpkc_locator_config_t *p_locator,
+ vpkc_update_manager_t **p_manager);
+
+/**
+ * Returns the currently installed version of the app.
+ */
+size_t vpkc_get_current_version(vpkc_update_manager_t *p_manager,
+ char *psz_version,
+ size_t c_version);
+
+/**
+ * Returns the currently installed app id.
+ */
+size_t vpkc_get_app_id(vpkc_update_manager_t *p_manager, char *psz_id, size_t c_id);
+
+/**
+ * Returns whether the app is in portable mode. On Windows this can be true or false.
+ * On MacOS and Linux this will always be true.
+ */
+bool vpkc_is_portable(vpkc_update_manager_t *p_manager);
+
+/**
+ * Returns an UpdateInfo object if there is an update downloaded which still needs to be applied.
+ * You can pass the UpdateInfo object to waitExitThenApplyUpdate to apply the update.
+ */
+bool vpkc_update_pending_restart(vpkc_update_manager_t *p_manager, struct vpkc_asset_t **p_asset);
+
+/**
+ * Checks for updates, returning None if there are none available. If there are updates available, this method will return an
+ * UpdateInfo object containing the latest available release, and any delta updates that can be applied if they are available.
+ */
+vpkc_update_check_t vpkc_check_for_updates(vpkc_update_manager_t *p_manager,
+ struct vpkc_update_info_t **p_update);
+
+/**
+ * Downloads the specified updates to the local app packages directory. Progress is reported back to the caller via an optional callback.
+ * This function will acquire a global update lock so may fail if there is already another update operation in progress.
+ * - If the update contains delta packages and the delta feature is enabled
+ * this method will attempt to unpack and prepare them.
+ * - If there is no delta update available, or there is an error preparing delta
+ * packages, this method will fall back to downloading the full version of the update.
+ */
+bool vpkc_download_updates(vpkc_update_manager_t *p_manager,
+ struct vpkc_update_info_t *p_update,
+ vpkc_progress_callback_t cb_progress,
+ void *p_user_data);
+
+/**
+ * This will launch the Velopack updater and tell it to wait for this program to exit gracefully.
+ * You should then clean up any state and exit your app. The updater will apply updates and then
+ * optionally restart your app. The updater will only wait for 60 seconds before giving up.
+ */
+bool vpkc_wait_exit_then_apply_updates(vpkc_update_manager_t *p_manager,
+ struct vpkc_asset_t *p_asset,
+ bool b_silent,
+ bool b_restart,
+ char **p_restart_args,
+ size_t c_restart_args);
+
+/**
+ * This will launch the Velopack updater and optionally wait for a program to exit gracefully.
+ * This method is unsafe because it does not necessarily wait for any / the correct process to exit
+ * before applying updates. The `vpkc_wait_exit_then_apply_updates` method is recommended for most use cases.
+ * If dw_wait_pid is 0, the updater will not wait for any process to exit before applying updates (Not Recommended).
+ */
+bool vpkc_unsafe_apply_updates(vpkc_update_manager_t *p_manager,
+ struct vpkc_asset_t *p_asset,
+ bool b_silent,
+ uint32_t dw_wait_pid,
+ bool b_restart,
+ char **p_restart_args,
+ size_t c_restart_args);
+
+/**
+ * Frees a vpkc_update_manager_t instance.
+ */
+void vpkc_free_update_manager(vpkc_update_manager_t *p_manager);
+
+/**
+ * Frees a vpkc_update_info_t instance.
+ */
+void vpkc_free_update_info(struct vpkc_update_info_t *p_update_info);
+
+/**
+ * Frees a vpkc_asset_t instance.
+ */
+void vpkc_free_asset(struct vpkc_asset_t *p_asset);
+
+/**
+ * VelopackApp helps you to handle app activation events correctly.
+ * This should be used as early as possible in your application startup code.
+ * (eg. the beginning of main() or wherever your entry point is)
+ */
+void vpkc_app_run(void *p_user_data);
+
+/**
+ * Set whether to automatically apply downloaded updates on startup. This is ON by default.
+ */
+void vpkc_app_set_auto_apply_on_startup(bool b_auto_apply);
+
+/**
+ * Override the command line arguments used by VelopackApp. (by default this is env::args().skip(1))
+ */
+void vpkc_app_set_args(char **p_args, size_t c_args);
+
+/**
+ * VelopackLocator provides some utility functions for locating the current app important paths (eg. path to packages, update binary, and so forth).
+ */
+void vpkc_app_set_locator(struct vpkc_locator_config_t *p_locator);
+
+/**
+ * WARNING: FastCallback hooks are run during critical stages of Velopack operations.
+ * Your code will be run and then the process will exit.
+ * If your code has not completed within 30 seconds, it will be terminated.
+ * Only supported on windows; On other operating systems, this will never be called.
+ */
+void vpkc_app_set_hook_after_install(vpkc_hook_callback_t cb_after_install);
+
+/**
+ * WARNING: FastCallback hooks are run during critical stages of Velopack operations.
+ * Your code will be run and then the process will exit.
+ * If your code has not completed within 30 seconds, it will be terminated.
+ * Only supported on windows; On other operating systems, this will never be called.
+ */
+void vpkc_app_set_hook_before_uninstall(vpkc_hook_callback_t cb_before_uninstall);
+
+/**
+ * WARNING: FastCallback hooks are run during critical stages of Velopack operations.
+ * Your code will be run and then the process will exit.
+ * If your code has not completed within 30 seconds, it will be terminated.
+ * Only supported on windows; On other operating systems, this will never be called.
+ */
+void vpkc_app_set_hook_before_update(vpkc_hook_callback_t cb_before_update);
+
+/**
+ * WARNING: FastCallback hooks are run during critical stages of Velopack operations.
+ * Your code will be run and then the process will exit.
+ * If your code has not completed within 30 seconds, it will be terminated.
+ * Only supported on windows; On other operating systems, this will never be called.
+ */
+void vpkc_app_set_hook_after_update(vpkc_hook_callback_t cb_after_update);
+
+/**
+ * This hook is triggered when the application is started for the first time after installation.
+ */
+void vpkc_app_set_hook_first_run(vpkc_hook_callback_t cb_first_run);
+
+/**
+ * This hook is triggered when the application is restarted by Velopack after installing updates.
+ */
+void vpkc_app_set_hook_restarted(vpkc_hook_callback_t cb_restarted);
+
+/**
+ * Get the last error message that occurred in the Velopack library.
+ */
+size_t vpkc_get_last_error(char *psz_error, size_t c_error);
+
+/**
+ * Set a custom log callback. This will be called for all log messages generated by the Velopack library.
+ */
+void vpkc_set_logger(vpkc_log_callback_t cb_log,
+ void *p_user_data);
+
+#ifdef __cplusplus
+} // extern "C"
+#endif // __cplusplus
+
+#endif /* VELOPACK_H */
diff --git a/windows/vendor/velopack/include/Velopack.hpp b/windows/vendor/velopack/include/Velopack.hpp
new file mode 100644
index 0000000..64460c9
--- /dev/null
+++ b/windows/vendor/velopack/include/Velopack.hpp
@@ -0,0 +1,851 @@
+//! This header provides the C++ API for the Velopack library.
+//! This C++ API is a thin wrapper around the C API, providing a more idiomatic C++ interface.
+#ifndef VELOPACK_HPP
+#define VELOPACK_HPP
+
+#include <string>
+#include <optional>
+#include <vector>
+#include <stdexcept>
+#include <memory>
+#include <functional>
+
+#include "Velopack.h"
+
+#if !defined(_WIN32)
+#include <string.h>
+#endif
+
+namespace Velopack {
+
+static inline void throw_last_error()
+{
+ size_t neededSize = vpkc_get_last_error(nullptr, 0);
+ std::string strError(neededSize, '\0');
+ vpkc_get_last_error(&strError[0], neededSize);
+ throw std::runtime_error(strError);
+}
+
+static inline std::optional<std::string> to_cpp_string(const char* psz)
+{
+ return psz == nullptr ? std::optional<std::string>("") : std::optional<std::string>(psz);
+}
+
+static inline char* alloc_c_string(const std::optional<std::string>& str)
+{
+ if (!str.has_value()) { return nullptr; }
+ return alloc_c_string(str.value());
+}
+
+static inline char* alloc_c_string(const std::string& str)
+{
+ char* result = new char[str.size() + 1]; // +1 for null-terminator
+#ifdef _WIN32
+ strcpy_s(result, str.size() + 1, str.c_str()); // Copy string content
+#else
+ strcpy(result, str.c_str()); // Copy string content
+#endif
+ result[str.size()] = '\0'; // Null-terminate the string
+ return result;
+}
+
+static inline void free_c_string(char* str)
+{
+ delete[] str;
+}
+
+static inline char** alloc_c_string_vec(const std::vector<std::string>& dto, size_t* count)
+{
+ if (dto.empty()) {
+ *count = 0;
+ return nullptr;
+ }
+ *count = dto.size();
+ char** arr = new char* [*count];
+ for (size_t i = 0; i < *count; ++i) {
+ arr[i] = alloc_c_string(dto[i]);
+ }
+ return arr;
+}
+
+static inline void free_c_string_vec(char** arr, size_t size)
+{
+ for (size_t i = 0; i < size; ++i) {
+ free_c_string(arr[i]);
+ arr[i] = nullptr;
+ }
+ delete[] arr;
+}
+
+template<typename T>
+inline T unwrap(const std::optional<T>& opt, const std::string& message = "Expected value not present") {
+ if (!opt.has_value()) {
+ throw std::runtime_error(message);
+ }
+ return opt.value();
+}
+
+// !! AUTO-GENERATED-START CPP_TYPES
+
+/** VelopackLocator provides some utility functions for locating the current app important paths (eg. path to packages, update binary, and so forth). */
+struct VelopackLocatorConfig {
+ /** The root directory of the current app. */
+ std::string RootAppDir;
+ /** The path to the Update.exe binary. */
+ std::string UpdateExePath;
+ /** The path to the packages' directory. */
+ std::string PackagesDir;
+ /** The current app manifest. */
+ std::string ManifestPath;
+ /** The directory containing the application's user binaries. */
+ std::string CurrentBinaryDir;
+ /** Whether the current application is portable or installed. */
+ bool IsPortable;
+};
+
+static inline std::optional<VelopackLocatorConfig> to_cpp_VelopackLocatorConfig(const vpkc_locator_config_t* dto) {
+ if (dto == nullptr) { return std::nullopt; }
+ return std::optional<VelopackLocatorConfig>({
+ unwrap(to_cpp_string(dto->RootAppDir), "Required property RootAppDir was null"),
+ unwrap(to_cpp_string(dto->UpdateExePath), "Required property UpdateExePath was null"),
+ unwrap(to_cpp_string(dto->PackagesDir), "Required property PackagesDir was null"),
+ unwrap(to_cpp_string(dto->ManifestPath), "Required property ManifestPath was null"),
+ unwrap(to_cpp_string(dto->CurrentBinaryDir), "Required property CurrentBinaryDir was null"),
+ dto->IsPortable,
+ });
+}
+
+static inline std::vector<VelopackLocatorConfig> to_cpp_VelopackLocatorConfig_vec(const vpkc_locator_config_t* const* arr, size_t c) {
+ if (arr == nullptr || c < 1) { return std::vector<VelopackLocatorConfig>(); }
+ std::vector<VelopackLocatorConfig> result;
+ result.reserve(c);
+ for (size_t i = 0; i < c; ++i) {
+ auto dto = arr[i];
+ if (dto == nullptr) { continue; }
+ result.push_back(unwrap(to_cpp_VelopackLocatorConfig(dto)));
+ }
+ return result;
+}
+
+static inline vpkc_locator_config_t* alloc_c_VelopackLocatorConfig_ptr(const VelopackLocatorConfig* dto) {
+ if (dto == nullptr) { return nullptr; }
+ vpkc_locator_config_t* obj = new vpkc_locator_config_t{};
+ obj->RootAppDir = alloc_c_string(dto->RootAppDir);
+ obj->UpdateExePath = alloc_c_string(dto->UpdateExePath);
+ obj->PackagesDir = alloc_c_string(dto->PackagesDir);
+ obj->ManifestPath = alloc_c_string(dto->ManifestPath);
+ obj->CurrentBinaryDir = alloc_c_string(dto->CurrentBinaryDir);
+ obj->IsPortable = dto->IsPortable;
+ return obj;
+}
+
+static inline vpkc_locator_config_t* alloc_c_VelopackLocatorConfig(const std::optional<VelopackLocatorConfig>& dto) {
+ if (!dto.has_value()) { return nullptr; }
+ VelopackLocatorConfig obj = unwrap(dto);
+ return alloc_c_VelopackLocatorConfig_ptr(&obj);
+}
+
+static inline vpkc_locator_config_t** alloc_c_VelopackLocatorConfig_vec(const std::vector<VelopackLocatorConfig>& dto, size_t* count) {
+ if (dto.empty()) {
+ *count = 0;
+ return nullptr;
+ }
+ *count = dto.size();
+ vpkc_locator_config_t** arr = new vpkc_locator_config_t*[*count];
+ for (size_t i = 0; i < *count; ++i) {
+ arr[i] = alloc_c_VelopackLocatorConfig(dto[i]);
+ }
+ return arr;
+}
+
+static inline void free_c_VelopackLocatorConfig(vpkc_locator_config_t* obj) {
+ if (obj == nullptr) { return; }
+ free_c_string(obj->RootAppDir);
+ free_c_string(obj->UpdateExePath);
+ free_c_string(obj->PackagesDir);
+ free_c_string(obj->ManifestPath);
+ free_c_string(obj->CurrentBinaryDir);
+
+ delete obj;
+}
+
+static inline void free_c_VelopackLocatorConfig_vec(vpkc_locator_config_t** arr, size_t count) {
+ if (arr == nullptr || count < 1) { return; }
+ for (size_t i = 0; i < count; ++i) {
+ free_c_VelopackLocatorConfig(arr[i]);
+ }
+ delete[] arr;
+}
+
+/** An individual Velopack asset, could refer to an asset on-disk or in a remote package feed. */
+struct VelopackAsset {
+ /** The name or Id of the package containing this release. */
+ std::string PackageId;
+ /** The version of this release. */
+ std::string Version;
+ /** The type of asset (eg. "Full" or "Delta"). */
+ std::string Type;
+ /** The filename of the update package containing this release. */
+ std::string FileName;
+ /** The SHA1 checksum of the update package containing this release. */
+ std::string SHA1;
+ /** The SHA256 checksum of the update package containing this release. */
+ std::string SHA256;
+ /** The size in bytes of the update package containing this release. */
+ uint64_t Size;
+ /** The release notes in markdown format, as passed to Velopack when packaging the release. This may be an empty string. */
+ std::string NotesMarkdown;
+ /** The release notes in HTML format, transformed from Markdown when packaging the release. This may be an empty string. */
+ std::string NotesHtml;
+};
+
+static inline std::optional<VelopackAsset> to_cpp_VelopackAsset(const vpkc_asset_t* dto) {
+ if (dto == nullptr) { return std::nullopt; }
+ return std::optional<VelopackAsset>({
+ unwrap(to_cpp_string(dto->PackageId), "Required property PackageId was null"),
+ unwrap(to_cpp_string(dto->Version), "Required property Version was null"),
+ unwrap(to_cpp_string(dto->Type), "Required property Type was null"),
+ unwrap(to_cpp_string(dto->FileName), "Required property FileName was null"),
+ unwrap(to_cpp_string(dto->SHA1), "Required property SHA1 was null"),
+ unwrap(to_cpp_string(dto->SHA256), "Required property SHA256 was null"),
+ dto->Size,
+ unwrap(to_cpp_string(dto->NotesMarkdown), "Required property NotesMarkdown was null"),
+ unwrap(to_cpp_string(dto->NotesHtml), "Required property NotesHtml was null"),
+ });
+}
+
+static inline std::vector<VelopackAsset> to_cpp_VelopackAsset_vec(const vpkc_asset_t* const* arr, size_t c) {
+ if (arr == nullptr || c < 1) { return std::vector<VelopackAsset>(); }
+ std::vector<VelopackAsset> result;
+ result.reserve(c);
+ for (size_t i = 0; i < c; ++i) {
+ auto dto = arr[i];
+ if (dto == nullptr) { continue; }
+ result.push_back(unwrap(to_cpp_VelopackAsset(dto)));
+ }
+ return result;
+}
+
+static inline vpkc_asset_t* alloc_c_VelopackAsset_ptr(const VelopackAsset* dto) {
+ if (dto == nullptr) { return nullptr; }
+ vpkc_asset_t* obj = new vpkc_asset_t{};
+ obj->PackageId = alloc_c_string(dto->PackageId);
+ obj->Version = alloc_c_string(dto->Version);
+ obj->Type = alloc_c_string(dto->Type);
+ obj->FileName = alloc_c_string(dto->FileName);
+ obj->SHA1 = alloc_c_string(dto->SHA1);
+ obj->SHA256 = alloc_c_string(dto->SHA256);
+ obj->Size = dto->Size;
+ obj->NotesMarkdown = alloc_c_string(dto->NotesMarkdown);
+ obj->NotesHtml = alloc_c_string(dto->NotesHtml);
+ return obj;
+}
+
+static inline vpkc_asset_t* alloc_c_VelopackAsset(const std::optional<VelopackAsset>& dto) {
+ if (!dto.has_value()) { return nullptr; }
+ VelopackAsset obj = unwrap(dto);
+ return alloc_c_VelopackAsset_ptr(&obj);
+}
+
+static inline vpkc_asset_t** alloc_c_VelopackAsset_vec(const std::vector<VelopackAsset>& dto, size_t* count) {
+ if (dto.empty()) {
+ *count = 0;
+ return nullptr;
+ }
+ *count = dto.size();
+ vpkc_asset_t** arr = new vpkc_asset_t*[*count];
+ for (size_t i = 0; i < *count; ++i) {
+ arr[i] = alloc_c_VelopackAsset(dto[i]);
+ }
+ return arr;
+}
+
+static inline void free_c_VelopackAsset(vpkc_asset_t* obj) {
+ if (obj == nullptr) { return; }
+ free_c_string(obj->PackageId);
+ free_c_string(obj->Version);
+ free_c_string(obj->Type);
+ free_c_string(obj->FileName);
+ free_c_string(obj->SHA1);
+ free_c_string(obj->SHA256);
+
+ free_c_string(obj->NotesMarkdown);
+ free_c_string(obj->NotesHtml);
+ delete obj;
+}
+
+static inline void free_c_VelopackAsset_vec(vpkc_asset_t** arr, size_t count) {
+ if (arr == nullptr || count < 1) { return; }
+ for (size_t i = 0; i < count; ++i) {
+ free_c_VelopackAsset(arr[i]);
+ }
+ delete[] arr;
+}
+
+/** Holds information about the current version and pending updates, such as how many there are, and access to release notes. */
+struct UpdateInfo {
+ /** The available version that we are updating to. */
+ VelopackAsset TargetFullRelease;
+ /** The base release that this update is based on. This is only available if the update is a delta update. */
+ std::optional<VelopackAsset> BaseRelease;
+ /** The list of delta updates that can be applied to the base version to get to the target version. */
+ std::vector<VelopackAsset> DeltasToTarget;
+ /**
+ * True if the update is a version downgrade or lateral move (such as when switching channels to the same version number).
+ * In this case, only full updates are allowed, and any local packages on disk newer than the downloaded version will be
+ * deleted.
+ */
+ bool IsDowngrade;
+};
+
+static inline std::optional<UpdateInfo> to_cpp_UpdateInfo(const vpkc_update_info_t* dto) {
+ if (dto == nullptr) { return std::nullopt; }
+ return std::optional<UpdateInfo>({
+ unwrap(to_cpp_VelopackAsset(dto->TargetFullRelease), "Required property TargetFullRelease was null"),
+ to_cpp_VelopackAsset(dto->BaseRelease),
+ to_cpp_VelopackAsset_vec(dto->DeltasToTarget, dto->DeltasToTargetCount),
+ dto->IsDowngrade,
+ });
+}
+
+static inline std::vector<UpdateInfo> to_cpp_UpdateInfo_vec(const vpkc_update_info_t* const* arr, size_t c) {
+ if (arr == nullptr || c < 1) { return std::vector<UpdateInfo>(); }
+ std::vector<UpdateInfo> result;
+ result.reserve(c);
+ for (size_t i = 0; i < c; ++i) {
+ auto dto = arr[i];
+ if (dto == nullptr) { continue; }
+ result.push_back(unwrap(to_cpp_UpdateInfo(dto)));
+ }
+ return result;
+}
+
+static inline vpkc_update_info_t* alloc_c_UpdateInfo_ptr(const UpdateInfo* dto) {
+ if (dto == nullptr) { return nullptr; }
+ vpkc_update_info_t* obj = new vpkc_update_info_t{};
+ obj->TargetFullRelease = alloc_c_VelopackAsset(dto->TargetFullRelease);
+ obj->BaseRelease = alloc_c_VelopackAsset(dto->BaseRelease);
+ obj->DeltasToTarget = alloc_c_VelopackAsset_vec(dto->DeltasToTarget, &obj->DeltasToTargetCount);
+ obj->IsDowngrade = dto->IsDowngrade;
+ return obj;
+}
+
+static inline vpkc_update_info_t* alloc_c_UpdateInfo(const std::optional<UpdateInfo>& dto) {
+ if (!dto.has_value()) { return nullptr; }
+ UpdateInfo obj = unwrap(dto);
+ return alloc_c_UpdateInfo_ptr(&obj);
+}
+
+static inline vpkc_update_info_t** alloc_c_UpdateInfo_vec(const std::vector<UpdateInfo>& dto, size_t* count) {
+ if (dto.empty()) {
+ *count = 0;
+ return nullptr;
+ }
+ *count = dto.size();
+ vpkc_update_info_t** arr = new vpkc_update_info_t*[*count];
+ for (size_t i = 0; i < *count; ++i) {
+ arr[i] = alloc_c_UpdateInfo(dto[i]);
+ }
+ return arr;
+}
+
+static inline void free_c_UpdateInfo(vpkc_update_info_t* obj) {
+ if (obj == nullptr) { return; }
+ free_c_VelopackAsset(obj->TargetFullRelease);
+ free_c_VelopackAsset(obj->BaseRelease);
+ free_c_VelopackAsset_vec(obj->DeltasToTarget, obj->DeltasToTargetCount);
+
+ delete obj;
+}
+
+static inline void free_c_UpdateInfo_vec(vpkc_update_info_t** arr, size_t count) {
+ if (arr == nullptr || count < 1) { return; }
+ for (size_t i = 0; i < count; ++i) {
+ free_c_UpdateInfo(arr[i]);
+ }
+ delete[] arr;
+}
+
+/** Options to customise the behaviour of UpdateManager. */
+struct UpdateOptions {
+ /**
+ * Allows UpdateManager to update to a version that's lower than the current version (i.e. downgrading).
+ * This could happen if a release has bugs and was retracted from the release feed, or if you're using
+ * ExplicitChannel to switch channels to another channel where the latest version on that
+ * channel is lower than the current version.
+ */
+ bool AllowVersionDowngrade;
+ /**
+ * **This option should usually be left None**.
+ * Overrides the default channel used to fetch updates.
+ * The default channel will be whatever channel was specified on the command line when building this release.
+ * For example, if the current release was packaged with '--channel beta', then the default channel will be 'beta'.
+ * This allows users to automatically receive updates from the same channel they installed from. This options
+ * allows you to explicitly switch channels, for example if the user wished to switch back to the 'stable' channel
+ * without having to reinstall the application.
+ */
+ std::optional<std::string> ExplicitChannel;
+ /**
+ * Sets the maximum number of deltas to consider before falling back to a full update.
+ * The default is 10. Set to a negative number (eg. -1) to disable deltas.
+ */
+ int32_t MaximumDeltasBeforeFallback;
+};
+
+static inline std::optional<UpdateOptions> to_cpp_UpdateOptions(const vpkc_update_options_t* dto) {
+ if (dto == nullptr) { return std::nullopt; }
+ return std::optional<UpdateOptions>({
+ dto->AllowVersionDowngrade,
+ to_cpp_string(dto->ExplicitChannel),
+ dto->MaximumDeltasBeforeFallback,
+ });
+}
+
+static inline std::vector<UpdateOptions> to_cpp_UpdateOptions_vec(const vpkc_update_options_t* const* arr, size_t c) {
+ if (arr == nullptr || c < 1) { return std::vector<UpdateOptions>(); }
+ std::vector<UpdateOptions> result;
+ result.reserve(c);
+ for (size_t i = 0; i < c; ++i) {
+ auto dto = arr[i];
+ if (dto == nullptr) { continue; }
+ result.push_back(unwrap(to_cpp_UpdateOptions(dto)));
+ }
+ return result;
+}
+
+static inline vpkc_update_options_t* alloc_c_UpdateOptions_ptr(const UpdateOptions* dto) {
+ if (dto == nullptr) { return nullptr; }
+ vpkc_update_options_t* obj = new vpkc_update_options_t{};
+ obj->AllowVersionDowngrade = dto->AllowVersionDowngrade;
+ obj->ExplicitChannel = alloc_c_string(dto->ExplicitChannel);
+ obj->MaximumDeltasBeforeFallback = dto->MaximumDeltasBeforeFallback;
+ return obj;
+}
+
+static inline vpkc_update_options_t* alloc_c_UpdateOptions(const std::optional<UpdateOptions>& dto) {
+ if (!dto.has_value()) { return nullptr; }
+ UpdateOptions obj = unwrap(dto);
+ return alloc_c_UpdateOptions_ptr(&obj);
+}
+
+static inline vpkc_update_options_t** alloc_c_UpdateOptions_vec(const std::vector<UpdateOptions>& dto, size_t* count) {
+ if (dto.empty()) {
+ *count = 0;
+ return nullptr;
+ }
+ *count = dto.size();
+ vpkc_update_options_t** arr = new vpkc_update_options_t*[*count];
+ for (size_t i = 0; i < *count; ++i) {
+ arr[i] = alloc_c_UpdateOptions(dto[i]);
+ }
+ return arr;
+}
+
+static inline void free_c_UpdateOptions(vpkc_update_options_t* obj) {
+ if (obj == nullptr) { return; }
+
+ free_c_string(obj->ExplicitChannel);
+
+ delete obj;
+}
+
+static inline void free_c_UpdateOptions_vec(vpkc_update_options_t** arr, size_t count) {
+ if (arr == nullptr || count < 1) { return; }
+ for (size_t i = 0; i < count; ++i) {
+ free_c_UpdateOptions(arr[i]);
+ }
+ delete[] arr;
+}
+// !! AUTO-GENERATED-END CPP_TYPES
+
+/**
+ * VelopackApp helps you to handle app activation events correctly.
+ * This should be used as early as possible in your application startup code.
+ * (eg. the beginning of main() or wherever your entry point is)
+ */
+class VelopackApp {
+private:
+ VelopackApp() {};
+public:
+ /**
+ * Build a new VelopackApp instance.
+ */
+ static VelopackApp Build() {
+ return VelopackApp();
+ };
+
+ /**
+ * Attach a custom callback to receive log messages from Velopack.
+ */
+ VelopackApp& SetLogger(vpkc_log_callback_t cbInstall, void* p_user_data) {
+ vpkc_set_logger(cbInstall, p_user_data);
+ return *this;
+ };
+
+ /**
+ * Set whether to automatically apply downloaded updates on startup. This is ON by default.
+ */
+ VelopackApp& SetAutoApplyOnStartup(bool bAutoApply) {
+ vpkc_app_set_auto_apply_on_startup(bAutoApply);
+ return *this;
+ };
+
+ /**
+ * Override the command line arguments used by VelopackApp. (by default this is env::args().skip(1))
+ */
+ VelopackApp& SetArgs(const std::vector<std::string>& args) {
+ size_t c;
+ char** pArgs = alloc_c_string_vec(args, &c);
+ vpkc_app_set_args(pArgs, c);
+ free_c_string_vec(pArgs, c);
+ return *this;
+ };
+
+ /**
+ * VelopackLocator provides some utility functions for locating the current app important paths (eg. path to packages, update binary, and so forth).
+ */
+ VelopackApp& SetLocator(const VelopackLocatorConfig& locator) {
+ vpkc_locator_config_t* vpkc_locator = alloc_c_VelopackLocatorConfig(locator);
+ vpkc_app_set_locator(vpkc_locator);
+ free_c_VelopackLocatorConfig(vpkc_locator);
+ return *this;
+ };
+
+ /**
+ * WARNING: FastCallback hooks are run during critical stages of Velopack operations.
+ * Your code will be run and then the process will exit.
+ * If your code has not completed within 30 seconds, it will be terminated.
+ * Only supported on windows; On other operating systems, this will never be called.
+ */
+ VelopackApp& OnAfterInstall(vpkc_hook_callback_t cbInstall) {
+ vpkc_app_set_hook_after_install(cbInstall);
+ return *this;
+ };
+
+ /**
+ * WARNING: FastCallback hooks are run during critical stages of Velopack operations.
+ * Your code will be run and then the process will exit.
+ * If your code has not completed within 30 seconds, it will be terminated.
+ * Only supported on windows; On other operating systems, this will never be called.
+ */
+ VelopackApp& OnBeforeUninstall(vpkc_hook_callback_t cbInstall) {
+ vpkc_app_set_hook_before_uninstall(cbInstall);
+ return *this;
+ };
+
+ /**
+ * WARNING: FastCallback hooks are run during critical stages of Velopack operations.
+ * Your code will be run and then the process will exit.
+ * If your code has not completed within 30 seconds, it will be terminated.
+ * Only supported on windows; On other operating systems, this will never be called.
+ */
+ VelopackApp& OnBeforeUpdate(vpkc_hook_callback_t cbInstall) {
+ vpkc_app_set_hook_before_update(cbInstall);
+ return *this;
+ };
+
+ /**
+ * WARNING: FastCallback hooks are run during critical stages of Velopack operations.
+ * Your code will be run and then the process will exit.
+ * If your code has not completed within 30 seconds, it will be terminated.
+ * Only supported on windows; On other operating systems, this will never be called.
+ */
+ VelopackApp& OnAfterUpdate(vpkc_hook_callback_t cbInstall) {
+ vpkc_app_set_hook_after_update(cbInstall);
+ return *this;
+ };
+
+ /**
+ * This hook is triggered when the application is started for the first time after installation.
+ */
+ VelopackApp& OnFirstRun(vpkc_hook_callback_t cbInstall) {
+ vpkc_app_set_hook_first_run(cbInstall);
+ return *this;
+ };
+
+ /**
+ * This hook is triggered when the application is restarted by Velopack after installing updates.
+ */
+ VelopackApp& OnRestarted(vpkc_hook_callback_t cbInstall) {
+ vpkc_app_set_hook_restarted(cbInstall);
+ return *this;
+ };
+
+ /**
+ * Runs the Velopack startup logic. This should be the first thing to run in your app.
+ * In some circumstances it may terminate/restart the process to perform tasks.
+ */
+ void Run(void* pUserData = 0) {
+ vpkc_app_run(pUserData);
+ };
+};
+
+/**
+ * Progress callback function. Call with values between 0 and 100 inclusive.
+ */
+typedef std::function<void(int16_t)> vpkc_progress_send_t;
+
+/**
+ * Abstract class for retrieving release feeds and downloading assets. You should subclass this and
+ * implement/override the GetReleaseFeed and DownloadReleaseEntry methods.
+ * This class is used by the UpdateManager to fetch release feeds and download assets in a custom way.
+ * SAFETY: It is your responsibility to ensure that a derived class instance is thread-safe,
+ * as Velopack may call methods on this class from multiple threads.
+ */
+class IUpdateSource {
+ friend class UpdateManager;
+ friend class FileSource;
+ friend class HttpSource;
+private:
+ IUpdateSource(vpkc_update_source_t* pSource) : m_pSource(pSource) {}
+ vpkc_update_source_t* m_pSource = 0;
+public:
+ virtual ~IUpdateSource() {
+ vpkc_free_source(m_pSource);
+ }
+ IUpdateSource() {
+ m_pSource = vpkc_new_source_custom_callback(
+ [](void* userData, const char* releasesName) {
+ IUpdateSource* source = reinterpret_cast<IUpdateSource*>(userData);
+ std::string json = source->GetReleaseFeed(releasesName);
+ return alloc_c_string(json);
+ },
+ [](void* userData, char* pszFeed) {
+ free_c_string(pszFeed);
+ },
+ [](void* userData, const struct vpkc_asset_t *pAsset, const char* pszLocalPath, size_t progressCallbackId) {
+ IUpdateSource* source = reinterpret_cast<IUpdateSource*>(userData);
+ VelopackAsset asset = to_cpp_VelopackAsset(pAsset).value();
+ std::string localPath = to_cpp_string(pszLocalPath).value();
+ std::function<void(int16_t)> progress_callback = [progressCallbackId](int16_t progress) {
+ vpkc_source_report_progress(progressCallbackId, progress);
+ };
+ return source->DownloadReleaseEntry(asset, localPath, progress_callback);
+ },
+ this);
+ }
+
+ /**
+ * Fetches the release feed json for the specified releases name, and returns it as a string.
+ */
+ virtual const std::string GetReleaseFeed(const std::string releasesName) = 0;
+
+ /**
+ * Downloads an asset to the specified local file path. Progress is reported back to Velopack via a callback.
+ */
+ virtual bool DownloadReleaseEntry(const VelopackAsset& asset, const std::string localFilePath, vpkc_progress_send_t progress) = 0;
+};
+
+/**
+ * A simple update source that reads release feeds and downloads assets from a local file path.
+ */
+class FileSource : public IUpdateSource {
+public:
+ FileSource(const std::string& filePath) : IUpdateSource(vpkc_new_source_file(filePath.c_str())) { }
+ const std::string GetReleaseFeed(const std::string releasesName) override {
+ throw std::runtime_error("Not implemented");
+ }
+ bool DownloadReleaseEntry(const VelopackAsset& asset, const std::string localFilePath, vpkc_progress_send_t progress) override {
+ throw std::runtime_error("Not implemented");
+ }
+};
+
+/**
+ * A simple update source that reads release feeds and downloads assets from an remote http url.
+ */
+class HttpSource : public IUpdateSource {
+public:
+ HttpSource(const std::string& httpUrl) : IUpdateSource(vpkc_new_source_http_url(httpUrl.c_str())) { }
+ const std::string GetReleaseFeed(const std::string releasesName) override {
+ throw std::runtime_error("Not implemented");
+ }
+ bool DownloadReleaseEntry(const VelopackAsset& asset, const std::string localFilePath, vpkc_progress_send_t progress) override {
+ throw std::runtime_error("Not implemented");
+ }
+};
+
+/**
+ * Provides functionality for checking for updates, downloading updates, and applying updates to the current application.
+ */
+class UpdateManager {
+private:
+ vpkc_update_manager_t* m_pManager = 0;
+ std::unique_ptr<IUpdateSource> m_pUpdateSource;
+
+public:
+ /**
+ * Create a new UpdateManager instance.
+ * @param urlOrPath Location of the http update server or the local update directory path containing releases.
+ * @param options Optional extra configuration for update manager.
+ * @param locator Override the default locator configuration (usually used for testing / mocks).
+ */
+ UpdateManager(const std::string& urlOrPath, const UpdateOptions* options = nullptr, const VelopackLocatorConfig* locator = nullptr) {
+ vpkc_update_options_t* pOptions = alloc_c_UpdateOptions_ptr(options);
+ vpkc_locator_config_t* pLocator = alloc_c_VelopackLocatorConfig_ptr(locator);
+ bool result = vpkc_new_update_manager(urlOrPath.c_str(), pOptions, pLocator, &m_pManager);
+ free_c_UpdateOptions(pOptions);
+ free_c_VelopackLocatorConfig(pLocator);
+ if (!result) {
+ throw_last_error();
+ }
+ };
+
+ /**
+ * Create a new UpdateManager instance.
+ * @param updateSource The source to use for retrieving feed and downloading assets.
+ * @param options Optional extra configuration for update manager.
+ * @param locator Override the default locator configuration (usually used for testing / mocks).
+ */
+ template <typename T, typename = std::enable_if_t<std::is_base_of_v<IUpdateSource, T>>>
+ UpdateManager(std::unique_ptr<T> pUpdateSource, const UpdateOptions* options = nullptr, const VelopackLocatorConfig* locator = nullptr) {
+ vpkc_update_options_t* pOptions = alloc_c_UpdateOptions_ptr(options);
+ vpkc_locator_config_t* pLocator = alloc_c_VelopackLocatorConfig_ptr(locator);
+ m_pUpdateSource = std::unique_ptr<IUpdateSource>(static_cast<IUpdateSource*>(pUpdateSource.release()));
+ vpkc_update_source_t* pSource = m_pUpdateSource->m_pSource;
+ bool result = vpkc_new_update_manager_with_source(pSource, pOptions, pLocator, &m_pManager);
+ free_c_UpdateOptions(pOptions);
+ free_c_VelopackLocatorConfig(pLocator);
+ if (!result) {
+ throw_last_error();
+ }
+ };
+
+ /**
+ * Destructor for UpdateManager.
+ */
+ ~UpdateManager() {
+ if (m_pManager != nullptr) {
+ vpkc_free_update_manager(m_pManager);
+ m_pManager = nullptr;
+ }
+ };
+
+ /**
+ * Returns whether the app is in portable mode. On Windows this can be true or false.
+ * On MacOS and Linux this will always be true.
+ */
+ bool IsPortable() noexcept {
+ return vpkc_is_portable(m_pManager);
+ };
+
+ /**
+ * Returns the currently installed version of the app.
+ */
+ std::string GetCurrentVersion() noexcept {
+ size_t neededSize = vpkc_get_current_version(m_pManager, nullptr, 0);
+ std::string strVersion(neededSize, '\0');
+ vpkc_get_current_version(m_pManager, &strVersion[0], neededSize);
+ return strVersion;
+ };
+
+ /**
+ * Returns the currently installed app id.
+ */
+ std::string GetAppId() noexcept {
+ size_t neededSize = vpkc_get_app_id(m_pManager, nullptr, 0);
+ std::string strId(neededSize, '\0');
+ vpkc_get_app_id(m_pManager, &strId[0], neededSize);
+ return strId;
+ };
+
+ /**
+ * Returns an UpdateInfo object if there is an update downloaded which still needs to be applied.
+ * You can pass the UpdateInfo object to waitExitThenApplyUpdate to apply the update.
+ */
+ std::optional<VelopackAsset> UpdatePendingRestart() noexcept {
+ vpkc_asset_t* asset;
+ if (vpkc_update_pending_restart(m_pManager, &asset)) {
+ VelopackAsset cpp_asset = to_cpp_VelopackAsset(asset).value();
+ vpkc_free_asset(asset);
+ return cpp_asset;
+ }
+ return std::nullopt;
+ };
+
+ /**
+ * Checks for updates, returning None if there are none available. If there are updates available, this method will return an
+ * UpdateInfo object containing the latest available release, and any delta updates that can be applied if they are available.
+ */
+ std::optional<UpdateInfo> CheckForUpdates() {
+ vpkc_update_info_t* update;
+ vpkc_update_check_t result = vpkc_check_for_updates(m_pManager, &update);
+ switch (result) {
+ case vpkc_update_check_t::UPDATE_ERROR:
+ throw_last_error();
+ return std::nullopt;
+ case vpkc_update_check_t::NO_UPDATE_AVAILABLE:
+ case vpkc_update_check_t::REMOTE_IS_EMPTY:
+ return std::nullopt;
+ case vpkc_update_check_t::UPDATE_AVAILABLE:
+ UpdateInfo cpp_info = to_cpp_UpdateInfo(update).value();
+ vpkc_free_update_info(update);
+ return cpp_info;
+ }
+ return std::nullopt;
+ };
+
+ /**
+ * Downloads the specified updates to the local app packages directory. Progress is reported back to the caller via an optional callback.
+ * This function will acquire a global update lock so may fail if there is already another update operation in progress.
+ * - If the update contains delta packages and the delta feature is enabled
+ * this method will attempt to unpack and prepare them.
+ * - If there is no delta update available, or there is an error preparing delta
+ * packages, this method will fall back to downloading the full version of the update.
+ */
+ void DownloadUpdates(const UpdateInfo& update, vpkc_progress_callback_t progress = nullptr, void* pUserData = 0) {
+ vpkc_update_info_t* vpkc_update = alloc_c_UpdateInfo(update);
+ bool result = vpkc_download_updates(m_pManager, vpkc_update, progress, pUserData);
+ free_c_UpdateInfo(vpkc_update);
+ if (!result) {
+ throw_last_error();
+ }
+ };
+
+ /**
+ * This will launch the Velopack updater and tell it to wait for this program to exit gracefully.
+ * You should then clean up any state and exit your app. The updater will apply updates and then
+ * optionally restart your app. The updater will only wait for 60 seconds before giving up.
+ */
+ void WaitExitThenApplyUpdates(const UpdateInfo& asset, bool silent = false, bool restart = true, std::vector<std::string> restartArgs = {}) {
+ this->WaitExitThenApplyUpdates(asset.TargetFullRelease, silent, restart, restartArgs);
+ };
+
+ /**
+ * This will launch the Velopack updater and tell it to wait for this program to exit gracefully.
+ * You should then clean up any state and exit your app. The updater will apply updates and then
+ * optionally restart your app. The updater will only wait for 60 seconds before giving up.
+ */
+ void WaitExitThenApplyUpdates(const VelopackAsset& asset, bool silent = false, bool restart = true, std::vector<std::string> restartArgs = {}) {
+ size_t cRestartArgs;
+ char** pRestartArgs = alloc_c_string_vec(restartArgs, &cRestartArgs);
+ vpkc_asset_t* vpkc_asset = alloc_c_VelopackAsset(asset);
+ bool result = vpkc_wait_exit_then_apply_updates(m_pManager, vpkc_asset, silent, restart, pRestartArgs, cRestartArgs);
+ free_c_string_vec(pRestartArgs, cRestartArgs);
+ free_c_VelopackAsset(vpkc_asset);
+ if (!result) {
+ throw_last_error();
+ }
+ };
+
+ /**
+ * This will launch the Velopack updater and optionally wait for a program to exit gracefully.
+ * This method is unsafe because it does not necessarily wait for any / the correct process to exit
+ * before applying updates. The `WaitExitThenApplyUpdates` method is recommended for most use cases.
+ * If waitPid is 0, the updater will not wait for any process to exit before applying updates (Not Recommended).
+ */
+ void UnsafeApplyUpdates(const VelopackAsset& asset, bool silent, uint32_t waitPid, bool restart, std::vector<std::string> restartArgs) {
+ size_t cRestartArgs;
+ char** pRestartArgs = alloc_c_string_vec(restartArgs, &cRestartArgs);
+ vpkc_asset_t* vpkc_asset = alloc_c_VelopackAsset(asset);
+ bool result = vpkc_unsafe_apply_updates(m_pManager, vpkc_asset, silent, waitPid, restart, pRestartArgs, cRestartArgs);
+ free_c_string_vec(pRestartArgs, cRestartArgs);
+ free_c_VelopackAsset(vpkc_asset);
+ if (!result) {
+ throw_last_error();
+ }
+ };
+};
+
+} // namespace Velopack
+
+#endif // VELOPACK_HPP
diff --git a/windows/vendor/velopack/lib/velopack_libc_win_x64_msvc.lib b/windows/vendor/velopack/lib/velopack_libc_win_x64_msvc.lib
new file mode 100644
index 0000000..2f6957e
Binary files /dev/null and b/windows/vendor/velopack/lib/velopack_libc_win_x64_msvc.lib differ