Skip to content

Commit 7996b86

Browse files
committed
Port installer flow to iOS runtime
1 parent a2f0079 commit 7996b86

14 files changed

Lines changed: 1625 additions & 59 deletions

File tree

UnleashedRecomp/CMakeLists.txt

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ set(UNLEASHED_RECOMP_COMPILE_DEFINITIONS
7878

7979
if (NOT CMAKE_SYSTEM_NAME STREQUAL "iOS")
8080
list(APPEND UNLEASHED_RECOMP_COMPILE_DEFINITIONS SDL_MAIN_HANDLED)
81+
else()
82+
list(APPEND UNLEASHED_RECOMP_COMPILE_DEFINITIONS UNLEASHED_RECOMP_IOS)
8183
endif()
8284

8385
add_compile_definitions(${UNLEASHED_RECOMP_COMPILE_DEFINITIONS})
@@ -116,10 +118,18 @@ elseif (CMAKE_SYSTEM_NAME MATCHES "Linux")
116118
"os/linux/user_linux.cpp"
117119
"os/linux/version_linux.cpp"
118120
)
121+
elseif (CMAKE_SYSTEM_NAME STREQUAL "iOS")
122+
set(UNLEASHED_RECOMP_OS_CXX_SOURCES
123+
"os/ios/logger_ios.cpp"
124+
"os/ios/media_ios.cpp"
125+
"os/ios/process_ios.mm"
126+
"os/ios/user_ios.mm"
127+
"os/ios/version_ios.mm"
128+
)
119129
elseif (APPLE)
120130
set(UNLEASHED_RECOMP_OS_CXX_SOURCES
121131
"os/macos/logger_macos.cpp"
122-
"os/macos/media_macos.cpp"
132+
"os/macos/media_macos.cpp"
123133
"os/macos/process_macos.cpp"
124134
"os/macos/user_macos.cpp"
125135
"os/macos/version_macos.cpp"
@@ -453,6 +463,12 @@ if (CMAKE_SYSTEM_NAME STREQUAL "iOS" AND TARGET SDL2::SDL2main)
453463
list(PREPEND UNLEASHED_RECOMP_SDL_LIBS SDL2::SDL2main)
454464
endif()
455465

466+
set(UNLEASHED_RECOMP_PLATFORM_LIBS)
467+
if (CMAKE_SYSTEM_NAME STREQUAL "iOS")
468+
list(APPEND UNLEASHED_RECOMP_PLATFORM_LIBS MoltenVK)
469+
target_link_options(UnleashedRecomp PRIVATE "LINKER:-u,_vkGetInstanceProcAddr")
470+
endif()
471+
456472
target_link_libraries(UnleashedRecomp PRIVATE
457473
fmt::fmt
458474
libzstd_static
@@ -463,11 +479,12 @@ target_link_libraries(UnleashedRecomp PRIVATE
463479
${UNLEASHED_RECOMP_SDL_LIBS}
464480
SDL2_mixer
465481
tomlplusplus::tomlplusplus
466-
UnleashedRecompLib
467-
xxHash::xxhash
468-
CURL::libcurl
469-
plume
470-
)
482+
UnleashedRecompLib
483+
xxHash::xxhash
484+
CURL::libcurl
485+
plume
486+
${UNLEASHED_RECOMP_PLATFORM_LIBS}
487+
)
471488

472489
target_include_directories(UnleashedRecomp PRIVATE
473490
${CMAKE_CURRENT_SOURCE_DIR}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <os/logger.h>
2+
3+
void os::logger::Init()
4+
{
5+
}
6+
7+
void os::logger::Log(const std::string_view str, ELogType type, const char* func)
8+
{
9+
(void)type;
10+
11+
if (func)
12+
{
13+
fmt::println("[{}] {}", func, str);
14+
}
15+
else
16+
{
17+
fmt::println("{}", str);
18+
}
19+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include <os/media.h>
2+
3+
bool os::media::IsExternalMediaPlaying()
4+
{
5+
return false;
6+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#include <os/process.h>
2+
3+
#import <Foundation/Foundation.h>
4+
5+
#include <mach-o/dyld.h>
6+
#include <sys/param.h>
7+
#include <unistd.h>
8+
9+
std::filesystem::path os::process::GetExecutablePath()
10+
{
11+
uint32_t exePathSize = PATH_MAX;
12+
char exePath[PATH_MAX] = {};
13+
if (_NSGetExecutablePath(exePath, &exePathSize) == 0)
14+
{
15+
return std::filesystem::path(std::u8string_view(reinterpret_cast<const char8_t*>(exePath)));
16+
}
17+
18+
return {};
19+
}
20+
21+
std::filesystem::path os::process::GetExecutableRoot()
22+
{
23+
@autoreleasepool
24+
{
25+
NSString* resourcePath = [[NSBundle mainBundle] resourcePath];
26+
if (resourcePath.length > 0)
27+
return std::filesystem::path(std::u8string_view(reinterpret_cast<const char8_t*>(resourcePath.UTF8String)));
28+
}
29+
30+
return GetExecutablePath().remove_filename();
31+
}
32+
33+
std::filesystem::path os::process::GetWorkingDirectory()
34+
{
35+
char cwd[PATH_MAX] = {};
36+
if (getcwd(cwd, sizeof(cwd)) != nullptr)
37+
return std::filesystem::path(std::u8string_view(reinterpret_cast<const char8_t*>(cwd)));
38+
39+
return {};
40+
}
41+
42+
bool os::process::SetWorkingDirectory(const std::filesystem::path& path)
43+
{
44+
return chdir(path.c_str()) == 0;
45+
}
46+
47+
bool os::process::StartProcess(const std::filesystem::path& path, const std::vector<std::string>& args, std::filesystem::path work)
48+
{
49+
(void)path;
50+
(void)args;
51+
(void)work;
52+
return false;
53+
}
54+
55+
void os::process::CheckConsole()
56+
{
57+
g_consoleVisible = false;
58+
}
59+
60+
void os::process::ShowConsole()
61+
{
62+
}

UnleashedRecomp/os/ios/user_ios.mm

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include <os/user.h>
2+
3+
#import <UIKit/UIKit.h>
4+
5+
bool os::user::IsDarkTheme()
6+
{
7+
if (@available(iOS 13.0, *))
8+
return UIScreen.mainScreen.traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark;
9+
10+
return false;
11+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <os/version.h>
2+
3+
#import <UIKit/UIKit.h>
4+
5+
os::version::OSVersion os::version::GetOSVersion()
6+
{
7+
os::version::OSVersion result;
8+
9+
NSOperatingSystemVersion version = NSProcessInfo.processInfo.operatingSystemVersion;
10+
result.Major = static_cast<uint32_t>(version.majorVersion);
11+
result.Minor = static_cast<uint32_t>(version.minorVersion);
12+
result.Build = static_cast<uint32_t>(version.patchVersion);
13+
14+
return result;
15+
}

UnleashedRecomp/res/ios/Info.plist.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,12 @@
5757
<string>${MACOSX_BUNDLE_BUNDLE_VERSION}</string>
5858
<key>LSRequiresIPhoneOS</key>
5959
<true/>
60+
<key>LSSupportsOpeningDocumentsInPlace</key>
61+
<true/>
6062
<key>MinimumOSVersion</key>
6163
<string>13.0</string>
64+
<key>UIFileSharingEnabled</key>
65+
<true/>
6266
<key>UIApplicationSupportsIndirectInputEvents</key>
6367
<true/>
6468
<key>UILaunchScreen</key>

UnleashedRecomp/ui/installer_wizard.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,7 +1109,7 @@ static bool ConvertPathSet(const nfdpathset_t *pathSet, std::list<std::filesyste
11091109

11101110
static void PickerThreadProcess()
11111111
{
1112-
const nfdpathset_t *pathSet;
1112+
const nfdpathset_t *pathSet = nullptr;
11131113
nfdresult_t result = NFD_ERROR;
11141114
if (g_currentPickerFolderMode)
11151115
{
@@ -1146,7 +1146,7 @@ static void PickerStart(bool folderMode) {
11461146
g_currentPickerVisible = true;
11471147

11481148
// Optional single thread mode for testing on systems that do not interact well with the separate thread being used for NFD.
1149-
#ifdef __APPLE__
1149+
#if defined(__APPLE__) && !defined(UNLEASHED_RECOMP_IOS)
11501150
constexpr bool singleThreadMode = true;
11511151
#else
11521152
constexpr bool singleThreadMode = false;

UnleashedRecomp/user/paths.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ std::filesystem::path BuildUserPath()
2222
userPath = std::filesystem::path{ knownPath } / USER_DIRECTORY;
2323

2424
CoTaskMemFree(knownPath);
25+
#elif defined(UNLEASHED_RECOMP_IOS)
26+
const char* homeDir = getenv("HOME");
27+
if (homeDir != nullptr)
28+
{
29+
userPath = std::filesystem::path(homeDir) / "Documents" / USER_DIRECTORY;
30+
}
2531
#elif defined(__linux__) || defined(__APPLE__)
2632
const char* homeDir = getenv("HOME");
2733
#if defined(__linux__)

thirdparty/CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,13 @@ endif()
2525

2626
add_subdirectory("${UNLEASHED_RECOMP_THIRDPARTY_ROOT}/msdf-atlas-gen")
2727
if (CMAKE_SYSTEM_NAME STREQUAL "iOS")
28-
add_library(nfd STATIC "${UNLEASHED_RECOMP_THIRDPARTY_ROOT}/nfd_ios_stub.c")
28+
find_library(UIKIT_LIBRARY UIKit REQUIRED)
29+
find_library(FOUNDATION_LIBRARY Foundation REQUIRED)
30+
31+
add_library(nfd STATIC "${UNLEASHED_RECOMP_THIRDPARTY_ROOT}/nfd_ios.mm")
2932
add_library(nfd::nfd ALIAS nfd)
3033
target_include_directories(nfd PUBLIC "${UNLEASHED_RECOMP_THIRDPARTY_ROOT}/nativefiledialog-extended/src/include")
34+
target_link_libraries(nfd PUBLIC ${UIKIT_LIBRARY} ${FOUNDATION_LIBRARY})
3135
else()
3236
add_subdirectory("${UNLEASHED_RECOMP_THIRDPARTY_ROOT}/nativefiledialog-extended")
3337
endif()
@@ -36,6 +40,6 @@ add_subdirectory("${UNLEASHED_RECOMP_THIRDPARTY_ROOT}/SDL")
3640
add_subdirectory("${UNLEASHED_RECOMP_THIRDPARTY_ROOT}/SDL_mixer")
3741
add_subdirectory("${UNLEASHED_RECOMP_THIRDPARTY_ROOT}/plume")
3842

39-
if (APPLE AND NOT CMAKE_SYSTEM_NAME STREQUAL "iOS")
43+
if (APPLE)
4044
add_subdirectory("${UNLEASHED_RECOMP_THIRDPARTY_ROOT}/MoltenVK")
4145
endif()

0 commit comments

Comments
 (0)