Loading...
Searching...
No Matches
ml::Paths Class Reference

Where an installed app finds its assets and keeps its user data. More...

#include <Malena/Utilities/Paths.h>

Static Public Member Functions

static const std::string & executablePath ()
static std::string join (const std::string &a, const std::string &b)
static const std::string & resourceDir ()
static std::string userDataDir (const std::string &appName)

Detailed Description

Where an installed app finds its assets and keeps its user data.

A development build runs from its build directory, so relative paths like "assets/logo.png" resolve against the current working directory and everything works. An installed app has neither property:

  • Launched from Finder, a macOS .app has a working directory of "/" — every CWD-relative asset path misses.
  • Writing next to the executable fails once the app lives in /Applications or C:\Program Files, which are not user-writable.

These two helpers give the app an install-safe answer on every platform. Use resourceDir() for read-only files that ship with the app (assets, bundled content) and userDataDir() for anything the app writes (config, save data, flags). Both return paths WITHOUT a trailing separator.

Definition at line 30 of file Paths.h.

Member Function Documentation

◆ executablePath()

const std::string & ml::Paths::executablePath ( )
static

Absolute path to the running executable ("" if undeterminable).

◆ join()

std::string ml::Paths::join ( const std::string & a,
const std::string & b )
static

Join two path segments with the platform separator.

◆ resourceDir()

const std::string & ml::Paths::resourceDir ( )
static

Absolute path to the directory holding the running executable, except on macOS inside a .app bundle, where it's the bundle's Contents/Resources — the conventional location for bundled assets.

Returns "." if the executable path can't be determined, which preserves the CWD-relative behaviour a dev build already relies on.

◆ userDataDir()

std::string ml::Paths::userDataDir ( const std::string & appName)
static

Absolute path to a per-user, writable directory for this app, created on first call: macOS: ~/Library/Application Support/{appName} Windows: %APPDATA%%\{appName} Linux: $XDG_CONFIG_HOME/{appName}, else ~/.config/{appName}

Falls back to "." if neither the home directory nor the platform variable is available, and if the directory can't be created.

Parameters
appNameFolder name to use — the application's name.

The documentation for this class was generated from the following file: