ValleyBell / vgmplay-libvgm

a new VGMPlay, based on libvgm
74 stars 10 forks source link

Load ini from OS-preferred config paths #9

Open OPNA2608 opened 2 years ago

OPNA2608 commented 2 years ago

macOS: ~/Library/Application Support/vgmplay/VGMPlay.ini (or what the other unixoids are doing)

Other Unixoids (i.e. Linux, BSDs): $XDG_CONFIG_HOME/vgmplay/VGMPlay.ini

ValleyBell commented 2 years ago

The current search paths (as defined in main.cpp: InitAppSearchPaths) are, starting with lowest priority:

  1. [Unix only] /usr/share/vgmplay/
  2. path of the executable (resolved symlink)
  3. called executable path (from argv[0])
  4. user configuration directory
    • [Windows]: $HOME/.vgmplay/
    • [Unix with XDG path]: $XDG_CONFIG_HOME/vgmplay/
    • [Unix without XDG path]: $HOME/.config/vgmplay/
  5. working directory (./)

For each path, it checks for VGMPlay.ini and vgmplay.ini. (The lowercase file name takes priority.)


How would I obtain the "Application Support" path on MacOS?

I also recently realized that on Unix I should check /etc/vgmplay/ as well.

OPNA2608 commented 2 years ago

(I opened this with not much testing or sleep, sorry)

  1. [Unix only] /usr/share/vgmplay/

I think this should use CMake GNUInstallDirs' CMAKE_INSTALL_FULL_DATADIR to JustWork:tm: without having to manually set SHARE_PREFIX on weirder installations. I wasn't aware this was a thing without taking a look at the code because my system doesn't use that path. Also, an install() rule for the ini file would nicely complete this.

No complaints with the rest of the list you outlined.


The most modern way I've found for obtaining the Application Support path so far is by using NSSearchPathForDirectoriesInDomains in ObjC and interfacing with it from normal C/C++:

dir.h

const char* getApplicationSupportPath();

dir.m

#include <Foundation/NSPathUtilities.h>
#include "dir.h"

const char* getApplicationSupportPath() {
  NSArray *paths = NSSearchPathForDirectoriesInDomains (NSApplicationSupportDirectory, NSUserDomainMask, YES);
  return [[paths objectAtIndex:0] UTF8String];
}

This requires some small APPLE-specific additions to the CMake script aside from conditionally compiling those new files, namely enabling OBJC support and finding & linking against the Foundation framework:

enable_language(OBJC)
find_library(FOUNDATION Foundation REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE ${FOUNDATION})

There are other, pure C APIs for getting that path like sysdir_start_search_path_enumeration (available since macOS 10.12) or NSStartSearchPathEnumeration (dunno when introduced, works as far back as 10.3, deprecated by the former) if you'd rather not touch ObjC, though I haven't tested them. Or you could always just hardcode that path, though iunno if there are any scenarios where this might cause problems.

ValleyBell commented 2 years ago

The SHARE_PREFIX thing is a leftover from the old VGMPlay that I somehow completely missed. I'll make sure to improve the installation using proper CMake stuff.

I think I'll use the hardcoded path solution for macOS based on furnace, because I have no way to test it by myself.