diff --git a/CMakeLists.txt b/CMakeLists.txt index b284b1576..17f670282 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1297,12 +1297,21 @@ set(OC_C4GROUPS get_target_property(C4GROUP_LOCATION c4group LOCATION) get_target_property(CLONK_LOCATION clonk LOCATION) foreach(group ${OC_C4GROUPS}) - add_custom_command( - OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${group} - COMMAND ${C4GROUP_LOCATION} ${CMAKE_CURRENT_SOURCE_DIR}/planet/${group} -t ${CMAKE_CURRENT_BINARY_DIR}/${group} - DEPENDS c4group ${CMAKE_CURRENT_SOURCE_DIR}/planet/${group} - VERBATIM - ) + if (APPLE) + add_custom_command(TARGET clonk + POST_BUILD COMMAND "/bin/sh" "${CMAKE_CURRENT_SOURCE_DIR}/tools/osx_pack_gamedata.sh" + "${C4GROUP_LOCATION}" + "${CMAKE_CURRENT_SOURCE_DIR}/planet/${group}" + DEPENDS c4group + ) + else() + add_custom_command( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${group} + COMMAND ${C4GROUP_LOCATION} ${CMAKE_CURRENT_SOURCE_DIR}/planet/${group} -t ${CMAKE_CURRENT_BINARY_DIR}/${group} + DEPENDS c4group ${CMAKE_CURRENT_SOURCE_DIR}/planet/${group} + VERBATIM + ) + endif() endforeach() find_program(MAKENSIS makensis PATHS [HKEY_LOCAL_MACHINE\\SOFTWARE\\NSIS]) diff --git a/src/config/C4Reloc.cpp b/src/config/C4Reloc.cpp index 749fa1d81..8ad688076 100644 --- a/src/config/C4Reloc.cpp +++ b/src/config/C4Reloc.cpp @@ -19,6 +19,7 @@ #include #include +#include C4Reloc Reloc; // singleton @@ -31,9 +32,15 @@ void C4Reloc::Init() // but for distribution it might make sense to disable it. // TODO: We might also want to add ExePath/planet if it exists, so that we don't // need to run the engine in planet/. + +#ifdef USE_COCOA + AddPath(::Application.GetGameDataPath().getData()); +#else AddPath(Config.General.ExePath.getData()); - AddPath(Config.General.UserDataPath); AddPath(Config.General.SystemDataPath); +#endif + + AddPath(Config.General.UserDataPath); } bool C4Reloc::AddPath(const char* path) diff --git a/src/platform/C4App.h b/src/platform/C4App.h index d9f66be51..7056f57d5 100644 --- a/src/platform/C4App.h +++ b/src/platform/C4App.h @@ -177,6 +177,7 @@ protected: # endif #ifdef USE_COCOA void HandleNSEvent(/*NSEvent*/void* event); + StdStrBuf GetGameDataPath(); #endif const char * Location; pthread_t MainThread; diff --git a/src/platform/C4AppMac.mm b/src/platform/C4AppMac.mm index 330dca4db..a53fba9ad 100644 --- a/src/platform/C4AppMac.mm +++ b/src/platform/C4AppMac.mm @@ -161,6 +161,11 @@ void CStdApp::RestoreVideoMode() { } +StdStrBuf CStdApp::GetGameDataPath() +{ + return StdCopyStrBuf([[[NSBundle mainBundle] resourcePath] fileSystemRepresentation]); +} + #endif bool IsGermanSystem() diff --git a/src/platform/ClonkAppDelegate.mm b/src/platform/ClonkAppDelegate.mm index 4e9a698de..67808bdfb 100644 --- a/src/platform/ClonkAppDelegate.mm +++ b/src/platform/ClonkAppDelegate.mm @@ -99,7 +99,6 @@ { if (!([self argsLookLikeItShouldBeInstallation] && [self installAddOn])) { - [[NSFileManager defaultManager] changeCurrentDirectoryPath:[self clonkDirectory]]; [NSApp activateIgnoringOtherApps:YES]; [self makeFakeArgs]; diff --git a/tools/osx_pack_gamedata.sh b/tools/osx_pack_gamedata.sh new file mode 100644 index 000000000..b8249326f --- /dev/null +++ b/tools/osx_pack_gamedata.sh @@ -0,0 +1,27 @@ +#!/bin/sh + +C4GROUP=$1 +SRC_GROUP=$2 + +RESOURCES=$TARGET_BUILD_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH +TARGET_GROUP=$RESOURCES/`basename $SRC_GROUP` + +should_update() { + for i in `find $SRC_GROUP`; do + if [ $i -nt $TARGET_GROUP ]; then return 0; fi + done + return 1 +} + +if [ "$CONFIGURATION" == "Release" ] +then if should_update + then echo Packing $TARGET_GROUP... + rm -f $TARGET_GROUP + cd $RESOURCES + $C4GROUP $SRC_GROUP -t $TARGET_GROUP + else echo No changes found for $TARGET_GROUP, skipping + fi +else echo Linking $TARGET_GROUP... + rm -f $TARGET_GROUP + ln -sf $SRC_GROUP $TARGET_GROUP +fi