Skip to content

Commit 76d8833

Browse files
authored
Add option for portable binary (using flameshot.ini in app folder) (flameshot-org#4531)
* Option to build a portable binary, which is using flameshot.ini in application folder. * Align Qt version * Fix appveyor * Fix appveyor * Fix appveyor
1 parent 42c462b commit 76d8833

File tree

5 files changed

+31
-48
lines changed

5 files changed

+31
-48
lines changed

.github/workflows/Windows-pack.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
strategy:
3737
fail-fast: false
3838
matrix:
39-
qt_ver: [6.9.1]
39+
qt_ver: [6.9.3]
4040
qt_target: [desktop]
4141
config:
4242
- {
@@ -119,7 +119,7 @@ jobs:
119119
-DCMAKE_TOOLCHAIN_FILE="${{ github.workspace }}\vcpkg\scripts\buildsystems\vcpkg.cmake" `
120120
-DENABLE_OPENSSL=ON `
121121
-DCMAKE_BUILD_TYPE=Release `
122-
-DRUN_IN_PLACE=${{ contains(matrix.type, 'portable') }}
122+
-DUSE_PORTABLE_CONFIG=${{ contains(matrix.type, 'portable') }}
123123
124124
- name: Compile
125125
working-directory: build

.github/workflows/build_cmake.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ jobs:
9696
os: windows-2022,
9797
cc: "cl", cxx: "cl",
9898
environment_script: "C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Auxiliary/Build/vcvars64.bat",
99-
qt_ver: '6.9.1'
99+
qt_ver: '6.9.3'
100100
}
101101

102102
steps:

CMakeLists.txt

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ endif()
5353

5454

5555
# Configuration options
56-
set(DEFAULT_RUN_IN_PLACE FALSE)
56+
set(DEFAULT_USE_PORTABLE_CONFIG FALSE)
5757
if(WIN32)
58-
set(DEFAULT_RUN_IN_PLACE TRUE)
58+
set(DEFAULT_USE_PORTABLE_CONFIG TRUE)
5959
# For Windows RC file.
6060
add_definitions(-DFLAMESHOT_VERSION_MAJOR=${CMAKE_PROJECT_VERSION_MAJOR})
6161
add_definitions(-DFLAMESHOT_VERSION_MINOR=${CMAKE_PROJECT_VERSION_MINOR})
@@ -65,10 +65,12 @@ if(WIN32)
6565
elseif(APPLE)
6666
set(Qt6_DIR "$(brew --prefix qt6)/lib/cmake/Qt6/" CACHE PATH "directory where Qt6Config.cmake exists.")
6767
endif()
68-
set(RUN_IN_PLACE
69-
${DEFAULT_RUN_IN_PLACE}
70-
CACHE BOOL "Run directly in source directory structure")
71-
68+
set(USE_PORTABLE_CONFIG
69+
${DEFAULT_USE_PORTABLE_CONFIG}
70+
CACHE BOOL "Store config in application folder")
71+
if(USE_PORTABLE_CONFIG)
72+
add_compile_definitions(USE_PORTABLE_CONFIG)
73+
endif()
7274

7375
option(FLAMESHOT_DEBUG_CAPTURE "Enable mode to make debugging easier" OFF)
7476
option(USE_MONOCHROME_ICON "Build using monochrome icon as default" OFF)
@@ -158,13 +160,8 @@ if(WIN32)
158160
# Include all dynamically linked runtime libraries such as MSVCRxxx.dll
159161
include(InstallRequiredSystemLibraries)
160162

161-
if(RUN_IN_PLACE)
162-
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
163-
set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}-win64")
164-
else()
165-
set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}-win32")
166-
endif()
167-
163+
if(USE_PORTABLE_CONFIG)
164+
set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}-win64")
168165
set(CPACK_GENERATOR ZIP)
169166

170167
else()
@@ -189,13 +186,7 @@ if(WIN32)
189186
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/packaging/win-installer/LICENSE/GPL-3.0.txt")
190187
set(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/README.md")
191188

192-
# The correct way would be to include both x32 and x64 into one installer and install the appropriate one. CMake
193-
# does not support that, so there are two separate GUID's
194-
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
195-
set(CPACK_WIX_UPGRADE_GUID "26D8062A-66D9-48D9-8924-42090FB9B3F9")
196-
else()
197-
set(CPACK_WIX_UPGRADE_GUID "2C53E1B9-51D9-4429-AAE4-B02221959AA5")
198-
endif()
189+
set(CPACK_WIX_UPGRADE_GUID "26D8062A-66D9-48D9-8924-42090FB9B3F9")
199190
endif()
200191
elseif(APPLE)
201192
set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY 0)

appveyor.yml

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,28 @@ image:
33
clone_folder: c:\projects\source
44

55
environment:
6-
Qt6_INSTALL_DIR: 'C:\Qt\6.9\msvc2022_64'
6+
Qt6_INSTALL_DIR: 'C:\Qt\6.9.3\msvc2022_64'
77
PATH: '%Qt6_INSTALL_DIR%\bin;%PATH%'
8+
matrix:
9+
- PORTABLE_CONFIG: OFF
10+
- PORTABLE_CONFIG: ON
811

912
build_script:
10-
- cmd: >-
11-
13+
- cmd: |-
1214
set QTDIR=%Qt6_INSTALL_DIR%
13-
1415
set "VCINSTALLDIR=C:\Program Files (x86)\Microsoft Visual Studio\2022\Community\VC"
15-
1616
set "OPENSSL_ROOT_DIR=C:/OpenSSL-v111-Win64"
17-
18-
cmake -S c:\projects\source -B build -G "Visual Studio 17 2022" -DCMAKE_BUILD_TYPE:STRING=Release -DENABLE_OPENSSL=ON -DRUN_IN_PLACE=OFF
19-
20-
cmake --build build --parallel 2 --config "Release"
21-
22-
cd build
23-
24-
cpack -G WIX -B package
25-
26-
mkdir artifact
27-
28-
cp package/*.msi artifact/.
29-
30-
cp src/Release/*.exe artifact/.
31-
32-
7z a -tzip artifact.zip artifact/
17+
cmake -S C:\projects\source -B build -G "Visual Studio 17 2022" -DCMAKE_BUILD_TYPE=Release -DENABLE_OPENSSL=ON -DUSE_PORTABLE_CONFIG=%PORTABLE_CONFIG%
18+
cmake --build build --parallel 2 --config Release
19+
- cmd: cd build
20+
- cmd: if "%PORTABLE_CONFIG%"=="OFF" cpack -G WIX -B package
21+
- cmd: if "%PORTABLE_CONFIG%"=="ON" (mkdir portable_exe & copy src\Release\*.exe portable_exe\. & 7z a -tzip portable_exe.zip portable_exe\)
3322

3423
artifacts:
3524
- path: build\package\*.msi
3625
name: installer
37-
- path: build\src\Release\*.exe
38-
name: executable
39-
- path: build\artifact.zip
40-
name: archive
26+
- path: build\portable_exe.zip
27+
name: portable exe
4128

4229
deploy:
4330
- provider: Webhook

src/utils/confighandler.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,15 @@ static QMap<QString, QSharedPointer<KeySequence>> recognizedShortcuts = {
197197
// CLASS CONFIGHANDLER
198198

199199
ConfigHandler::ConfigHandler()
200+
#ifndef USE_PORTABLE_CONFIG
200201
: m_settings(QSettings::IniFormat,
201202
QSettings::UserScope,
202203
qApp->organizationName(),
203204
qApp->applicationName())
205+
#else
206+
: m_settings(qApp->applicationDirPath() + "/flameshot.ini",
207+
QSettings::IniFormat)
208+
#endif
204209
{
205210
static bool firstInitialization = true;
206211
if (firstInitialization) {

0 commit comments

Comments
 (0)