/* bzflag
 * Copyright (c) 1993 - 2008 Tim Riker
 *
 * This package is free software;  you can redistribute it and/or
 * modify it under the terms of the license found in the file
 * named LICENSE that should have accompanied this file.
 *
 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 */

#include <Carbon/Carbon.h>

// if -directory is not used, this function is used to get the default path
// to the data directory which is located in the same directory as the
// application bundle
char *GetMacOSXDataPath(void)
{
  ::CFBundleRef	appBundle		= NULL;
  ::CFURLRef	resourceURL		= NULL;
  char *		string			= NULL;
  static char	basePath[2048]	= "<undefined resource path>";

  if ((appBundle = ::CFBundleGetMainBundle()) == NULL
      || (resourceURL = ::CFBundleCopyResourcesDirectoryURL(appBundle)) == NULL) {
    return NULL;
  }
  if(!::CFURLGetFileSystemRepresentation(resourceURL,
					 true, reinterpret_cast<UInt8 *>(basePath), sizeof(basePath))) {
    string = NULL;
  } else {
    string = basePath;
  }
  ::CFRelease(resourceURL);
  fprintf(stderr, "data path is \"%s\"\n", string);
  return string;
}

// Local Variables: ***
// mode:C++ ***
// tab-width: 8 ***
// c-basic-offset: 2 ***
// indent-tabs-mode: t ***
// End: ***
// ex: shiftwidth=2 tabstop=8
