Skip to content

Commit 85abc83

Browse files
committed
refactor(CMake): Use cmake_host_system_information with VIEW 32_64 for registry queries
1 parent d81e743 commit 85abc83

File tree

2 files changed

+64
-25
lines changed

2 files changed

+64
-25
lines changed

Generals/CMakeLists.txt

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,47 @@ add_subdirectory(Code)
1515

1616
# If we are building on windows for windows, try and get the game install path from the registry.
1717
if("${CMAKE_HOST_SYSTEM}" MATCHES "Windows" AND "${CMAKE_SYSTEM}" MATCHES "Windows")
18-
# Check the CD registry path
18+
# Check the EA App/CD registry path (checks both 32-bit and 64-bit registry views)
1919
if(NOT RTS_INSTALL_PREFIX_GENERALS)
20-
get_filename_component(RTS_INSTALL_PREFIX_GENERALS "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Electronic Arts\\EA Games\\Generals;InstallPath]" ABSOLUTE CACHE)
21-
endif()
22-
23-
# Check the WOW6432Node registry path (for EA App on 64-bit Windows)
24-
if(NOT RTS_INSTALL_PREFIX_GENERALS OR "${RTS_INSTALL_PREFIX_GENERALS}" STREQUAL "/registry")
25-
get_filename_component(RTS_INSTALL_PREFIX_GENERALS "[HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\Electronic Arts\\EA Games\\Generals;InstallPath]" ABSOLUTE CACHE)
20+
cmake_host_system_information(RESULT _generals_path
21+
QUERY WINDOWS_REGISTRY
22+
"HKEY_LOCAL_MACHINE/SOFTWARE/Electronic Arts/EA Games/Generals"
23+
VALUE InstallPath
24+
VIEW 32_64
25+
ERROR_VARIABLE _reg_error)
26+
if(NOT _reg_error AND _generals_path)
27+
set(RTS_INSTALL_PREFIX_GENERALS "${_generals_path}" CACHE PATH "Generals install path from registry")
28+
endif()
2629
endif()
2730

2831
# Check the "First Decade" registry path
29-
if(NOT RTS_INSTALL_PREFIX_GENERALS OR "${RTS_INSTALL_PREFIX_GENERALS}" STREQUAL "/registry")
30-
get_filename_component(RTS_INSTALL_PREFIX_GENERALS "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Electronic Arts\\EA Games\\Command and Conquer The First Decade;gr_folder]" ABSOLUTE CACHE)
32+
if(NOT RTS_INSTALL_PREFIX_GENERALS)
33+
cmake_host_system_information(RESULT _generals_path
34+
QUERY WINDOWS_REGISTRY
35+
"HKEY_LOCAL_MACHINE/SOFTWARE/Electronic Arts/EA Games/Command and Conquer The First Decade"
36+
VALUE gr_folder
37+
VIEW 32_64
38+
ERROR_VARIABLE _reg_error)
39+
if(NOT _reg_error AND _generals_path)
40+
set(RTS_INSTALL_PREFIX_GENERALS "${_generals_path}" CACHE PATH "Generals install path from registry")
41+
endif()
3142
endif()
3243

33-
# Check the Steam registry path
34-
if(NOT RTS_INSTALL_PREFIX_GENERALS OR "${RTS_INSTALL_PREFIX_GENERALS}" STREQUAL "/registry")
35-
get_filename_component(RTS_INSTALL_PREFIX_GENERALS "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Electronic Arts\\EA Games\\Generals;installPath]" ABSOLUTE CACHE)
44+
# Check alternate capitalization (installPath vs InstallPath)
45+
if(NOT RTS_INSTALL_PREFIX_GENERALS)
46+
cmake_host_system_information(RESULT _generals_path
47+
QUERY WINDOWS_REGISTRY
48+
"HKEY_LOCAL_MACHINE/SOFTWARE/Electronic Arts/EA Games/Generals"
49+
VALUE installPath
50+
VIEW 32_64
51+
ERROR_VARIABLE _reg_error)
52+
if(NOT _reg_error AND _generals_path)
53+
set(RTS_INSTALL_PREFIX_GENERALS "${_generals_path}" CACHE PATH "Generals install path from registry")
54+
endif()
3655
endif()
3756
endif()
3857

39-
if(RTS_INSTALL_PREFIX_GENERALS AND NOT "${RTS_INSTALL_PREFIX_GENERALS}" STREQUAL "/registry")
58+
if(RTS_INSTALL_PREFIX_GENERALS)
4059
install(TARGETS g_generals RUNTIME DESTINATION "${RTS_INSTALL_PREFIX_GENERALS}")
4160
install(FILES $<TARGET_PDB_FILE:g_generals> DESTINATION "${RTS_INSTALL_PREFIX_GENERALS}" OPTIONAL)
4261

GeneralsMD/CMakeLists.txt

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,47 @@ add_subdirectory(Code)
1515

1616
# If we are building on windows for windows, try and get the game install path from the registry.
1717
if("${CMAKE_HOST_SYSTEM}" MATCHES "Windows" AND "${CMAKE_SYSTEM}" MATCHES "Windows")
18+
# Check the EA App/CD registry path (checks both 32-bit and 64-bit registry views)
1819
if(NOT RTS_INSTALL_PREFIX_ZEROHOUR)
19-
get_filename_component(RTS_INSTALL_PREFIX_ZEROHOUR "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Electronic Arts\\EA Games\\Command and Conquer Generals Zero Hour;InstallPath]" ABSOLUTE CACHE)
20-
endif()
21-
22-
# Check the WOW6432Node registry path (for EA App on 64-bit Windows)
23-
if(NOT RTS_INSTALL_PREFIX_ZEROHOUR OR "${RTS_INSTALL_PREFIX_ZEROHOUR}" STREQUAL "/registry")
24-
get_filename_component(RTS_INSTALL_PREFIX_ZEROHOUR "[HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\Electronic Arts\\EA Games\\Command and Conquer Generals Zero Hour;InstallPath]" ABSOLUTE CACHE)
20+
cmake_host_system_information(RESULT _zerohour_path
21+
QUERY WINDOWS_REGISTRY
22+
"HKEY_LOCAL_MACHINE/SOFTWARE/Electronic Arts/EA Games/Command and Conquer Generals Zero Hour"
23+
VALUE InstallPath
24+
VIEW 32_64
25+
ERROR_VARIABLE _reg_error)
26+
if(NOT _reg_error AND _zerohour_path)
27+
set(RTS_INSTALL_PREFIX_ZEROHOUR "${_zerohour_path}" CACHE PATH "Zero Hour install path from registry")
28+
endif()
2529
endif()
2630

2731
# Check the "First Decade" registry path
28-
if(NOT RTS_INSTALL_PREFIX_ZEROHOUR OR "${RTS_INSTALL_PREFIX_ZEROHOUR}" STREQUAL "/registry")
29-
get_filename_component(RTS_INSTALL_PREFIX_ZEROHOUR "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Electronic Arts\\EA Games\\Command and Conquer The First Decade;zh_folder]" ABSOLUTE CACHE)
32+
if(NOT RTS_INSTALL_PREFIX_ZEROHOUR)
33+
cmake_host_system_information(RESULT _zerohour_path
34+
QUERY WINDOWS_REGISTRY
35+
"HKEY_LOCAL_MACHINE/SOFTWARE/Electronic Arts/EA Games/Command and Conquer The First Decade"
36+
VALUE zh_folder
37+
VIEW 32_64
38+
ERROR_VARIABLE _reg_error)
39+
if(NOT _reg_error AND _zerohour_path)
40+
set(RTS_INSTALL_PREFIX_ZEROHOUR "${_zerohour_path}" CACHE PATH "Zero Hour install path from registry")
41+
endif()
3042
endif()
3143

32-
# Check the Steam registry path
33-
if(NOT RTS_INSTALL_PREFIX_ZEROHOUR OR "${RTS_INSTALL_PREFIX_ZEROHOUR}" STREQUAL "/registry")
34-
get_filename_component(RTS_INSTALL_PREFIX_ZEROHOUR "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Electronic Arts\\EA Games\\ZeroHour;installPath]" ABSOLUTE CACHE)
44+
# Check alternate registry location (ZeroHour vs full name)
45+
if(NOT RTS_INSTALL_PREFIX_ZEROHOUR)
46+
cmake_host_system_information(RESULT _zerohour_path
47+
QUERY WINDOWS_REGISTRY
48+
"HKEY_LOCAL_MACHINE/SOFTWARE/Electronic Arts/EA Games/ZeroHour"
49+
VALUE installPath
50+
VIEW 32_64
51+
ERROR_VARIABLE _reg_error)
52+
if(NOT _reg_error AND _zerohour_path)
53+
set(RTS_INSTALL_PREFIX_ZEROHOUR "${_zerohour_path}" CACHE PATH "Zero Hour install path from registry")
54+
endif()
3555
endif()
3656
endif()
3757

38-
if(RTS_INSTALL_PREFIX_ZEROHOUR AND NOT "${RTS_INSTALL_PREFIX_ZEROHOUR}" STREQUAL "/registry")
58+
if(RTS_INSTALL_PREFIX_ZEROHOUR)
3959
install(TARGETS z_generals RUNTIME DESTINATION "${RTS_INSTALL_PREFIX_ZEROHOUR}")
4060
install(FILES $<TARGET_PDB_FILE:z_generals> DESTINATION "${RTS_INSTALL_PREFIX_ZEROHOUR}" OPTIONAL)
4161

0 commit comments

Comments
 (0)