From 76d883362fa1872f3e0aa31c179c98ebbd0effff Mon Sep 17 00:00:00 2001 From: El Thoro Date: Tue, 24 Feb 2026 13:46:32 +0100 Subject: [PATCH] Add option for portable binary (using flameshot.ini in app folder) (#4531) * Option to build a portable binary, which is using flameshot.ini in application folder. * Align Qt version * Fix appveyor * Fix appveyor * Fix appveyor --- .github/workflows/Windows-pack.yml | 4 ++-- .github/workflows/build_cmake.yml | 2 +- CMakeLists.txt | 31 +++++++++---------------- appveyor.yml | 37 ++++++++++-------------------- src/utils/confighandler.cpp | 5 ++++ 5 files changed, 31 insertions(+), 48 deletions(-) diff --git a/.github/workflows/Windows-pack.yml b/.github/workflows/Windows-pack.yml index 0c68cf2307..3ca1f943e8 100644 --- a/.github/workflows/Windows-pack.yml +++ b/.github/workflows/Windows-pack.yml @@ -36,7 +36,7 @@ jobs: strategy: fail-fast: false matrix: - qt_ver: [6.9.1] + qt_ver: [6.9.3] qt_target: [desktop] config: - { @@ -119,7 +119,7 @@ jobs: -DCMAKE_TOOLCHAIN_FILE="${{ github.workspace }}\vcpkg\scripts\buildsystems\vcpkg.cmake" ` -DENABLE_OPENSSL=ON ` -DCMAKE_BUILD_TYPE=Release ` - -DRUN_IN_PLACE=${{ contains(matrix.type, 'portable') }} + -DUSE_PORTABLE_CONFIG=${{ contains(matrix.type, 'portable') }} - name: Compile working-directory: build diff --git a/.github/workflows/build_cmake.yml b/.github/workflows/build_cmake.yml index 4a03b05141..48b97dec90 100644 --- a/.github/workflows/build_cmake.yml +++ b/.github/workflows/build_cmake.yml @@ -96,7 +96,7 @@ jobs: os: windows-2022, cc: "cl", cxx: "cl", environment_script: "C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Auxiliary/Build/vcvars64.bat", - qt_ver: '6.9.1' + qt_ver: '6.9.3' } steps: diff --git a/CMakeLists.txt b/CMakeLists.txt index f555879da3..2678f1e56d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,9 +53,9 @@ endif() # Configuration options -set(DEFAULT_RUN_IN_PLACE FALSE) +set(DEFAULT_USE_PORTABLE_CONFIG FALSE) if(WIN32) - set(DEFAULT_RUN_IN_PLACE TRUE) + set(DEFAULT_USE_PORTABLE_CONFIG TRUE) # For Windows RC file. add_definitions(-DFLAMESHOT_VERSION_MAJOR=${CMAKE_PROJECT_VERSION_MAJOR}) add_definitions(-DFLAMESHOT_VERSION_MINOR=${CMAKE_PROJECT_VERSION_MINOR}) @@ -65,10 +65,12 @@ if(WIN32) elseif(APPLE) set(Qt6_DIR "$(brew --prefix qt6)/lib/cmake/Qt6/" CACHE PATH "directory where Qt6Config.cmake exists.") endif() -set(RUN_IN_PLACE - ${DEFAULT_RUN_IN_PLACE} - CACHE BOOL "Run directly in source directory structure") - +set(USE_PORTABLE_CONFIG + ${DEFAULT_USE_PORTABLE_CONFIG} + CACHE BOOL "Store config in application folder") +if(USE_PORTABLE_CONFIG) +add_compile_definitions(USE_PORTABLE_CONFIG) +endif() option(FLAMESHOT_DEBUG_CAPTURE "Enable mode to make debugging easier" OFF) option(USE_MONOCHROME_ICON "Build using monochrome icon as default" OFF) @@ -158,13 +160,8 @@ if(WIN32) # Include all dynamically linked runtime libraries such as MSVCRxxx.dll include(InstallRequiredSystemLibraries) - if(RUN_IN_PLACE) - if(CMAKE_SIZEOF_VOID_P EQUAL 8) - set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}-win64") - else() - set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}-win32") - endif() - + if(USE_PORTABLE_CONFIG) + set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}-win64") set(CPACK_GENERATOR ZIP) else() @@ -189,13 +186,7 @@ if(WIN32) set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/packaging/win-installer/LICENSE/GPL-3.0.txt") set(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/README.md") - # The correct way would be to include both x32 and x64 into one installer and install the appropriate one. CMake - # does not support that, so there are two separate GUID's - if(CMAKE_SIZEOF_VOID_P EQUAL 8) - set(CPACK_WIX_UPGRADE_GUID "26D8062A-66D9-48D9-8924-42090FB9B3F9") - else() - set(CPACK_WIX_UPGRADE_GUID "2C53E1B9-51D9-4429-AAE4-B02221959AA5") - endif() + set(CPACK_WIX_UPGRADE_GUID "26D8062A-66D9-48D9-8924-42090FB9B3F9") endif() elseif(APPLE) set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY 0) diff --git a/appveyor.yml b/appveyor.yml index 83661e966e..0106d2889e 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -3,41 +3,28 @@ image: clone_folder: c:\projects\source environment: - Qt6_INSTALL_DIR: 'C:\Qt\6.9\msvc2022_64' + Qt6_INSTALL_DIR: 'C:\Qt\6.9.3\msvc2022_64' PATH: '%Qt6_INSTALL_DIR%\bin;%PATH%' + matrix: + - PORTABLE_CONFIG: OFF + - PORTABLE_CONFIG: ON build_script: -- cmd: >- - +- cmd: |- set QTDIR=%Qt6_INSTALL_DIR% - set "VCINSTALLDIR=C:\Program Files (x86)\Microsoft Visual Studio\2022\Community\VC" - set "OPENSSL_ROOT_DIR=C:/OpenSSL-v111-Win64" - - cmake -S c:\projects\source -B build -G "Visual Studio 17 2022" -DCMAKE_BUILD_TYPE:STRING=Release -DENABLE_OPENSSL=ON -DRUN_IN_PLACE=OFF - - cmake --build build --parallel 2 --config "Release" - - cd build - - cpack -G WIX -B package - - mkdir artifact - - cp package/*.msi artifact/. - - cp src/Release/*.exe artifact/. - - 7z a -tzip artifact.zip artifact/ + cmake -S C:\projects\source -B build -G "Visual Studio 17 2022" -DCMAKE_BUILD_TYPE=Release -DENABLE_OPENSSL=ON -DUSE_PORTABLE_CONFIG=%PORTABLE_CONFIG% + cmake --build build --parallel 2 --config Release +- cmd: cd build +- cmd: if "%PORTABLE_CONFIG%"=="OFF" cpack -G WIX -B package +- cmd: if "%PORTABLE_CONFIG%"=="ON" (mkdir portable_exe & copy src\Release\*.exe portable_exe\. & 7z a -tzip portable_exe.zip portable_exe\) artifacts: - path: build\package\*.msi name: installer -- path: build\src\Release\*.exe - name: executable -- path: build\artifact.zip - name: archive +- path: build\portable_exe.zip + name: portable exe deploy: - provider: Webhook diff --git a/src/utils/confighandler.cpp b/src/utils/confighandler.cpp index b3ef56a2d0..3569735f6e 100644 --- a/src/utils/confighandler.cpp +++ b/src/utils/confighandler.cpp @@ -197,10 +197,15 @@ static QMap> recognizedShortcuts = { // CLASS CONFIGHANDLER ConfigHandler::ConfigHandler() +#ifndef USE_PORTABLE_CONFIG : m_settings(QSettings::IniFormat, QSettings::UserScope, qApp->organizationName(), qApp->applicationName()) +#else + : m_settings(qApp->applicationDirPath() + "/flameshot.ini", + QSettings::IniFormat) +#endif { static bool firstInitialization = true; if (firstInitialization) {