feat(garage_updates): an auto updater for garage apps
Asks Garage for the newest release of a project, downloads it with resume, checks the sha256, installs it beside the old one and restarts into it. Splash on garage_ui, a native stub and a first time installer for windows, bundle swap on mac, the system installer on android. No-op on web. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KHotisA4hV2xmuZsHTksFX
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
444933b004
commit
d3b232f0ee
@@ -0,0 +1,114 @@
|
||||
# the first-time installer for an app that uses garage_updates. built once by
|
||||
# the developer, per app:
|
||||
#
|
||||
# cmake -S . -B build -A x64 -DGARAGE_APP_NAME="Garage Stash" -DGARAGE_APP_ID=net.imbenji.stash
|
||||
# -DGARAGE_PROJECT_ID=<project id> -DGARAGE_EXE_NAME=garage_stash.exe -DGARAGE_ICON=C:/.../app_icon.ico
|
||||
# cmake --build build --config Release
|
||||
#
|
||||
# and out comes "<AppName>-Setup.exe" with the stub inside it. build_installer.bat
|
||||
# does the same with shorter flags.
|
||||
cmake_minimum_required(VERSION 3.15)
|
||||
project(garage_installer LANGUAGES CXX)
|
||||
|
||||
# static runtime, its handed to people who have nothing installed yet
|
||||
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
|
||||
|
||||
set(GARAGE_APP_NAME "" CACHE STRING "The apps name as people see it")
|
||||
set(GARAGE_APP_ID "" CACHE STRING "A stable id, e.g. net.imbenji.stash. Names the uninstall entry")
|
||||
set(GARAGE_PROJECT_ID "" CACHE STRING "The Garage project the releases are published on")
|
||||
set(GARAGE_EXE_NAME "" CACHE STRING "The apps exe inside a build, e.g. garage_stash.exe")
|
||||
set(GARAGE_API_BASE "https://pay.imbenji.net/api" CACHE STRING "Where the update check goes")
|
||||
set(GARAGE_PUBLISHER "" CACHE STRING "Shown in Installed apps. Optional")
|
||||
set(GARAGE_ICON "" CACHE FILEPATH "An .ico for the installer, the stub and the shortcuts. Optional")
|
||||
set(GARAGE_DEFAULT_LOCATION "me" CACHE STRING "me (LocalAppData) or everyone (Program Files)")
|
||||
option(GARAGE_SHOW_CHOICE "Ask just me / everyone. Off goes with the default without asking" ON)
|
||||
option(GARAGE_DESKTOP_SHORTCUT "A desktop shortcut as well as the start menu one" OFF)
|
||||
|
||||
foreach(_needed GARAGE_APP_NAME GARAGE_APP_ID GARAGE_PROJECT_ID GARAGE_EXE_NAME)
|
||||
if("${${_needed}}" STREQUAL "")
|
||||
message(FATAL_ERROR "${_needed} has to be set, e.g. -D${_needed}=...")
|
||||
endif()
|
||||
endforeach()
|
||||
if(NOT GARAGE_EXE_NAME MATCHES "\\.exe$")
|
||||
message(FATAL_ERROR "GARAGE_EXE_NAME is the file name with .exe on it, got \"${GARAGE_EXE_NAME}\"")
|
||||
endif()
|
||||
if(GARAGE_APP_ID MATCHES "[\\\\/:*?\"<>| ]")
|
||||
message(FATAL_ERROR "GARAGE_APP_ID ends up as a folder and a registry key, keep it to letters, digits, dots and dashes")
|
||||
endif()
|
||||
if(NOT GARAGE_DEFAULT_LOCATION MATCHES "^(me|everyone)$")
|
||||
message(FATAL_ERROR "GARAGE_DEFAULT_LOCATION is me or everyone, got \"${GARAGE_DEFAULT_LOCATION}\"")
|
||||
endif()
|
||||
if(GARAGE_ICON AND NOT EXISTS "${GARAGE_ICON}")
|
||||
message(FATAL_ERROR "GARAGE_ICON: theres no ${GARAGE_ICON}")
|
||||
endif()
|
||||
|
||||
|
||||
# these land inside L"..." in a header
|
||||
foreach(_text GARAGE_APP_NAME GARAGE_APP_ID GARAGE_PROJECT_ID GARAGE_EXE_NAME GARAGE_API_BASE GARAGE_PUBLISHER)
|
||||
string(REPLACE "\\" "\\\\" ${_text}_C "${${_text}}")
|
||||
string(REPLACE "\"" "\\\"" ${_text}_C "${${_text}_C}")
|
||||
endforeach()
|
||||
# no slash on the end, the code puts its own on
|
||||
string(REGEX REPLACE "/+$" "" GARAGE_API_BASE_C "${GARAGE_API_BASE_C}")
|
||||
|
||||
set(GARAGE_DEFAULT_EVERYONE_C 0)
|
||||
if(GARAGE_DEFAULT_LOCATION STREQUAL "everyone")
|
||||
set(GARAGE_DEFAULT_EVERYONE_C 1)
|
||||
endif()
|
||||
set(GARAGE_SHOW_CHOICE_C 0)
|
||||
if(GARAGE_SHOW_CHOICE)
|
||||
set(GARAGE_SHOW_CHOICE_C 1)
|
||||
endif()
|
||||
set(GARAGE_DESKTOP_SHORTCUT_C 0)
|
||||
if(GARAGE_DESKTOP_SHORTCUT)
|
||||
set(GARAGE_DESKTOP_SHORTCUT_C 1)
|
||||
endif()
|
||||
|
||||
set(_generated "${CMAKE_CURRENT_BINARY_DIR}/generated")
|
||||
configure_file("installer_config.h.in" "${_generated}/installer_config.h" @ONLY)
|
||||
|
||||
|
||||
# the stub is the plugins one, built here with this apps icon on it and put
|
||||
# somewhere the .rc can name
|
||||
set(_stub_dir "${CMAKE_CURRENT_SOURCE_DIR}/../windows/stub")
|
||||
set(GARAGE_STUB_ICON "${GARAGE_ICON}")
|
||||
set(GARAGE_STUB_OUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/stub_out")
|
||||
add_subdirectory("${_stub_dir}" "${CMAKE_CURRENT_BINARY_DIR}/stub")
|
||||
set(GARAGE_STUB_FILE "${GARAGE_STUB_OUT_DIR}/garage_stub.exe")
|
||||
|
||||
set(GARAGE_ICON_LINE "")
|
||||
if(GARAGE_ICON)
|
||||
file(TO_CMAKE_PATH "${GARAGE_ICON}" _icon)
|
||||
set(GARAGE_ICON_LINE "1 ICON \"${_icon}\"")
|
||||
endif()
|
||||
set(GARAGE_MANIFEST_FILE "${CMAKE_CURRENT_SOURCE_DIR}/installer.exe.manifest")
|
||||
configure_file("installer.rc.in" "${_generated}/installer.rc" @ONLY)
|
||||
|
||||
set(_sources "installer.cpp" "${_generated}/installer_config.h" "${_generated}/installer.rc")
|
||||
if(MSVC)
|
||||
list(APPEND _sources "installer.exe.manifest")
|
||||
endif()
|
||||
|
||||
add_executable(garage_installer WIN32 ${_sources})
|
||||
target_compile_features(garage_installer PRIVATE cxx_std_17)
|
||||
target_compile_definitions(garage_installer PRIVATE UNICODE _UNICODE)
|
||||
target_include_directories(garage_installer PRIVATE "${_generated}" "${_stub_dir}")
|
||||
if(MSVC)
|
||||
target_compile_options(garage_installer PRIVATE /W4 /EHsc /utf-8)
|
||||
else()
|
||||
# not msvc, so nothing merges the manifest for us. it goes in through the .rc
|
||||
set_property(SOURCE "${_generated}/installer.rc" APPEND PROPERTY COMPILE_DEFINITIONS GARAGE_RC_MANIFEST)
|
||||
endif()
|
||||
if(MINGW)
|
||||
target_link_options(garage_installer PRIVATE -municode "-Wl,--subsystem,windows")
|
||||
endif()
|
||||
target_link_libraries(garage_installer PRIVATE
|
||||
user32 shell32 advapi32 ole32 uuid comctl32 winhttp bcrypt)
|
||||
|
||||
# the .rc pulls the stub in as a file, which cmake cant see for itself
|
||||
add_dependencies(garage_installer garage_stub)
|
||||
set_property(SOURCE "${_generated}/installer.rc" APPEND PROPERTY OBJECT_DEPENDS "${GARAGE_STUB_FILE}")
|
||||
|
||||
# the name with whatever a file name cant have taken out
|
||||
string(REGEX REPLACE "[\\\\/:*?\"<>|]" "" _file_name "${GARAGE_APP_NAME}")
|
||||
set_target_properties(garage_installer PROPERTIES OUTPUT_NAME "${_file_name}-Setup")
|
||||
@@ -0,0 +1,82 @@
|
||||
@echo off
|
||||
setlocal
|
||||
|
||||
rem builds "<AppName>-Setup.exe" for one app. needs cmake and visual studio's
|
||||
rem c++ tools, the same things flutter build windows needs.
|
||||
rem
|
||||
rem build_installer.bat --name "Garage Stash" --id net.imbenji.stash ^
|
||||
rem --project <garage project id> --exe garage_stash.exe ^
|
||||
rem --icon C:\path\app_icon.ico
|
||||
rem
|
||||
rem optional:
|
||||
rem --api <url> where the update check goes (default pay.imbenji.net/api)
|
||||
rem --publisher "<name>" shown in Installed apps
|
||||
rem --default me^|everyone which one is ticked to begin with (default me)
|
||||
rem --hide-choice dont ask, go with the default
|
||||
rem --desktop a desktop shortcut as well
|
||||
rem --arch x64^|arm64 default x64
|
||||
rem --out <folder> where the exe is put (default: the folder youre in)
|
||||
|
||||
set "HERE=%~dp0"
|
||||
set "NAME="
|
||||
set "ID="
|
||||
set "PROJECT="
|
||||
set "EXE="
|
||||
set "ICON="
|
||||
set "API=https://pay.imbenji.net/api"
|
||||
set "PUBLISHER="
|
||||
set "LOCATION=me"
|
||||
set "CHOICE=ON"
|
||||
set "DESKTOP=OFF"
|
||||
set "ARCH=x64"
|
||||
set "OUT=%CD%"
|
||||
|
||||
:args
|
||||
if "%~1"=="" goto run
|
||||
if /i "%~1"=="--name" ( set "NAME=%~2" & shift & shift & goto args )
|
||||
if /i "%~1"=="--id" ( set "ID=%~2" & shift & shift & goto args )
|
||||
if /i "%~1"=="--project" ( set "PROJECT=%~2" & shift & shift & goto args )
|
||||
if /i "%~1"=="--exe" ( set "EXE=%~2" & shift & shift & goto args )
|
||||
if /i "%~1"=="--icon" ( set "ICON=%~f2" & shift & shift & goto args )
|
||||
if /i "%~1"=="--api" ( set "API=%~2" & shift & shift & goto args )
|
||||
if /i "%~1"=="--publisher" ( set "PUBLISHER=%~2" & shift & shift & goto args )
|
||||
if /i "%~1"=="--default" ( set "LOCATION=%~2" & shift & shift & goto args )
|
||||
if /i "%~1"=="--arch" ( set "ARCH=%~2" & shift & shift & goto args )
|
||||
if /i "%~1"=="--out" ( set "OUT=%~f2" & shift & shift & goto args )
|
||||
if /i "%~1"=="--hide-choice" ( set "CHOICE=OFF" & shift & goto args )
|
||||
if /i "%~1"=="--desktop" ( set "DESKTOP=ON" & shift & goto args )
|
||||
echo build_installer: dont know what "%~1" is
|
||||
exit /b 2
|
||||
|
||||
:run
|
||||
if "%NAME%"=="" ( echo build_installer: --name is needed & exit /b 2 )
|
||||
if "%ID%"=="" ( echo build_installer: --id is needed & exit /b 2 )
|
||||
if "%PROJECT%"=="" ( echo build_installer: --project is needed & exit /b 2 )
|
||||
if "%EXE%"=="" ( echo build_installer: --exe is needed & exit /b 2 )
|
||||
|
||||
set "VSARCH=x64"
|
||||
if /i "%ARCH%"=="arm64" set "VSARCH=ARM64"
|
||||
|
||||
rem one build folder per app and arch, so two apps dont share a cache
|
||||
set "BUILD=%HERE%build\%ID%-%ARCH%"
|
||||
|
||||
rem cmake wants forward slashes in a path it is going to paste in to an .rc
|
||||
if defined ICON set "ICON=%ICON:\=/%"
|
||||
|
||||
cmake -S "%HERE%." -B "%BUILD%" -A %VSARCH% ^
|
||||
"-DGARAGE_APP_NAME=%NAME%" "-DGARAGE_APP_ID=%ID%" "-DGARAGE_PROJECT_ID=%PROJECT%" ^
|
||||
"-DGARAGE_EXE_NAME=%EXE%" "-DGARAGE_API_BASE=%API%" "-DGARAGE_PUBLISHER=%PUBLISHER%" ^
|
||||
"-DGARAGE_ICON=%ICON%" "-DGARAGE_DEFAULT_LOCATION=%LOCATION%" ^
|
||||
-DGARAGE_SHOW_CHOICE=%CHOICE% -DGARAGE_DESKTOP_SHORTCUT=%DESKTOP%
|
||||
if errorlevel 1 ( echo build_installer: cmake couldnt set the build up & exit /b 1 )
|
||||
|
||||
cmake --build "%BUILD%" --config Release
|
||||
if errorlevel 1 ( echo build_installer: the build failed & exit /b 1 )
|
||||
|
||||
if not exist "%OUT%" mkdir "%OUT%"
|
||||
copy /y "%BUILD%\Release\*-Setup.exe" "%OUT%\" >nul
|
||||
if errorlevel 1 ( echo build_installer: built, but couldnt copy the exe out of %BUILD%\Release & exit /b 1 )
|
||||
|
||||
echo.
|
||||
echo the installer is in %OUT%
|
||||
endlocal
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
|
||||
<!-- asInvoker on purpose. "just me" never needs admin, and "everyone" asks for it itself -->
|
||||
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
|
||||
<security>
|
||||
<requestedPrivileges>
|
||||
<requestedExecutionLevel level="asInvoker" uiAccess="false"/>
|
||||
</requestedPrivileges>
|
||||
</security>
|
||||
</trustInfo>
|
||||
<!-- the task dialog only exists in version 6 of the common controls -->
|
||||
<dependency>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0"
|
||||
processorArchitecture="*" publicKeyToken="6595b64144ccf1df" language="*"/>
|
||||
</dependentAssembly>
|
||||
</dependency>
|
||||
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
|
||||
<application>
|
||||
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
|
||||
</application>
|
||||
</compatibility>
|
||||
<application xmlns="urn:schemas-microsoft-com:asm.v3">
|
||||
<windowsSettings>
|
||||
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
|
||||
<longPathAware xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">true</longPathAware>
|
||||
</windowsSettings>
|
||||
</application>
|
||||
</assembly>
|
||||
@@ -0,0 +1,12 @@
|
||||
// made by cmake. the icon, the stub and (not for msvc) the manifest
|
||||
#pragma code_page(65001)
|
||||
|
||||
@GARAGE_ICON_LINE@
|
||||
|
||||
// the stub, whole. its written out as <root>\<AppExe>.exe
|
||||
STUB RCDATA "@GARAGE_STUB_FILE@"
|
||||
|
||||
// msvc gets the manifest handed to the linker instead, two of them collide
|
||||
#ifdef GARAGE_RC_MANIFEST
|
||||
1 24 "@GARAGE_MANIFEST_FILE@"
|
||||
#endif
|
||||
@@ -0,0 +1,24 @@
|
||||
// made by cmake from the values the installer was built with. dont edit the
|
||||
// copy in the build folder, it gets written over.
|
||||
#pragma once
|
||||
|
||||
// what people see: the window, the shortcut, the folder, "installed apps"
|
||||
#define GARAGE_APP_NAME L"@GARAGE_APP_NAME_C@"
|
||||
|
||||
// the key of the uninstall entry, and the folder under %LOCALAPPDATA% that
|
||||
// downloads go to when the install itself is read only
|
||||
#define GARAGE_APP_ID L"@GARAGE_APP_ID_C@"
|
||||
|
||||
#define GARAGE_PROJECT_ID L"@GARAGE_PROJECT_ID_C@"
|
||||
#define GARAGE_API_BASE L"@GARAGE_API_BASE_C@"
|
||||
|
||||
// the apps exe inside a build. the stub goes in root under the same name
|
||||
#define GARAGE_EXE_NAME L"@GARAGE_EXE_NAME_C@"
|
||||
|
||||
#define GARAGE_PUBLISHER L"@GARAGE_PUBLISHER_C@"
|
||||
|
||||
// 1 is "everyone on this pc" (program files), 0 is "just me"
|
||||
#define GARAGE_DEFAULT_EVERYONE @GARAGE_DEFAULT_EVERYONE_C@
|
||||
// 0 never asks and goes with the default
|
||||
#define GARAGE_SHOW_CHOICE @GARAGE_SHOW_CHOICE_C@
|
||||
#define GARAGE_DESKTOP_SHORTCUT @GARAGE_DESKTOP_SHORTCUT_C@
|
||||
Reference in New Issue
Block a user