Skip to content

Commit

Permalink
Update C++ quick start
Browse files Browse the repository at this point in the history
  • Loading branch information
caesay committed Oct 20, 2024
1 parent 4dc320d commit 929e364
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 53 deletions.
73 changes: 31 additions & 42 deletions docs/getting-started/cpp.mdx
Original file line number Diff line number Diff line change
@@ -1,60 +1,54 @@
# Getting Started: C++
# Getting Started: C / C++
<AppliesTo all />
Get started with our cross-platform C++ header library.

1. Copy [Velopack.hpp](https://github.com/velopack/velopack.fusion/blob/master/for-cpp/Velopack.hpp) and [Velopack.cpp](https://github.com/velopack/velopack.fusion/blob/master/for-cpp/Velopack.cpp) into your project.

0. Configure Unicode Support:
#### Windows
On Windows, to enable unicode support for this library you ***must***
[configure the UTF-8 code page](https://learn.microsoft.com/en-us/windows/apps/design/globalizing/use-utf8-code-page) via your application
manifest. Failure to do so will potentially result in your application ***failing to update*** if there are any unicode characters in your user's
file paths, username, etc.
```xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<application>
<windowsSettings>
<activeCodePage xmlns="http://schemas.microsoft.com/SMI/2019/WindowsSettings">UTF-8</activeCodePage>
</windowsSettings>
</application>
</assembly>
```
#### Linux & MacOS
- If you are using Qt and `QString` is available, there's nothing further you need to do.
- If you are not using Qt, you'll need to [install ICU4C](https://icu.unicode.org/). Like many other C libraries,
installing the development package with your package manager (`apt`, `brew` etc) *should* be sufficient to make it available to compilers.
Get started with our cross-platform C / C++ library.

The Velopack C / C++ library is a pre-compiled dynamic library, which you can link into your application to enable auto-updates and installers.
There is a C and a C++ API available in [Velopack.h](https://github.com/velopack/velopack/blob/develop/src/lib-cpp/include/Velopack.h),
so this library is suitable for C / C++ application as well as other programming languages which support calling C functions eg. p/invoke.

:::tip
All the strings (eg. `char*` or `std::string`) are expected to be UTF-8 encoded.
On Windows, you may need to convert `wchar_t*` and `std::wstring` to UTF-8 before passing it to the library.
:::

1. Download the latest `velopack_libc_{version}.zip` from [GitHub Releases](https://github.com/velopack/velopack/releases) and include it into your project.

0. Add the `Velopack::startup()` to your entry point (eg. `main()` or `wmain()`) as early as possible, ideally the first statement to run:
0. Add the `include` directory to your include path, and add the appropriate binary from `lib` to your linker options.

0. Add `VelopackApp` to your entry point (eg. `main()` or `wmain()`) as early as possible, ideally the first statement to run:
```cpp
#include "Velopack.hpp"
#include "Velopack.h"

wmain(int argc**, wchar_t *argv[ ], wchar_t *envp[ ])
{
// Velopack may exit / restart your app at this statement
Velopack::startup(argv, argc);
// This should run as early as possible in the main method.
// Velopack may exit / restart the app at this point.
// See VelopackApp class for more options/configuration.
Velopack::VelopackApp::Build().Run();

// ... your other startup code here
}
```

0. Add auto-updates somewhere to your app:
```cpp
#include "Velopack.hpp"
#include <memory>
#include "Velopack.h"

static void update_app()
{
Velopack::UpdateManagerSync manager{};
manager.setUrlOrPath("https://the.place/you-host/updates");
Velopack::UpdateManager manager("https://the.place/you-host/updates");

auto updInfo = manager.checkForUpdates();
if (updInfo == nullptr) {
auto updInfo = manager.CheckForUpdates();
if (!updInfo.has_value()) {
return; // no updates available
}

manager.downloadUpdates(updInfo->targetFullRelease.get());
manager.applyUpdatesAndRestart(updInfo->targetFullRelease.get());
// download the update, optionally providing progress callbacks
manager.DownloadUpdates(updInfo.value());

// prepare the Updater in a new process, and wait 60 seconds for this process to exit
manager.WaitExitThenApplyUpdate(updInfo.value());
exit(0); // exit the app to apply the update
}
```

Expand All @@ -69,11 +63,6 @@ Get started with our cross-platform C++ header library.

0. Compile your app to a program using your usual compiler (eg. msvc, cmake, gcc, etc)

0. Copy `Vfusion.exe`, `VfusionMac` or `VfusionNix` to your build output folder. This is a manual step for now, but may be automated in the future. You can compile this yourself, download a [recent build artifact](https://github.com/velopack/velopack.fusion/actions), or grab the latest [npm release](https://www.npmjs.com/package/velopack?activeTab=code) which also bundles the binaries.
:::warning
Until this is automated, failing to copy the fusion binary to your update directory will result in your app being unable to update.
:::

0. Package your Velopack release / installers:
```sh
vpk pack -u MyAppUniqueId -v 1.0.0 -p /myBuildDir -e myexename.exe
Expand Down
22 changes: 12 additions & 10 deletions docs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,18 @@ You can host updates anywhere static files can be served, eg. cloud file storage
## Language Support
There are libraries planned or supported for the languages below.

| Lang | Status | Runtime Deps | Async | Links |
|:-:|---|---|---|---|
| C# | ✅ Ready | ✅ None | ✅ Yes | [quick start](./getting-started/csharp.mdx), [docs](./reference/cs/Velopack/), [nuget.org](https://nuget.org/packages/velopack) |
| Rust | ✅ Ready | ✅ None | ✅ Yes | [quick start](./getting-started/rust.mdx), [docs](https://docs.rs/velopack), [crates.io](https://crates.io/crates/velopack) |
| JS | ✅ Ready | ✅ None | ✅ Yes | [quick start](./getting-started/electron.mdx), [docs](./reference/js), [npmjs.com](https://www.npmjs.com/package/velopack) |
| C++ | 🔶 Experimental | 🔶 vfusion.exe | ❌ No | [quick start](./getting-started/cpp.mdx), [docs](./reference/cpp/api.md), [velopack.hpp](https://github.com/velopack/velopack.fusion/tree/master/for-cpp) |
| Java | Planned | - | - | - | - |
| Python | Planned | - | - | - | - |
| Swift | Planned | - | - | - | - |
| Go | Planned | - | - | - | - |
| Lang | Status | Links |
|:-:|---|---|
| C# | ✅ Ready | [quick-start](./getting-started/csharp.mdx), [docs](./reference/cs/Velopack/), [nuget.org](https://nuget.org/packages/velopack) |
| Rust | ✅ Ready | [quick-start](./getting-started/rust.mdx), [docs](https://docs.rs/velopack), [crates.io](https://crates.io/crates/velopack) |
| JS | ✅ Ready | [quick-start](./getting-started/electron.mdx), [docs](./reference/js), [npmjs.com](https://www.npmjs.com/package/velopack) |
| C++ | ✅ Ready | [quick-start](./getting-started/cpp.mdx), [docs](./reference/cpp/api.md), [gh-releases](https://github.com/velopack/velopack/releases) |
| Java | Planned | - | - |
| Python | Planned | - | - |
| Swift | Planned | - | - |
| Go | Planned | - | - |

Don't see your language here? [Open an issue](https://github.com/velopack/velopack/issues/new) to request and tell us how great it is!

## Migrating to Velopack
It should be easy to migrate to Velopack from other update frameworks. We do have some guides, but if we're missing one for your case please let us know about it on GitHub or Discord!
Expand Down
4 changes: 4 additions & 0 deletions docs/reference/cpp/api.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
:::warning
## This page is currently out of date. Please see the [C++ Quick Start](../../getting-started/cpp.mdx) for the most accurate information.
:::

# Velopack C++ Reference

Members | Descriptions
Expand Down
2 changes: 1 addition & 1 deletion sidebars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const sidebars: SidebarsConfig = {
label: 'Quick Start',
items: [
doc("getting-started/csharp", "C# / .NET"),
doc("getting-started/cpp", "C++"),
doc("getting-started/cpp", "C / C++"),
doc("getting-started/electron", "JS / Electron"),
doc("getting-started/rust", "Rust"),
doc("getting-started/uno", "C# / Uno Platform"),
Expand Down

0 comments on commit 929e364

Please sign in to comment.