Get the right path for "content" folder for XMLs on Mac OS X

Hi there, i got a problem on my multiplatforms project.
I need to load XML files that define my spritesheets, so i load the actual sheets like:

_content.Load(@“Sprites/sheet01”);

but i load XML as XDocument like this:

XDocument XMLinput = XDocument.Load(_content.RootDirectory + “/” + _sheetName + “.xml”);

on win & linux it’s ok. but on mac osx the game searches for content folder in the “resources” folder, except for xmls, it searches the content folder in the “macOS” folder… ?!?

If Content.RootDirectory doesn’t return the right path, how can i get the right one ON EVERY PLATFORMS?

Thanks :slight_smile:

Hi,

If you bundle your Mac build in an .app bundle with MonoKickstart, the location of your “Content” folder needs some path hacking (because it is expected to be in “macOS/resources”, and standard file I/O will try to load from the executing directory). For this purpose, you should open files as much as possible with TitleContainer, which will resolve the correct content path for you, no matter the target system (e.g. TitleContainer.OpenStream(_content.RootDirectory + "/" + _sheetName + ".xml");).

In case you can’t use TitleContainer, you can use a hack like this:

private static string _trackPath = "Content/Musics/";

...

if (!File.Exists(_trackPath + "track01.xnb")) // MacOS hack if content can't be found
{
      _trackPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..", "Resources", _trackPath);
}   

But as a rule of thumb, always use TitleContainer for non-content file I/O.

Thanks a lot!
It seems to be what i was looking for, i’ll give it a try later tonight!

Many thanks,
Greg.