os/macosx/macos.m
author bjarni
Thu, 02 Mar 2006 21:43:09 +0000
changeset 3127 56a9c0db7c18
parent 2847 65c54f935db6
child 3130 c65ad41ee90b
permissions -rw-r--r--
(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
It also adds a new error window, which can be used just like assert, but it is also active when asserts are turned off
This is useful for places where it's really important to check even if assert is turned off. It's not used in the code yet
2847
65c54f935db6 (svn r3395) Add Id tag (and svn property) to macosx files.
peter1138
parents: 2827
diff changeset
     1
/* $Id$ */
65c54f935db6 (svn r3395) Add Id tag (and svn property) to macosx files.
peter1138
parents: 2827
diff changeset
     2
2188
640a0a5f77ea (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
     3
#include <AppKit/AppKit.h>
640a0a5f77ea (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
     4
3127
56a9c0db7c18 (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
     5
#include <mach/mach.h>
56a9c0db7c18 (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
     6
#include <mach/mach_host.h>
56a9c0db7c18 (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/host_info.h>
56a9c0db7c18 (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/machine.h>
56a9c0db7c18 (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 <stdio.h>
56a9c0db7c18 (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 "../../stdafx.h"
56a9c0db7c18 (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 "../../openttd.h"
56a9c0db7c18 (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 "../../newgrf.h"
56a9c0db7c18 (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 "../../gfx.h"
56a9c0db7c18 (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
    14
56a9c0db7c18 (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
#ifndef CPU_SUBTYPE_POWERPC_970
56a9c0db7c18 (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
#define CPU_SUBTYPE_POWERPC_970 ((cpu_subtype_t) 100)
56a9c0db7c18 (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
#endif
56a9c0db7c18 (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
2188
640a0a5f77ea (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
    19
/*
640a0a5f77ea (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
 * This file contains objective C
640a0a5f77ea (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
 * Apple uses objective C instead of plain C to interact with OS specific/native functions
640a0a5f77ea (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
 *
640a0a5f77ea (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
 * Note: TrueLight's crosscompiler can handle this, but it likely needs a manual modification for each change in this file.
640a0a5f77ea (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
 * To insure that the crosscompiler still works, let him try any changes before they are committed
640a0a5f77ea (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
 */
640a0a5f77ea (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
3127
56a9c0db7c18 (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
    27
static char *GetOSString(void)
56a9c0db7c18 (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
    28
{
56a9c0db7c18 (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
    29
	static char buffer[175];
56a9c0db7c18 (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
    30
	char CPU[20];
56a9c0db7c18 (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
	char OS[20];
56a9c0db7c18 (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
	char newgrf[125];
56a9c0db7c18 (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
    33
	long		sysVersion;
56a9c0db7c18 (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
    extern const char _openttd_revision[];
56a9c0db7c18 (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
56a9c0db7c18 (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
    36
56a9c0db7c18 (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
	// get the hardware info
56a9c0db7c18 (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
	host_basic_info_data_t hostInfo;
56a9c0db7c18 (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
	mach_msg_type_number_t infoCount;
56a9c0db7c18 (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
56a9c0db7c18 (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
	infoCount = HOST_BASIC_INFO_COUNT;
56a9c0db7c18 (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
	host_info(mach_host_self(), HOST_BASIC_INFO,
56a9c0db7c18 (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
			  (host_info_t)&hostInfo, &infoCount);
56a9c0db7c18 (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
    44
56a9c0db7c18 (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
    45
	// replace the hardware info with strings, that tells a bit more than just an int
56a9c0db7c18 (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
#ifdef __POWERPC__
56a9c0db7c18 (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
	switch (hostInfo.cpu_subtype) {
56a9c0db7c18 (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
		case CPU_SUBTYPE_POWERPC_750:
56a9c0db7c18 (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
			sprintf(CPU,"G3");
56a9c0db7c18 (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
    50
			break;
56a9c0db7c18 (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:
56a9c0db7c18 (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_7450:
56a9c0db7c18 (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
    53
			sprintf(CPU,"G4");
56a9c0db7c18 (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
    54
			break;
56a9c0db7c18 (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
    55
		case CPU_SUBTYPE_POWERPC_970:
56a9c0db7c18 (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
    56
			sprintf(CPU,"G5");
56a9c0db7c18 (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
    57
			break;
56a9c0db7c18 (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
    58
		default:
56a9c0db7c18 (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
    59
			sprintf(CPU,"Unknown PPC");
56a9c0db7c18 (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
    60
	}
56a9c0db7c18 (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
    61
#else
56a9c0db7c18 (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
	// it looks odd to have a switch for two cases, but it leaves room for easy expansion. Odds are that Apple will some day use newer CPUs than i686
56a9c0db7c18 (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
	switch (hostInfo.cpu_subtype) {
56a9c0db7c18 (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
		case CPU_SUBTYPE_PENTPRO:
56a9c0db7c18 (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
			sprintf(CPU,"i686");
56a9c0db7c18 (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
    66
			break;
56a9c0db7c18 (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
		default:
56a9c0db7c18 (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
			sprintf(CPU,"Unknown Intel");
56a9c0db7c18 (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
    69
	}
56a9c0db7c18 (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
    70
#endif
56a9c0db7c18 (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
    71
56a9c0db7c18 (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
	// get the version of OSX
56a9c0db7c18 (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
	if( Gestalt( gestaltSystemVersion, &sysVersion ) != noErr ) {
56a9c0db7c18 (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,"Undetected");
56a9c0db7c18 (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
	} else {
56a9c0db7c18 (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
56a9c0db7c18 (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
		int		majorHiNib, majorLoNib, minorNib, bugNib;
56a9c0db7c18 (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
    78
56a9c0db7c18 (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
    79
		majorHiNib = (sysVersion & 0x0000F000) >> 12;
56a9c0db7c18 (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
		majorLoNib = (sysVersion & 0x00000F00) >> 8;
56a9c0db7c18 (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
		minorNib = (sysVersion & 0x000000F0) >> 4;
56a9c0db7c18 (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
		bugNib = sysVersion & 0x0000000F;
56a9c0db7c18 (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
    83
56a9c0db7c18 (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
		sprintf(OS, "%d%d.%d.%d", majorHiNib, majorLoNib, minorNib, bugNib);
56a9c0db7c18 (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
	}
56a9c0db7c18 (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
56a9c0db7c18 (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
	// make a list of used newgrf files
56a9c0db7c18 (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
    88
	if (_first_grffile != NULL) {
56a9c0db7c18 (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
    89
		GRFFile *file;
56a9c0db7c18 (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
    90
		newgrf[0] = 0;
56a9c0db7c18 (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
    91
56a9c0db7c18 (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
    92
56a9c0db7c18 (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
    93
		for (file = _first_grffile; file != NULL; file = file->next) {
56a9c0db7c18 (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
    94
			sprintf(newgrf, "%s %s", newgrf, file->filename);
56a9c0db7c18 (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
    95
		}
56a9c0db7c18 (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
	} else {
56a9c0db7c18 (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
		sprintf(newgrf, "none");
56a9c0db7c18 (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
	}
56a9c0db7c18 (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
	sprintf(buffer, "Please add this info: (tip: copy-paste works)\nCPU: %s, OSX: %s, OpenTTD version: %s\nNewGRF files:%s", CPU, OS, _openttd_revision, newgrf);
56a9c0db7c18 (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
   100
	return buffer;
56a9c0db7c18 (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
   101
}
56a9c0db7c18 (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
   102
2827
12c9eda7edcd (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2741
diff changeset
   103
12c9eda7edcd (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2741
diff changeset
   104
#ifdef WITH_SDL
12c9eda7edcd (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2741
diff changeset
   105
2188
640a0a5f77ea (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
void ShowMacDialog ( const char *title, const char *message, const char *buttonLabel )
640a0a5f77ea (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
{
640a0a5f77ea (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
   108
	NSRunAlertPanel([NSString stringWithCString: title], [NSString stringWithCString: message], [NSString stringWithCString: buttonLabel], nil, nil);
640a0a5f77ea (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
   109
}
640a0a5f77ea (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
   110
2827
12c9eda7edcd (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2741
diff changeset
   111
#elif defined WITH_COCOA
12c9eda7edcd (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2741
diff changeset
   112
12c9eda7edcd (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2741
diff changeset
   113
void CocoaDialog ( const char *title, const char *message, const char *buttonLabel );
12c9eda7edcd (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2741
diff changeset
   114
12c9eda7edcd (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2741
diff changeset
   115
void ShowMacDialog ( const char *title, const char *message, const char *buttonLabel )
12c9eda7edcd (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2741
diff changeset
   116
{
12c9eda7edcd (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2741
diff changeset
   117
	CocoaDialog(title, message, buttonLabel);
12c9eda7edcd (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2741
diff changeset
   118
}
12c9eda7edcd (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2741
diff changeset
   119
12c9eda7edcd (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2741
diff changeset
   120
12c9eda7edcd (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2741
diff changeset
   121
#else
12c9eda7edcd (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2741
diff changeset
   122
12c9eda7edcd (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2741
diff changeset
   123
void ShowMacDialog ( const char *title, const char *message, const char *buttonLabel )
12c9eda7edcd (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2741
diff changeset
   124
{
12c9eda7edcd (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2741
diff changeset
   125
	fprintf(stderr, "%s: %s\n", title, message);
12c9eda7edcd (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2741
diff changeset
   126
}
12c9eda7edcd (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2741
diff changeset
   127
12c9eda7edcd (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2741
diff changeset
   128
#endif
12c9eda7edcd (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2741
diff changeset
   129
2223
b9564d70ec3d (svn r2741) -Feature: [OSX] added a window to display asserts on OSX (Tobin)
bjarni
parents: 2188
diff changeset
   130
void ShowMacAssertDialog ( const char *function, const char *file, const int line, const char *expression )
b9564d70ec3d (svn r2741) -Feature: [OSX] added a window to display asserts on OSX (Tobin)
bjarni
parents: 2188
diff changeset
   131
{
2736
3d6487cbbb69 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents: 2223
diff changeset
   132
	const char *buffer =
3127
56a9c0db7c18 (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
   133
	[[NSString stringWithFormat:@"An assertion has failed and OpenTTD must quit.\n%s in %s (line %d)\n\"%s\"\n\nYou should report this error the OpenTTD developers if you think you found a bug.\n\n%s",
56a9c0db7c18 (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
   134
		function, file, line, expression, GetOSString()] cString];
2223
b9564d70ec3d (svn r2741) -Feature: [OSX] added a window to display asserts on OSX (Tobin)
bjarni
parents: 2188
diff changeset
   135
	NSLog(@"%s", buffer);
3127
56a9c0db7c18 (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
   136
	ToggleFullScreen(0);
2223
b9564d70ec3d (svn r2741) -Feature: [OSX] added a window to display asserts on OSX (Tobin)
bjarni
parents: 2188
diff changeset
   137
	ShowMacDialog( "Assertion Failed", buffer, "Quit" );
2736
3d6487cbbb69 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents: 2223
diff changeset
   138
2223
b9564d70ec3d (svn r2741) -Feature: [OSX] added a window to display asserts on OSX (Tobin)
bjarni
parents: 2188
diff changeset
   139
	// abort so that a debugger has a chance to notice
b9564d70ec3d (svn r2741) -Feature: [OSX] added a window to display asserts on OSX (Tobin)
bjarni
parents: 2188
diff changeset
   140
	abort();
b9564d70ec3d (svn r2741) -Feature: [OSX] added a window to display asserts on OSX (Tobin)
bjarni
parents: 2188
diff changeset
   141
}
3127
56a9c0db7c18 (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
   142
56a9c0db7c18 (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
   143
56a9c0db7c18 (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
   144
void ShowMacErrorDialog(const char *error)
56a9c0db7c18 (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
   145
{
56a9c0db7c18 (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
	const char *buffer =
56a9c0db7c18 (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
	[[NSString stringWithFormat:@"Please update to the newest version of OpenTTD\nIf the problem presists, please report this to\nhttp://bugs.openttd.org\n\n%s", GetOSString()] cString];
56a9c0db7c18 (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
	ToggleFullScreen(0);
56a9c0db7c18 (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
	ShowMacDialog(error, buffer, "Quit" );
56a9c0db7c18 (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
	abort();
56a9c0db7c18 (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
   151
}