src/os/macosx/macos.mm
author bjarni
Fri, 30 Nov 2007 13:26:24 +0000
changeset 8480 0ca368be883d
parent 8461 385ca6f76feb
child 8482 3b66c16ebb6c
permissions -rw-r--r--
(svn r11540) -Fix: [OSX] Don't try to compile the quartz video driver on OSX 10.3. It will fail
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
#define MAC_OS_X_VERSION_MIN_REQUIRED    MAC_OS_X_VERSION_10_3
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
     4
#include <AvailabilityMacros.h>
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
     5
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
     6
#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
     7
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
     8
#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
     9
#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
    10
#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
    11
#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
    12
#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
    13
#include "../../stdafx.h"
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
    14
#include "../../macros.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;
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
    37
	extern const char _openttd_revision[];
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
    38
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
	// 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
    40
	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
    41
	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
    42
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
    43
	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
    44
	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
    45
		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
    46
	);
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
    47
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
	// 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
    49
	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
    50
#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
    51
		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
    52
		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
    53
		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
    54
		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
    55
		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
    56
#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
    57
		/* 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
    58
		 * 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
    59
		 */
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
		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
    61
		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
    62
#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
    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
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
    65
	// 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
    66
	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
    67
		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
    68
	} 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
    69
		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
    70
		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
    71
		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
    72
		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
    73
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
		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
    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
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
    77
	// 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
    78
/*	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
    79
		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
    80
		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
    81
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
    82
		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
    83
			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
    84
			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
    85
		}
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
    86
	} 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
    87
		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
    88
//	}
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
    89
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
	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
    91
		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
    92
		"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
    93
		"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
    94
		"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
    95
		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
    96
	);
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
    97
	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
    98
}
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
    99
2827
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2741
diff changeset
   100
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2741
diff changeset
   101
#ifdef WITH_SDL
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2741
diff changeset
   102
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
   103
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
   104
{
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
	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
   106
}
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
   107
2827
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2741
diff changeset
   108
#elif defined WITH_COCOA
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2741
diff changeset
   109
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
   110
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
   111
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
   112
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
   113
{
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2741
diff changeset
   114
	CocoaDialog(title, message, buttonLabel);
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
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2741
diff changeset
   118
#else
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2741
diff changeset
   119
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
   120
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
   121
{
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2741
diff changeset
   122
	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
   123
}
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2741
diff changeset
   124
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2741
diff changeset
   125
#endif
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2741
diff changeset
   126
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
   127
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
   128
{
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
   129
	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
   130
		[[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
   131
			"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
   132
			"%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
   133
			"\"%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
   134
			"\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
			"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
   136
			"\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
   137
			"%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
   138
			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
   139
		];
2223
29d61b962cb0 (svn r2741) -Feature: [OSX] added a window to display asserts on OSX (Tobin)
bjarni
parents: 2188
diff changeset
   140
	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
   141
	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
   142
	ShowMacDialog("Assertion Failed", buffer, "Quit");
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents: 2223
diff changeset
   143
2223
29d61b962cb0 (svn r2741) -Feature: [OSX] added a window to display asserts on OSX (Tobin)
bjarni
parents: 2188
diff changeset
   144
	// 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
   145
	abort();
29d61b962cb0 (svn r2741) -Feature: [OSX] added a window to display asserts on OSX (Tobin)
bjarni
parents: 2188
diff changeset
   146
}
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
   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
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
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
   150
{
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
   151
	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
   152
		[[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
   153
			"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
   154
			"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
   155
			"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
   156
			"\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
   157
			"%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
   158
			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
   159
		];
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
   160
	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
   161
	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
   162
	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
   163
}
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
   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
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
/** 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
   167
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
   168
{
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
	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
   170
	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
   171
	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
   172
	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
   173
	/* 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
   174
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
	/* 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
   176
	 * 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
   177
#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
   178
	/* 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
   179
	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
   180
		[ 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
   181
	} 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
   182
#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
   183
	/* 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
   184
	{
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
   185
#endif
8461
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   186
		[ 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
   187
	}
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
   188
	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
   189
}
8461
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
/*
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   193
 * 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
   194
 * 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
   195
 * 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
   196
 * and GetMacOSVersionMinor() instead.
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   197
 */
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   198
static long GetMacOSVersion()
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   199
{
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   200
	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
   201
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   202
	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
   203
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   204
	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
   205
	 return sysVersion;
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
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   208
long GetMacOSVersionMajor()
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   209
{
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   210
	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
   211
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   212
	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
   213
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   214
	sysVersion = GetMacOSVersion();
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   215
	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
   216
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   217
	if (sysVersion >= 0x1040) {
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   218
		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
   219
	} else {
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   220
		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
   221
	}
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   222
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   223
	return sysVersion;
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
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   226
long GetMacOSVersionMinor()
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   227
{
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   228
	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
   229
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   230
	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
   231
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   232
	sysVersion = GetMacOSVersion();
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   233
	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
   234
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   235
	if (sysVersion >= 0x1040) {
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   236
		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
   237
	} else {
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   238
		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
   239
	}
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   240
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   241
	return sysVersion;
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
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   244
long GetMacOSVersionBugfix()
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   245
{
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   246
	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
   247
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   248
	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
   249
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   250
	sysVersion = GetMacOSVersion();
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   251
	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
   252
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   253
	if (sysVersion >= 0x1040) {
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   254
		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
   255
	} else {
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   256
		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
   257
	}
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   258
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   259
	return sysVersion;
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8335
diff changeset
   260
}