Files
gronod 6aaf73d70c
Build macOS app / Build DOOM.app (push) Canceled after 0s
macOS port: add app build workflow
2026-09-18 20:01:16 +01:00

87 lines
1.6 KiB
C

// Emacs style mode select -*- C -*-
//-----------------------------------------------------------------------------
//
// $Id:$
//
// DESCRIPTION:
// macOS-specific system helpers: app-bundle detection and
// user-writable data directory lookup.
//
//-----------------------------------------------------------------------------
static const char
rcsid[] = "$Id:$";
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <CoreFoundation/CoreFoundation.h>
// stdbool.h (pulled in by CoreFoundation) defines false/true as macros,
// which clashes with doomtype's enum boolean if a doom header ever
// follows this include.
#undef false
#undef true
#include "i_mac.h"
int I_IsBundled (void)
{
CFBundleRef bundle = CFBundleGetMainBundle ();
if (!bundle)
return 0;
return CFBundleGetIdentifier (bundle) != NULL;
}
void I_GetBundleResourcesDir (char *out, size_t len)
{
CFURLRef url;
if (!len)
return;
out[0] = '\0';
if (!I_IsBundled ())
return;
url = CFBundleCopyResourcesDirectoryURL (CFBundleGetMainBundle ());
if (!url)
return;
CFURLGetFileSystemRepresentation (url, 1, (UInt8*)out, (CFIndex)len);
CFRelease (url);
}
void I_GetAppSupportDir (char *out, size_t len)
{
const char *home;
if (!len)
return;
out[0] = '\0';
home = getenv ("HOME");
if (!home)
return;
snprintf (out, len, "%s/Library/Application Support/DOOM", home);
mkdir (out, 0755);
}
void I_PrepareAppEnvironment (void)
{
char dir[1024];
if (!I_IsBundled ())
return;
I_GetAppSupportDir (dir, sizeof (dir));
if (dir[0])
chdir (dir);
}