Skip to content

Commit 871ce23

Browse files
committed
windows installer:
- also install settings to correct location, don't override old ones - refactor the directoyr finding in installer builds
1 parent ab6c56e commit 871ce23

File tree

7 files changed

+44
-29
lines changed

7 files changed

+44
-29
lines changed

meson.build

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ project(
1414
version: '0.5.5',
1515
)
1616

17+
oopetris_author = 'Coder2k'
18+
oopetris_name = 'OOPetris'
19+
1720
subdir('tools/options')
1821

1922
subdir('tools/dependencies')
@@ -90,6 +93,8 @@ else
9093
command: [
9194
makensis,
9295
'-DVERSION=' + meson.project_version(),
96+
'-DNAME=' + oopetris_name,
97+
'-DAUTHOR=' + oopetris_author,
9398
'-DPROJECT_SOURCE_DIR=' + meson.project_source_root(),
9499
'-DPROJECT_BUILD_DIR=' + meson.project_build_root(),
95100
nsis_script,

platforms/windows/meson.build

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ patch_version = version_arr[2].to_int()
88
rc_conf = configuration_data(
99
{
1010
'OOPETRIS_VERSION': meson.project_version(),
11+
'OOPETRIS_NAME': oopetris_name,
12+
'OOPETRIS_AUTHOR': oopetris_author,
1113
'OOPETRIS_MAJOR_VERSION': major_version,
1214
'OOPETRIS_MINOR_VERSION': minor_version,
1315
'OOPETRIS_PATCH_VERSION': patch_version,
14-
'PROJECT_SOURCE_DIR': meson.project_source_root().replace('\\','/'),
16+
'PROJECT_SOURCE_DIR': meson.project_source_root().replace('\\', '/'),
1517
},
1618
)
1719

platforms/windows/oopetris.rc.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ VS_VERSION_INFO VERSIONINFO
99
BEGIN
1010
BLOCK "040904B0"
1111
BEGIN
12-
VALUE "FileDescription", "OOpetris"
12+
VALUE "FileDescription", "@OOPETRIS_NAME@"
1313
VALUE "FileVersion", "@[email protected]"
14-
VALUE "ProductName", "OOpetris"
14+
VALUE "ProductName", "@OOPETRIS_NAME@"
1515
VALUE "ProductVersion", "@OOPETRIS_VERSION@"
1616
END
1717
END

src/helper/constants.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ namespace constants {
77
#define STRINGIFY(a) STRINGIFY_HELPER_(a) //NOLINT(cppcoreguidelines-macro-usage)
88
#define STRINGIFY_HELPER_(a) #a //NOLINT(cppcoreguidelines-macro-usage)
99

10-
#if !defined(OOPETRIS_VERSION)
11-
#define OOPETRIS_VERSION "Unknown"
10+
#if !defined(OOPETRIS_NAME) || !defined(OOPETRIS_AUTHOR) || !defined(OOPETRIS_VERSION)
11+
#error "not all needed OOPETRIS_* macros defined"
1212
#endif
1313

1414

15-
constexpr auto program_name = StaticString{ "oopetris" };
16-
constexpr auto author = StaticString{ "coder2k" };
15+
constexpr auto program_name = StaticString{ STRINGIFY(OOPETRIS_NAME) };
16+
constexpr auto author = StaticString{ STRINGIFY(OOPETRIS_AUTHOR) };
1717
constexpr auto version = StaticString{ STRINGIFY(OOPETRIS_VERSION) };
1818
constexpr auto music_change_level = 30;
1919
constexpr auto recordings_directory = "recordings";

src/helper/graphic_utils.cpp

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ std::vector<std::string> utils::supported_features() {
3737
}
3838
return std::filesystem::path{ std::string{ pref_path } };
3939
#elif defined(__CONSOLE__)
40-
// this is in the sdcard of the switch, since internal storage is read-only for applications!
40+
// this is in the sdcard of the switch / 3ds , since internal storage is read-only for applications!
4141
return std::filesystem::path{ "." };
4242
#elif defined(BUILD_INSTALLER)
4343
#if defined(FLATPAK_BUILD)
@@ -48,13 +48,14 @@ std::vector<std::string> utils::supported_features() {
4848
}
4949

5050
return std::filesystem::path{ data_home };
51-
#else
52-
// this call also creates the dir (at least tries to) it returns
51+
#elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
5352
char* pref_path = SDL_GetPrefPath(constants::author, constants::program_name);
5453
if (!pref_path) {
5554
throw std::runtime_error{ "Failed in getting the Pref Path: " + std::string{ SDL_GetError() } };
5655
}
57-
return std::filesystem::path{ std::string{ pref_path } };
56+
return std::filesystem::path{ pref_path };
57+
#else
58+
#error "unrecognized installer build"
5859
#endif
5960
#else
6061
// this is only used in local build for debugging, when compiling in release mode the path is real path where the app can store many things without interfering with other things (eg. AppData\Roaming\... on Windows or .local/share/... on Linux )
@@ -72,24 +73,18 @@ std::vector<std::string> utils::supported_features() {
7273
// this is in the internal storage of the nintendo switch, it ios mounted by libnx (runtime switch support library) and filled at compile time with assets (its called ROMFS there)
7374
return std::filesystem::path{ "romfs:/assets" };
7475
#elif defined(BUILD_INSTALLER)
75-
76-
#if defined(FLATPAK_BUILD)
7776
// if you build in BUILD_INSTALLER mode, you have to assure that the data is there e.g. music + fonts!
78-
const char* resource_path = "/app/share/oopetris/";
77+
#if defined(FLATPAK_BUILD)
78+
return std::filesystem::path{ "/app/share/oopetris/assets/" };
7979
#elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
8080
char* resource_path = SDL_GetBasePath();
8181
if (!resource_path) {
8282
throw std::runtime_error{ "Failed in getting the Base Path: " + std::string{ SDL_GetError() } };
8383
}
84-
84+
return std::filesystem::path{ resource_path } / "assets";
8585
#else
86-
char* resource_path = SDL_GetPrefPath(constants::author, constants::program_name);
87-
if (!resource_path) {
88-
throw std::runtime_error{ "Failed in getting the Pref Path: " + std::string{ SDL_GetError() } };
89-
}
90-
86+
#error "unrecognized installer build"
9187
#endif
92-
return std::filesystem::path{ std::string{ resource_path } } / "assets";
9388
#else
9489
return std::filesystem::path{ "assets" };
9590
#endif

tools/installer/setup.nsi

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,16 @@
1717
!error "PROJECT_BUILD_DIR not specified"
1818
!endif
1919

20+
!ifndef NAME
21+
!error "NAME not specified"
22+
!endif
23+
24+
!ifndef AUTHOR
25+
!error "AUTHOR not specified"
26+
!endif
2027

2128
;--------------------------------
2229
; Custom defines
23-
!define NAME "OOPetris"
2430
!define APPFILE "oopetris.exe"
2531
!define APP_UNINSTALLER_FILE "Uninstall.exe"
2632
!define SLUG "${NAME} v${VERSION}"
@@ -87,6 +93,11 @@ Section "Core App" CoreApp
8793
SetOutPath "$INSTDIR"
8894
File /a "${PROJECT_SOURCE_DIR}\subprojects\discord_game_sdk-3.2.1\lib\x86_64\discord_game_sdk.dll"
8995

96+
; install default settings (DO NOT Override)
97+
SetOutPath "$APPDATA\${AUTHOR}\${NAME}"
98+
SetOverwrite off
99+
File "${PROJECT_SOURCE_DIR}\settings.json"
100+
SetOverwrite on
90101

91102
WriteRegStr HKCU "Software\${NAME}" "InstallDir" $INSTDIR
92103
WriteUninstaller "$INSTDIR\${APP_UNINSTALLER_FILE}"
@@ -172,6 +183,8 @@ Section "Uninstall"
172183
RMDir /r "$INSTDIR"
173184
${RMDirUP} "$INSTDIR"
174185

186+
; note settings are NOT removed!
187+
175188
; delete start menu entry
176189
Delete '$SMPROGRAMS\${NAME}\${NAME}.lnk'
177190
Delete '$SMPROGRAMS\${NAME}\Uninstall ${NAME}.lnk'
@@ -191,4 +204,4 @@ Section "Uninstall"
191204

192205
; delete the whole reg key
193206
DeleteRegKey HKCU "Software\${NAME}"
194-
SectionEnd
207+
SectionEnd

tools/options/meson.build

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
21
core_lib = {
32
'src_files': [],
43
'inc_dirs': [],
5-
'compile_args': ['-DOOPETRIS_VERSION=' + meson.project_version()],
4+
'compile_args': [
5+
'-DOOPETRIS_VERSION=' + meson.project_version(),
6+
'-DOOPETRIS_NAME=' + oopetris_name,
7+
'-DOOPETRIS_AUTHOR=' + oopetris_author,
8+
],
69
'deps': [],
710
}
811

@@ -23,7 +26,6 @@ graphics_lib = {
2326
global_deps = []
2427
graphic_application_deps = []
2528

26-
2729
cpp = meson.get_compiler('cpp')
2830

2931
build_with_libcpp = false
@@ -64,10 +66,8 @@ if (
6466
get_option('buildtype') == 'debug'
6567
or get_option('buildtype') == 'debugoptimized'
6668
)
67-
#TODO: replace with ! NDEBUG in cpp files and remove this
69+
#TODO: replace with ! NDEBUG in cpp files and remove this
6870
core_lib += {
6971
'compile_args': [core_lib.get('compile_args'), '-DDEBUG_BUILD'],
7072
}
7173
endif
72-
73-

0 commit comments

Comments
 (0)