src/os/macosx/macos.mm
author skidd13
Wed, 28 May 2008 16:50:05 +0000
changeset 10762 ad9b3f3325cf
parent 10402 b168fbb99f7c
permissions -rw-r--r--
(svn r13312) -Update: apply english.txt changes from r13311 to other languages
2847
5c667829bc67 (svn r3395) Add Id tag (and svn property) to macosx files.
peter1138
parents: 2827
diff changeset
     1
/* $Id$ */
5c667829bc67 (svn r3395) Add Id tag (and svn property) to macosx files.
peter1138
parents: 2827
diff changeset
     2
8461
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
     3
#include <AvailabilityMacros.h>
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
     4
2188
9acde6fcc645 (svn r2703) - Feature: [OSX] Added a native alert window to show whatever error() needs to print (Tobin made this, while I fixed some issued in it)
bjarni
parents:
diff changeset
     5
#include <AppKit/AppKit.h>
9acde6fcc645 (svn r2703) - Feature: [OSX] Added a native alert window to show whatever error() needs to print (Tobin made this, while I fixed some issued in it)
bjarni
parents:
diff changeset
     6
3127
c734d50ad134 (svn r3740) -Feature: [OSX] added OS version, CPU type and newGRF settings to assert window and a message to tell people to add that to a bug report
bjarni
parents: 2847
diff changeset
     7
#include <mach/mach.h>
c734d50ad134 (svn r3740) -Feature: [OSX] added OS version, CPU type and newGRF settings to assert window and a message to tell people to add that to a bug report
bjarni
parents: 2847
diff changeset
     8
#include <mach/mach_host.h>
c734d50ad134 (svn r3740) -Feature: [OSX] added OS version, CPU type and newGRF settings to assert window and a message to tell people to add that to a bug report
bjarni
parents: 2847
diff changeset
     9
#include <mach/host_info.h>
c734d50ad134 (svn r3740) -Feature: [OSX] added OS version, CPU type and newGRF settings to assert window and a message to tell people to add that to a bug report
bjarni
parents: 2847
diff changeset
    10
#include <mach/machine.h>
c734d50ad134 (svn r3740) -Feature: [OSX] added OS version, CPU type and newGRF settings to assert window and a message to tell people to add that to a bug report
bjarni
parents: 2847
diff changeset
    11
#include <stdio.h>
c734d50ad134 (svn r3740) -Feature: [OSX] added OS version, CPU type and newGRF settings to assert window and a message to tell people to add that to a bug report
bjarni
parents: 2847
diff changeset
    12
#include "../../stdafx.h"
8613
e4df81162916 (svn r11678) -Fix (r11674): [OSX] fixed compilation
bjarni
parents: 8482
diff changeset
    13
#include "../../core/bitmath_func.hpp"
10402
b168fbb99f7c (svn r12944) -Codechange: use rev.h instead of externs at many places
smatz
parents: 8613
diff changeset
    14
#include "../../rev.h"
3127
c734d50ad134 (svn r3740) -Feature: [OSX] added OS version, CPU type and newGRF settings to assert window and a message to tell people to add that to a bug report
bjarni
parents: 2847
diff changeset
    15
c734d50ad134 (svn r3740) -Feature: [OSX] added OS version, CPU type and newGRF settings to assert window and a message to tell people to add that to a bug report
bjarni
parents: 2847
diff changeset
    16
#ifndef CPU_SUBTYPE_POWERPC_970
c734d50ad134 (svn r3740) -Feature: [OSX] added OS version, CPU type and newGRF settings to assert window and a message to tell people to add that to a bug report
bjarni
parents: 2847
diff changeset
    17
#define CPU_SUBTYPE_POWERPC_970 ((cpu_subtype_t) 100)
c734d50ad134 (svn r3740) -Feature: [OSX] added OS version, CPU type and newGRF settings to assert window and a message to tell people to add that to a bug report
bjarni
parents: 2847
diff changeset
    18
#endif
c734d50ad134 (svn r3740) -Feature: [OSX] added OS version, CPU type and newGRF settings to assert window and a message to tell people to add that to a bug report
bjarni
parents: 2847
diff changeset
    19
2188
9acde6fcc645 (svn r2703) - Feature: [OSX] Added a native alert window to show whatever error() needs to print (Tobin made this, while I fixed some issued in it)
bjarni
parents:
diff changeset
    20
/*
9acde6fcc645 (svn r2703) - Feature: [OSX] Added a native alert window to show whatever error() needs to print (Tobin made this, while I fixed some issued in it)
bjarni
parents:
diff changeset
    21
 * This file contains objective C
9acde6fcc645 (svn r2703) - Feature: [OSX] Added a native alert window to show whatever error() needs to print (Tobin made this, while I fixed some issued in it)
bjarni
parents:
diff changeset
    22
 * Apple uses objective C instead of plain C to interact with OS specific/native functions
9acde6fcc645 (svn r2703) - Feature: [OSX] Added a native alert window to show whatever error() needs to print (Tobin made this, while I fixed some issued in it)
bjarni
parents:
diff changeset
    23
 *
9acde6fcc645 (svn r2703) - Feature: [OSX] Added a native alert window to show whatever error() needs to print (Tobin made this, while I fixed some issued in it)
bjarni
parents:
diff changeset
    24
 * Note: TrueLight's crosscompiler can handle this, but it likely needs a manual modification for each change in this file.
9acde6fcc645 (svn r2703) - Feature: [OSX] Added a native alert window to show whatever error() needs to print (Tobin made this, while I fixed some issued in it)
bjarni
parents:
diff changeset
    25
 * To insure that the crosscompiler still works, let him try any changes before they are committed
9acde6fcc645 (svn r2703) - Feature: [OSX] Added a native alert window to show whatever error() needs to print (Tobin made this, while I fixed some issued in it)
bjarni
parents:
diff changeset
    26
 */
9acde6fcc645 (svn r2703) - Feature: [OSX] Added a native alert window to show whatever error() needs to print (Tobin made this, while I fixed some issued in it)
bjarni
parents:
diff changeset
    27
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
    28
void ToggleFullScreen(bool fs);
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
    29
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6192
diff changeset
    30
static char *GetOSString()
3127
c734d50ad134 (svn r3740) -Feature: [OSX] added OS version, CPU type and newGRF settings to assert window and a message to tell people to add that to a bug report
bjarni
parents: 2847
diff changeset
    31
{
c734d50ad134 (svn r3740) -Feature: [OSX] added OS version, CPU type and newGRF settings to assert window and a message to tell people to add that to a bug report
bjarni
parents: 2847
diff changeset
    32
	static char buffer[175];
3130
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
    33
	const char* CPU;
3127
c734d50ad134 (svn r3740) -Feature: [OSX] added OS version, CPU type and newGRF settings to assert window and a message to tell people to add that to a bug report
bjarni
parents: 2847
diff changeset
    34
	char OS[20];
c734d50ad134 (svn r3740) -Feature: [OSX] added OS version, CPU type and newGRF settings to assert window and a message to tell people to add that to a bug report
bjarni
parents: 2847
diff changeset
    35
	char newgrf[125];
3130
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
    36
	long sysVersion;
3127
c734d50ad134 (svn r3740) -Feature: [OSX] added OS version, CPU type and newGRF settings to assert window and a message to tell people to add that to a bug report
bjarni
parents: 2847
diff changeset
    37
c734d50ad134 (svn r3740) -Feature: [OSX] added OS version, CPU type and newGRF settings to assert window and a message to tell people to add that to a bug report
bjarni
parents: 2847
diff changeset
    38
	// get the hardware info
c734d50ad134 (svn r3740) -Feature: [OSX] added OS version, CPU type and newGRF settings to assert window and a message to tell people to add that to a bug report
bjarni
parents: 2847
diff changeset
    39
	host_basic_info_data_t hostInfo;
c734d50ad134 (svn r3740) -Feature: [OSX] added OS version, CPU type and newGRF settings to assert window and a message to tell people to add that to a bug report
bjarni
parents: 2847
diff changeset
    40
	mach_msg_type_number_t infoCount;
c734d50ad134 (svn r3740) -Feature: [OSX] added OS version, CPU type and newGRF settings to assert window and a message to tell people to add that to a bug report
bjarni
parents: 2847
diff changeset
    41
c734d50ad134 (svn r3740) -Feature: [OSX] added OS version, CPU type and newGRF settings to assert window and a message to tell people to add that to a bug report
bjarni
parents: 2847
diff changeset
    42
	infoCount = HOST_BASIC_INFO_COUNT;
3130
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
    43
	host_info(
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
    44
		mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hostInfo, &infoCount
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
    45
	);
3127
c734d50ad134 (svn r3740) -Feature: [OSX] added OS version, CPU type and newGRF settings to assert window and a message to tell people to add that to a bug report
bjarni
parents: 2847
diff changeset
    46
c734d50ad134 (svn r3740) -Feature: [OSX] added OS version, CPU type and newGRF settings to assert window and a message to tell people to add that to a bug report
bjarni
parents: 2847
diff changeset
    47
	// replace the hardware info with strings, that tells a bit more than just an int
c734d50ad134 (svn r3740) -Feature: [OSX] added OS version, CPU type and newGRF settings to assert window and a message to tell people to add that to a bug report
bjarni
parents: 2847
diff changeset
    48
	switch (hostInfo.cpu_subtype) {
3130
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
    49
#ifdef __POWERPC__
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
    50
		case CPU_SUBTYPE_POWERPC_750:  CPU = "G3"; break;
3127
c734d50ad134 (svn r3740) -Feature: [OSX] added OS version, CPU type and newGRF settings to assert window and a message to tell people to add that to a bug report
bjarni
parents: 2847
diff changeset
    51
		case CPU_SUBTYPE_POWERPC_7400:
3130
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
    52
		case CPU_SUBTYPE_POWERPC_7450: CPU = "G4"; break;
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
    53
		case CPU_SUBTYPE_POWERPC_970:  CPU = "G5"; break;
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
    54
		default:                       CPU = "Unknown PPC"; break;
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
    55
#else
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
    56
		/* it looks odd to have a switch for two cases, but it leaves room for easy
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
    57
		 * expansion. Odds are that Apple will some day use newer CPUs than i686
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
    58
		 */
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
    59
		case CPU_SUBTYPE_PENTPRO: CPU = "i686"; break;
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
    60
		default:                  CPU = "Unknown Intel"; break;
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
    61
#endif
3127
c734d50ad134 (svn r3740) -Feature: [OSX] added OS version, CPU type and newGRF settings to assert window and a message to tell people to add that to a bug report
bjarni
parents: 2847
diff changeset
    62
	}
c734d50ad134 (svn r3740) -Feature: [OSX] added OS version, CPU type and newGRF settings to assert window and a message to tell people to add that to a bug report
bjarni
parents: 2847
diff changeset
    63
c734d50ad134 (svn r3740) -Feature: [OSX] added OS version, CPU type and newGRF settings to assert window and a message to tell people to add that to a bug report
bjarni
parents: 2847
diff changeset
    64
	// get the version of OSX
3130
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
    65
	if (Gestalt(gestaltSystemVersion, &sysVersion) != noErr) {
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
    66
		sprintf(OS, "Undetected");
3127
c734d50ad134 (svn r3740) -Feature: [OSX] added OS version, CPU type and newGRF settings to assert window and a message to tell people to add that to a bug report
bjarni
parents: 2847
diff changeset
    67
	} else {
3130
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
    68
		int majorHiNib = GB(sysVersion, 12, 4);
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
    69
		int majorLoNib = GB(sysVersion,  8, 4);
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
    70
		int minorNib   = GB(sysVersion,  4, 4);
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
    71
		int bugNib     = GB(sysVersion,  0, 4);
3127
c734d50ad134 (svn r3740) -Feature: [OSX] added OS version, CPU type and newGRF settings to assert window and a message to tell people to add that to a bug report
bjarni
parents: 2847
diff changeset
    72
c734d50ad134 (svn r3740) -Feature: [OSX] added OS version, CPU type and newGRF settings to assert window and a message to tell people to add that to a bug report
bjarni
parents: 2847
diff changeset
    73
		sprintf(OS, "%d%d.%d.%d", majorHiNib, majorLoNib, minorNib, bugNib);
c734d50ad134 (svn r3740) -Feature: [OSX] added OS version, CPU type and newGRF settings to assert window and a message to tell people to add that to a bug report
bjarni
parents: 2847
diff changeset
    74
	}
c734d50ad134 (svn r3740) -Feature: [OSX] added OS version, CPU type and newGRF settings to assert window and a message to tell people to add that to a bug report
bjarni
parents: 2847
diff changeset
    75
c734d50ad134 (svn r3740) -Feature: [OSX] added OS version, CPU type and newGRF settings to assert window and a message to tell people to add that to a bug report
bjarni
parents: 2847
diff changeset
    76
	// make a list of used newgrf files
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
    77
/*	if (_first_grffile != NULL) {
3130
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
    78
		char* n = newgrf;
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
    79
		const GRFFile* file;
3127
c734d50ad134 (svn r3740) -Feature: [OSX] added OS version, CPU type and newGRF settings to assert window and a message to tell people to add that to a bug report
bjarni
parents: 2847
diff changeset
    80
c734d50ad134 (svn r3740) -Feature: [OSX] added OS version, CPU type and newGRF settings to assert window and a message to tell people to add that to a bug report
bjarni
parents: 2847
diff changeset
    81
		for (file = _first_grffile; file != NULL; file = file->next) {
3130
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
    82
			n = strecpy(n, " ", lastof(newgrf));
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
    83
			n = strecpy(n, file->filename, lastof(newgrf));
3127
c734d50ad134 (svn r3740) -Feature: [OSX] added OS version, CPU type and newGRF settings to assert window and a message to tell people to add that to a bug report
bjarni
parents: 2847
diff changeset
    84
		}
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
    85
	} else {*/
3127
c734d50ad134 (svn r3740) -Feature: [OSX] added OS version, CPU type and newGRF settings to assert window and a message to tell people to add that to a bug report
bjarni
parents: 2847
diff changeset
    86
		sprintf(newgrf, "none");
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
    87
//	}
3130
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
    88
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
    89
	snprintf(
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
    90
		buffer, lengthof(buffer),
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
    91
		"Please add this info: (tip: copy-paste works)\n"
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
    92
		"CPU: %s, OSX: %s, OpenTTD version: %s\n"
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
    93
		"NewGRF files:%s",
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
    94
		CPU, OS, _openttd_revision, newgrf
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
    95
	);
3127
c734d50ad134 (svn r3740) -Feature: [OSX] added OS version, CPU type and newGRF settings to assert window and a message to tell people to add that to a bug report
bjarni
parents: 2847
diff changeset
    96
	return buffer;
c734d50ad134 (svn r3740) -Feature: [OSX] added OS version, CPU type and newGRF settings to assert window and a message to tell people to add that to a bug report
bjarni
parents: 2847
diff changeset
    97
}
c734d50ad134 (svn r3740) -Feature: [OSX] added OS version, CPU type and newGRF settings to assert window and a message to tell people to add that to a bug report
bjarni
parents: 2847
diff changeset
    98
2827
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2741
diff changeset
    99
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2741
diff changeset
   100
#ifdef WITH_SDL
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2741
diff changeset
   101
3130
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
   102
void ShowMacDialog(const char* title, const char* message, const char* buttonLabel)
2188
9acde6fcc645 (svn r2703) - Feature: [OSX] Added a native alert window to show whatever error() needs to print (Tobin made this, while I fixed some issued in it)
bjarni
parents:
diff changeset
   103
{
9acde6fcc645 (svn r2703) - Feature: [OSX] Added a native alert window to show whatever error() needs to print (Tobin made this, while I fixed some issued in it)
bjarni
parents:
diff changeset
   104
	NSRunAlertPanel([NSString stringWithCString: title], [NSString stringWithCString: message], [NSString stringWithCString: buttonLabel], nil, nil);
9acde6fcc645 (svn r2703) - Feature: [OSX] Added a native alert window to show whatever error() needs to print (Tobin made this, while I fixed some issued in it)
bjarni
parents:
diff changeset
   105
}
9acde6fcc645 (svn r2703) - Feature: [OSX] Added a native alert window to show whatever error() needs to print (Tobin made this, while I fixed some issued in it)
bjarni
parents:
diff changeset
   106
2827
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2741
diff changeset
   107
#elif defined WITH_COCOA
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2741
diff changeset
   108
3130
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
   109
void CocoaDialog(const char* title, const char* message, const char* buttonLabel);
2827
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2741
diff changeset
   110
3130
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
   111
void ShowMacDialog(const char* title, const char* message, const char* buttonLabel)
2827
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2741
diff changeset
   112
{
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2741
diff changeset
   113
	CocoaDialog(title, message, buttonLabel);
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2741
diff changeset
   114
}
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2741
diff changeset
   115
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2741
diff changeset
   116
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2741
diff changeset
   117
#else
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2741
diff changeset
   118
3130
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
   119
void ShowMacDialog(const char* title, const char* message, const char* buttonLabel)
2827
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2741
diff changeset
   120
{
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2741
diff changeset
   121
	fprintf(stderr, "%s: %s\n", title, message);
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2741
diff changeset
   122
}
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2741
diff changeset
   123
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2741
diff changeset
   124
#endif
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2741
diff changeset
   125
3130
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
   126
void ShowMacAssertDialog(const char* function, const char* file, const int line, const char* expression)
2223
29d61b962cb0 (svn r2741) -Feature: [OSX] added a window to display asserts on OSX (Tobin)
bjarni
parents: 2188
diff changeset
   127
{
3130
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
   128
	const char* buffer =
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
   129
		[[NSString stringWithFormat:@
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
   130
			"An assertion has failed and OpenTTD must quit.\n"
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
   131
			"%s in %s (line %d)\n"
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
   132
			"\"%s\"\n"
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
   133
			"\n"
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
   134
			"You should report this error the OpenTTD developers if you think you found a bug.\n"
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
   135
			"\n"
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
   136
			"%s",
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
   137
			function, file, line, expression, GetOSString()] cString
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
   138
		];
2223
29d61b962cb0 (svn r2741) -Feature: [OSX] added a window to display asserts on OSX (Tobin)
bjarni
parents: 2188
diff changeset
   139
	NSLog(@"%s", buffer);
3127
c734d50ad134 (svn r3740) -Feature: [OSX] added OS version, CPU type and newGRF settings to assert window and a message to tell people to add that to a bug report
bjarni
parents: 2847
diff changeset
   140
	ToggleFullScreen(0);
3130
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
   141
	ShowMacDialog("Assertion Failed", buffer, "Quit");
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents: 2223
diff changeset
   142
2223
29d61b962cb0 (svn r2741) -Feature: [OSX] added a window to display asserts on OSX (Tobin)
bjarni
parents: 2188
diff changeset
   143
	// abort so that a debugger has a chance to notice
29d61b962cb0 (svn r2741) -Feature: [OSX] added a window to display asserts on OSX (Tobin)
bjarni
parents: 2188
diff changeset
   144
	abort();
29d61b962cb0 (svn r2741) -Feature: [OSX] added a window to display asserts on OSX (Tobin)
bjarni
parents: 2188
diff changeset
   145
}
3127
c734d50ad134 (svn r3740) -Feature: [OSX] added OS version, CPU type and newGRF settings to assert window and a message to tell people to add that to a bug report
bjarni
parents: 2847
diff changeset
   146
c734d50ad134 (svn r3740) -Feature: [OSX] added OS version, CPU type and newGRF settings to assert window and a message to tell people to add that to a bug report
bjarni
parents: 2847
diff changeset
   147
c734d50ad134 (svn r3740) -Feature: [OSX] added OS version, CPU type and newGRF settings to assert window and a message to tell people to add that to a bug report
bjarni
parents: 2847
diff changeset
   148
void ShowMacErrorDialog(const char *error)
c734d50ad134 (svn r3740) -Feature: [OSX] added OS version, CPU type and newGRF settings to assert window and a message to tell people to add that to a bug report
bjarni
parents: 2847
diff changeset
   149
{
3130
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
   150
	const char* buffer =
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
   151
		[[NSString stringWithFormat:@
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
   152
			"Please update to the newest version of OpenTTD\n"
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
   153
			"If the problem presists, please report this to\n"
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
   154
			"http://bugs.openttd.org\n"
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
   155
			"\n"
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
   156
			"%s",
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
   157
			GetOSString()] cString
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
   158
		];
3127
c734d50ad134 (svn r3740) -Feature: [OSX] added OS version, CPU type and newGRF settings to assert window and a message to tell people to add that to a bug report
bjarni
parents: 2847
diff changeset
   159
	ToggleFullScreen(0);
3130
87a9577f6945 (svn r3745) Fix two buffer overflows, one case of undefined behavior (the destination buffer of sprintf() may not alias with one of its arguments) and some other minor stuff introduced in r3740
tron
parents: 3127
diff changeset
   160
	ShowMacDialog(error, buffer, "Quit");
3127
c734d50ad134 (svn r3740) -Feature: [OSX] added OS version, CPU type and newGRF settings to assert window and a message to tell people to add that to a bug report
bjarni
parents: 2847
diff changeset
   161
	abort();
c734d50ad134 (svn r3740) -Feature: [OSX] added OS version, CPU type and newGRF settings to assert window and a message to tell people to add that to a bug report
bjarni
parents: 2847
diff changeset
   162
}
7931
855327e1ab53 (svn r10851) -Feature [OSX]: OpenTTD will now pick the same language as finder is set to if no config file is found (ln-)
bjarni
parents: 6573
diff changeset
   163
855327e1ab53 (svn r10851) -Feature [OSX]: OpenTTD will now pick the same language as finder is set to if no config file is found (ln-)
bjarni
parents: 6573
diff changeset
   164
855327e1ab53 (svn r10851) -Feature [OSX]: OpenTTD will now pick the same language as finder is set to if no config file is found (ln-)
bjarni
parents: 6573
diff changeset
   165
/** Determine the current user's locale. */
855327e1ab53 (svn r10851) -Feature [OSX]: OpenTTD will now pick the same language as finder is set to if no config file is found (ln-)
bjarni
parents: 6573
diff changeset
   166
const char *GetCurrentLocale(const char *)
855327e1ab53 (svn r10851) -Feature [OSX]: OpenTTD will now pick the same language as finder is set to if no config file is found (ln-)
bjarni
parents: 6573
diff changeset
   167
{
855327e1ab53 (svn r10851) -Feature [OSX]: OpenTTD will now pick the same language as finder is set to if no config file is found (ln-)
bjarni
parents: 6573
diff changeset
   168
	static char retbuf[32] = { '\0' };
855327e1ab53 (svn r10851) -Feature [OSX]: OpenTTD will now pick the same language as finder is set to if no config file is found (ln-)
bjarni
parents: 6573
diff changeset
   169
	NSUserDefaults* defs = [NSUserDefaults standardUserDefaults];
855327e1ab53 (svn r10851) -Feature [OSX]: OpenTTD will now pick the same language as finder is set to if no config file is found (ln-)
bjarni
parents: 6573
diff changeset
   170
	NSArray* languages = [defs objectForKey:@"AppleLanguages"];
855327e1ab53 (svn r10851) -Feature [OSX]: OpenTTD will now pick the same language as finder is set to if no config file is found (ln-)
bjarni
parents: 6573
diff changeset
   171
	NSString* preferredLang = [languages objectAtIndex:0];
855327e1ab53 (svn r10851) -Feature [OSX]: OpenTTD will now pick the same language as finder is set to if no config file is found (ln-)
bjarni
parents: 6573
diff changeset
   172
	/* preferredLang is either 2 or 5 characters long ("xx" or "xx_YY"). */
8480
0ca368be883d (svn r11540) -Fix: [OSX] Don't try to compile the quartz video driver on OSX 10.3. It will fail
bjarni
parents: 8461
diff changeset
   173
0ca368be883d (svn r11540) -Fix: [OSX] Don't try to compile the quartz video driver on OSX 10.3. It will fail
bjarni
parents: 8461
diff changeset
   174
	/* MacOS 10.3.9 can't handle encoding:NSASCIIStringEncoding
0ca368be883d (svn r11540) -Fix: [OSX] Don't try to compile the quartz video driver on OSX 10.3. It will fail
bjarni
parents: 8461
diff changeset
   175
	 * we will completely disable compiling it for such old targets to avoid a warning */
0ca368be883d (svn r11540) -Fix: [OSX] Don't try to compile the quartz video driver on OSX 10.3. It will fail
bjarni
parents: 8461
diff changeset
   176
#if (MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_3)
0ca368be883d (svn r11540) -Fix: [OSX] Don't try to compile the quartz video driver on OSX 10.3. It will fail
bjarni
parents: 8461
diff changeset
   177
	/* Note: MAC_OS_X_VERSION_MAX_ALLOWED is the current OSX version/SDK by default */
8461
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   178
	if (MacOSVersionIsAtLeast(10, 4, 0)) {
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   179
		[ preferredLang getCString:retbuf maxLength:32 encoding:NSASCIIStringEncoding ];
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   180
	} else {
8480
0ca368be883d (svn r11540) -Fix: [OSX] Don't try to compile the quartz video driver on OSX 10.3. It will fail
bjarni
parents: 8461
diff changeset
   181
#else
0ca368be883d (svn r11540) -Fix: [OSX] Don't try to compile the quartz video driver on OSX 10.3. It will fail
bjarni
parents: 8461
diff changeset
   182
	/* 10.3.9 needs to start the { too */
0ca368be883d (svn r11540) -Fix: [OSX] Don't try to compile the quartz video driver on OSX 10.3. It will fail
bjarni
parents: 8461
diff changeset
   183
	{
0ca368be883d (svn r11540) -Fix: [OSX] Don't try to compile the quartz video driver on OSX 10.3. It will fail
bjarni
parents: 8461
diff changeset
   184
#endif
8461
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   185
		[ preferredLang getCString:retbuf maxLength:32 ];
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   186
	}
7931
855327e1ab53 (svn r10851) -Feature [OSX]: OpenTTD will now pick the same language as finder is set to if no config file is found (ln-)
bjarni
parents: 6573
diff changeset
   187
	return retbuf;
855327e1ab53 (svn r10851) -Feature [OSX]: OpenTTD will now pick the same language as finder is set to if no config file is found (ln-)
bjarni
parents: 6573
diff changeset
   188
}
8461
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   189
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   190
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   191
/*
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   192
 * This will only give an accurate result for versions before OS X 10.8 since it uses bcd encoding
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   193
 * for the minor and bugfix version numbers and a scheme of representing all numbers from 9 and up
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   194
 * with 9. This means we can't tell OS X 10.9 from 10.9 or 10.11. Please use GetMacOSVersionMajor()
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   195
 * and GetMacOSVersionMinor() instead.
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   196
 */
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   197
static long GetMacOSVersion()
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   198
{
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   199
	static long sysVersion = -1;
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   200
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   201
	if (sysVersion != -1) return sysVersion;
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   202
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   203
	if (Gestalt(gestaltSystemVersion, &sysVersion) != noErr) sysVersion = -1;
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   204
	 return sysVersion;
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   205
}
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   206
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   207
long GetMacOSVersionMajor()
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   208
{
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   209
	static long sysVersion = -1;
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   210
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   211
	if (sysVersion != -1) return sysVersion;
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   212
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   213
	sysVersion = GetMacOSVersion();
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   214
	if (sysVersion == -1) return -1;
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   215
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   216
	if (sysVersion >= 0x1040) {
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   217
		if (Gestalt(gestaltSystemVersionMajor, &sysVersion) != noErr) sysVersion = -1;
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   218
	} else {
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   219
		sysVersion = GB(sysVersion, 12, 4) * 10 + GB(sysVersion,  8, 4);
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   220
	}
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   221
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   222
	return sysVersion;
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   223
}
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   224
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   225
long GetMacOSVersionMinor()
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   226
{
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   227
	static long sysVersion = -1;
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   228
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   229
	if (sysVersion != -1) return sysVersion;
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   230
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   231
	sysVersion = GetMacOSVersion();
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   232
	if (sysVersion == -1) return -1;
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   233
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   234
	if (sysVersion >= 0x1040) {
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   235
		if (Gestalt(gestaltSystemVersionMinor, &sysVersion) != noErr) sysVersion = -1;
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   236
	} else {
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   237
		sysVersion = GB(sysVersion,  4, 4);
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   238
	}
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   239
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   240
	return sysVersion;
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   241
}
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   242
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   243
long GetMacOSVersionBugfix()
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   244
{
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   245
	static long sysVersion = -1;
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   246
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   247
	if (sysVersion != -1) return sysVersion;
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   248
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   249
	sysVersion = GetMacOSVersion();
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   250
	if (sysVersion == -1) return -1;
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   251
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   252
	if (sysVersion >= 0x1040) {
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   253
		if (Gestalt(gestaltSystemVersionBugFix, &sysVersion) != noErr) sysVersion = -1;
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   254
	} else {
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   255
		sysVersion = GB(sysVersion,  0, 4);
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   256
	}
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   257
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   258
	return sysVersion;
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   259
}