2014-10-06 18:36:58 +02:00
|
|
|
/*****************************************************************************
|
2018-06-15 14:07:34 +02:00
|
|
|
* Copyright (c) 2014-2018 OpenRCT2 developers
|
2015-10-20 20:16:30 +02:00
|
|
|
*
|
2018-06-15 14:07:34 +02:00
|
|
|
* For a complete list of all authors, please refer to contributors.md
|
|
|
|
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
2015-10-20 20:16:30 +02:00
|
|
|
*
|
2018-06-15 14:07:34 +02:00
|
|
|
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
2014-10-06 18:36:58 +02:00
|
|
|
*****************************************************************************/
|
|
|
|
|
2015-11-27 18:01:22 +01:00
|
|
|
#if defined(__APPLE__) && defined(__MACH__)
|
2014-10-06 18:36:58 +02:00
|
|
|
|
2018-06-21 12:48:12 +02:00
|
|
|
#include "../config/Config.h"
|
|
|
|
#include "../localisation/Language.h"
|
|
|
|
#include "../util/Util.h"
|
|
|
|
#include "platform.h"
|
|
|
|
|
|
|
|
// undefine `interface` and `abstract`, because it's causing conflicts with Objective-C's keywords
|
|
|
|
#undef interface
|
|
|
|
#undef abstract
|
|
|
|
|
2018-02-05 14:50:16 +01:00
|
|
|
#import <AppKit/AppKit.h>
|
|
|
|
#import <Foundation/Foundation.h>
|
2015-12-13 00:22:14 +01:00
|
|
|
#include <mach-o/dyld.h>
|
2017-10-24 18:36:40 +02:00
|
|
|
#include <pwd.h>
|
2014-10-06 18:36:58 +02:00
|
|
|
|
2017-03-13 23:03:29 +01:00
|
|
|
void macos_disallow_automatic_window_tabbing()
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
@autoreleasepool {
|
2018-06-22 23:04:38 +02:00
|
|
|
if ([NSWindow respondsToSelector:@selector(setAllowsAutomaticWindowTabbing:)])
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
[NSWindow setAllowsAutomaticWindowTabbing:NO];
|
|
|
|
}
|
|
|
|
}
|
2017-03-13 23:03:29 +01:00
|
|
|
}
|
|
|
|
|
2018-06-22 23:04:38 +02:00
|
|
|
utf8* macos_str_decomp_to_precomp(utf8* input)
|
2017-05-11 09:43:53 +02:00
|
|
|
{
|
2018-06-22 23:04:38 +02:00
|
|
|
@autoreleasepool {
|
|
|
|
if (input == NULL)
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-06-22 23:04:38 +02:00
|
|
|
NSString* inputDecomp = [NSString stringWithUTF8String:input];
|
2017-06-06 23:24:18 +02:00
|
|
|
return strdup([inputDecomp.precomposedStringWithCanonicalMapping cStringUsingEncoding:NSUTF8StringEncoding]);
|
|
|
|
}
|
2017-05-11 09:43:53 +02:00
|
|
|
}
|
|
|
|
|
2018-03-09 16:40:40 +01:00
|
|
|
#ifndef NO_TTF
|
2018-06-22 23:04:38 +02:00
|
|
|
bool platform_get_font_path(TTFFontDescriptor* font, utf8* buffer, size_t size)
|
2015-12-24 18:52:33 +01:00
|
|
|
{
|
2018-06-22 23:04:38 +02:00
|
|
|
@autoreleasepool {
|
2018-07-21 11:50:45 +02:00
|
|
|
CTFontDescriptorRef fontRef = CTFontDescriptorCreateWithNameAndSize(
|
|
|
|
(CFStringRef)[NSString stringWithUTF8String:font->font_name], 0.0);
|
2017-06-06 23:24:18 +02:00
|
|
|
CFURLRef url = (CFURLRef)CTFontDescriptorCopyAttribute(fontRef, kCTFontURLAttribute);
|
2018-06-22 23:04:38 +02:00
|
|
|
if (url)
|
|
|
|
{
|
|
|
|
NSString* fontPath = [NSString stringWithString:[(NSURL*)CFBridgingRelease(url) path]];
|
2017-06-06 23:24:18 +02:00
|
|
|
safe_strcpy(buffer, fontPath.UTF8String, size);
|
|
|
|
return true;
|
2018-06-22 23:04:38 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2015-12-24 18:52:33 +01:00
|
|
|
}
|
2018-03-09 16:40:40 +01:00
|
|
|
#endif // NO_TTF
|
2015-12-24 18:52:33 +01:00
|
|
|
|
2018-06-22 23:04:38 +02:00
|
|
|
bool platform_has_matching_language(NSString* preferredLocale, uint16_t* languageIdentifier)
|
2016-08-21 16:28:24 +02:00
|
|
|
{
|
2018-06-22 23:04:38 +02:00
|
|
|
@autoreleasepool {
|
|
|
|
if ([preferredLocale isEqualToString:@"en"] || [preferredLocale isEqualToString:@"en-CA"])
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
*languageIdentifier = LANGUAGE_ENGLISH_US;
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2018-06-22 23:04:38 +02:00
|
|
|
if ([preferredLocale isEqualToString:@"zh-CN"])
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
*languageIdentifier = LANGUAGE_CHINESE_SIMPLIFIED;
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2018-06-22 23:04:38 +02:00
|
|
|
if ([preferredLocale isEqualToString:@"zh-TW"])
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
*languageIdentifier = LANGUAGE_CHINESE_TRADITIONAL;
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find an exact match (language and region)
|
2018-06-22 23:04:38 +02:00
|
|
|
for (int i = 1; i < LANGUAGE_COUNT; i++)
|
|
|
|
{
|
|
|
|
if ([preferredLocale isEqualToString:[NSString stringWithUTF8String:LanguagesDescriptors[i].locale]])
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
*languageIdentifier = i;
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only check for a matching language
|
2018-06-22 23:04:38 +02:00
|
|
|
NSString* languageCode = [[preferredLocale componentsSeparatedByString:@"-"] firstObject];
|
|
|
|
for (int i = 1; i < LANGUAGE_COUNT; i++)
|
|
|
|
{
|
2018-07-21 11:50:45 +02:00
|
|
|
NSString* optionLanguageCode = [
|
|
|
|
[[NSString stringWithUTF8String:LanguagesDescriptors[i].locale] componentsSeparatedByString:@"-"] firstObject];
|
2018-06-22 23:04:38 +02:00
|
|
|
if ([languageCode isEqualToString:optionLanguageCode])
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
*languageIdentifier = i;
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NO;
|
|
|
|
}
|
2016-08-21 16:28:24 +02:00
|
|
|
}
|
|
|
|
|
2018-06-20 17:28:51 +02:00
|
|
|
uint16_t platform_get_locale_language()
|
2016-08-21 16:28:24 +02:00
|
|
|
{
|
2018-06-22 23:04:38 +02:00
|
|
|
@autoreleasepool {
|
|
|
|
NSArray<NSString*>* preferredLanguages = [NSLocale preferredLanguages];
|
|
|
|
for (NSString* preferredLanguage in preferredLanguages)
|
|
|
|
{
|
2018-06-20 17:28:51 +02:00
|
|
|
uint16_t languageIdentifier;
|
2018-06-22 23:04:38 +02:00
|
|
|
if (platform_has_matching_language(preferredLanguage, &languageIdentifier))
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
return languageIdentifier;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fallback
|
|
|
|
return LANGUAGE_ENGLISH_UK;
|
|
|
|
}
|
2016-08-21 16:28:24 +02:00
|
|
|
}
|
|
|
|
|
2018-06-20 17:28:51 +02:00
|
|
|
uint8_t platform_get_locale_currency()
|
2016-08-21 15:14:54 +02:00
|
|
|
{
|
2018-06-22 23:04:38 +02:00
|
|
|
@autoreleasepool {
|
|
|
|
NSString* currencyCode = [[NSLocale currentLocale] objectForKey:NSLocaleCurrencyCode];
|
2017-06-06 23:24:18 +02:00
|
|
|
return platform_get_currency_value(currencyCode.UTF8String);
|
|
|
|
}
|
2016-08-21 15:14:54 +02:00
|
|
|
}
|
|
|
|
|
2018-06-20 17:28:51 +02:00
|
|
|
uint8_t platform_get_locale_measurement_format()
|
2016-08-21 15:14:54 +02:00
|
|
|
{
|
2018-06-22 23:04:38 +02:00
|
|
|
@autoreleasepool {
|
|
|
|
NSNumber* metricSystem = [[NSLocale currentLocale] objectForKey:NSLocaleUsesMetricSystem];
|
2016-08-21 15:14:54 +02:00
|
|
|
|
2018-06-22 23:04:38 +02:00
|
|
|
if (metricSystem.boolValue)
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
return MEASUREMENT_FORMAT_METRIC;
|
|
|
|
}
|
2016-11-13 20:17:49 +01:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
return MEASUREMENT_FORMAT_IMPERIAL;
|
|
|
|
}
|
2016-08-21 15:14:54 +02:00
|
|
|
}
|
|
|
|
|
2018-06-22 23:04:38 +02:00
|
|
|
void platform_get_changelog_path(utf8* outPath, size_t outSize)
|
2017-08-07 14:00:28 +02:00
|
|
|
{
|
|
|
|
platform_get_openrct_data_path(outPath, outSize);
|
|
|
|
safe_strcat_path(outPath, "changelog.txt", outSize);
|
|
|
|
}
|
|
|
|
|
2018-06-22 23:04:38 +02:00
|
|
|
bool platform_get_steam_path(utf8* outPath, size_t outSize)
|
2017-10-24 18:36:40 +02:00
|
|
|
{
|
|
|
|
char steamPath[1024] = { 0 };
|
2018-06-22 23:04:38 +02:00
|
|
|
const char* homeDir = getpwuid(getuid())->pw_dir;
|
2017-10-24 18:36:40 +02:00
|
|
|
if (homeDir != NULL)
|
|
|
|
{
|
|
|
|
safe_strcpy(steamPath, homeDir, sizeof(steamPath));
|
2018-07-21 11:50:45 +02:00
|
|
|
safe_strcat_path(
|
|
|
|
steamPath, "Library/Application Support/Steam/Steam.AppBundle/Steam/Contents/MacOS/steamapps", sizeof(steamPath));
|
2017-10-24 18:36:40 +02:00
|
|
|
if (platform_directory_exists(steamPath))
|
|
|
|
{
|
|
|
|
safe_strcpy(outPath, steamPath, outSize);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-11-27 18:01:22 +01:00
|
|
|
#endif
|