Sha256: 42a15ecf49332e2c8a201183e7cc9ec25580c6859be48e3d2151e23b6b93a8ef

Contents?: true

Size: 1.94 KB

Versions: 5

Compression:

Stored size: 1.94 KB

Contents

#include <Gosu/Platform.hpp>
#if defined(GOSU_IS_MAC)

#import <Gosu/Directories.hpp>
#import <Foundation/Foundation.h>
#import <unistd.h>

void Gosu::use_resource_directory()
{
    chdir(resource_prefix().c_str());
}

const std::string& Gosu::user_settings_prefix()
{
    static const std::string user_settings_prefix = [] {
        @autoreleasepool {
            NSString* library =
                    NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES)
                            .firstObject;
            NSString* preferences = [library stringByAppendingPathComponent:@"Preferences"];

            return std::string{preferences.UTF8String ?: "."} + "/";
        }
    }();
    return user_settings_prefix;
}

const std::string& Gosu::user_documents_prefix()
{
    static const std::string user_documents_prefix = [] {
        @autoreleasepool {
            NSString* documents =
                    NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)
                            .firstObject;

            return std::string{documents.UTF8String ?: "."} + "/";
        }
    }();
    return user_documents_prefix;
}

const std::string& Gosu::resource_prefix()
{
    static const std::string resource_prefix = [] {
        @autoreleasepool {
            NSString* resources = [NSBundle mainBundle].resourcePath;
            return std::string{resources.UTF8String ?: "."} + "/";
        }
    }();
    return resource_prefix;
}

const std::string& Gosu::shared_resource_prefix()
{
#ifdef GOSU_IS_IPHONE
    return resource_prefix();
#else
    static const std::string shared_resource_prefix = [] {
        @autoreleasepool {
            NSString* bundle_path = [NSBundle mainBundle].bundlePath;
            NSString* containing_path = [bundle_path stringByDeletingLastPathComponent];
            return std::string{containing_path.UTF8String ?: "."};
        }
    }();
    return shared_resource_prefix;
#endif
}

#endif

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
gosu-1.4.6 src/DirectoriesApple.cpp
gosu-1.4.5 src/DirectoriesApple.cpp
gosu-1.4.5.pre1 src/DirectoriesApple.cpp
gosu-1.4.4 src/DirectoriesApple.cpp
gosu-1.4.3 src/DirectoriesApple.cpp